Merge pull request #12649 from electron/clang-format-brightray
clang-format brightray
This commit is contained in:
commit
c090dd2f81
61 changed files with 1547 additions and 1684 deletions
|
@ -21,8 +21,8 @@ enum {
|
||||||
PATH_START = 11000,
|
PATH_START = 11000,
|
||||||
|
|
||||||
DIR_USER_DATA = PATH_START, // Directory where user data can be written.
|
DIR_USER_DATA = PATH_START, // Directory where user data can be written.
|
||||||
DIR_USER_CACHE, // Directory where user cache can be written.
|
DIR_USER_CACHE, // Directory where user cache can be written.
|
||||||
DIR_APP_LOGS, // Directory where app logs live
|
DIR_APP_LOGS, // Directory where app logs live
|
||||||
|
|
||||||
#if defined(OS_LINUX)
|
#if defined(OS_LINUX)
|
||||||
DIR_APP_DATA, // Application Data directory under the user profile.
|
DIR_APP_DATA, // Application Data directory under the user profile.
|
||||||
|
|
|
@ -51,14 +51,12 @@ BrowserClient* BrowserClient::Get() {
|
||||||
return g_browser_client;
|
return g_browser_client;
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserClient::BrowserClient()
|
BrowserClient::BrowserClient() : browser_main_parts_(nullptr) {
|
||||||
: browser_main_parts_(nullptr) {
|
|
||||||
DCHECK(!g_browser_client);
|
DCHECK(!g_browser_client);
|
||||||
g_browser_client = this;
|
g_browser_client = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowserClient::~BrowserClient() {
|
BrowserClient::~BrowserClient() {}
|
||||||
}
|
|
||||||
|
|
||||||
NotificationPresenter* BrowserClient::GetNotificationPresenter() {
|
NotificationPresenter* BrowserClient::GetNotificationPresenter() {
|
||||||
if (!notification_presenter_) {
|
if (!notification_presenter_) {
|
||||||
|
|
|
@ -61,8 +61,8 @@ class BrowserContext::ResourceContext : public content::ResourceContext {
|
||||||
BrowserContext::BrowserContextMap BrowserContext::browser_context_map_;
|
BrowserContext::BrowserContextMap BrowserContext::browser_context_map_;
|
||||||
|
|
||||||
// static
|
// static
|
||||||
scoped_refptr<BrowserContext> BrowserContext::Get(
|
scoped_refptr<BrowserContext> BrowserContext::Get(const std::string& partition,
|
||||||
const std::string& partition, bool in_memory) {
|
bool in_memory) {
|
||||||
PartitionKey key(partition, in_memory);
|
PartitionKey key(partition, in_memory);
|
||||||
if (browser_context_map_[key].get())
|
if (browser_context_map_[key].get())
|
||||||
return WrapRefCounted(browser_context_map_[key].get());
|
return WrapRefCounted(browser_context_map_[key].get());
|
||||||
|
@ -137,13 +137,9 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext(
|
||||||
content::URLRequestInterceptorScopedVector protocol_interceptors) {
|
content::URLRequestInterceptorScopedVector protocol_interceptors) {
|
||||||
DCHECK(!url_request_getter_.get());
|
DCHECK(!url_request_getter_.get());
|
||||||
url_request_getter_ = new URLRequestContextGetter(
|
url_request_getter_ = new URLRequestContextGetter(
|
||||||
this,
|
this, static_cast<NetLog*>(BrowserClient::Get()->GetNetLog()), GetPath(),
|
||||||
static_cast<NetLog*>(BrowserClient::Get()->GetNetLog()),
|
in_memory_, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
|
||||||
GetPath(),
|
protocol_handlers, std::move(protocol_interceptors));
|
||||||
in_memory_,
|
|
||||||
BrowserThread::GetTaskRunnerForThread(BrowserThread::IO),
|
|
||||||
protocol_handlers,
|
|
||||||
std::move(protocol_interceptors));
|
|
||||||
resource_context_->set_url_request_context_getter(url_request_getter_.get());
|
resource_context_->set_url_request_context_getter(url_request_getter_.get());
|
||||||
return url_request_getter_.get();
|
return url_request_getter_.get();
|
||||||
}
|
}
|
||||||
|
@ -204,8 +200,7 @@ content::PermissionManager* BrowserContext::GetPermissionManager() {
|
||||||
return permission_manager_.get();
|
return permission_manager_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
content::BackgroundFetchDelegate*
|
content::BackgroundFetchDelegate* BrowserContext::GetBackgroundFetchDelegate() {
|
||||||
BrowserContext::GetBackgroundFetchDelegate() {
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,8 +223,7 @@ BrowserContext::CreateRequestContextForStoragePartition(
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
net::URLRequestContextGetter*
|
net::URLRequestContextGetter* BrowserContext::CreateMediaRequestContext() {
|
||||||
BrowserContext::CreateMediaRequestContext() {
|
|
||||||
return url_request_getter_.get();
|
return url_request_getter_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,8 @@ class BrowserContext : public base::RefCounted<BrowserContext>,
|
||||||
public:
|
public:
|
||||||
// Get the BrowserContext according to its |partition| and |in_memory|,
|
// Get the BrowserContext according to its |partition| and |in_memory|,
|
||||||
// empty pointer when be returned when there is no matching BrowserContext.
|
// empty pointer when be returned when there is no matching BrowserContext.
|
||||||
static scoped_refptr<BrowserContext> Get(
|
static scoped_refptr<BrowserContext> Get(const std::string& partition,
|
||||||
const std::string& partition, bool in_memory);
|
bool in_memory);
|
||||||
|
|
||||||
base::WeakPtr<BrowserContext> GetWeakPtr() {
|
base::WeakPtr<BrowserContext> GetWeakPtr() {
|
||||||
return weak_factory_.GetWeakPtr();
|
return weak_factory_.GetWeakPtr();
|
||||||
|
|
|
@ -98,8 +98,7 @@ void OverrideLinuxAppDataPath() {
|
||||||
if (PathService::Get(DIR_APP_DATA, &path))
|
if (PathService::Get(DIR_APP_DATA, &path))
|
||||||
return;
|
return;
|
||||||
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
std::unique_ptr<base::Environment> env(base::Environment::Create());
|
||||||
path = base::nix::GetXDGDirectory(env.get(),
|
path = base::nix::GetXDGDirectory(env.get(), base::nix::kXdgConfigHomeEnvVar,
|
||||||
base::nix::kXdgConfigHomeEnvVar,
|
|
||||||
base::nix::kDotConfigDir);
|
base::nix::kDotConfigDir);
|
||||||
PathService::Override(DIR_APP_DATA, path);
|
PathService::Override(DIR_APP_DATA, path);
|
||||||
}
|
}
|
||||||
|
@ -167,11 +166,9 @@ base::string16 MediaStringProvider(media::MessageId id) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
BrowserMainParts::BrowserMainParts() {
|
BrowserMainParts::BrowserMainParts() {}
|
||||||
}
|
|
||||||
|
|
||||||
BrowserMainParts::~BrowserMainParts() {
|
BrowserMainParts::~BrowserMainParts() {}
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(OS_WIN) || defined(OS_LINUX)
|
#if defined(OS_WIN) || defined(OS_LINUX)
|
||||||
void OverrideAppLogsPath() {
|
void OverrideAppLogsPath() {
|
||||||
|
@ -220,7 +217,7 @@ void BrowserMainParts::ToolkitInitialized() {
|
||||||
gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont;
|
gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont;
|
||||||
gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize;
|
gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize;
|
||||||
|
|
||||||
wchar_t module_name[MAX_PATH] = { 0 };
|
wchar_t module_name[MAX_PATH] = {0};
|
||||||
if (GetModuleFileName(NULL, module_name, MAX_PATH))
|
if (GetModuleFileName(NULL, module_name, MAX_PATH))
|
||||||
ui::CursorLoaderWin::SetCursorResourceModule(module_name);
|
ui::CursorLoaderWin::SetCursorResourceModule(module_name);
|
||||||
#endif
|
#endif
|
||||||
|
@ -304,7 +301,7 @@ int BrowserMainParts::PreCreateThreads() {
|
||||||
|
|
||||||
// Initialize the app locale.
|
// Initialize the app locale.
|
||||||
BrowserClient::SetApplicationLocale(
|
BrowserClient::SetApplicationLocale(
|
||||||
l10n_util::GetApplicationLocale(custom_locale_));
|
l10n_util::GetApplicationLocale(custom_locale_));
|
||||||
|
|
||||||
// Manage global state of net and other IO thread related.
|
// Manage global state of net and other IO thread related.
|
||||||
io_thread_ = std::make_unique<IOThread>();
|
io_thread_ = std::make_unique<IOThread>();
|
||||||
|
|
|
@ -7,15 +7,13 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy()
|
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy()
|
||||||
: hide_inspected_contents_(false) {
|
: hide_inspected_contents_(false) {}
|
||||||
}
|
|
||||||
|
|
||||||
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
|
DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy(
|
||||||
const gfx::Rect& bounds)
|
const gfx::Rect& bounds)
|
||||||
: bounds_(bounds),
|
: bounds_(bounds),
|
||||||
hide_inspected_contents_(bounds_.IsEmpty() && !bounds_.x() &&
|
hide_inspected_contents_(bounds_.IsEmpty() && !bounds_.x() &&
|
||||||
!bounds_.y()) {
|
!bounds_.y()) {}
|
||||||
}
|
|
||||||
|
|
||||||
void DevToolsContentsResizingStrategy::CopyFrom(
|
void DevToolsContentsResizingStrategy::CopyFrom(
|
||||||
const DevToolsContentsResizingStrategy& strategy) {
|
const DevToolsContentsResizingStrategy& strategy) {
|
||||||
|
@ -26,7 +24,7 @@ void DevToolsContentsResizingStrategy::CopyFrom(
|
||||||
bool DevToolsContentsResizingStrategy::Equals(
|
bool DevToolsContentsResizingStrategy::Equals(
|
||||||
const DevToolsContentsResizingStrategy& strategy) {
|
const DevToolsContentsResizingStrategy& strategy) {
|
||||||
return bounds_ == strategy.bounds() &&
|
return bounds_ == strategy.bounds() &&
|
||||||
hide_inspected_contents_ == strategy.hide_inspected_contents();
|
hide_inspected_contents_ == strategy.hide_inspected_contents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyDevToolsContentsResizingStrategy(
|
void ApplyDevToolsContentsResizingStrategy(
|
||||||
|
@ -34,13 +32,13 @@ void ApplyDevToolsContentsResizingStrategy(
|
||||||
const gfx::Size& container_size,
|
const gfx::Size& container_size,
|
||||||
gfx::Rect* new_devtools_bounds,
|
gfx::Rect* new_devtools_bounds,
|
||||||
gfx::Rect* new_contents_bounds) {
|
gfx::Rect* new_contents_bounds) {
|
||||||
new_devtools_bounds->SetRect(
|
new_devtools_bounds->SetRect(0, 0, container_size.width(),
|
||||||
0, 0, container_size.width(), container_size.height());
|
container_size.height());
|
||||||
|
|
||||||
const gfx::Rect& bounds = strategy.bounds();
|
const gfx::Rect& bounds = strategy.bounds();
|
||||||
if (bounds.size().IsEmpty() && !strategy.hide_inspected_contents()) {
|
if (bounds.size().IsEmpty() && !strategy.hide_inspected_contents()) {
|
||||||
new_contents_bounds->SetRect(
|
new_contents_bounds->SetRect(0, 0, container_size.width(),
|
||||||
0, 0, container_size.width(), container_size.height());
|
container_size.height());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,7 @@
|
||||||
class DevToolsContentsResizingStrategy {
|
class DevToolsContentsResizingStrategy {
|
||||||
public:
|
public:
|
||||||
DevToolsContentsResizingStrategy();
|
DevToolsContentsResizingStrategy();
|
||||||
explicit DevToolsContentsResizingStrategy(
|
explicit DevToolsContentsResizingStrategy(const gfx::Rect& bounds);
|
||||||
const gfx::Rect& bounds);
|
|
||||||
|
|
||||||
void CopyFrom(const DevToolsContentsResizingStrategy& strategy);
|
void CopyFrom(const DevToolsContentsResizingStrategy& strategy);
|
||||||
bool Equals(const DevToolsContentsResizingStrategy& strategy);
|
bool Equals(const DevToolsContentsResizingStrategy& strategy);
|
||||||
|
|
|
@ -33,8 +33,7 @@ bool GetValue(const base::Value& value, gfx::Rect* rect) {
|
||||||
int y = 0;
|
int y = 0;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
if (!dict->GetInteger("x", &x) ||
|
if (!dict->GetInteger("x", &x) || !dict->GetInteger("y", &y) ||
|
||||||
!dict->GetInteger("y", &y) ||
|
|
||||||
!dict->GetInteger("width", &width) ||
|
!dict->GetInteger("width", &width) ||
|
||||||
!dict->GetInteger("height", &height))
|
!dict->GetInteger("height", &height))
|
||||||
return false;
|
return false;
|
||||||
|
@ -69,8 +68,7 @@ template <typename T, typename... Ts>
|
||||||
struct ParamTuple<T, Ts...> {
|
struct ParamTuple<T, Ts...> {
|
||||||
bool Parse(const base::ListValue& list,
|
bool Parse(const base::ListValue& list,
|
||||||
const base::ListValue::const_iterator& it) {
|
const base::ListValue::const_iterator& it) {
|
||||||
return it != list.end() && GetValue(*it, &head) &&
|
return it != list.end() && GetValue(*it, &head) && tail.Parse(list, it + 1);
|
||||||
tail.Parse(list, it + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename H, typename... As>
|
template <typename H, typename... As>
|
||||||
|
@ -82,7 +80,7 @@ struct ParamTuple<T, Ts...> {
|
||||||
ParamTuple<Ts...> tail;
|
ParamTuple<Ts...> tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename... As>
|
template <typename... As>
|
||||||
bool ParseAndHandle(const base::Callback<void(As...)>& handler,
|
bool ParseAndHandle(const base::Callback<void(As...)>& handler,
|
||||||
const DispatchCallback& callback,
|
const DispatchCallback& callback,
|
||||||
const base::ListValue& list) {
|
const base::ListValue& list) {
|
||||||
|
@ -93,7 +91,7 @@ bool ParseAndHandle(const base::Callback<void(As...)>& handler,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... As>
|
template <typename... As>
|
||||||
bool ParseAndHandleWithCallback(
|
bool ParseAndHandleWithCallback(
|
||||||
const base::Callback<void(const DispatchCallback&, As...)>& handler,
|
const base::Callback<void(const DispatchCallback&, As...)>& handler,
|
||||||
const DispatchCallback& callback,
|
const DispatchCallback& callback,
|
||||||
|
@ -126,28 +124,28 @@ class DispatcherImpl : public DevToolsEmbedderMessageDispatcher {
|
||||||
return it != handlers_.end() && it->second.Run(callback, *params);
|
return it != handlers_.end() && it->second.Run(callback, *params);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... As>
|
template <typename... As>
|
||||||
void RegisterHandler(const std::string& method,
|
void RegisterHandler(const std::string& method,
|
||||||
void (Delegate::*handler)(As...),
|
void (Delegate::*handler)(As...),
|
||||||
Delegate* delegate) {
|
Delegate* delegate) {
|
||||||
handlers_[method] = base::Bind(&ParseAndHandle<As...>,
|
handlers_[method] =
|
||||||
base::Bind(handler,
|
base::Bind(&ParseAndHandle<As...>,
|
||||||
base::Unretained(delegate)));
|
base::Bind(handler, base::Unretained(delegate)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... As>
|
template <typename... As>
|
||||||
void RegisterHandlerWithCallback(
|
void RegisterHandlerWithCallback(
|
||||||
const std::string& method,
|
const std::string& method,
|
||||||
void (Delegate::*handler)(const DispatchCallback&, As...),
|
void (Delegate::*handler)(const DispatchCallback&, As...),
|
||||||
Delegate* delegate) {
|
Delegate* delegate) {
|
||||||
handlers_[method] = base::Bind(&ParseAndHandleWithCallback<As...>,
|
handlers_[method] =
|
||||||
base::Bind(handler,
|
base::Bind(&ParseAndHandleWithCallback<As...>,
|
||||||
base::Unretained(delegate)));
|
base::Bind(handler, base::Unretained(delegate)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Handler = base::Callback<bool(const DispatchCallback&,
|
using Handler =
|
||||||
const base::ListValue&)>;
|
base::Callback<bool(const DispatchCallback&, const base::ListValue&)>;
|
||||||
using HandlerMap = std::map<std::string, Handler>;
|
using HandlerMap = std::map<std::string, Handler>;
|
||||||
HandlerMap handlers_;
|
HandlerMap handlers_;
|
||||||
};
|
};
|
||||||
|
@ -165,15 +163,15 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(
|
||||||
&Delegate::SetInspectedPageBounds, delegate);
|
&Delegate::SetInspectedPageBounds, delegate);
|
||||||
d->RegisterHandler("inspectElementCompleted",
|
d->RegisterHandler("inspectElementCompleted",
|
||||||
&Delegate::InspectElementCompleted, delegate);
|
&Delegate::InspectElementCompleted, delegate);
|
||||||
d->RegisterHandler("inspectedURLChanged",
|
d->RegisterHandler("inspectedURLChanged", &Delegate::InspectedURLChanged,
|
||||||
&Delegate::InspectedURLChanged, delegate);
|
delegate);
|
||||||
d->RegisterHandlerWithCallback("setIsDocked",
|
d->RegisterHandlerWithCallback("setIsDocked", &Delegate::SetIsDocked,
|
||||||
&Delegate::SetIsDocked, delegate);
|
delegate);
|
||||||
d->RegisterHandler("openInNewTab", &Delegate::OpenInNewTab, delegate);
|
d->RegisterHandler("openInNewTab", &Delegate::OpenInNewTab, delegate);
|
||||||
d->RegisterHandler("save", &Delegate::SaveToFile, delegate);
|
d->RegisterHandler("save", &Delegate::SaveToFile, delegate);
|
||||||
d->RegisterHandler("append", &Delegate::AppendToFile, delegate);
|
d->RegisterHandler("append", &Delegate::AppendToFile, delegate);
|
||||||
d->RegisterHandler("requestFileSystems",
|
d->RegisterHandler("requestFileSystems", &Delegate::RequestFileSystems,
|
||||||
&Delegate::RequestFileSystems, delegate);
|
delegate);
|
||||||
d->RegisterHandler("addFileSystem", &Delegate::AddFileSystem, delegate);
|
d->RegisterHandler("addFileSystem", &Delegate::AddFileSystem, delegate);
|
||||||
d->RegisterHandler("removeFileSystem", &Delegate::RemoveFileSystem, delegate);
|
d->RegisterHandler("removeFileSystem", &Delegate::RemoveFileSystem, delegate);
|
||||||
d->RegisterHandler("upgradeDraggedFileSystemPermissions",
|
d->RegisterHandler("upgradeDraggedFileSystemPermissions",
|
||||||
|
@ -193,10 +191,10 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(
|
||||||
d->RegisterHandler("dispatchProtocolMessage",
|
d->RegisterHandler("dispatchProtocolMessage",
|
||||||
&Delegate::DispatchProtocolMessageFromDevToolsFrontend,
|
&Delegate::DispatchProtocolMessageFromDevToolsFrontend,
|
||||||
delegate);
|
delegate);
|
||||||
d->RegisterHandlerWithCallback("sendJsonRequest",
|
d->RegisterHandlerWithCallback("sendJsonRequest", &Delegate::SendJsonRequest,
|
||||||
&Delegate::SendJsonRequest, delegate);
|
delegate);
|
||||||
d->RegisterHandlerWithCallback("getPreferences",
|
d->RegisterHandlerWithCallback("getPreferences", &Delegate::GetPreferences,
|
||||||
&Delegate::GetPreferences, delegate);
|
delegate);
|
||||||
d->RegisterHandler("setPreference", &Delegate::SetPreference, delegate);
|
d->RegisterHandler("setPreference", &Delegate::SetPreference, delegate);
|
||||||
d->RegisterHandler("removePreference", &Delegate::RemovePreference, delegate);
|
d->RegisterHandler("removePreference", &Delegate::RemovePreference, delegate);
|
||||||
d->RegisterHandler("clearPreferences", &Delegate::ClearPreferences, delegate);
|
d->RegisterHandler("clearPreferences", &Delegate::ClearPreferences, delegate);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
namespace base {
|
namespace base {
|
||||||
class ListValue;
|
class ListValue;
|
||||||
class Value;
|
class Value;
|
||||||
}
|
} // namespace base
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ class Index {
|
||||||
FileIdsMap file_ids_;
|
FileIdsMap file_ids_;
|
||||||
FileId last_file_id_;
|
FileId last_file_id_;
|
||||||
// The index in this vector is the trigram id.
|
// The index in this vector is the trigram id.
|
||||||
vector<vector<FileId> > index_;
|
vector<vector<FileId>> index_;
|
||||||
typedef map<FilePath, Time> IndexedFilesMap;
|
typedef map<FilePath, Time> IndexedFilesMap;
|
||||||
IndexedFilesMap index_times_;
|
IndexedFilesMap index_times_;
|
||||||
vector<bool> is_normalized_;
|
vector<bool> is_normalized_;
|
||||||
|
@ -175,10 +175,10 @@ vector<FilePath> Index::Search(string query) {
|
||||||
vector<TrigramChar> trigram_chars;
|
vector<TrigramChar> trigram_chars;
|
||||||
trigram_chars.reserve(query.size());
|
trigram_chars.reserve(query.size());
|
||||||
for (size_t i = 0; i < query.size(); ++i) {
|
for (size_t i = 0; i < query.size(); ++i) {
|
||||||
TrigramChar trigram_char = TrigramCharForChar(data[i]);
|
TrigramChar trigram_char = TrigramCharForChar(data[i]);
|
||||||
if (trigram_char == kBinaryTrigramChar)
|
if (trigram_char == kBinaryTrigramChar)
|
||||||
trigram_char = kUndefinedTrigramChar;
|
trigram_char = kUndefinedTrigramChar;
|
||||||
trigram_chars.push_back(trigram_char);
|
trigram_chars.push_back(trigram_char);
|
||||||
}
|
}
|
||||||
vector<Trigram> trigrams;
|
vector<Trigram> trigrams;
|
||||||
for (size_t i = 0; i + 2 < query.size(); ++i) {
|
for (size_t i = 0; i + 2 < query.size(); ++i) {
|
||||||
|
@ -192,21 +192,19 @@ vector<FilePath> Index::Search(string query) {
|
||||||
for (; it != trigrams.end(); ++it) {
|
for (; it != trigrams.end(); ++it) {
|
||||||
Trigram trigram = *it;
|
Trigram trigram = *it;
|
||||||
if (first) {
|
if (first) {
|
||||||
std::copy(index_[trigram].begin(),
|
std::copy(index_[trigram].begin(), index_[trigram].end(),
|
||||||
index_[trigram].end(),
|
|
||||||
std::inserter(file_ids, file_ids.begin()));
|
std::inserter(file_ids, file_ids.begin()));
|
||||||
first = false;
|
first = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
set<FileId> intersection = base::STLSetIntersection<set<FileId> >(
|
set<FileId> intersection =
|
||||||
file_ids, index_[trigram]);
|
base::STLSetIntersection<set<FileId>>(file_ids, index_[trigram]);
|
||||||
file_ids.swap(intersection);
|
file_ids.swap(intersection);
|
||||||
}
|
}
|
||||||
vector<FilePath> result;
|
vector<FilePath> result;
|
||||||
FileIdsMap::const_iterator ids_it = file_ids_.begin();
|
FileIdsMap::const_iterator ids_it = file_ids_.begin();
|
||||||
for (; ids_it != file_ids_.end(); ++ids_it) {
|
for (; ids_it != file_ids_.end(); ++ids_it) {
|
||||||
if (trigrams.empty() ||
|
if (trigrams.empty() || file_ids.find(ids_it->second) != file_ids.end()) {
|
||||||
file_ids.find(ids_it->second) != file_ids.end()) {
|
|
||||||
result.push_back(ids_it->first);
|
result.push_back(ids_it->first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,15 +278,13 @@ DevToolsFileSystemIndexer::FileSystemIndexingJob::~FileSystemIndexingJob() {}
|
||||||
void DevToolsFileSystemIndexer::FileSystemIndexingJob::Start() {
|
void DevToolsFileSystemIndexer::FileSystemIndexingJob::Start() {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
BrowserThread::PostTask(
|
BrowserThread::PostTask(
|
||||||
BrowserThread::FILE,
|
BrowserThread::FILE, FROM_HERE,
|
||||||
FROM_HERE,
|
|
||||||
Bind(&FileSystemIndexingJob::CollectFilesToIndex, this));
|
Bind(&FileSystemIndexingJob::CollectFilesToIndex, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevToolsFileSystemIndexer::FileSystemIndexingJob::Stop() {
|
void DevToolsFileSystemIndexer::FileSystemIndexingJob::Stop() {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
BrowserThread::PostTask(BrowserThread::FILE,
|
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
|
||||||
FROM_HERE,
|
|
||||||
Bind(&FileSystemIndexingJob::StopOnFileThread, this));
|
Bind(&FileSystemIndexingJob::StopOnFileThread, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,8 +303,7 @@ void DevToolsFileSystemIndexer::FileSystemIndexingJob::CollectFilesToIndex() {
|
||||||
FilePath file_path = file_enumerator_->Next();
|
FilePath file_path = file_enumerator_->Next();
|
||||||
if (file_path.empty()) {
|
if (file_path.empty()) {
|
||||||
BrowserThread::PostTask(
|
BrowserThread::PostTask(
|
||||||
BrowserThread::UI,
|
BrowserThread::UI, FROM_HERE,
|
||||||
FROM_HERE,
|
|
||||||
Bind(total_work_callback_, file_path_times_.size()));
|
Bind(total_work_callback_, file_path_times_.size()));
|
||||||
indexing_it_ = file_path_times_.begin();
|
indexing_it_ = file_path_times_.begin();
|
||||||
IndexFiles();
|
IndexFiles();
|
||||||
|
@ -322,8 +317,7 @@ void DevToolsFileSystemIndexer::FileSystemIndexingJob::CollectFilesToIndex() {
|
||||||
file_path_times_[file_path] = current_last_modified_time;
|
file_path_times_[file_path] = current_last_modified_time;
|
||||||
}
|
}
|
||||||
BrowserThread::PostTask(
|
BrowserThread::PostTask(
|
||||||
BrowserThread::FILE,
|
BrowserThread::FILE, FROM_HERE,
|
||||||
FROM_HERE,
|
|
||||||
Bind(&FileSystemIndexingJob::CollectFilesToIndex, this));
|
Bind(&FileSystemIndexingJob::CollectFilesToIndex, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,9 +332,8 @@ void DevToolsFileSystemIndexer::FileSystemIndexingJob::IndexFiles() {
|
||||||
}
|
}
|
||||||
FilePath file_path = indexing_it_->first;
|
FilePath file_path = indexing_it_->first;
|
||||||
current_file_.CreateOrOpen(
|
current_file_.CreateOrOpen(
|
||||||
file_path,
|
file_path, base::File::FLAG_OPEN | base::File::FLAG_READ,
|
||||||
base::File::FLAG_OPEN | base::File::FLAG_READ,
|
Bind(&FileSystemIndexingJob::StartFileIndexing, this));
|
||||||
Bind(&FileSystemIndexingJob::StartFileIndexing, this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevToolsFileSystemIndexer::FileSystemIndexingJob::StartFileIndexing(
|
void DevToolsFileSystemIndexer::FileSystemIndexingJob::StartFileIndexing(
|
||||||
|
@ -408,8 +401,8 @@ void DevToolsFileSystemIndexer::FileSystemIndexingJob::FinishFileIndexing(
|
||||||
CloseFile();
|
CloseFile();
|
||||||
if (success) {
|
if (success) {
|
||||||
FilePath file_path = indexing_it_->first;
|
FilePath file_path = indexing_it_->first;
|
||||||
g_trigram_index.Get().SetTrigramsForFile(
|
g_trigram_index.Get().SetTrigramsForFile(file_path, current_trigrams_,
|
||||||
file_path, current_trigrams_, file_path_times_[file_path]);
|
file_path_times_[file_path]);
|
||||||
}
|
}
|
||||||
ReportWorked();
|
ReportWorked();
|
||||||
++indexing_it_;
|
++indexing_it_;
|
||||||
|
@ -435,14 +428,13 @@ void DevToolsFileSystemIndexer::FileSystemIndexingJob::ReportWorked() {
|
||||||
++files_indexed_;
|
++files_indexed_;
|
||||||
if (should_send_worked_nitification) {
|
if (should_send_worked_nitification) {
|
||||||
last_worked_notification_time_ = current_time;
|
last_worked_notification_time_ = current_time;
|
||||||
BrowserThread::PostTask(
|
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
|
||||||
BrowserThread::UI, FROM_HERE, Bind(worked_callback_, files_indexed_));
|
Bind(worked_callback_, files_indexed_));
|
||||||
files_indexed_ = 0;
|
files_indexed_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DevToolsFileSystemIndexer::DevToolsFileSystemIndexer() {
|
DevToolsFileSystemIndexer::DevToolsFileSystemIndexer() {}
|
||||||
}
|
|
||||||
|
|
||||||
DevToolsFileSystemIndexer::~DevToolsFileSystemIndexer() {}
|
DevToolsFileSystemIndexer::~DevToolsFileSystemIndexer() {}
|
||||||
|
|
||||||
|
@ -453,11 +445,9 @@ DevToolsFileSystemIndexer::IndexPath(
|
||||||
const WorkedCallback& worked_callback,
|
const WorkedCallback& worked_callback,
|
||||||
const DoneCallback& done_callback) {
|
const DoneCallback& done_callback) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
scoped_refptr<FileSystemIndexingJob> indexing_job =
|
scoped_refptr<FileSystemIndexingJob> indexing_job = new FileSystemIndexingJob(
|
||||||
new FileSystemIndexingJob(FilePath::FromUTF8Unsafe(file_system_path),
|
FilePath::FromUTF8Unsafe(file_system_path), total_work_callback,
|
||||||
total_work_callback,
|
worked_callback, done_callback);
|
||||||
worked_callback,
|
|
||||||
done_callback);
|
|
||||||
indexing_job->Start();
|
indexing_job->Start();
|
||||||
return indexing_job;
|
return indexing_job;
|
||||||
}
|
}
|
||||||
|
@ -467,13 +457,9 @@ void DevToolsFileSystemIndexer::SearchInPath(const string& file_system_path,
|
||||||
const SearchCallback& callback) {
|
const SearchCallback& callback) {
|
||||||
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
DCHECK_CURRENTLY_ON(BrowserThread::UI);
|
||||||
BrowserThread::PostTask(
|
BrowserThread::PostTask(
|
||||||
BrowserThread::FILE,
|
BrowserThread::FILE, FROM_HERE,
|
||||||
FROM_HERE,
|
Bind(&DevToolsFileSystemIndexer::SearchInPathOnFileThread, this,
|
||||||
Bind(&DevToolsFileSystemIndexer::SearchInPathOnFileThread,
|
file_system_path, query, callback));
|
||||||
this,
|
|
||||||
file_system_path,
|
|
||||||
query,
|
|
||||||
callback));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevToolsFileSystemIndexer::SearchInPathOnFileThread(
|
void DevToolsFileSystemIndexer::SearchInPathOnFileThread(
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace base {
|
||||||
class FilePath;
|
class FilePath;
|
||||||
class FileEnumerator;
|
class FileEnumerator;
|
||||||
class Time;
|
class Time;
|
||||||
}
|
} // namespace base
|
||||||
|
|
||||||
namespace content {
|
namespace content {
|
||||||
class WebContents;
|
class WebContents;
|
||||||
|
@ -56,9 +56,7 @@ class DevToolsFileSystemIndexer
|
||||||
void IndexFiles();
|
void IndexFiles();
|
||||||
void StartFileIndexing(base::File::Error error);
|
void StartFileIndexing(base::File::Error error);
|
||||||
void ReadFromFile();
|
void ReadFromFile();
|
||||||
void OnRead(base::File::Error error,
|
void OnRead(base::File::Error error, const char* data, int bytes_read);
|
||||||
const char* data,
|
|
||||||
int bytes_read);
|
|
||||||
void FinishFileIndexing(bool success);
|
void FinishFileIndexing(bool success);
|
||||||
void CloseFile();
|
void CloseFile();
|
||||||
void CloseCallback(base::File::Error error);
|
void CloseCallback(base::File::Error error);
|
||||||
|
|
|
@ -34,8 +34,7 @@ namespace {
|
||||||
class TCPServerSocketFactory : public content::DevToolsSocketFactory {
|
class TCPServerSocketFactory : public content::DevToolsSocketFactory {
|
||||||
public:
|
public:
|
||||||
TCPServerSocketFactory(const std::string& address, int port)
|
TCPServerSocketFactory(const std::string& address, int port)
|
||||||
: address_(address), port_(port) {
|
: address_(address), port_(port) {}
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// content::ServerSocketFactory.
|
// content::ServerSocketFactory.
|
||||||
|
@ -58,8 +57,7 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory {
|
||||||
DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory);
|
DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::unique_ptr<content::DevToolsSocketFactory>
|
std::unique_ptr<content::DevToolsSocketFactory> CreateSocketFactory() {
|
||||||
CreateSocketFactory() {
|
|
||||||
auto& command_line = *base::CommandLine::ForCurrentProcess();
|
auto& command_line = *base::CommandLine::ForCurrentProcess();
|
||||||
// See if the user specified a port on the command line (useful for
|
// See if the user specified a port on the command line (useful for
|
||||||
// automation). If not, use an ephemeral port by specifying 0.
|
// automation). If not, use an ephemeral port by specifying 0.
|
||||||
|
@ -68,8 +66,8 @@ CreateSocketFactory() {
|
||||||
int temp_port;
|
int temp_port;
|
||||||
std::string port_str =
|
std::string port_str =
|
||||||
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
|
command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort);
|
||||||
if (base::StringToInt(port_str, &temp_port) &&
|
if (base::StringToInt(port_str, &temp_port) && temp_port > 0 &&
|
||||||
temp_port > 0 && temp_port < 65535) {
|
temp_port < 65535) {
|
||||||
port = temp_port;
|
port = temp_port;
|
||||||
} else {
|
} else {
|
||||||
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
|
DLOG(WARNING) << "Invalid http debugger port number " << temp_port;
|
||||||
|
@ -86,19 +84,14 @@ CreateSocketFactory() {
|
||||||
// static
|
// static
|
||||||
void DevToolsManagerDelegate::StartHttpHandler() {
|
void DevToolsManagerDelegate::StartHttpHandler() {
|
||||||
content::DevToolsAgentHost::StartRemoteDebuggingServer(
|
content::DevToolsAgentHost::StartRemoteDebuggingServer(
|
||||||
CreateSocketFactory(),
|
CreateSocketFactory(), std::string(), base::FilePath(), base::FilePath());
|
||||||
std::string(),
|
|
||||||
base::FilePath(),
|
|
||||||
base::FilePath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DevToolsManagerDelegate::DevToolsManagerDelegate() {}
|
DevToolsManagerDelegate::DevToolsManagerDelegate() {}
|
||||||
|
|
||||||
DevToolsManagerDelegate::~DevToolsManagerDelegate() {
|
DevToolsManagerDelegate::~DevToolsManagerDelegate() {}
|
||||||
}
|
|
||||||
|
|
||||||
void DevToolsManagerDelegate::Inspect(content::DevToolsAgentHost* agent_host) {
|
void DevToolsManagerDelegate::Inspect(content::DevToolsAgentHost* agent_host) {}
|
||||||
}
|
|
||||||
|
|
||||||
bool DevToolsManagerDelegate::HandleCommand(
|
bool DevToolsManagerDelegate::HandleCommand(
|
||||||
content::DevToolsAgentHost* agent_host,
|
content::DevToolsAgentHost* agent_host,
|
||||||
|
@ -113,8 +106,9 @@ DevToolsManagerDelegate::CreateNewTarget(const GURL& url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DevToolsManagerDelegate::GetDiscoveryPageHTML() {
|
std::string DevToolsManagerDelegate::GetDiscoveryPageHTML() {
|
||||||
return ResourceBundle::GetSharedInstance().GetRawDataResource(
|
return ResourceBundle::GetSharedInstance()
|
||||||
IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string();
|
.GetRawDataResource(IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE)
|
||||||
|
.as_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string DevToolsManagerDelegate::GetFrontendResource(
|
std::string DevToolsManagerDelegate::GetFrontendResource(
|
||||||
|
|
|
@ -22,10 +22,9 @@ class DevToolsManagerDelegate : public content::DevToolsManagerDelegate {
|
||||||
|
|
||||||
// DevToolsManagerDelegate implementation.
|
// DevToolsManagerDelegate implementation.
|
||||||
void Inspect(content::DevToolsAgentHost* agent_host) override;
|
void Inspect(content::DevToolsAgentHost* agent_host) override;
|
||||||
bool HandleCommand(
|
bool HandleCommand(content::DevToolsAgentHost* agent_host,
|
||||||
content::DevToolsAgentHost* agent_host,
|
int session_id,
|
||||||
int session_id,
|
base::DictionaryValue* command) override;
|
||||||
base::DictionaryValue* command) override;
|
|
||||||
scoped_refptr<content::DevToolsAgentHost> CreateNewTarget(
|
scoped_refptr<content::DevToolsAgentHost> CreateNewTarget(
|
||||||
const GURL& url) override;
|
const GURL& url) override;
|
||||||
std::string GetDiscoveryPageHTML() override;
|
std::string GetDiscoveryPageHTML() override;
|
||||||
|
|
|
@ -23,7 +23,8 @@ const char kChromeUIDevToolsBundledPath[] = "bundled";
|
||||||
|
|
||||||
std::string PathWithoutParams(const std::string& path) {
|
std::string PathWithoutParams(const std::string& path) {
|
||||||
return GURL(std::string("chrome-devtools://devtools/") + path)
|
return GURL(std::string("chrome-devtools://devtools/") + path)
|
||||||
.path().substr(1);
|
.path()
|
||||||
|
.substr(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetMimeTypeForPath(const std::string& path) {
|
std::string GetMimeTypeForPath(const std::string& path) {
|
||||||
|
@ -57,9 +58,7 @@ class BundledDataSource : public content::URLDataSource {
|
||||||
BundledDataSource() {}
|
BundledDataSource() {}
|
||||||
|
|
||||||
// content::URLDataSource implementation.
|
// content::URLDataSource implementation.
|
||||||
std::string GetSource() const override {
|
std::string GetSource() const override { return kChromeUIDevToolsHost; }
|
||||||
return kChromeUIDevToolsHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
void StartDataRequest(
|
void StartDataRequest(
|
||||||
const std::string& path,
|
const std::string& path,
|
||||||
|
@ -83,17 +82,11 @@ class BundledDataSource : public content::URLDataSource {
|
||||||
return GetMimeTypeForPath(path);
|
return GetMimeTypeForPath(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShouldAddContentSecurityPolicy() const override {
|
bool ShouldAddContentSecurityPolicy() const override { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShouldDenyXFrameOptions() const override {
|
bool ShouldDenyXFrameOptions() const override { return false; }
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShouldServeMimeTypeAsContentTypeHeader() const override {
|
bool ShouldServeMimeTypeAsContentTypeHeader() const override { return true; }
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void StartBundledDataRequest(const std::string& path,
|
void StartBundledDataRequest(const std::string& path,
|
||||||
const GotDataCallback& callback) {
|
const GotDataCallback& callback) {
|
||||||
|
|
|
@ -11,22 +11,21 @@ class InspectableWebContentsDelegate {
|
||||||
|
|
||||||
// Requested by WebContents of devtools.
|
// Requested by WebContents of devtools.
|
||||||
virtual void DevToolsReloadPage() {}
|
virtual void DevToolsReloadPage() {}
|
||||||
virtual void DevToolsSaveToFile(
|
virtual void DevToolsSaveToFile(const std::string& url,
|
||||||
const std::string& url, const std::string& content, bool save_as) {}
|
const std::string& content,
|
||||||
virtual void DevToolsAppendToFile(
|
bool save_as) {}
|
||||||
const std::string& url, const std::string& content) {}
|
virtual void DevToolsAppendToFile(const std::string& url,
|
||||||
|
const std::string& content) {}
|
||||||
virtual void DevToolsRequestFileSystems() {}
|
virtual void DevToolsRequestFileSystems() {}
|
||||||
virtual void DevToolsAddFileSystem(
|
virtual void DevToolsAddFileSystem(const base::FilePath& file_system_path) {}
|
||||||
const base::FilePath& file_system_path) {}
|
|
||||||
virtual void DevToolsRemoveFileSystem(
|
virtual void DevToolsRemoveFileSystem(
|
||||||
const base::FilePath& file_system_path) {}
|
const base::FilePath& file_system_path) {}
|
||||||
virtual void DevToolsIndexPath(
|
virtual void DevToolsIndexPath(int request_id,
|
||||||
int request_id, const std::string& file_system_path) {}
|
const std::string& file_system_path) {}
|
||||||
virtual void DevToolsStopIndexing(int request_id) {}
|
virtual void DevToolsStopIndexing(int request_id) {}
|
||||||
virtual void DevToolsSearchInPath(
|
virtual void DevToolsSearchInPath(int request_id,
|
||||||
int request_id,
|
const std::string& file_system_path,
|
||||||
const std::string& file_system_path,
|
const std::string& query) {}
|
||||||
const std::string& query) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -42,9 +42,9 @@ namespace brightray {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0,
|
const double kPresetZoomFactors[] = {0.25, 0.333, 0.5, 0.666, 0.75, 0.9,
|
||||||
1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0,
|
1.0, 1.1, 1.25, 1.5, 1.75, 2.0,
|
||||||
5.0 };
|
2.5, 3.0, 4.0, 5.0};
|
||||||
|
|
||||||
const char kChromeUIDevToolsURL[] =
|
const char kChromeUIDevToolsURL[] =
|
||||||
"chrome-devtools://devtools/bundled/inspector.html?"
|
"chrome-devtools://devtools/bundled/inspector.html?"
|
||||||
|
@ -117,18 +117,16 @@ double GetNextZoomLevel(double level, bool out) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GURL GetRemoteBaseURL() {
|
GURL GetRemoteBaseURL() {
|
||||||
return GURL(base::StringPrintf(
|
return GURL(base::StringPrintf("%s%s/%s/",
|
||||||
"%s%s/%s/",
|
kChromeUIDevToolsRemoteFrontendBase,
|
||||||
kChromeUIDevToolsRemoteFrontendBase,
|
kChromeUIDevToolsRemoteFrontendPath,
|
||||||
kChromeUIDevToolsRemoteFrontendPath,
|
content::GetWebKitRevision().c_str()));
|
||||||
content::GetWebKitRevision().c_str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GURL GetDevToolsURL(bool can_dock) {
|
GURL GetDevToolsURL(bool can_dock) {
|
||||||
auto url_string =
|
auto url_string = base::StringPrintf(kChromeUIDevToolsURL,
|
||||||
base::StringPrintf(kChromeUIDevToolsURL,
|
GetRemoteBaseURL().spec().c_str(),
|
||||||
GetRemoteBaseURL().spec().c_str(),
|
can_dock ? "true" : "");
|
||||||
can_dock ? "true" : "");
|
|
||||||
return GURL(url_string);
|
return GURL(url_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,12 +155,9 @@ class ResponseWriter : public net::URLFetcherResponseWriter {
|
||||||
ResponseWriter::ResponseWriter(
|
ResponseWriter::ResponseWriter(
|
||||||
base::WeakPtr<InspectableWebContentsImpl> bindings,
|
base::WeakPtr<InspectableWebContentsImpl> bindings,
|
||||||
int stream_id)
|
int stream_id)
|
||||||
: bindings_(bindings),
|
: bindings_(bindings), stream_id_(stream_id) {}
|
||||||
stream_id_(stream_id) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ResponseWriter::~ResponseWriter() {
|
ResponseWriter::~ResponseWriter() {}
|
||||||
}
|
|
||||||
|
|
||||||
int ResponseWriter::Initialize(const net::CompletionCallback& callback) {
|
int ResponseWriter::Initialize(const net::CompletionCallback& callback) {
|
||||||
return net::OK;
|
return net::OK;
|
||||||
|
@ -172,14 +167,13 @@ int ResponseWriter::Write(net::IOBuffer* buffer,
|
||||||
int num_bytes,
|
int num_bytes,
|
||||||
const net::CompletionCallback& callback) {
|
const net::CompletionCallback& callback) {
|
||||||
auto* id = new base::Value(stream_id_);
|
auto* id = new base::Value(stream_id_);
|
||||||
base::Value* chunk =
|
base::Value* chunk = new base::Value(std::string(buffer->data(), num_bytes));
|
||||||
new base::Value(std::string(buffer->data(), num_bytes));
|
|
||||||
|
|
||||||
content::BrowserThread::PostTask(
|
content::BrowserThread::PostTask(
|
||||||
content::BrowserThread::UI, FROM_HERE,
|
content::BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(&InspectableWebContentsImpl::CallClientFunction,
|
base::Bind(&InspectableWebContentsImpl::CallClientFunction, bindings_,
|
||||||
bindings_, "DevToolsAPI.streamWrite",
|
"DevToolsAPI.streamWrite", base::Owned(id), base::Owned(chunk),
|
||||||
base::Owned(id), base::Owned(chunk), nullptr));
|
nullptr));
|
||||||
return num_bytes;
|
return num_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,8 +217,9 @@ InspectableWebContentsImpl::InspectableWebContentsImpl(
|
||||||
if (!IsPointInScreen(devtools_bounds_.origin())) {
|
if (!IsPointInScreen(devtools_bounds_.origin())) {
|
||||||
gfx::Rect display;
|
gfx::Rect display;
|
||||||
if (web_contents->GetNativeView()) {
|
if (web_contents->GetNativeView()) {
|
||||||
display = display::Screen::GetScreen()->
|
display = display::Screen::GetScreen()
|
||||||
GetDisplayNearestView(web_contents->GetNativeView()).bounds();
|
->GetDisplayNearestView(web_contents->GetNativeView())
|
||||||
|
.bounds();
|
||||||
} else {
|
} else {
|
||||||
display = display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
|
display = display::Screen::GetScreen()->GetPrimaryDisplay().bounds();
|
||||||
}
|
}
|
||||||
|
@ -311,9 +306,8 @@ void InspectableWebContentsImpl::ShowDevTools() {
|
||||||
|
|
||||||
if (!external_devtools_web_contents_) { // no external devtools
|
if (!external_devtools_web_contents_) { // no external devtools
|
||||||
managed_devtools_web_contents_.reset(
|
managed_devtools_web_contents_.reset(
|
||||||
content::WebContents::Create(
|
content::WebContents::Create(content::WebContents::CreateParams(
|
||||||
content::WebContents::CreateParams(
|
web_contents_->GetBrowserContext())));
|
||||||
web_contents_->GetBrowserContext())));
|
|
||||||
managed_devtools_web_contents_->SetDelegate(this);
|
managed_devtools_web_contents_->SetDelegate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,10 +315,8 @@ void InspectableWebContentsImpl::ShowDevTools() {
|
||||||
AttachTo(content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()));
|
AttachTo(content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()));
|
||||||
|
|
||||||
GetDevToolsWebContents()->GetController().LoadURL(
|
GetDevToolsWebContents()->GetController().LoadURL(
|
||||||
GetDevToolsURL(can_dock_),
|
GetDevToolsURL(can_dock_), content::Referrer(),
|
||||||
content::Referrer(),
|
ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string());
|
||||||
ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
|
|
||||||
std::string());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::CloseDevTools() {
|
void InspectableWebContentsImpl::CloseDevTools() {
|
||||||
|
@ -406,8 +398,7 @@ void InspectableWebContentsImpl::UpdateDevToolsZoomLevel(double level) {
|
||||||
|
|
||||||
void InspectableWebContentsImpl::ActivateWindow() {
|
void InspectableWebContentsImpl::ActivateWindow() {
|
||||||
// Set the zoom level.
|
// Set the zoom level.
|
||||||
SetZoomLevelForWebContents(GetDevToolsWebContents(),
|
SetZoomLevelForWebContents(GetDevToolsWebContents(), GetDevToolsZoomLevel());
|
||||||
GetDevToolsZoomLevel());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::CloseWindow() {
|
void InspectableWebContentsImpl::CloseWindow() {
|
||||||
|
@ -424,8 +415,8 @@ void InspectableWebContentsImpl::LoadCompleted() {
|
||||||
SetIsDocked(DispatchCallback(), false);
|
SetIsDocked(DispatchCallback(), false);
|
||||||
} else {
|
} else {
|
||||||
if (dock_state_.empty()) {
|
if (dock_state_.empty()) {
|
||||||
const base::DictionaryValue* prefs = pref_service_->GetDictionary(
|
const base::DictionaryValue* prefs =
|
||||||
kDevToolsPreferences);
|
pref_service_->GetDictionary(kDevToolsPreferences);
|
||||||
std::string current_dock_state;
|
std::string current_dock_state;
|
||||||
prefs->GetString("currentDockState", ¤t_dock_state);
|
prefs->GetString("currentDockState", ¤t_dock_state);
|
||||||
base::RemoveChars(current_dock_state, "\"", &dock_state_);
|
base::RemoveChars(current_dock_state, "\"", &dock_state_);
|
||||||
|
@ -449,13 +440,12 @@ void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) {
|
||||||
view_->SetContentsResizingStrategy(contents_resizing_strategy_);
|
view_->SetContentsResizingStrategy(contents_resizing_strategy_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::InspectElementCompleted() {
|
void InspectableWebContentsImpl::InspectElementCompleted() {}
|
||||||
}
|
|
||||||
|
|
||||||
void InspectableWebContentsImpl::InspectedURLChanged(const std::string& url) {
|
void InspectableWebContentsImpl::InspectedURLChanged(const std::string& url) {
|
||||||
if (managed_devtools_web_contents_)
|
if (managed_devtools_web_contents_)
|
||||||
view_->SetTitle(base::UTF8ToUTF16(base::StringPrintf(kTitleFormat,
|
view_->SetTitle(
|
||||||
url.c_str())));
|
base::UTF8ToUTF16(base::StringPrintf(kTitleFormat, url.c_str())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::LoadNetworkResource(
|
void InspectableWebContentsImpl::LoadNetworkResource(
|
||||||
|
@ -493,17 +483,17 @@ void InspectableWebContentsImpl::SetIsDocked(const DispatchCallback& callback,
|
||||||
callback.Run(nullptr);
|
callback.Run(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) {
|
void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) {}
|
||||||
}
|
|
||||||
|
|
||||||
void InspectableWebContentsImpl::SaveToFile(
|
void InspectableWebContentsImpl::SaveToFile(const std::string& url,
|
||||||
const std::string& url, const std::string& content, bool save_as) {
|
const std::string& content,
|
||||||
|
bool save_as) {
|
||||||
if (delegate_)
|
if (delegate_)
|
||||||
delegate_->DevToolsSaveToFile(url, content, save_as);
|
delegate_->DevToolsSaveToFile(url, content, save_as);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::AppendToFile(
|
void InspectableWebContentsImpl::AppendToFile(const std::string& url,
|
||||||
const std::string& url, const std::string& content) {
|
const std::string& content) {
|
||||||
if (delegate_)
|
if (delegate_)
|
||||||
delegate_->DevToolsAppendToFile(url, content);
|
delegate_->DevToolsAppendToFile(url, content);
|
||||||
}
|
}
|
||||||
|
@ -528,11 +518,11 @@ void InspectableWebContentsImpl::RemoveFileSystem(
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::UpgradeDraggedFileSystemPermissions(
|
void InspectableWebContentsImpl::UpgradeDraggedFileSystemPermissions(
|
||||||
const std::string& file_system_url) {
|
const std::string& file_system_url) {}
|
||||||
}
|
|
||||||
|
|
||||||
void InspectableWebContentsImpl::IndexPath(
|
void InspectableWebContentsImpl::IndexPath(
|
||||||
int request_id, const std::string& file_system_path) {
|
int request_id,
|
||||||
|
const std::string& file_system_path) {
|
||||||
if (delegate_)
|
if (delegate_)
|
||||||
delegate_->DevToolsIndexPath(request_id, file_system_path);
|
delegate_->DevToolsIndexPath(request_id, file_system_path);
|
||||||
}
|
}
|
||||||
|
@ -551,8 +541,7 @@ void InspectableWebContentsImpl::SearchInPath(
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::SetWhitelistedShortcuts(
|
void InspectableWebContentsImpl::SetWhitelistedShortcuts(
|
||||||
const std::string& message) {
|
const std::string& message) {}
|
||||||
}
|
|
||||||
|
|
||||||
void InspectableWebContentsImpl::ZoomIn() {
|
void InspectableWebContentsImpl::ZoomIn() {
|
||||||
double new_level = GetNextZoomLevel(GetDevToolsZoomLevel(), false);
|
double new_level = GetNextZoomLevel(GetDevToolsZoomLevel(), false);
|
||||||
|
@ -571,16 +560,16 @@ void InspectableWebContentsImpl::ResetZoom() {
|
||||||
UpdateDevToolsZoomLevel(0.);
|
UpdateDevToolsZoomLevel(0.);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) {
|
void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) {}
|
||||||
}
|
|
||||||
|
|
||||||
void InspectableWebContentsImpl::DispatchProtocolMessageFromDevToolsFrontend(
|
void InspectableWebContentsImpl::DispatchProtocolMessageFromDevToolsFrontend(
|
||||||
const std::string& message) {
|
const std::string& message) {
|
||||||
// If the devtools wants to reload the page, hijack the message and handle it
|
// If the devtools wants to reload the page, hijack the message and handle it
|
||||||
// to the delegate.
|
// to the delegate.
|
||||||
if (base::MatchPattern(message, "{\"id\":*,"
|
if (base::MatchPattern(message,
|
||||||
"\"method\":\"Page.reload\","
|
"{\"id\":*,"
|
||||||
"\"params\":*}")) {
|
"\"method\":\"Page.reload\","
|
||||||
|
"\"params\":*}")) {
|
||||||
if (delegate_)
|
if (delegate_)
|
||||||
delegate_->DevToolsReloadPage();
|
delegate_->DevToolsReloadPage();
|
||||||
return;
|
return;
|
||||||
|
@ -599,8 +588,8 @@ void InspectableWebContentsImpl::SendJsonRequest(
|
||||||
|
|
||||||
void InspectableWebContentsImpl::GetPreferences(
|
void InspectableWebContentsImpl::GetPreferences(
|
||||||
const DispatchCallback& callback) {
|
const DispatchCallback& callback) {
|
||||||
const base::DictionaryValue* prefs = pref_service_->GetDictionary(
|
const base::DictionaryValue* prefs =
|
||||||
kDevToolsPreferences);
|
pref_service_->GetDictionary(kDevToolsPreferences);
|
||||||
callback.Run(prefs);
|
callback.Run(prefs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,11 +623,10 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(
|
||||||
|
|
||||||
base::DictionaryValue* dict = nullptr;
|
base::DictionaryValue* dict = nullptr;
|
||||||
std::unique_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
|
std::unique_ptr<base::Value> parsed_message(base::JSONReader::Read(message));
|
||||||
if (!parsed_message ||
|
if (!parsed_message || !parsed_message->GetAsDictionary(&dict) ||
|
||||||
!parsed_message->GetAsDictionary(&dict) ||
|
|
||||||
!dict->GetString(kFrontendHostMethod, &method) ||
|
!dict->GetString(kFrontendHostMethod, &method) ||
|
||||||
(dict->HasKey(kFrontendHostParams) &&
|
(dict->HasKey(kFrontendHostParams) &&
|
||||||
!dict->GetList(kFrontendHostParams, ¶ms))) {
|
!dict->GetList(kFrontendHostParams, ¶ms))) {
|
||||||
LOG(ERROR) << "Invalid message was sent to embedder: " << message;
|
LOG(ERROR) << "Invalid message was sent to embedder: " << message;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -646,20 +634,19 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(
|
||||||
dict->GetInteger(kFrontendHostId, &id);
|
dict->GetInteger(kFrontendHostId, &id);
|
||||||
embedder_message_dispatcher_->Dispatch(
|
embedder_message_dispatcher_->Dispatch(
|
||||||
base::Bind(&InspectableWebContentsImpl::SendMessageAck,
|
base::Bind(&InspectableWebContentsImpl::SendMessageAck,
|
||||||
weak_factory_.GetWeakPtr(),
|
weak_factory_.GetWeakPtr(), id),
|
||||||
id),
|
method, params);
|
||||||
method,
|
|
||||||
params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::DispatchProtocolMessage(
|
void InspectableWebContentsImpl::DispatchProtocolMessage(
|
||||||
content::DevToolsAgentHost* agent_host, const std::string& message) {
|
content::DevToolsAgentHost* agent_host,
|
||||||
|
const std::string& message) {
|
||||||
if (!frontend_loaded_)
|
if (!frontend_loaded_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (message.length() < kMaxMessageChunkSize) {
|
if (message.length() < kMaxMessageChunkSize) {
|
||||||
base::string16 javascript = base::UTF8ToUTF16(
|
base::string16 javascript =
|
||||||
"DevToolsAPI.dispatchMessage(" + message + ");");
|
base::UTF8ToUTF16("DevToolsAPI.dispatchMessage(" + message + ");");
|
||||||
GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript(javascript);
|
GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript(javascript);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -667,14 +654,14 @@ void InspectableWebContentsImpl::DispatchProtocolMessage(
|
||||||
base::Value total_size(static_cast<int>(message.length()));
|
base::Value total_size(static_cast<int>(message.length()));
|
||||||
for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
|
for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) {
|
||||||
base::Value message_value(message.substr(pos, kMaxMessageChunkSize));
|
base::Value message_value(message.substr(pos, kMaxMessageChunkSize));
|
||||||
CallClientFunction("DevToolsAPI.dispatchMessageChunk",
|
CallClientFunction("DevToolsAPI.dispatchMessageChunk", &message_value,
|
||||||
&message_value, pos ? nullptr : &total_size, nullptr);
|
pos ? nullptr : &total_size, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::AgentHostClosed(
|
void InspectableWebContentsImpl::AgentHostClosed(
|
||||||
content::DevToolsAgentHost* agent_host, bool replaced) {
|
content::DevToolsAgentHost* agent_host,
|
||||||
}
|
bool replaced) {}
|
||||||
|
|
||||||
void InspectableWebContentsImpl::RenderFrameHostChanged(
|
void InspectableWebContentsImpl::RenderFrameHostChanged(
|
||||||
content::RenderFrameHost* old_host,
|
content::RenderFrameHost* old_host,
|
||||||
|
@ -707,8 +694,9 @@ bool InspectableWebContentsImpl::DidAddMessageToConsole(
|
||||||
const base::string16& message,
|
const base::string16& message,
|
||||||
int32_t line_no,
|
int32_t line_no,
|
||||||
const base::string16& source_id) {
|
const base::string16& source_id) {
|
||||||
logging::LogMessage("CONSOLE", line_no, level).stream() << "\"" <<
|
logging::LogMessage("CONSOLE", line_no, level).stream()
|
||||||
message << "\", source: " << source_id << " (" << line_no << ")";
|
<< "\"" << message << "\", source: " << source_id << " (" << line_no
|
||||||
|
<< ")";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -846,8 +834,7 @@ void InspectableWebContentsImpl::OnURLFetchComplete(
|
||||||
void InspectableWebContentsImpl::SendMessageAck(int request_id,
|
void InspectableWebContentsImpl::SendMessageAck(int request_id,
|
||||||
const base::Value* arg) {
|
const base::Value* arg) {
|
||||||
base::Value id_value(request_id);
|
base::Value id_value(request_id);
|
||||||
CallClientFunction("DevToolsAPI.embedderMessageAck",
|
CallClientFunction("DevToolsAPI.embedderMessageAck", &id_value, arg, nullptr);
|
||||||
&id_value, arg, nullptr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -29,13 +29,13 @@ namespace brightray {
|
||||||
class InspectableWebContentsDelegate;
|
class InspectableWebContentsDelegate;
|
||||||
class InspectableWebContentsView;
|
class InspectableWebContentsView;
|
||||||
|
|
||||||
class InspectableWebContentsImpl :
|
class InspectableWebContentsImpl
|
||||||
public InspectableWebContents,
|
: public InspectableWebContents,
|
||||||
public content::DevToolsAgentHostClient,
|
public content::DevToolsAgentHostClient,
|
||||||
public content::WebContentsObserver,
|
public content::WebContentsObserver,
|
||||||
public content::WebContentsDelegate,
|
public content::WebContentsDelegate,
|
||||||
public DevToolsEmbedderMessageDispatcher::Delegate,
|
public DevToolsEmbedderMessageDispatcher::Delegate,
|
||||||
public net::URLFetcherDelegate {
|
public net::URLFetcherDelegate {
|
||||||
public:
|
public:
|
||||||
static void RegisterPrefs(PrefRegistrySimple* pref_registry);
|
static void RegisterPrefs(PrefRegistrySimple* pref_registry);
|
||||||
|
|
||||||
|
@ -156,8 +156,8 @@ class InspectableWebContentsImpl :
|
||||||
const GURL& target_url,
|
const GURL& target_url,
|
||||||
const std::string& partition_id,
|
const std::string& partition_id,
|
||||||
content::SessionStorageNamespace* session_storage_namespace) override;
|
content::SessionStorageNamespace* session_storage_namespace) override;
|
||||||
void HandleKeyboardEvent(
|
void HandleKeyboardEvent(content::WebContents*,
|
||||||
content::WebContents*, const content::NativeWebKeyboardEvent&) override;
|
const content::NativeWebKeyboardEvent&) override;
|
||||||
void CloseContents(content::WebContents* source) override;
|
void CloseContents(content::WebContents* source) override;
|
||||||
content::ColorChooser* OpenColorChooser(
|
content::ColorChooser* OpenColorChooser(
|
||||||
content::WebContents* source,
|
content::WebContents* source,
|
||||||
|
@ -172,8 +172,7 @@ class InspectableWebContentsImpl :
|
||||||
// net::URLFetcherDelegate:
|
// net::URLFetcherDelegate:
|
||||||
void OnURLFetchComplete(const net::URLFetcher* source) override;
|
void OnURLFetchComplete(const net::URLFetcher* source) override;
|
||||||
|
|
||||||
void SendMessageAck(int request_id,
|
void SendMessageAck(int request_id, const base::Value* arg1);
|
||||||
const base::Value* arg1);
|
|
||||||
|
|
||||||
bool frontend_loaded_;
|
bool frontend_loaded_;
|
||||||
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
scoped_refptr<content::DevToolsAgentHost> agent_host_;
|
||||||
|
|
|
@ -25,9 +25,7 @@ class InspectableWebContentsView {
|
||||||
void SetDelegate(InspectableWebContentsViewDelegate* delegate) {
|
void SetDelegate(InspectableWebContentsViewDelegate* delegate) {
|
||||||
delegate_ = delegate;
|
delegate_ = delegate;
|
||||||
}
|
}
|
||||||
InspectableWebContentsViewDelegate* GetDelegate() const {
|
InspectableWebContentsViewDelegate* GetDelegate() const { return delegate_; }
|
||||||
return delegate_;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(TOOLKIT_VIEWS)
|
#if defined(TOOLKIT_VIEWS)
|
||||||
// Returns the container control, which has devtools view attached.
|
// Returns the container control, which has devtools view attached.
|
||||||
|
|
|
@ -7,4 +7,3 @@ gfx::ImageSkia InspectableWebContentsViewDelegate::GetDevToolsWindowIcon() {
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ class InspectableWebContentsViewDelegate {
|
||||||
|
|
||||||
#if defined(USE_X11)
|
#if defined(USE_X11)
|
||||||
// Called when creating devtools window.
|
// Called when creating devtools window.
|
||||||
virtual void GetDevToolsWindowWMClass(
|
virtual void GetDevToolsWindowWMClass(std::string* name,
|
||||||
std::string* name, std::string* class_name) {}
|
std::string* class_name) {}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
namespace net {
|
namespace net {
|
||||||
class URLRequestContext;
|
class URLRequestContext;
|
||||||
class URLRequestContextGetter;
|
class URLRequestContextGetter;
|
||||||
}
|
} // namespace net
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@
|
||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
LibNotifyLoader::LibNotifyLoader() : loaded_(false) {
|
LibNotifyLoader::LibNotifyLoader() : loaded_(false) {}
|
||||||
}
|
|
||||||
|
|
||||||
LibNotifyLoader::~LibNotifyLoader() {
|
LibNotifyLoader::~LibNotifyLoader() {
|
||||||
CleanUp(loaded_);
|
CleanUp(loaded_);
|
||||||
|
@ -21,17 +20,15 @@ bool LibNotifyLoader::Load(const std::string& library_name) {
|
||||||
if (!library_)
|
if (!library_)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
notify_is_initted =
|
notify_is_initted = reinterpret_cast<decltype(this->notify_is_initted)>(
|
||||||
reinterpret_cast<decltype(this->notify_is_initted)>(
|
dlsym(library_, "notify_is_initted"));
|
||||||
dlsym(library_, "notify_is_initted"));
|
|
||||||
if (!notify_is_initted) {
|
if (!notify_is_initted) {
|
||||||
CleanUp(true);
|
CleanUp(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
notify_init =
|
notify_init = reinterpret_cast<decltype(this->notify_init)>(
|
||||||
reinterpret_cast<decltype(this->notify_init)>(
|
dlsym(library_, "notify_init"));
|
||||||
dlsym(library_, "notify_init"));
|
|
||||||
if (!notify_init) {
|
if (!notify_init) {
|
||||||
CleanUp(true);
|
CleanUp(true);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -29,7 +29,7 @@ const std::set<std::string>& GetServerCapabilities() {
|
||||||
static std::set<std::string> caps;
|
static std::set<std::string> caps;
|
||||||
if (caps.empty()) {
|
if (caps.empty()) {
|
||||||
auto capabilities = libnotify_loader_.notify_get_server_caps();
|
auto capabilities = libnotify_loader_.notify_get_server_caps();
|
||||||
for (auto l=capabilities; l != nullptr; l=l->next)
|
for (auto l = capabilities; l != nullptr; l = l->next)
|
||||||
caps.insert(static_cast<const char*>(l->data));
|
caps.insert(static_cast<const char*>(l->data));
|
||||||
g_list_free_full(capabilities, g_free);
|
g_list_free_full(capabilities, g_free);
|
||||||
}
|
}
|
||||||
|
@ -48,10 +48,9 @@ bool NotifierSupportsActions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_and_clear_error(GError* error, const char* context) {
|
void log_and_clear_error(GError* error, const char* context) {
|
||||||
LOG(ERROR) << context
|
LOG(ERROR) << context << ": domain=" << error->domain
|
||||||
<< ": domain=" << error->domain
|
<< " code=" << error->code << " message=\"" << error->message
|
||||||
<< " code=" << error->code
|
<< '"';
|
||||||
<< " message=\"" << error->message << '"';
|
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,9 +75,7 @@ bool LibnotifyNotification::Initialize() {
|
||||||
|
|
||||||
LibnotifyNotification::LibnotifyNotification(NotificationDelegate* delegate,
|
LibnotifyNotification::LibnotifyNotification(NotificationDelegate* delegate,
|
||||||
NotificationPresenter* presenter)
|
NotificationPresenter* presenter)
|
||||||
: Notification(delegate, presenter),
|
: Notification(delegate, presenter), notification_(nullptr) {}
|
||||||
notification_(nullptr) {
|
|
||||||
}
|
|
||||||
|
|
||||||
LibnotifyNotification::~LibnotifyNotification() {
|
LibnotifyNotification::~LibnotifyNotification() {
|
||||||
if (notification_) {
|
if (notification_) {
|
||||||
|
@ -90,11 +87,10 @@ LibnotifyNotification::~LibnotifyNotification() {
|
||||||
void LibnotifyNotification::Show(const NotificationOptions& options) {
|
void LibnotifyNotification::Show(const NotificationOptions& options) {
|
||||||
notification_ = libnotify_loader_.notify_notification_new(
|
notification_ = libnotify_loader_.notify_notification_new(
|
||||||
base::UTF16ToUTF8(options.title).c_str(),
|
base::UTF16ToUTF8(options.title).c_str(),
|
||||||
base::UTF16ToUTF8(options.msg).c_str(),
|
base::UTF16ToUTF8(options.msg).c_str(), nullptr);
|
||||||
nullptr);
|
|
||||||
|
|
||||||
g_signal_connect(
|
g_signal_connect(notification_, "closed",
|
||||||
notification_, "closed", G_CALLBACK(OnNotificationClosedThunk), this);
|
G_CALLBACK(OnNotificationClosedThunk), this);
|
||||||
|
|
||||||
// NB: On Unity and on any other DE using Notify-OSD, adding a notification
|
// NB: On Unity and on any other DE using Notify-OSD, adding a notification
|
||||||
// action will cause the notification to display as a modal dialog box.
|
// action will cause the notification to display as a modal dialog box.
|
||||||
|
@ -106,10 +102,10 @@ void LibnotifyNotification::Show(const NotificationOptions& options) {
|
||||||
|
|
||||||
if (!options.icon.drawsNothing()) {
|
if (!options.icon.drawsNothing()) {
|
||||||
GdkPixbuf* pixbuf = libgtkui::GdkPixbufFromSkBitmap(options.icon);
|
GdkPixbuf* pixbuf = libgtkui::GdkPixbufFromSkBitmap(options.icon);
|
||||||
libnotify_loader_.notify_notification_set_image_from_pixbuf(
|
libnotify_loader_.notify_notification_set_image_from_pixbuf(notification_,
|
||||||
notification_, pixbuf);
|
pixbuf);
|
||||||
libnotify_loader_.notify_notification_set_timeout(
|
libnotify_loader_.notify_notification_set_timeout(notification_,
|
||||||
notification_, NOTIFY_EXPIRES_DEFAULT);
|
NOTIFY_EXPIRES_DEFAULT);
|
||||||
g_object_unref(pixbuf);
|
g_object_unref(pixbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,8 +117,8 @@ void LibnotifyNotification::Show(const NotificationOptions& options) {
|
||||||
// Always try to append notifications.
|
// Always try to append notifications.
|
||||||
// Unique tags can be used to prevent this.
|
// Unique tags can be used to prevent this.
|
||||||
if (HasCapability("append")) {
|
if (HasCapability("append")) {
|
||||||
libnotify_loader_.notify_notification_set_hint_string(
|
libnotify_loader_.notify_notification_set_hint_string(notification_,
|
||||||
notification_, "append", "true");
|
"append", "true");
|
||||||
} else if (HasCapability("x-canonical-append")) {
|
} else if (HasCapability("x-canonical-append")) {
|
||||||
libnotify_loader_.notify_notification_set_hint_string(
|
libnotify_loader_.notify_notification_set_hint_string(
|
||||||
notification_, "x-canonical-append", "true");
|
notification_, "x-canonical-append", "true");
|
||||||
|
@ -172,8 +168,8 @@ void LibnotifyNotification::OnNotificationClosed(
|
||||||
NotificationDismissed();
|
NotificationDismissed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibnotifyNotification::OnNotificationView(
|
void LibnotifyNotification::OnNotificationView(NotifyNotification* notification,
|
||||||
NotifyNotification* notification, char* action) {
|
char* action) {
|
||||||
NotificationClicked();
|
NotificationClicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,15 @@ class LibnotifyNotification : public Notification {
|
||||||
void Dismiss() override;
|
void Dismiss() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CHROMEG_CALLBACK_0(LibnotifyNotification, void, OnNotificationClosed,
|
CHROMEG_CALLBACK_0(LibnotifyNotification,
|
||||||
|
void,
|
||||||
|
OnNotificationClosed,
|
||||||
NotifyNotification*);
|
NotifyNotification*);
|
||||||
CHROMEG_CALLBACK_1(LibnotifyNotification, void, OnNotificationView,
|
CHROMEG_CALLBACK_1(LibnotifyNotification,
|
||||||
NotifyNotification*, char*);
|
void,
|
||||||
|
OnNotificationView,
|
||||||
|
NotifyNotification*,
|
||||||
|
char*);
|
||||||
|
|
||||||
NotifyNotification* notification_;
|
NotifyNotification* notification_;
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,9 @@ NotificationPresenter* NotificationPresenter::Create() {
|
||||||
return new NotificationPresenterLinux;
|
return new NotificationPresenterLinux;
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationPresenterLinux::NotificationPresenterLinux() {
|
NotificationPresenterLinux::NotificationPresenterLinux() {}
|
||||||
}
|
|
||||||
|
|
||||||
NotificationPresenterLinux::~NotificationPresenterLinux() {
|
NotificationPresenterLinux::~NotificationPresenterLinux() {}
|
||||||
}
|
|
||||||
|
|
||||||
Notification* NotificationPresenterLinux::CreateNotificationObject(
|
Notification* NotificationPresenterLinux::CreateNotificationObject(
|
||||||
NotificationDelegate* delegate) {
|
NotificationDelegate* delegate) {
|
||||||
|
|
|
@ -10,8 +10,8 @@ class InspectableWebContentsViewMac;
|
||||||
|
|
||||||
using brightray::InspectableWebContentsViewMac;
|
using brightray::InspectableWebContentsViewMac;
|
||||||
|
|
||||||
@interface BRYInspectableWebContentsView : BaseView<NSWindowDelegate> {
|
@interface BRYInspectableWebContentsView : BaseView <NSWindowDelegate> {
|
||||||
@private
|
@private
|
||||||
brightray::InspectableWebContentsViewMac* inspectableWebContentsView_;
|
brightray::InspectableWebContentsViewMac* inspectableWebContentsView_;
|
||||||
|
|
||||||
base::scoped_nsobject<NSWindow> devtools_window_;
|
base::scoped_nsobject<NSWindow> devtools_window_;
|
||||||
|
@ -22,14 +22,16 @@ using brightray::InspectableWebContentsViewMac;
|
||||||
DevToolsContentsResizingStrategy strategy_;
|
DevToolsContentsResizingStrategy strategy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view;
|
- (instancetype)initWithInspectableWebContentsViewMac:
|
||||||
|
(InspectableWebContentsViewMac*)view;
|
||||||
- (void)removeObservers;
|
- (void)removeObservers;
|
||||||
- (void)notifyDevToolsFocused;
|
- (void)notifyDevToolsFocused;
|
||||||
- (void)setDevToolsVisible:(BOOL)visible;
|
- (void)setDevToolsVisible:(BOOL)visible;
|
||||||
- (BOOL)isDevToolsVisible;
|
- (BOOL)isDevToolsVisible;
|
||||||
- (BOOL)isDevToolsFocused;
|
- (BOOL)isDevToolsFocused;
|
||||||
- (void)setIsDocked:(BOOL)docked;
|
- (void)setIsDocked:(BOOL)docked;
|
||||||
- (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy;
|
- (void)setContentsResizingStrategy:
|
||||||
|
(const DevToolsContentsResizingStrategy&)strategy;
|
||||||
- (void)setTitle:(NSString*)title;
|
- (void)setTitle:(NSString*)title;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -11,12 +11,13 @@ namespace brightray {
|
||||||
class NotificationPresenterMac;
|
class NotificationPresenterMac;
|
||||||
}
|
}
|
||||||
|
|
||||||
@interface NotificationCenterDelegate :
|
@interface NotificationCenterDelegate
|
||||||
NSObject<NSUserNotificationCenterDelegate> {
|
: NSObject <NSUserNotificationCenterDelegate> {
|
||||||
@private
|
@private
|
||||||
brightray::NotificationPresenterMac* presenter_;
|
brightray::NotificationPresenterMac* presenter_;
|
||||||
}
|
}
|
||||||
- (instancetype)initWithPresenter:(brightray::NotificationPresenterMac*)presenter;
|
- (instancetype)initWithPresenter:
|
||||||
|
(brightray::NotificationPresenterMac*)presenter;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif // BROWSER_MAC_NOTIFICATION_DELEGATE_H_
|
#endif // BROWSER_MAC_NOTIFICATION_DELEGATE_H_
|
||||||
|
|
|
@ -127,11 +127,9 @@ void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() {
|
||||||
is_device_enumeration_disabled_ = true;
|
is_device_enumeration_disabled_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() {
|
void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() {}
|
||||||
}
|
|
||||||
|
|
||||||
void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() {
|
void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() {}
|
||||||
}
|
|
||||||
|
|
||||||
void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
|
void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
|
||||||
int render_process_id,
|
int render_process_id,
|
||||||
|
@ -139,20 +137,16 @@ void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
|
||||||
int page_request_id,
|
int page_request_id,
|
||||||
const GURL& security_origin,
|
const GURL& security_origin,
|
||||||
content::MediaStreamType stream_type,
|
content::MediaStreamType stream_type,
|
||||||
content::MediaRequestState state) {
|
content::MediaRequestState state) {}
|
||||||
}
|
|
||||||
|
|
||||||
void MediaCaptureDevicesDispatcher::OnCreatingAudioStream(
|
void MediaCaptureDevicesDispatcher::OnCreatingAudioStream(int render_process_id,
|
||||||
int render_process_id,
|
int render_view_id) {}
|
||||||
int render_view_id) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void MediaCaptureDevicesDispatcher::OnSetCapturingLinkSecured(
|
void MediaCaptureDevicesDispatcher::OnSetCapturingLinkSecured(
|
||||||
int render_process_id,
|
int render_process_id,
|
||||||
int render_frame_id,
|
int render_frame_id,
|
||||||
int page_request_id,
|
int page_request_id,
|
||||||
content::MediaStreamType stream_type,
|
content::MediaStreamType stream_type,
|
||||||
bool is_secure) {
|
bool is_secure) {}
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -34,10 +34,10 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver {
|
||||||
|
|
||||||
// Helpers for picking particular requested devices, identified by raw id.
|
// Helpers for picking particular requested devices, identified by raw id.
|
||||||
// If the device requested is not available it will return NULL.
|
// If the device requested is not available it will return NULL.
|
||||||
const content::MediaStreamDevice*
|
const content::MediaStreamDevice* GetRequestedAudioDevice(
|
||||||
GetRequestedAudioDevice(const std::string& requested_audio_device_id);
|
const std::string& requested_audio_device_id);
|
||||||
const content::MediaStreamDevice*
|
const content::MediaStreamDevice* GetRequestedVideoDevice(
|
||||||
GetRequestedVideoDevice(const std::string& requested_video_device_id);
|
const std::string& requested_video_device_id);
|
||||||
|
|
||||||
// Returns the first available audio or video device, or NULL if no devices
|
// Returns the first available audio or video device, or NULL if no devices
|
||||||
// are available.
|
// are available.
|
||||||
|
@ -52,13 +52,12 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver {
|
||||||
// Overridden from content::MediaObserver:
|
// Overridden from content::MediaObserver:
|
||||||
void OnAudioCaptureDevicesChanged() override;
|
void OnAudioCaptureDevicesChanged() override;
|
||||||
void OnVideoCaptureDevicesChanged() override;
|
void OnVideoCaptureDevicesChanged() override;
|
||||||
void OnMediaRequestStateChanged(
|
void OnMediaRequestStateChanged(int render_process_id,
|
||||||
int render_process_id,
|
int render_view_id,
|
||||||
int render_view_id,
|
int page_request_id,
|
||||||
int page_request_id,
|
const GURL& security_origin,
|
||||||
const GURL& security_origin,
|
content::MediaStreamType stream_type,
|
||||||
content::MediaStreamType stream_type,
|
content::MediaRequestState state) override;
|
||||||
content::MediaRequestState state) override;
|
|
||||||
void OnCreatingAudioStream(int render_process_id,
|
void OnCreatingAudioStream(int render_process_id,
|
||||||
int render_view_id) override;
|
int render_view_id) override;
|
||||||
void OnSetCapturingLinkSecured(int render_process_id,
|
void OnSetCapturingLinkSecured(int render_process_id,
|
||||||
|
|
|
@ -35,8 +35,7 @@ MediaStreamDevicesController::MediaStreamDevicesController(
|
||||||
request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY),
|
request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY),
|
||||||
webcam_requested_(
|
webcam_requested_(
|
||||||
request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE ||
|
request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE ||
|
||||||
request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {
|
request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) {}
|
||||||
}
|
|
||||||
|
|
||||||
MediaStreamDevicesController::~MediaStreamDevicesController() {
|
MediaStreamDevicesController::~MediaStreamDevicesController() {
|
||||||
if (!callback_.is_null()) {
|
if (!callback_.is_null()) {
|
||||||
|
@ -76,35 +75,38 @@ void MediaStreamDevicesController::Accept() {
|
||||||
// For open device request pick the desired device or fall back to the
|
// For open device request pick the desired device or fall back to the
|
||||||
// first available of the given type.
|
// first available of the given type.
|
||||||
if (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
|
if (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
|
||||||
device = MediaCaptureDevicesDispatcher::GetInstance()->
|
device =
|
||||||
GetRequestedAudioDevice(request_.requested_audio_device_id);
|
MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
|
->GetRequestedAudioDevice(request_.requested_audio_device_id);
|
||||||
// TODO(wjia): Confirm this is the intended behavior.
|
// TODO(wjia): Confirm this is the intended behavior.
|
||||||
if (!device) {
|
if (!device) {
|
||||||
device = MediaCaptureDevicesDispatcher::GetInstance()->
|
device = MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
GetFirstAvailableAudioDevice();
|
->GetFirstAvailableAudioDevice();
|
||||||
}
|
}
|
||||||
} else if (request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
|
} else if (request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
|
||||||
// Pepper API opens only one device at a time.
|
// Pepper API opens only one device at a time.
|
||||||
device = MediaCaptureDevicesDispatcher::GetInstance()->
|
device =
|
||||||
GetRequestedVideoDevice(request_.requested_video_device_id);
|
MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
|
->GetRequestedVideoDevice(request_.requested_video_device_id);
|
||||||
// TODO(wjia): Confirm this is the intended behavior.
|
// TODO(wjia): Confirm this is the intended behavior.
|
||||||
if (!device) {
|
if (!device) {
|
||||||
device = MediaCaptureDevicesDispatcher::GetInstance()->
|
device = MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
GetFirstAvailableVideoDevice();
|
->GetFirstAvailableVideoDevice();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (device)
|
if (device)
|
||||||
devices.push_back(*device);
|
devices.push_back(*device);
|
||||||
break;
|
break;
|
||||||
} case content::MEDIA_GENERATE_STREAM: {
|
}
|
||||||
|
case content::MEDIA_GENERATE_STREAM: {
|
||||||
bool needs_audio_device = microphone_requested_;
|
bool needs_audio_device = microphone_requested_;
|
||||||
bool needs_video_device = webcam_requested_;
|
bool needs_video_device = webcam_requested_;
|
||||||
|
|
||||||
// Get the exact audio or video device if an id is specified.
|
// Get the exact audio or video device if an id is specified.
|
||||||
if (!request_.requested_audio_device_id.empty()) {
|
if (!request_.requested_audio_device_id.empty()) {
|
||||||
const content::MediaStreamDevice* audio_device =
|
const content::MediaStreamDevice* audio_device =
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()->
|
MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
GetRequestedAudioDevice(request_.requested_audio_device_id);
|
->GetRequestedAudioDevice(request_.requested_audio_device_id);
|
||||||
if (audio_device) {
|
if (audio_device) {
|
||||||
devices.push_back(*audio_device);
|
devices.push_back(*audio_device);
|
||||||
needs_audio_device = false;
|
needs_audio_device = false;
|
||||||
|
@ -112,8 +114,8 @@ void MediaStreamDevicesController::Accept() {
|
||||||
}
|
}
|
||||||
if (!request_.requested_video_device_id.empty()) {
|
if (!request_.requested_video_device_id.empty()) {
|
||||||
const content::MediaStreamDevice* video_device =
|
const content::MediaStreamDevice* video_device =
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()->
|
MediaCaptureDevicesDispatcher::GetInstance()
|
||||||
GetRequestedVideoDevice(request_.requested_video_device_id);
|
->GetRequestedVideoDevice(request_.requested_video_device_id);
|
||||||
if (video_device) {
|
if (video_device) {
|
||||||
devices.push_back(*video_device);
|
devices.push_back(*video_device);
|
||||||
needs_video_device = false;
|
needs_video_device = false;
|
||||||
|
@ -123,18 +125,15 @@ void MediaStreamDevicesController::Accept() {
|
||||||
// If either or both audio and video devices were requested but not
|
// If either or both audio and video devices were requested but not
|
||||||
// specified by id, get the default devices.
|
// specified by id, get the default devices.
|
||||||
if (needs_audio_device || needs_video_device) {
|
if (needs_audio_device || needs_video_device) {
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()->
|
MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevices(
|
||||||
GetDefaultDevices(needs_audio_device,
|
needs_audio_device, needs_video_device, &devices);
|
||||||
needs_video_device,
|
|
||||||
&devices);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} case content::MEDIA_DEVICE_ACCESS:
|
}
|
||||||
|
case content::MEDIA_DEVICE_ACCESS:
|
||||||
// Get the default devices for the request.
|
// Get the default devices for the request.
|
||||||
MediaCaptureDevicesDispatcher::GetInstance()->
|
MediaCaptureDevicesDispatcher::GetInstance()->GetDefaultDevices(
|
||||||
GetDefaultDevices(microphone_requested_,
|
microphone_requested_, webcam_requested_, &devices);
|
||||||
webcam_requested_,
|
|
||||||
&devices);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,8 +148,7 @@ void MediaStreamDevicesController::Deny(
|
||||||
content::MediaStreamRequestResult result) {
|
content::MediaStreamRequestResult result) {
|
||||||
content::MediaResponseCallback cb = callback_;
|
content::MediaResponseCallback cb = callback_;
|
||||||
callback_.Reset();
|
callback_.Reset();
|
||||||
cb.Run(content::MediaStreamDevices(),
|
cb.Run(content::MediaStreamDevices(), result,
|
||||||
result,
|
|
||||||
std::unique_ptr<content::MediaStreamUI>());
|
std::unique_ptr<content::MediaStreamUI>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,12 +156,12 @@ void MediaStreamDevicesController::HandleUserMediaRequest() {
|
||||||
content::MediaStreamDevices devices;
|
content::MediaStreamDevices devices;
|
||||||
|
|
||||||
if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE) {
|
if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE) {
|
||||||
devices.push_back(content::MediaStreamDevice(
|
devices.push_back(
|
||||||
content::MEDIA_TAB_AUDIO_CAPTURE, "", ""));
|
content::MediaStreamDevice(content::MEDIA_TAB_AUDIO_CAPTURE, "", ""));
|
||||||
}
|
}
|
||||||
if (request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) {
|
if (request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) {
|
||||||
devices.push_back(content::MediaStreamDevice(
|
devices.push_back(
|
||||||
content::MEDIA_TAB_VIDEO_CAPTURE, "", ""));
|
content::MediaStreamDevice(content::MEDIA_TAB_VIDEO_CAPTURE, "", ""));
|
||||||
}
|
}
|
||||||
if (request_.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE) {
|
if (request_.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE) {
|
||||||
devices.push_back(content::MediaStreamDevice(
|
devices.push_back(content::MediaStreamDevice(
|
||||||
|
@ -175,22 +173,21 @@ void MediaStreamDevicesController::HandleUserMediaRequest() {
|
||||||
// (i.e. chooseDesktopMedia() API wasn't used to generate device id).
|
// (i.e. chooseDesktopMedia() API wasn't used to generate device id).
|
||||||
if (request_.requested_video_device_id.empty()) {
|
if (request_.requested_video_device_id.empty()) {
|
||||||
screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN,
|
screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN,
|
||||||
-1 /* kFullDesktopScreenId */);
|
-1 /* kFullDesktopScreenId */);
|
||||||
} else {
|
} else {
|
||||||
screen_id =
|
screen_id =
|
||||||
content::DesktopMediaID::Parse(request_.requested_video_device_id);
|
content::DesktopMediaID::Parse(request_.requested_video_device_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
devices.push_back(
|
devices.push_back(content::MediaStreamDevice(
|
||||||
content::MediaStreamDevice(content::MEDIA_DESKTOP_VIDEO_CAPTURE,
|
content::MEDIA_DESKTOP_VIDEO_CAPTURE, screen_id.ToString(), "Screen"));
|
||||||
screen_id.ToString(), "Screen"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
content::MediaResponseCallback cb = callback_;
|
content::MediaResponseCallback cb = callback_;
|
||||||
callback_.Reset();
|
callback_.Reset();
|
||||||
cb.Run(devices,
|
cb.Run(devices,
|
||||||
devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE :
|
devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE
|
||||||
content::MEDIA_DEVICE_OK,
|
: content::MEDIA_DEVICE_OK,
|
||||||
std::unique_ptr<content::MediaStreamUI>());
|
std::unique_ptr<content::MediaStreamUI>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,7 @@ std::unique_ptr<base::DictionaryValue> GetConstants() {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
NetLog::NetLog() {
|
NetLog::NetLog() {}
|
||||||
}
|
|
||||||
|
|
||||||
NetLog::~NetLog() {
|
NetLog::~NetLog() {
|
||||||
if (file_net_log_observer_) {
|
if (file_net_log_observer_) {
|
||||||
|
|
|
@ -32,13 +32,11 @@ NetworkDelegate::NetworkDelegate() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkDelegate::~NetworkDelegate() {
|
NetworkDelegate::~NetworkDelegate() {}
|
||||||
}
|
|
||||||
|
|
||||||
int NetworkDelegate::OnBeforeURLRequest(
|
int NetworkDelegate::OnBeforeURLRequest(net::URLRequest* request,
|
||||||
net::URLRequest* request,
|
const net::CompletionCallback& callback,
|
||||||
const net::CompletionCallback& callback,
|
GURL* new_url) {
|
||||||
GURL* new_url) {
|
|
||||||
for (const auto& domain : ignore_connections_limit_domains_) {
|
for (const auto& domain : ignore_connections_limit_domains_) {
|
||||||
if (request->url().DomainIs(domain)) {
|
if (request->url().DomainIs(domain)) {
|
||||||
// Allow unlimited concurrent connections.
|
// Allow unlimited concurrent connections.
|
||||||
|
@ -60,15 +58,13 @@ int NetworkDelegate::OnBeforeStartTransaction(
|
||||||
|
|
||||||
void NetworkDelegate::OnStartTransaction(
|
void NetworkDelegate::OnStartTransaction(
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
const net::HttpRequestHeaders& headers) {
|
const net::HttpRequestHeaders& headers) {}
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnBeforeSendHeaders(
|
void NetworkDelegate::OnBeforeSendHeaders(
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
const net::ProxyInfo& proxy_info,
|
const net::ProxyInfo& proxy_info,
|
||||||
const net::ProxyRetryInfoMap& proxy_retry_info,
|
const net::ProxyRetryInfoMap& proxy_retry_info,
|
||||||
net::HttpRequestHeaders* headers) {
|
net::HttpRequestHeaders* headers) {}
|
||||||
}
|
|
||||||
|
|
||||||
int NetworkDelegate::OnHeadersReceived(
|
int NetworkDelegate::OnHeadersReceived(
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
|
@ -80,29 +76,22 @@ int NetworkDelegate::OnHeadersReceived(
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
|
void NetworkDelegate::OnBeforeRedirect(net::URLRequest* request,
|
||||||
const GURL& new_location) {
|
const GURL& new_location) {}
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnResponseStarted(net::URLRequest* request) {
|
void NetworkDelegate::OnResponseStarted(net::URLRequest* request) {}
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request,
|
void NetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request,
|
||||||
int64_t bytes_read) {
|
int64_t bytes_read) {}
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnNetworkBytesSent(net::URLRequest* request,
|
void NetworkDelegate::OnNetworkBytesSent(net::URLRequest* request,
|
||||||
int64_t bytes_sent) {
|
int64_t bytes_sent) {}
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {
|
void NetworkDelegate::OnCompleted(net::URLRequest* request, bool started) {}
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
|
void NetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {}
|
||||||
}
|
|
||||||
|
|
||||||
void NetworkDelegate::OnPACScriptError(int line_number,
|
void NetworkDelegate::OnPACScriptError(int line_number,
|
||||||
const base::string16& error) {
|
const base::string16& error) {}
|
||||||
}
|
|
||||||
|
|
||||||
NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired(
|
NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired(
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
|
@ -113,13 +102,13 @@ NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired(
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
|
bool NetworkDelegate::OnCanGetCookies(const net::URLRequest& request,
|
||||||
const net::CookieList& cookie_list) {
|
const net::CookieList& cookie_list) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
|
bool NetworkDelegate::OnCanSetCookie(const net::URLRequest& request,
|
||||||
const std::string& cookie_line,
|
const std::string& cookie_line,
|
||||||
net::CookieOptions* options) {
|
net::CookieOptions* options) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,15 +148,13 @@ bool NetworkDelegate::OnCanSendReportingReport(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkDelegate::OnCanSetReportingClient(
|
bool NetworkDelegate::OnCanSetReportingClient(const url::Origin& origin,
|
||||||
const url::Origin& origin,
|
const GURL& endpoint) const {
|
||||||
const GURL& endpoint) const {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NetworkDelegate::OnCanUseReportingClient(
|
bool NetworkDelegate::OnCanUseReportingClient(const url::Origin& origin,
|
||||||
const url::Origin& origin,
|
const GURL& endpoint) const {
|
||||||
const GURL& endpoint) const {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,7 @@ class NetworkDelegate : public net::NetworkDelegate {
|
||||||
int64_t bytes_sent) override;
|
int64_t bytes_sent) override;
|
||||||
void OnCompleted(net::URLRequest* request, bool started) override;
|
void OnCompleted(net::URLRequest* request, bool started) override;
|
||||||
void OnURLRequestDestroyed(net::URLRequest* request) override;
|
void OnURLRequestDestroyed(net::URLRequest* request) override;
|
||||||
void OnPACScriptError(int line_number,
|
void OnPACScriptError(int line_number, const base::string16& error) override;
|
||||||
const base::string16& error) override;
|
|
||||||
AuthRequiredResponse OnAuthRequired(
|
AuthRequiredResponse OnAuthRequired(
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
const net::AuthChallengeInfo& auth_info,
|
const net::AuthChallengeInfo& auth_info,
|
||||||
|
|
|
@ -11,10 +11,7 @@ namespace brightray {
|
||||||
|
|
||||||
Notification::Notification(NotificationDelegate* delegate,
|
Notification::Notification(NotificationDelegate* delegate,
|
||||||
NotificationPresenter* presenter)
|
NotificationPresenter* presenter)
|
||||||
: delegate_(delegate),
|
: delegate_(delegate), presenter_(presenter), weak_factory_(this) {}
|
||||||
presenter_(presenter),
|
|
||||||
weak_factory_(this) {
|
|
||||||
}
|
|
||||||
|
|
||||||
Notification::~Notification() {
|
Notification::~Notification() {
|
||||||
if (delegate())
|
if (delegate())
|
||||||
|
|
|
@ -8,8 +8,7 @@
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
NotificationPresenter::NotificationPresenter() {
|
NotificationPresenter::NotificationPresenter() {}
|
||||||
}
|
|
||||||
|
|
||||||
NotificationPresenter::~NotificationPresenter() {
|
NotificationPresenter::~NotificationPresenter() {
|
||||||
for (Notification* notification : notifications_)
|
for (Notification* notification : notifications_)
|
||||||
|
|
|
@ -12,11 +12,9 @@
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
PermissionManager::PermissionManager() {
|
PermissionManager::PermissionManager() {}
|
||||||
}
|
|
||||||
|
|
||||||
PermissionManager::~PermissionManager() {
|
PermissionManager::~PermissionManager() {}
|
||||||
}
|
|
||||||
|
|
||||||
int PermissionManager::RequestPermission(
|
int PermissionManager::RequestPermission(
|
||||||
content::PermissionType permission,
|
content::PermissionType permission,
|
||||||
|
@ -25,8 +23,8 @@ int PermissionManager::RequestPermission(
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
const base::Callback<void(blink::mojom::PermissionStatus)>& callback) {
|
const base::Callback<void(blink::mojom::PermissionStatus)>& callback) {
|
||||||
if (permission == content::PermissionType::MIDI_SYSEX) {
|
if (permission == content::PermissionType::MIDI_SYSEX) {
|
||||||
content::ChildProcessSecurityPolicy::GetInstance()->
|
content::ChildProcessSecurityPolicy::GetInstance()
|
||||||
GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID());
|
->GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID());
|
||||||
}
|
}
|
||||||
callback.Run(blink::mojom::PermissionStatus::GRANTED);
|
callback.Run(blink::mojom::PermissionStatus::GRANTED);
|
||||||
return kNoPendingOperation;
|
return kNoPendingOperation;
|
||||||
|
@ -37,14 +35,14 @@ int PermissionManager::RequestPermissions(
|
||||||
content::RenderFrameHost* render_frame_host,
|
content::RenderFrameHost* render_frame_host,
|
||||||
const GURL& requesting_origin,
|
const GURL& requesting_origin,
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
const base::Callback<void(
|
const base::Callback<
|
||||||
const std::vector<blink::mojom::PermissionStatus>&)>& callback) {
|
void(const std::vector<blink::mojom::PermissionStatus>&)>& callback) {
|
||||||
std::vector<blink::mojom::PermissionStatus> permissionStatuses;
|
std::vector<blink::mojom::PermissionStatus> permissionStatuses;
|
||||||
|
|
||||||
for (auto permission : permissions) {
|
for (auto permission : permissions) {
|
||||||
if (permission == content::PermissionType::MIDI_SYSEX) {
|
if (permission == content::PermissionType::MIDI_SYSEX) {
|
||||||
content::ChildProcessSecurityPolicy::GetInstance()->
|
content::ChildProcessSecurityPolicy::GetInstance()
|
||||||
GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID());
|
->GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID());
|
||||||
}
|
}
|
||||||
|
|
||||||
permissionStatuses.push_back(blink::mojom::PermissionStatus::GRANTED);
|
permissionStatuses.push_back(blink::mojom::PermissionStatus::GRANTED);
|
||||||
|
@ -54,14 +52,11 @@ int PermissionManager::RequestPermissions(
|
||||||
return kNoPendingOperation;
|
return kNoPendingOperation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PermissionManager::CancelPermissionRequest(int request_id) {
|
void PermissionManager::CancelPermissionRequest(int request_id) {}
|
||||||
}
|
|
||||||
|
|
||||||
void PermissionManager::ResetPermission(
|
void PermissionManager::ResetPermission(content::PermissionType permission,
|
||||||
content::PermissionType permission,
|
const GURL& requesting_origin,
|
||||||
const GURL& requesting_origin,
|
const GURL& embedding_origin) {}
|
||||||
const GURL& embedding_origin) {
|
|
||||||
}
|
|
||||||
|
|
||||||
blink::mojom::PermissionStatus PermissionManager::GetPermissionStatus(
|
blink::mojom::PermissionStatus PermissionManager::GetPermissionStatus(
|
||||||
content::PermissionType permission,
|
content::PermissionType permission,
|
||||||
|
|
|
@ -77,9 +77,7 @@ class NotificationDelegateImpl final : public brightray::NotificationDelegate {
|
||||||
|
|
||||||
PlatformNotificationService::PlatformNotificationService(
|
PlatformNotificationService::PlatformNotificationService(
|
||||||
BrowserClient* browser_client)
|
BrowserClient* browser_client)
|
||||||
: browser_client_(browser_client),
|
: browser_client_(browser_client), render_process_id_(-1) {}
|
||||||
render_process_id_(-1) {
|
|
||||||
}
|
|
||||||
|
|
||||||
PlatformNotificationService::~PlatformNotificationService() {}
|
PlatformNotificationService::~PlatformNotificationService() {}
|
||||||
|
|
||||||
|
@ -128,17 +126,14 @@ void PlatformNotificationService::DisplayPersistentNotification(
|
||||||
const GURL& service_worker_scope,
|
const GURL& service_worker_scope,
|
||||||
const GURL& origin,
|
const GURL& origin,
|
||||||
const content::PlatformNotificationData& notification_data,
|
const content::PlatformNotificationData& notification_data,
|
||||||
const content::NotificationResources& notification_resources) {
|
const content::NotificationResources& notification_resources) {}
|
||||||
}
|
|
||||||
|
|
||||||
void PlatformNotificationService::ClosePersistentNotification(
|
void PlatformNotificationService::ClosePersistentNotification(
|
||||||
content::BrowserContext* browser_context,
|
content::BrowserContext* browser_context,
|
||||||
const std::string& notification_id) {
|
const std::string& notification_id) {}
|
||||||
}
|
|
||||||
|
|
||||||
void PlatformNotificationService::GetDisplayedNotifications(
|
void PlatformNotificationService::GetDisplayedNotifications(
|
||||||
content::BrowserContext* browser_context,
|
content::BrowserContext* browser_context,
|
||||||
const DisplayedNotificationsCallback& callback) {
|
const DisplayedNotificationsCallback& callback) {}
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -6,11 +6,9 @@
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
SpecialStoragePolicy::SpecialStoragePolicy() {
|
SpecialStoragePolicy::SpecialStoragePolicy() {}
|
||||||
}
|
|
||||||
|
|
||||||
SpecialStoragePolicy::~SpecialStoragePolicy() {
|
SpecialStoragePolicy::~SpecialStoragePolicy() {}
|
||||||
}
|
|
||||||
|
|
||||||
bool SpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
|
bool SpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -67,8 +67,8 @@ URLRequestContextGetter::Delegate::CreateURLRequestJobFactory(
|
||||||
new net::URLRequestJobFactoryImpl);
|
new net::URLRequestJobFactoryImpl);
|
||||||
|
|
||||||
for (auto& it : *protocol_handlers) {
|
for (auto& it : *protocol_handlers) {
|
||||||
job_factory->SetProtocolHandler(
|
job_factory->SetProtocolHandler(it.first,
|
||||||
it.first, base::WrapUnique(it.second.release()));
|
base::WrapUnique(it.second.release()));
|
||||||
}
|
}
|
||||||
protocol_handlers->clear();
|
protocol_handlers->clear();
|
||||||
|
|
||||||
|
@ -94,10 +94,7 @@ URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(
|
||||||
|
|
||||||
base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache"));
|
base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache"));
|
||||||
return new net::HttpCache::DefaultBackend(
|
return new net::HttpCache::DefaultBackend(
|
||||||
net::DISK_CACHE,
|
net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, cache_path, max_size);
|
||||||
net::CACHE_BACKEND_DEFAULT,
|
|
||||||
cache_path,
|
|
||||||
max_size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<net::CertVerifier>
|
std::unique_ptr<net::CertVerifier>
|
||||||
|
@ -113,7 +110,7 @@ URLRequestContextGetter::Delegate::CreateSSLConfigService() {
|
||||||
|
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
URLRequestContextGetter::Delegate::GetCookieableSchemes() {
|
URLRequestContextGetter::Delegate::GetCookieableSchemes() {
|
||||||
return { "http", "https", "ws", "wss" };
|
return {"http", "https", "ws", "wss"};
|
||||||
}
|
}
|
||||||
|
|
||||||
URLRequestContextGetter::URLRequestContextGetter(
|
URLRequestContextGetter::URLRequestContextGetter(
|
||||||
|
@ -144,12 +141,11 @@ URLRequestContextGetter::URLRequestContextGetter(
|
||||||
// We must create the proxy config service on the UI loop on Linux because it
|
// We must create the proxy config service on the UI loop on Linux because it
|
||||||
// must synchronously run on the glib message loop. This will be passed to
|
// must synchronously run on the glib message loop. This will be passed to
|
||||||
// the URLRequestContextStorage on the IO thread in GetURLRequestContext().
|
// the URLRequestContextStorage on the IO thread in GetURLRequestContext().
|
||||||
proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService(
|
proxy_config_service_ =
|
||||||
io_task_runner_);
|
net::ProxyService::CreateSystemProxyConfigService(io_task_runner_);
|
||||||
}
|
}
|
||||||
|
|
||||||
URLRequestContextGetter::~URLRequestContextGetter() {
|
URLRequestContextGetter::~URLRequestContextGetter() {}
|
||||||
}
|
|
||||||
|
|
||||||
void URLRequestContextGetter::NotifyContextShutdownOnIO() {
|
void URLRequestContextGetter::NotifyContextShutdownOnIO() {
|
||||||
context_shutting_down_ = true;
|
context_shutting_down_ = true;
|
||||||
|
@ -204,11 +200,11 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
||||||
|
|
||||||
storage_->set_network_delegate(delegate_->CreateNetworkDelegate());
|
storage_->set_network_delegate(delegate_->CreateNetworkDelegate());
|
||||||
|
|
||||||
auto cookie_path = in_memory_ ?
|
auto cookie_path = in_memory_
|
||||||
base::FilePath() : base_path_.Append(FILE_PATH_LITERAL("Cookies"));
|
? base::FilePath()
|
||||||
|
: base_path_.Append(FILE_PATH_LITERAL("Cookies"));
|
||||||
auto cookie_config = content::CookieStoreConfig(
|
auto cookie_config = content::CookieStoreConfig(
|
||||||
cookie_path,
|
cookie_path, content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
|
||||||
content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES,
|
|
||||||
nullptr);
|
nullptr);
|
||||||
cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes();
|
cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes();
|
||||||
std::unique_ptr<net::CookieStore> cookie_store =
|
std::unique_ptr<net::CookieStore> cookie_store =
|
||||||
|
@ -255,13 +251,11 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
||||||
auto proxy_config = net::ProxyConfig::CreateFromCustomPacURL(
|
auto proxy_config = net::ProxyConfig::CreateFromCustomPacURL(
|
||||||
GURL(command_line.GetSwitchValueASCII(switches::kProxyPacUrl)));
|
GURL(command_line.GetSwitchValueASCII(switches::kProxyPacUrl)));
|
||||||
proxy_config.set_pac_mandatory(true);
|
proxy_config.set_pac_mandatory(true);
|
||||||
storage_->set_proxy_service(net::ProxyService::CreateFixed(
|
storage_->set_proxy_service(net::ProxyService::CreateFixed(proxy_config));
|
||||||
proxy_config));
|
|
||||||
} else {
|
} else {
|
||||||
storage_->set_proxy_service(
|
storage_->set_proxy_service(
|
||||||
net::ProxyService::CreateUsingSystemProxyResolver(
|
net::ProxyService::CreateUsingSystemProxyResolver(
|
||||||
std::move(proxy_config_service_),
|
std::move(proxy_config_service_), net_log_));
|
||||||
net_log_));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> schemes;
|
std::vector<std::string> schemes;
|
||||||
|
@ -270,8 +264,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
||||||
schemes.push_back(std::string("ntlm"));
|
schemes.push_back(std::string("ntlm"));
|
||||||
schemes.push_back(std::string("negotiate"));
|
schemes.push_back(std::string("negotiate"));
|
||||||
#if defined(OS_POSIX)
|
#if defined(OS_POSIX)
|
||||||
http_auth_preferences_.reset(new net::HttpAuthPreferences(schemes,
|
http_auth_preferences_.reset(
|
||||||
std::string()));
|
new net::HttpAuthPreferences(schemes, std::string()));
|
||||||
#else
|
#else
|
||||||
http_auth_preferences_.reset(new net::HttpAuthPreferences(schemes));
|
http_auth_preferences_.reset(new net::HttpAuthPreferences(schemes));
|
||||||
#endif
|
#endif
|
||||||
|
@ -289,9 +283,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
||||||
switches::kAuthNegotiateDelegateWhitelist));
|
switches::kAuthNegotiateDelegateWhitelist));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto auth_handler_factory =
|
auto auth_handler_factory = net::HttpAuthHandlerRegistryFactory::Create(
|
||||||
net::HttpAuthHandlerRegistryFactory::Create(
|
http_auth_preferences_.get(), host_resolver.get());
|
||||||
http_auth_preferences_.get(), host_resolver.get());
|
|
||||||
|
|
||||||
std::unique_ptr<net::TransportSecurityState> transport_security_state =
|
std::unique_ptr<net::TransportSecurityState> transport_security_state =
|
||||||
base::WrapUnique(new net::TransportSecurityState);
|
base::WrapUnique(new net::TransportSecurityState);
|
||||||
|
|
|
@ -34,7 +34,7 @@ class NetworkDelegate;
|
||||||
class ProxyConfigService;
|
class ProxyConfigService;
|
||||||
class URLRequestContextStorage;
|
class URLRequestContextStorage;
|
||||||
class URLRequestJobFactory;
|
class URLRequestJobFactory;
|
||||||
}
|
} // namespace net
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
|
|
@ -87,8 +87,8 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews(
|
||||||
inspectable_web_contents_->GetWebContents());
|
inspectable_web_contents_->GetWebContents());
|
||||||
contents_web_view_ = contents_web_view;
|
contents_web_view_ = contents_web_view;
|
||||||
} else {
|
} else {
|
||||||
contents_web_view_ = new views::Label(
|
contents_web_view_ =
|
||||||
base::ASCIIToUTF16("No content under offscreen mode"));
|
new views::Label(base::ASCIIToUTF16("No content under offscreen mode"));
|
||||||
}
|
}
|
||||||
|
|
||||||
devtools_web_view_->SetVisible(false);
|
devtools_web_view_->SetVisible(false);
|
||||||
|
@ -168,9 +168,7 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) {
|
||||||
devtools_window_.reset(new views::Widget);
|
devtools_window_.reset(new views::Widget);
|
||||||
devtools_window_web_view_ = new views::WebView(NULL);
|
devtools_window_web_view_ = new views::WebView(NULL);
|
||||||
devtools_window_delegate_ = new DevToolsWindowDelegate(
|
devtools_window_delegate_ = new DevToolsWindowDelegate(
|
||||||
this,
|
this, devtools_window_web_view_, devtools_window_.get());
|
||||||
devtools_window_web_view_,
|
|
||||||
devtools_window_.get());
|
|
||||||
|
|
||||||
views::Widget::InitParams params;
|
views::Widget::InitParams params;
|
||||||
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
||||||
|
@ -213,8 +211,8 @@ void InspectableWebContentsViewViews::Layout() {
|
||||||
gfx::Size container_size(width(), height());
|
gfx::Size container_size(width(), height());
|
||||||
gfx::Rect new_devtools_bounds;
|
gfx::Rect new_devtools_bounds;
|
||||||
gfx::Rect new_contents_bounds;
|
gfx::Rect new_contents_bounds;
|
||||||
ApplyDevToolsContentsResizingStrategy(strategy_, container_size,
|
ApplyDevToolsContentsResizingStrategy(
|
||||||
&new_devtools_bounds, &new_contents_bounds);
|
strategy_, container_size, &new_devtools_bounds, &new_contents_bounds);
|
||||||
|
|
||||||
// DevTools cares about the specific position, so we have to compensate RTL
|
// DevTools cares about the specific position, so we have to compensate RTL
|
||||||
// layout here.
|
// layout here.
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace views {
|
||||||
class WebView;
|
class WebView;
|
||||||
class Widget;
|
class Widget;
|
||||||
class WidgetDelegate;
|
class WidgetDelegate;
|
||||||
}
|
} // namespace views
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
|
|
@ -30,17 +30,14 @@ bool IsDesktopEnvironmentUnity() {
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
ViewsDelegate::ViewsDelegate() {
|
ViewsDelegate::ViewsDelegate() {}
|
||||||
}
|
|
||||||
|
|
||||||
ViewsDelegate::~ViewsDelegate() {
|
ViewsDelegate::~ViewsDelegate() {}
|
||||||
}
|
|
||||||
|
|
||||||
void ViewsDelegate::SaveWindowPlacement(const views::Widget* window,
|
void ViewsDelegate::SaveWindowPlacement(const views::Widget* window,
|
||||||
const std::string& window_name,
|
const std::string& window_name,
|
||||||
const gfx::Rect& bounds,
|
const gfx::Rect& bounds,
|
||||||
ui::WindowShowState show_state) {
|
ui::WindowShowState show_state) {}
|
||||||
}
|
|
||||||
|
|
||||||
bool ViewsDelegate::GetSavedWindowPlacement(
|
bool ViewsDelegate::GetSavedWindowPlacement(
|
||||||
const views::Widget* widget,
|
const views::Widget* widget,
|
||||||
|
@ -50,23 +47,20 @@ bool ViewsDelegate::GetSavedWindowPlacement(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewsDelegate::NotifyAccessibilityEvent(
|
void ViewsDelegate::NotifyAccessibilityEvent(views::View* view,
|
||||||
views::View* view, ui::AXEvent event_type) {
|
ui::AXEvent event_type) {}
|
||||||
}
|
|
||||||
|
|
||||||
void ViewsDelegate::NotifyMenuItemFocused(
|
void ViewsDelegate::NotifyMenuItemFocused(const base::string16& menu_name,
|
||||||
const base::string16& menu_name,
|
const base::string16& menu_item_name,
|
||||||
const base::string16& menu_item_name,
|
int item_index,
|
||||||
int item_index,
|
int item_count,
|
||||||
int item_count,
|
bool has_submenu) {}
|
||||||
bool has_submenu) {
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
HICON ViewsDelegate::GetDefaultWindowIcon() const {
|
HICON ViewsDelegate::GetDefaultWindowIcon() const {
|
||||||
// Use current exe's icon as default window icon.
|
// Use current exe's icon as default window icon.
|
||||||
return LoadIcon(GetModuleHandle(NULL),
|
return LoadIcon(GetModuleHandle(NULL),
|
||||||
MAKEINTRESOURCE(1 /* IDR_MAINFRAME */));
|
MAKEINTRESOURCE(1 /* IDR_MAINFRAME */));
|
||||||
}
|
}
|
||||||
|
|
||||||
HICON ViewsDelegate::GetSmallWindowIcon() const {
|
HICON ViewsDelegate::GetSmallWindowIcon() const {
|
||||||
|
@ -88,11 +82,9 @@ views::NonClientFrameView* ViewsDelegate::CreateDefaultNonClientFrameView(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ViewsDelegate::AddRef() {
|
void ViewsDelegate::AddRef() {}
|
||||||
}
|
|
||||||
|
|
||||||
void ViewsDelegate::ReleaseRef() {
|
void ViewsDelegate::ReleaseRef() {}
|
||||||
}
|
|
||||||
|
|
||||||
content::WebContents* ViewsDelegate::CreateWebContents(
|
content::WebContents* ViewsDelegate::CreateWebContents(
|
||||||
content::BrowserContext* browser_context,
|
content::BrowserContext* browser_context,
|
||||||
|
@ -108,8 +100,7 @@ void ViewsDelegate::OnBeforeWidgetInit(
|
||||||
if (params->native_widget)
|
if (params->native_widget)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (params->parent &&
|
if (params->parent && params->type != views::Widget::InitParams::TYPE_MENU &&
|
||||||
params->type != views::Widget::InitParams::TYPE_MENU &&
|
|
||||||
params->type != views::Widget::InitParams::TYPE_TOOLTIP) {
|
params->type != views::Widget::InitParams::TYPE_TOOLTIP) {
|
||||||
params->native_widget = new views::NativeWidgetAura(delegate);
|
params->native_widget = new views::NativeWidgetAura(delegate);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -23,13 +23,12 @@ class ViewsDelegate : public views::ViewsDelegate {
|
||||||
const std::string& window_name,
|
const std::string& window_name,
|
||||||
const gfx::Rect& bounds,
|
const gfx::Rect& bounds,
|
||||||
ui::WindowShowState show_state) override;
|
ui::WindowShowState show_state) override;
|
||||||
bool GetSavedWindowPlacement(
|
bool GetSavedWindowPlacement(const views::Widget* widget,
|
||||||
const views::Widget* widget,
|
const std::string& window_name,
|
||||||
const std::string& window_name,
|
gfx::Rect* bounds,
|
||||||
gfx::Rect* bounds,
|
ui::WindowShowState* show_state) const override;
|
||||||
ui::WindowShowState* show_state) const override;
|
void NotifyAccessibilityEvent(views::View* view,
|
||||||
void NotifyAccessibilityEvent(
|
ui::AXEvent event_type) override;
|
||||||
views::View* view, ui::AXEvent event_type) override;
|
|
||||||
void NotifyMenuItemFocused(const base::string16& menu_name,
|
void NotifyMenuItemFocused(const base::string16& menu_name,
|
||||||
const base::string16& menu_item_name,
|
const base::string16& menu_item_name,
|
||||||
int item_index,
|
int item_index,
|
||||||
|
|
|
@ -23,14 +23,13 @@ WebUIControllerFactory* WebUIControllerFactory::GetInstance() {
|
||||||
return base::Singleton<WebUIControllerFactory>::get();
|
return base::Singleton<WebUIControllerFactory>::get();
|
||||||
}
|
}
|
||||||
|
|
||||||
WebUIControllerFactory::WebUIControllerFactory() {
|
WebUIControllerFactory::WebUIControllerFactory() {}
|
||||||
}
|
|
||||||
|
|
||||||
WebUIControllerFactory::~WebUIControllerFactory() {
|
WebUIControllerFactory::~WebUIControllerFactory() {}
|
||||||
}
|
|
||||||
|
|
||||||
content::WebUI::TypeID WebUIControllerFactory::GetWebUIType(
|
content::WebUI::TypeID WebUIControllerFactory::GetWebUIType(
|
||||||
content::BrowserContext* browser_context, const GURL& url) const {
|
content::BrowserContext* browser_context,
|
||||||
|
const GURL& url) const {
|
||||||
if (url.host() == kChromeUIDevToolsBundledHost) {
|
if (url.host() == kChromeUIDevToolsBundledHost) {
|
||||||
return const_cast<WebUIControllerFactory*>(this);
|
return const_cast<WebUIControllerFactory*>(this);
|
||||||
}
|
}
|
||||||
|
@ -39,17 +38,20 @@ content::WebUI::TypeID WebUIControllerFactory::GetWebUIType(
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebUIControllerFactory::UseWebUIForURL(
|
bool WebUIControllerFactory::UseWebUIForURL(
|
||||||
content::BrowserContext* browser_context, const GURL& url) const {
|
content::BrowserContext* browser_context,
|
||||||
|
const GURL& url) const {
|
||||||
return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI;
|
return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebUIControllerFactory::UseWebUIBindingsForURL(
|
bool WebUIControllerFactory::UseWebUIBindingsForURL(
|
||||||
content::BrowserContext* browser_context, const GURL& url) const {
|
content::BrowserContext* browser_context,
|
||||||
|
const GURL& url) const {
|
||||||
return UseWebUIForURL(browser_context, url);
|
return UseWebUIForURL(browser_context, url);
|
||||||
}
|
}
|
||||||
|
|
||||||
content::WebUIController* WebUIControllerFactory::CreateWebUIControllerForURL(
|
content::WebUIController* WebUIControllerFactory::CreateWebUIControllerForURL(
|
||||||
content::WebUI* web_ui, const GURL& url) const {
|
content::WebUI* web_ui,
|
||||||
|
const GURL& url) const {
|
||||||
if (url.host() == kChromeUIDevToolsBundledHost) {
|
if (url.host() == kChromeUIDevToolsBundledHost) {
|
||||||
auto browser_context = web_ui->GetWebContents()->GetBrowserContext();
|
auto browser_context = web_ui->GetWebContents()->GetBrowserContext();
|
||||||
return new DevToolsUI(browser_context, web_ui);
|
return new DevToolsUI(browser_context, web_ui);
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
#include "content/public/browser/web_ui_controller_factory.h"
|
#include "content/public/browser/web_ui_controller_factory.h"
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
template <typename T> struct DefaultSingletonTraits;
|
template <typename T>
|
||||||
|
struct DefaultSingletonTraits;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
@ -24,8 +25,8 @@ class WebUIControllerFactory : public content::WebUIControllerFactory {
|
||||||
WebUIControllerFactory();
|
WebUIControllerFactory();
|
||||||
virtual ~WebUIControllerFactory();
|
virtual ~WebUIControllerFactory();
|
||||||
|
|
||||||
content::WebUI::TypeID GetWebUIType(
|
content::WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context,
|
||||||
content::BrowserContext* browser_context, const GURL& url) const override;
|
const GURL& url) const override;
|
||||||
bool UseWebUIForURL(content::BrowserContext* browser_context,
|
bool UseWebUIForURL(content::BrowserContext* browser_context,
|
||||||
const GURL& url) const override;
|
const GURL& url) const override;
|
||||||
bool UseWebUIBindingsForURL(content::BrowserContext* browser_context,
|
bool UseWebUIBindingsForURL(content::BrowserContext* browser_context,
|
||||||
|
|
|
@ -62,11 +62,9 @@ NotificationPresenter* NotificationPresenter::Create() {
|
||||||
return presenter.release();
|
return presenter.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
NotificationPresenterWin::NotificationPresenterWin() {
|
NotificationPresenterWin::NotificationPresenterWin() {}
|
||||||
}
|
|
||||||
|
|
||||||
NotificationPresenterWin::~NotificationPresenterWin() {
|
NotificationPresenterWin::~NotificationPresenterWin() {}
|
||||||
}
|
|
||||||
|
|
||||||
bool NotificationPresenterWin::Init() {
|
bool NotificationPresenterWin::Init() {
|
||||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||||
|
@ -74,7 +72,8 @@ bool NotificationPresenterWin::Init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
base::string16 NotificationPresenterWin::SaveIconToFilesystem(
|
base::string16 NotificationPresenterWin::SaveIconToFilesystem(
|
||||||
const SkBitmap& icon, const GURL& origin) {
|
const SkBitmap& icon,
|
||||||
|
const GURL& origin) {
|
||||||
std::string filename;
|
std::string filename;
|
||||||
|
|
||||||
if (origin.is_valid()) {
|
if (origin.is_valid()) {
|
||||||
|
|
|
@ -8,41 +8,43 @@ namespace brightray {
|
||||||
|
|
||||||
brightray::Notification* NotificationPresenterWin7::CreateNotificationObject(
|
brightray::Notification* NotificationPresenterWin7::CreateNotificationObject(
|
||||||
NotificationDelegate* delegate) {
|
NotificationDelegate* delegate) {
|
||||||
return new Win32Notification(delegate, this);
|
return new Win32Notification(delegate, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32Notification* NotificationPresenterWin7::GetNotificationObjectByRef(
|
Win32Notification* NotificationPresenterWin7::GetNotificationObjectByRef(
|
||||||
const DesktopNotificationController::Notification& ref) {
|
const DesktopNotificationController::Notification& ref) {
|
||||||
for (auto n : this->notifications()) {
|
for (auto n : this->notifications()) {
|
||||||
auto w32n = static_cast<Win32Notification*>(n);
|
auto w32n = static_cast<Win32Notification*>(n);
|
||||||
if (w32n->GetRef() == ref)
|
if (w32n->GetRef() == ref)
|
||||||
return w32n;
|
return w32n;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Win32Notification* NotificationPresenterWin7::GetNotificationObjectByTag(
|
Win32Notification* NotificationPresenterWin7::GetNotificationObjectByTag(
|
||||||
const std::string& tag) {
|
const std::string& tag) {
|
||||||
for (auto n : this->notifications()) {
|
for (auto n : this->notifications()) {
|
||||||
auto w32n = static_cast<Win32Notification*>(n);
|
auto w32n = static_cast<Win32Notification*>(n);
|
||||||
if (w32n->GetTag() == tag)
|
if (w32n->GetTag() == tag)
|
||||||
return w32n;
|
return w32n;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationPresenterWin7::OnNotificationClicked(
|
void NotificationPresenterWin7::OnNotificationClicked(
|
||||||
Notification& notification) {
|
Notification& notification) {
|
||||||
auto n = GetNotificationObjectByRef(notification);
|
auto n = GetNotificationObjectByRef(notification);
|
||||||
if (n) n->NotificationClicked();
|
if (n)
|
||||||
|
n->NotificationClicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NotificationPresenterWin7::OnNotificationDismissed(
|
void NotificationPresenterWin7::OnNotificationDismissed(
|
||||||
Notification& notification) {
|
Notification& notification) {
|
||||||
auto n = GetNotificationObjectByRef(notification);
|
auto n = GetNotificationObjectByRef(notification);
|
||||||
if (n) n->NotificationDismissed();
|
if (n)
|
||||||
|
n->NotificationDismissed();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -6,25 +6,24 @@ namespace brightray {
|
||||||
|
|
||||||
class Win32Notification;
|
class Win32Notification;
|
||||||
|
|
||||||
class NotificationPresenterWin7 :
|
class NotificationPresenterWin7 : public NotificationPresenter,
|
||||||
public NotificationPresenter,
|
public DesktopNotificationController {
|
||||||
public DesktopNotificationController {
|
|
||||||
public:
|
public:
|
||||||
NotificationPresenterWin7() = default;
|
NotificationPresenterWin7() = default;
|
||||||
|
|
||||||
Win32Notification* GetNotificationObjectByRef(
|
Win32Notification* GetNotificationObjectByRef(
|
||||||
const DesktopNotificationController::Notification& ref);
|
const DesktopNotificationController::Notification& ref);
|
||||||
|
|
||||||
Win32Notification* GetNotificationObjectByTag(const std::string& tag);
|
Win32Notification* GetNotificationObjectByTag(const std::string& tag);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
brightray::Notification* CreateNotificationObject(
|
brightray::Notification* CreateNotificationObject(
|
||||||
NotificationDelegate* delegate) override;
|
NotificationDelegate* delegate) override;
|
||||||
|
|
||||||
void OnNotificationClicked(Notification& notification) override;
|
void OnNotificationClicked(Notification& notification) override;
|
||||||
void OnNotificationDismissed(Notification& notification) override;
|
void OnNotificationDismissed(Notification& notification) override;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7);
|
DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -6,18 +6,15 @@
|
||||||
|
|
||||||
#include <winstring.h>
|
#include <winstring.h>
|
||||||
|
|
||||||
ScopedHString::ScopedHString(const wchar_t* source)
|
ScopedHString::ScopedHString(const wchar_t* source) : str_(nullptr) {
|
||||||
: str_(nullptr) {
|
|
||||||
Reset(source);
|
Reset(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedHString::ScopedHString(const std::wstring& source)
|
ScopedHString::ScopedHString(const std::wstring& source) : str_(nullptr) {
|
||||||
: str_(nullptr) {
|
|
||||||
Reset(source);
|
Reset(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopedHString::ScopedHString() : str_(nullptr) {
|
ScopedHString::ScopedHString() : str_(nullptr) {}
|
||||||
}
|
|
||||||
|
|
||||||
ScopedHString::~ScopedHString() {
|
ScopedHString::~ScopedHString() {
|
||||||
Reset();
|
Reset();
|
||||||
|
|
|
@ -4,51 +4,57 @@
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
struct NotificationData {
|
struct NotificationData {
|
||||||
DesktopNotificationController* controller = nullptr;
|
DesktopNotificationController* controller = nullptr;
|
||||||
|
|
||||||
std::wstring caption;
|
std::wstring caption;
|
||||||
std::wstring body_text;
|
std::wstring body_text;
|
||||||
HBITMAP image = NULL;
|
HBITMAP image = NULL;
|
||||||
|
|
||||||
NotificationData() = default;
|
NotificationData() = default;
|
||||||
|
|
||||||
~NotificationData() {
|
~NotificationData() {
|
||||||
if (image) DeleteObject(image);
|
if (image)
|
||||||
}
|
DeleteObject(image);
|
||||||
|
}
|
||||||
|
|
||||||
NotificationData(const NotificationData& other) = delete;
|
NotificationData(const NotificationData& other) = delete;
|
||||||
NotificationData& operator=(const NotificationData& other) = delete;
|
NotificationData& operator=(const NotificationData& other) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
constexpr T ScaleForDpi(T value, unsigned dpi, unsigned source_dpi = 96) {
|
constexpr T ScaleForDpi(T value, unsigned dpi, unsigned source_dpi = 96) {
|
||||||
return value * dpi / source_dpi;
|
return value * dpi / source_dpi;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ScreenMetrics {
|
struct ScreenMetrics {
|
||||||
UINT dpi_x, dpi_y;
|
UINT dpi_x, dpi_y;
|
||||||
|
|
||||||
ScreenMetrics() {
|
ScreenMetrics() {
|
||||||
typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*);
|
typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*);
|
||||||
|
|
||||||
auto GetDpiForMonitor = reinterpret_cast<GetDpiForMonitor_t*>(
|
auto GetDpiForMonitor = reinterpret_cast<GetDpiForMonitor_t*>(
|
||||||
GetProcAddress(GetModuleHandle(TEXT("shcore")),
|
GetProcAddress(GetModuleHandle(TEXT("shcore")), "GetDpiForMonitor"));
|
||||||
"GetDpiForMonitor"));
|
|
||||||
|
|
||||||
if (GetDpiForMonitor) {
|
if (GetDpiForMonitor) {
|
||||||
auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY);
|
auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY);
|
||||||
if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK)
|
if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK)
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
HDC hdc = GetDC(NULL);
|
|
||||||
dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
|
|
||||||
dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
|
|
||||||
ReleaseDC(NULL, hdc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T> T X(T value) const { return ScaleForDpi(value, dpi_x); }
|
HDC hdc = GetDC(NULL);
|
||||||
template<class T> T Y(T value) const { return ScaleForDpi(value, dpi_y); }
|
dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
|
||||||
|
dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
|
||||||
|
ReleaseDC(NULL, hdc);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
T X(T value) const {
|
||||||
|
return ScaleForDpi(value, dpi_x);
|
||||||
|
}
|
||||||
|
template <class T>
|
||||||
|
T Y(T value) const {
|
||||||
|
return ScaleForDpi(value, dpi_y);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -13,393 +13,405 @@ using std::shared_ptr;
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
HBITMAP CopyBitmap(HBITMAP bitmap) {
|
HBITMAP CopyBitmap(HBITMAP bitmap) {
|
||||||
HBITMAP ret = NULL;
|
HBITMAP ret = NULL;
|
||||||
|
|
||||||
BITMAP bm;
|
BITMAP bm;
|
||||||
if (bitmap && GetObject(bitmap, sizeof(bm), &bm)) {
|
if (bitmap && GetObject(bitmap, sizeof(bm), &bm)) {
|
||||||
HDC hdc_screen = GetDC(NULL);
|
HDC hdc_screen = GetDC(NULL);
|
||||||
ret = CreateCompatibleBitmap(hdc_screen, bm.bmWidth, bm.bmHeight);
|
ret = CreateCompatibleBitmap(hdc_screen, bm.bmWidth, bm.bmHeight);
|
||||||
ReleaseDC(NULL, hdc_screen);
|
ReleaseDC(NULL, hdc_screen);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
HDC hdc_src = CreateCompatibleDC(NULL);
|
HDC hdc_src = CreateCompatibleDC(NULL);
|
||||||
HDC hdc_dst = CreateCompatibleDC(NULL);
|
HDC hdc_dst = CreateCompatibleDC(NULL);
|
||||||
SelectBitmap(hdc_src, bitmap);
|
SelectBitmap(hdc_src, bitmap);
|
||||||
SelectBitmap(hdc_dst, ret);
|
SelectBitmap(hdc_dst, ret);
|
||||||
BitBlt(hdc_dst, 0, 0, bm.bmWidth, bm.bmHeight,
|
BitBlt(hdc_dst, 0, 0, bm.bmWidth, bm.bmHeight, hdc_src, 0, 0, SRCCOPY);
|
||||||
hdc_src, 0, 0, SRCCOPY);
|
DeleteDC(hdc_dst);
|
||||||
DeleteDC(hdc_dst);
|
DeleteDC(hdc_src);
|
||||||
DeleteDC(hdc_src);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
HINSTANCE DesktopNotificationController::RegisterWndClasses() {
|
HINSTANCE DesktopNotificationController::RegisterWndClasses() {
|
||||||
// We keep a static `module` variable which serves a dual purpose:
|
// We keep a static `module` variable which serves a dual purpose:
|
||||||
// 1. Stores the HINSTANCE where the window classes are registered,
|
// 1. Stores the HINSTANCE where the window classes are registered,
|
||||||
// which can be passed to `CreateWindow`
|
// which can be passed to `CreateWindow`
|
||||||
// 2. Indicates whether we already attempted the registration so that
|
// 2. Indicates whether we already attempted the registration so that
|
||||||
// we don't do it twice (we don't retry even if registration fails,
|
// we don't do it twice (we don't retry even if registration fails,
|
||||||
// as there is no point).
|
// as there is no point).
|
||||||
static HMODULE module = NULL;
|
static HMODULE module = NULL;
|
||||||
|
|
||||||
if (!module) {
|
if (!module) {
|
||||||
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
||||||
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||||
reinterpret_cast<LPCWSTR>(&RegisterWndClasses),
|
reinterpret_cast<LPCWSTR>(&RegisterWndClasses),
|
||||||
&module)) {
|
&module)) {
|
||||||
Toast::Register(module);
|
Toast::Register(module);
|
||||||
|
|
||||||
WNDCLASSEX wc = { sizeof(wc) };
|
WNDCLASSEX wc = {sizeof(wc)};
|
||||||
wc.lpfnWndProc = &WndProc;
|
wc.lpfnWndProc = &WndProc;
|
||||||
wc.lpszClassName = class_name_;
|
wc.lpszClassName = class_name_;
|
||||||
wc.cbWndExtra = sizeof(DesktopNotificationController*);
|
wc.cbWndExtra = sizeof(DesktopNotificationController*);
|
||||||
wc.hInstance = module;
|
wc.hInstance = module;
|
||||||
|
|
||||||
RegisterClassEx(&wc);
|
RegisterClassEx(&wc);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopNotificationController::DesktopNotificationController(
|
DesktopNotificationController::DesktopNotificationController(
|
||||||
unsigned maximum_toasts) {
|
unsigned maximum_toasts) {
|
||||||
instances_.reserve(maximum_toasts);
|
instances_.reserve(maximum_toasts);
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopNotificationController::~DesktopNotificationController() {
|
DesktopNotificationController::~DesktopNotificationController() {
|
||||||
for (auto&& inst : instances_) DestroyToast(inst);
|
for (auto&& inst : instances_)
|
||||||
if (hwnd_controller_) DestroyWindow(hwnd_controller_);
|
DestroyToast(inst);
|
||||||
ClearAssets();
|
if (hwnd_controller_)
|
||||||
|
DestroyWindow(hwnd_controller_);
|
||||||
|
ClearAssets();
|
||||||
}
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK DesktopNotificationController::WndProc(
|
LRESULT CALLBACK DesktopNotificationController::WndProc(HWND hwnd,
|
||||||
HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) {
|
UINT message,
|
||||||
switch (message) {
|
WPARAM wparam,
|
||||||
case WM_CREATE:
|
LPARAM lparam) {
|
||||||
{
|
switch (message) {
|
||||||
auto& cs = reinterpret_cast<const CREATESTRUCT*&>(lparam);
|
case WM_CREATE: {
|
||||||
SetWindowLongPtr(hwnd, 0, (LONG_PTR)cs->lpCreateParams);
|
auto& cs = reinterpret_cast<const CREATESTRUCT*&>(lparam);
|
||||||
}
|
SetWindowLongPtr(hwnd, 0, (LONG_PTR)cs->lpCreateParams);
|
||||||
break;
|
} break;
|
||||||
|
|
||||||
case WM_TIMER:
|
case WM_TIMER:
|
||||||
if (wparam == TimerID_Animate) {
|
if (wparam == TimerID_Animate) {
|
||||||
Get(hwnd)->AnimateAll();
|
Get(hwnd)->AnimateAll();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case WM_DISPLAYCHANGE:
|
case WM_DISPLAYCHANGE: {
|
||||||
{
|
auto inst = Get(hwnd);
|
||||||
auto inst = Get(hwnd);
|
inst->ClearAssets();
|
||||||
inst->ClearAssets();
|
inst->AnimateAll();
|
||||||
inst->AnimateAll();
|
} break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WM_SETTINGCHANGE:
|
case WM_SETTINGCHANGE:
|
||||||
if (wparam == SPI_SETWORKAREA) {
|
if (wparam == SPI_SETWORKAREA) {
|
||||||
Get(hwnd)->AnimateAll();
|
Get(hwnd)->AnimateAll();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DefWindowProc(hwnd, message, wparam, lparam);
|
return DefWindowProc(hwnd, message, wparam, lparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationController::StartAnimation() {
|
void DesktopNotificationController::StartAnimation() {
|
||||||
_ASSERT(hwnd_controller_);
|
_ASSERT(hwnd_controller_);
|
||||||
|
|
||||||
if (!is_animating_ && hwnd_controller_) {
|
if (!is_animating_ && hwnd_controller_) {
|
||||||
// NOTE: 15ms is shorter than what we'd need for 60 fps, but since
|
// NOTE: 15ms is shorter than what we'd need for 60 fps, but since
|
||||||
// the timer is not accurate we must request a higher frame rate
|
// the timer is not accurate we must request a higher frame rate
|
||||||
// to get at least 60
|
// to get at least 60
|
||||||
|
|
||||||
SetTimer(hwnd_controller_, TimerID_Animate, 15, nullptr);
|
SetTimer(hwnd_controller_, TimerID_Animate, 15, nullptr);
|
||||||
is_animating_ = true;
|
is_animating_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HFONT DesktopNotificationController::GetCaptionFont() {
|
HFONT DesktopNotificationController::GetCaptionFont() {
|
||||||
InitializeFonts();
|
InitializeFonts();
|
||||||
return caption_font_;
|
return caption_font_;
|
||||||
}
|
}
|
||||||
|
|
||||||
HFONT DesktopNotificationController::GetBodyFont() {
|
HFONT DesktopNotificationController::GetBodyFont() {
|
||||||
InitializeFonts();
|
InitializeFonts();
|
||||||
return body_font_;
|
return body_font_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationController::InitializeFonts() {
|
void DesktopNotificationController::InitializeFonts() {
|
||||||
if (!body_font_) {
|
if (!body_font_) {
|
||||||
NONCLIENTMETRICS metrics = { sizeof(metrics) };
|
NONCLIENTMETRICS metrics = {sizeof(metrics)};
|
||||||
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) {
|
if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) {
|
||||||
auto base_height = metrics.lfMessageFont.lfHeight;
|
auto base_height = metrics.lfMessageFont.lfHeight;
|
||||||
|
|
||||||
HDC hdc = GetDC(NULL);
|
HDC hdc = GetDC(NULL);
|
||||||
auto base_dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
|
auto base_dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);
|
||||||
ReleaseDC(NULL, hdc);
|
ReleaseDC(NULL, hdc);
|
||||||
|
|
||||||
ScreenMetrics scr;
|
ScreenMetrics scr;
|
||||||
|
|
||||||
metrics.lfMessageFont.lfHeight =
|
metrics.lfMessageFont.lfHeight =
|
||||||
(LONG)ScaleForDpi(base_height * 1.1f, scr.dpi_y, base_dpi_y);
|
(LONG)ScaleForDpi(base_height * 1.1f, scr.dpi_y, base_dpi_y);
|
||||||
body_font_ = CreateFontIndirect(&metrics.lfMessageFont);
|
body_font_ = CreateFontIndirect(&metrics.lfMessageFont);
|
||||||
|
|
||||||
if (caption_font_) DeleteFont(caption_font_);
|
if (caption_font_)
|
||||||
metrics.lfMessageFont.lfHeight =
|
DeleteFont(caption_font_);
|
||||||
(LONG)ScaleForDpi(base_height * 1.4f, scr.dpi_y, base_dpi_y);
|
metrics.lfMessageFont.lfHeight =
|
||||||
caption_font_ = CreateFontIndirect(&metrics.lfMessageFont);
|
(LONG)ScaleForDpi(base_height * 1.4f, scr.dpi_y, base_dpi_y);
|
||||||
}
|
caption_font_ = CreateFontIndirect(&metrics.lfMessageFont);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationController::ClearAssets() {
|
void DesktopNotificationController::ClearAssets() {
|
||||||
if (caption_font_) { DeleteFont(caption_font_); caption_font_ = NULL; }
|
if (caption_font_) {
|
||||||
if (body_font_) { DeleteFont(body_font_); body_font_ = NULL; }
|
DeleteFont(caption_font_);
|
||||||
|
caption_font_ = NULL;
|
||||||
|
}
|
||||||
|
if (body_font_) {
|
||||||
|
DeleteFont(body_font_);
|
||||||
|
body_font_ = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationController::AnimateAll() {
|
void DesktopNotificationController::AnimateAll() {
|
||||||
// NOTE: This function refreshes position and size of all toasts according
|
// NOTE: This function refreshes position and size of all toasts according
|
||||||
// to all current conditions. Animation time is only one of the variables
|
// to all current conditions. Animation time is only one of the variables
|
||||||
// influencing them. Screen resolution is another.
|
// influencing them. Screen resolution is another.
|
||||||
|
|
||||||
bool keep_animating = false;
|
bool keep_animating = false;
|
||||||
|
|
||||||
if (!instances_.empty()) {
|
if (!instances_.empty()) {
|
||||||
RECT work_area;
|
RECT work_area;
|
||||||
if (SystemParametersInfo(SPI_GETWORKAREA, 0, &work_area, 0)) {
|
if (SystemParametersInfo(SPI_GETWORKAREA, 0, &work_area, 0)) {
|
||||||
ScreenMetrics metrics;
|
ScreenMetrics metrics;
|
||||||
POINT origin = { work_area.right,
|
POINT origin = {work_area.right,
|
||||||
work_area.bottom - metrics.Y(toast_margin_) };
|
work_area.bottom - metrics.Y(toast_margin_)};
|
||||||
|
|
||||||
auto hdwp =
|
auto hdwp = BeginDeferWindowPos(static_cast<int>(instances_.size()));
|
||||||
BeginDeferWindowPos(static_cast<int>(instances_.size()));
|
|
||||||
|
|
||||||
for (auto&& inst : instances_) {
|
for (auto&& inst : instances_) {
|
||||||
if (!inst.hwnd) continue;
|
if (!inst.hwnd)
|
||||||
|
continue;
|
||||||
|
|
||||||
auto notification = Toast::Get(inst.hwnd);
|
auto notification = Toast::Get(inst.hwnd);
|
||||||
hdwp = notification->Animate(hdwp, origin);
|
hdwp = notification->Animate(hdwp, origin);
|
||||||
if (!hdwp) break;
|
if (!hdwp)
|
||||||
keep_animating |= notification->IsAnimationActive();
|
break;
|
||||||
}
|
keep_animating |= notification->IsAnimationActive();
|
||||||
|
}
|
||||||
|
|
||||||
if (hdwp) EndDeferWindowPos(hdwp);
|
if (hdwp)
|
||||||
}
|
EndDeferWindowPos(hdwp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!keep_animating) {
|
if (!keep_animating) {
|
||||||
_ASSERT(hwnd_controller_);
|
_ASSERT(hwnd_controller_);
|
||||||
if (hwnd_controller_) KillTimer(hwnd_controller_, TimerID_Animate);
|
if (hwnd_controller_)
|
||||||
is_animating_ = false;
|
KillTimer(hwnd_controller_, TimerID_Animate);
|
||||||
|
is_animating_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Purge dismissed notifications and collapse the stack between
|
||||||
|
// items which are highlighted
|
||||||
|
if (!instances_.empty()) {
|
||||||
|
auto is_alive = [](ToastInstance& inst) {
|
||||||
|
return inst.hwnd && IsWindowVisible(inst.hwnd);
|
||||||
|
};
|
||||||
|
|
||||||
|
auto is_highlighted = [](ToastInstance& inst) {
|
||||||
|
return inst.hwnd && Toast::Get(inst.hwnd)->IsHighlighted();
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto it = instances_.begin();; ++it) {
|
||||||
|
// find next highlighted item
|
||||||
|
auto it2 = find_if(it, instances_.end(), is_highlighted);
|
||||||
|
|
||||||
|
// collapse the stack in front of the highlighted item
|
||||||
|
it = stable_partition(it, it2, is_alive);
|
||||||
|
|
||||||
|
// purge the dead items
|
||||||
|
for_each(it, it2, [this](auto&& inst) { DestroyToast(inst); });
|
||||||
|
|
||||||
|
if (it2 == instances_.end()) {
|
||||||
|
instances_.erase(it, it2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
it = move(it2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Purge dismissed notifications and collapse the stack between
|
// Set new toast positions
|
||||||
// items which are highlighted
|
if (!instances_.empty()) {
|
||||||
if (!instances_.empty()) {
|
ScreenMetrics metrics;
|
||||||
auto is_alive = [](ToastInstance& inst) {
|
auto margin = metrics.Y(toast_margin_);
|
||||||
return inst.hwnd && IsWindowVisible(inst.hwnd);
|
|
||||||
};
|
|
||||||
|
|
||||||
auto is_highlighted = [](ToastInstance& inst) {
|
int target_pos = 0;
|
||||||
return inst.hwnd && Toast::Get(inst.hwnd)->IsHighlighted();
|
for (auto&& inst : instances_) {
|
||||||
};
|
if (inst.hwnd) {
|
||||||
|
auto toast = Toast::Get(inst.hwnd);
|
||||||
|
|
||||||
for (auto it = instances_.begin();; ++it) {
|
if (toast->IsHighlighted())
|
||||||
// find next highlighted item
|
target_pos = toast->GetVerticalPosition();
|
||||||
auto it2 = find_if(it, instances_.end(), is_highlighted);
|
else
|
||||||
|
toast->SetVerticalPosition(target_pos);
|
||||||
|
|
||||||
// collapse the stack in front of the highlighted item
|
target_pos += toast->GetHeight() + margin;
|
||||||
it = stable_partition(it, it2, is_alive);
|
}
|
||||||
|
|
||||||
// purge the dead items
|
|
||||||
for_each(it, it2, [this](auto&& inst) { DestroyToast(inst); });
|
|
||||||
|
|
||||||
if (it2 == instances_.end()) {
|
|
||||||
instances_.erase(it, it2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
it = move(it2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Set new toast positions
|
// Create new toasts from the queue
|
||||||
if (!instances_.empty()) {
|
CheckQueue();
|
||||||
ScreenMetrics metrics;
|
|
||||||
auto margin = metrics.Y(toast_margin_);
|
|
||||||
|
|
||||||
int target_pos = 0;
|
|
||||||
for (auto&& inst : instances_) {
|
|
||||||
if (inst.hwnd) {
|
|
||||||
auto toast = Toast::Get(inst.hwnd);
|
|
||||||
|
|
||||||
if (toast->IsHighlighted())
|
|
||||||
target_pos = toast->GetVerticalPosition();
|
|
||||||
else
|
|
||||||
toast->SetVerticalPosition(target_pos);
|
|
||||||
|
|
||||||
target_pos += toast->GetHeight() + margin;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new toasts from the queue
|
|
||||||
CheckQueue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopNotificationController::Notification
|
DesktopNotificationController::Notification
|
||||||
DesktopNotificationController::AddNotification(
|
DesktopNotificationController::AddNotification(std::wstring caption,
|
||||||
std::wstring caption, std::wstring body_text, HBITMAP image) {
|
std::wstring body_text,
|
||||||
NotificationLink data(this);
|
HBITMAP image) {
|
||||||
|
NotificationLink data(this);
|
||||||
|
|
||||||
data->caption = move(caption);
|
data->caption = move(caption);
|
||||||
data->body_text = move(body_text);
|
data->body_text = move(body_text);
|
||||||
data->image = CopyBitmap(image);
|
data->image = CopyBitmap(image);
|
||||||
|
|
||||||
// Enqueue new notification
|
// Enqueue new notification
|
||||||
Notification ret { *queue_.insert(queue_.end(), move(data)) };
|
Notification ret{*queue_.insert(queue_.end(), move(data))};
|
||||||
CheckQueue();
|
CheckQueue();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationController::CloseNotification(
|
void DesktopNotificationController::CloseNotification(
|
||||||
Notification& notification) {
|
Notification& notification) {
|
||||||
// Remove it from the queue
|
// Remove it from the queue
|
||||||
auto it = find(queue_.begin(), queue_.end(), notification.data_);
|
auto it = find(queue_.begin(), queue_.end(), notification.data_);
|
||||||
if (it != queue_.end()) {
|
if (it != queue_.end()) {
|
||||||
queue_.erase(it);
|
queue_.erase(it);
|
||||||
this->OnNotificationClosed(notification);
|
this->OnNotificationClosed(notification);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dismiss active toast
|
// Dismiss active toast
|
||||||
auto hwnd = GetToast(notification.data_.get());
|
auto hwnd = GetToast(notification.data_.get());
|
||||||
if (hwnd) {
|
if (hwnd) {
|
||||||
auto toast = Toast::Get(hwnd);
|
auto toast = Toast::Get(hwnd);
|
||||||
toast->Dismiss();
|
toast->Dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationController::CheckQueue() {
|
void DesktopNotificationController::CheckQueue() {
|
||||||
while (instances_.size() < instances_.capacity() && !queue_.empty()) {
|
while (instances_.size() < instances_.capacity() && !queue_.empty()) {
|
||||||
CreateToast(move(queue_.front()));
|
CreateToast(move(queue_.front()));
|
||||||
queue_.pop_front();
|
queue_.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationController::CreateToast(NotificationLink&& data) {
|
void DesktopNotificationController::CreateToast(NotificationLink&& data) {
|
||||||
auto hinstance = RegisterWndClasses();
|
auto hinstance = RegisterWndClasses();
|
||||||
auto hwnd = Toast::Create(hinstance, data);
|
auto hwnd = Toast::Create(hinstance, data);
|
||||||
if (hwnd) {
|
if (hwnd) {
|
||||||
int toast_pos = 0;
|
int toast_pos = 0;
|
||||||
if (!instances_.empty()) {
|
if (!instances_.empty()) {
|
||||||
auto& item = instances_.back();
|
auto& item = instances_.back();
|
||||||
_ASSERT(item.hwnd);
|
_ASSERT(item.hwnd);
|
||||||
|
|
||||||
ScreenMetrics scr;
|
ScreenMetrics scr;
|
||||||
auto toast = Toast::Get(item.hwnd);
|
auto toast = Toast::Get(item.hwnd);
|
||||||
toast_pos = toast->GetVerticalPosition() +
|
toast_pos = toast->GetVerticalPosition() + toast->GetHeight() +
|
||||||
toast->GetHeight() +
|
scr.Y(toast_margin_);
|
||||||
scr.Y(toast_margin_);
|
|
||||||
}
|
|
||||||
|
|
||||||
instances_.push_back({ hwnd, move(data) });
|
|
||||||
|
|
||||||
if (!hwnd_controller_) {
|
|
||||||
// NOTE: We cannot use a message-only window because we need to
|
|
||||||
// receive system notifications
|
|
||||||
hwnd_controller_ = CreateWindow(class_name_, nullptr, 0,
|
|
||||||
0, 0, 0, 0,
|
|
||||||
NULL, NULL, hinstance, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto toast = Toast::Get(hwnd);
|
|
||||||
toast->PopUp(toast_pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instances_.push_back({hwnd, move(data)});
|
||||||
|
|
||||||
|
if (!hwnd_controller_) {
|
||||||
|
// NOTE: We cannot use a message-only window because we need to
|
||||||
|
// receive system notifications
|
||||||
|
hwnd_controller_ = CreateWindow(class_name_, nullptr, 0, 0, 0, 0, 0, NULL,
|
||||||
|
NULL, hinstance, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto toast = Toast::Get(hwnd);
|
||||||
|
toast->PopUp(toast_pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HWND DesktopNotificationController::GetToast(
|
HWND DesktopNotificationController::GetToast(
|
||||||
const NotificationData* data) const {
|
const NotificationData* data) const {
|
||||||
auto it = find_if(instances_.cbegin(), instances_.cend(),
|
auto it =
|
||||||
[data](auto&& inst) {
|
find_if(instances_.cbegin(), instances_.cend(), [data](auto&& inst) {
|
||||||
if (!inst.hwnd) return false;
|
if (!inst.hwnd)
|
||||||
auto toast = Toast::Get(inst.hwnd);
|
return false;
|
||||||
return data == toast->GetNotification().get();
|
auto toast = Toast::Get(inst.hwnd);
|
||||||
});
|
return data == toast->GetNotification().get();
|
||||||
|
});
|
||||||
|
|
||||||
return (it != instances_.cend()) ? it->hwnd : NULL;
|
return (it != instances_.cend()) ? it->hwnd : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationController::DestroyToast(ToastInstance& inst) {
|
void DesktopNotificationController::DestroyToast(ToastInstance& inst) {
|
||||||
if (inst.hwnd) {
|
if (inst.hwnd) {
|
||||||
auto data = Toast::Get(inst.hwnd)->GetNotification();
|
auto data = Toast::Get(inst.hwnd)->GetNotification();
|
||||||
|
|
||||||
DestroyWindow(inst.hwnd);
|
DestroyWindow(inst.hwnd);
|
||||||
inst.hwnd = NULL;
|
inst.hwnd = NULL;
|
||||||
|
|
||||||
Notification notification(data);
|
Notification notification(data);
|
||||||
OnNotificationClosed(notification);
|
OnNotificationClosed(notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopNotificationController::Notification::Notification(
|
DesktopNotificationController::Notification::Notification(
|
||||||
const shared_ptr<NotificationData>& data) :
|
const shared_ptr<NotificationData>& data)
|
||||||
data_(data) {
|
: data_(data) {
|
||||||
_ASSERT(data != nullptr);
|
_ASSERT(data != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DesktopNotificationController::Notification::operator==(
|
bool DesktopNotificationController::Notification::operator==(
|
||||||
const Notification& other) const {
|
const Notification& other) const {
|
||||||
return data_ == other.data_;
|
return data_ == other.data_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationController::Notification::Close() {
|
void DesktopNotificationController::Notification::Close() {
|
||||||
// No business calling this when not pointing to a valid instance
|
// No business calling this when not pointing to a valid instance
|
||||||
_ASSERT(data_);
|
_ASSERT(data_);
|
||||||
|
|
||||||
if (data_->controller)
|
if (data_->controller)
|
||||||
data_->controller->CloseNotification(*this);
|
data_->controller->CloseNotification(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DesktopNotificationController::Notification::Set(
|
void DesktopNotificationController::Notification::Set(std::wstring caption,
|
||||||
std::wstring caption, std::wstring body_text, HBITMAP image) {
|
std::wstring body_text,
|
||||||
// No business calling this when not pointing to a valid instance
|
HBITMAP image) {
|
||||||
_ASSERT(data_);
|
// No business calling this when not pointing to a valid instance
|
||||||
|
_ASSERT(data_);
|
||||||
|
|
||||||
// Do nothing when the notification has been closed
|
// Do nothing when the notification has been closed
|
||||||
if (!data_->controller)
|
if (!data_->controller)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (data_->image) DeleteBitmap(data_->image);
|
if (data_->image)
|
||||||
|
DeleteBitmap(data_->image);
|
||||||
|
|
||||||
data_->caption = move(caption);
|
data_->caption = move(caption);
|
||||||
data_->body_text = move(body_text);
|
data_->body_text = move(body_text);
|
||||||
data_->image = CopyBitmap(image);
|
data_->image = CopyBitmap(image);
|
||||||
|
|
||||||
auto hwnd = data_->controller->GetToast(data_.get());
|
auto hwnd = data_->controller->GetToast(data_.get());
|
||||||
if (hwnd) {
|
if (hwnd) {
|
||||||
auto toast = Toast::Get(hwnd);
|
auto toast = Toast::Get(hwnd);
|
||||||
toast->ResetContents();
|
toast->ResetContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change of contents can affect size and position of all toasts
|
// Change of contents can affect size and position of all toasts
|
||||||
data_->controller->StartAnimation();
|
data_->controller->StartAnimation();
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopNotificationController::NotificationLink::NotificationLink(
|
DesktopNotificationController::NotificationLink::NotificationLink(
|
||||||
DesktopNotificationController* controller) :
|
DesktopNotificationController* controller)
|
||||||
shared_ptr(make_shared<NotificationData>()) {
|
: shared_ptr(make_shared<NotificationData>()) {
|
||||||
get()->controller = controller;
|
get()->controller = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
DesktopNotificationController::NotificationLink::~NotificationLink() {
|
DesktopNotificationController::NotificationLink::~NotificationLink() {
|
||||||
auto p = get();
|
auto p = get();
|
||||||
if (p) p->controller = nullptr;
|
if (p)
|
||||||
|
p->controller = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <Windows.h>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
|
@ -11,95 +11,95 @@ struct NotificationData;
|
||||||
|
|
||||||
class DesktopNotificationController {
|
class DesktopNotificationController {
|
||||||
public:
|
public:
|
||||||
explicit DesktopNotificationController(unsigned maximum_toasts = 3);
|
explicit DesktopNotificationController(unsigned maximum_toasts = 3);
|
||||||
~DesktopNotificationController();
|
~DesktopNotificationController();
|
||||||
|
|
||||||
class Notification;
|
class Notification;
|
||||||
Notification AddNotification(std::wstring caption, std::wstring body_text,
|
Notification AddNotification(std::wstring caption,
|
||||||
HBITMAP image);
|
std::wstring body_text,
|
||||||
void CloseNotification(Notification& notification);
|
HBITMAP image);
|
||||||
|
void CloseNotification(Notification& notification);
|
||||||
|
|
||||||
// Event handlers -- override to receive the events
|
// Event handlers -- override to receive the events
|
||||||
private:
|
private:
|
||||||
virtual void OnNotificationClosed(Notification& notification) {}
|
virtual void OnNotificationClosed(Notification& notification) {}
|
||||||
virtual void OnNotificationClicked(Notification& notification) {}
|
virtual void OnNotificationClicked(Notification& notification) {}
|
||||||
virtual void OnNotificationDismissed(Notification& notification) {}
|
virtual void OnNotificationDismissed(Notification& notification) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static HINSTANCE RegisterWndClasses();
|
static HINSTANCE RegisterWndClasses();
|
||||||
void StartAnimation();
|
void StartAnimation();
|
||||||
HFONT GetCaptionFont();
|
HFONT GetCaptionFont();
|
||||||
HFONT GetBodyFont();
|
HFONT GetBodyFont();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum TimerID {
|
enum TimerID { TimerID_Animate = 1 };
|
||||||
TimerID_Animate = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr int toast_margin_ = 20;
|
static constexpr int toast_margin_ = 20;
|
||||||
|
|
||||||
// Wrapper around `NotificationData` which makes sure that
|
// Wrapper around `NotificationData` which makes sure that
|
||||||
// the `controller` member is cleared when the controller object
|
// the `controller` member is cleared when the controller object
|
||||||
// stops tracking the notification
|
// stops tracking the notification
|
||||||
struct NotificationLink : std::shared_ptr<NotificationData> {
|
struct NotificationLink : std::shared_ptr<NotificationData> {
|
||||||
explicit NotificationLink(DesktopNotificationController* controller);
|
explicit NotificationLink(DesktopNotificationController* controller);
|
||||||
~NotificationLink();
|
~NotificationLink();
|
||||||
|
|
||||||
NotificationLink(NotificationLink&&) = default;
|
NotificationLink(NotificationLink&&) = default;
|
||||||
NotificationLink(const NotificationLink&) = delete;
|
NotificationLink(const NotificationLink&) = delete;
|
||||||
NotificationLink& operator=(NotificationLink&&) = default;
|
NotificationLink& operator=(NotificationLink&&) = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ToastInstance {
|
struct ToastInstance {
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
NotificationLink data;
|
NotificationLink data;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Toast;
|
class Toast;
|
||||||
|
|
||||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
static LRESULT CALLBACK WndProc(HWND hwnd,
|
||||||
WPARAM wparam, LPARAM lparam);
|
UINT message,
|
||||||
static DesktopNotificationController* Get(HWND hwnd) {
|
WPARAM wparam,
|
||||||
return reinterpret_cast<DesktopNotificationController*>(
|
LPARAM lparam);
|
||||||
GetWindowLongPtr(hwnd, 0));
|
static DesktopNotificationController* Get(HWND hwnd) {
|
||||||
}
|
return reinterpret_cast<DesktopNotificationController*>(
|
||||||
|
GetWindowLongPtr(hwnd, 0));
|
||||||
|
}
|
||||||
|
|
||||||
DesktopNotificationController(
|
DesktopNotificationController(const DesktopNotificationController&) = delete;
|
||||||
const DesktopNotificationController&) = delete;
|
|
||||||
|
|
||||||
void InitializeFonts();
|
void InitializeFonts();
|
||||||
void ClearAssets();
|
void ClearAssets();
|
||||||
void AnimateAll();
|
void AnimateAll();
|
||||||
void CheckQueue();
|
void CheckQueue();
|
||||||
void CreateToast(NotificationLink&& data);
|
void CreateToast(NotificationLink&& data);
|
||||||
HWND GetToast(const NotificationData* data) const;
|
HWND GetToast(const NotificationData* data) const;
|
||||||
void DestroyToast(ToastInstance& inst);
|
void DestroyToast(ToastInstance& inst);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr const TCHAR class_name_[] =
|
static constexpr const TCHAR class_name_[] =
|
||||||
TEXT("DesktopNotificationController");
|
TEXT("DesktopNotificationController");
|
||||||
|
|
||||||
HWND hwnd_controller_ = NULL;
|
HWND hwnd_controller_ = NULL;
|
||||||
HFONT caption_font_ = NULL, body_font_ = NULL;
|
HFONT caption_font_ = NULL, body_font_ = NULL;
|
||||||
std::vector<ToastInstance> instances_;
|
std::vector<ToastInstance> instances_;
|
||||||
std::deque<NotificationLink> queue_;
|
std::deque<NotificationLink> queue_;
|
||||||
bool is_animating_ = false;
|
bool is_animating_ = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DesktopNotificationController::Notification {
|
class DesktopNotificationController::Notification {
|
||||||
public:
|
public:
|
||||||
Notification() = default;
|
Notification() = default;
|
||||||
explicit Notification(const std::shared_ptr<NotificationData>& data);
|
explicit Notification(const std::shared_ptr<NotificationData>& data);
|
||||||
|
|
||||||
bool operator==(const Notification& other) const;
|
bool operator==(const Notification& other) const;
|
||||||
|
|
||||||
void Close();
|
void Close();
|
||||||
void Set(std::wstring caption, std::wstring body_text, HBITMAP image);
|
void Set(std::wstring caption, std::wstring body_text, HBITMAP image);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<NotificationData> data_;
|
std::shared_ptr<NotificationData> data_;
|
||||||
|
|
||||||
friend class DesktopNotificationController;
|
friend class DesktopNotificationController;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -5,93 +5,88 @@ namespace brightray {
|
||||||
|
|
||||||
class DesktopNotificationController::Toast {
|
class DesktopNotificationController::Toast {
|
||||||
public:
|
public:
|
||||||
static void Register(HINSTANCE hinstance);
|
static void Register(HINSTANCE hinstance);
|
||||||
static HWND Create(HINSTANCE hinstance,
|
static HWND Create(HINSTANCE hinstance,
|
||||||
std::shared_ptr<NotificationData>& data);
|
std::shared_ptr<NotificationData>& data);
|
||||||
static Toast* Get(HWND hwnd) {
|
static Toast* Get(HWND hwnd) {
|
||||||
return reinterpret_cast<Toast*>(GetWindowLongPtr(hwnd, 0));
|
return reinterpret_cast<Toast*>(GetWindowLongPtr(hwnd, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
static LRESULT CALLBACK WndProc(HWND hwnd,
|
||||||
WPARAM wparam, LPARAM lparam);
|
UINT message,
|
||||||
|
WPARAM wparam,
|
||||||
|
LPARAM lparam);
|
||||||
|
|
||||||
const std::shared_ptr<NotificationData>& GetNotification() const {
|
const std::shared_ptr<NotificationData>& GetNotification() const {
|
||||||
return data_;
|
return data_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetContents();
|
void ResetContents();
|
||||||
|
|
||||||
void Dismiss();
|
void Dismiss();
|
||||||
|
|
||||||
void PopUp(int y);
|
void PopUp(int y);
|
||||||
void SetVerticalPosition(int y);
|
void SetVerticalPosition(int y);
|
||||||
int GetVerticalPosition() const {
|
int GetVerticalPosition() const { return vertical_pos_target_; }
|
||||||
return vertical_pos_target_;
|
int GetHeight() const { return toast_size_.cy; }
|
||||||
}
|
HDWP Animate(HDWP hdwp, const POINT& origin);
|
||||||
int GetHeight() const {
|
bool IsAnimationActive() const {
|
||||||
return toast_size_.cy;
|
return ease_in_active_ || ease_out_active_ || IsStackCollapseActive();
|
||||||
}
|
}
|
||||||
HDWP Animate(HDWP hdwp, const POINT& origin);
|
bool IsHighlighted() const {
|
||||||
bool IsAnimationActive() const {
|
_ASSERT(!(is_highlighted_ && !IsWindowVisible(hwnd_)));
|
||||||
return ease_in_active_ || ease_out_active_ || IsStackCollapseActive();
|
return is_highlighted_;
|
||||||
}
|
}
|
||||||
bool IsHighlighted() const {
|
|
||||||
_ASSERT(!(is_highlighted_ && !IsWindowVisible(hwnd_)));
|
|
||||||
return is_highlighted_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum TimerID {
|
enum TimerID { TimerID_AutoDismiss = 1 };
|
||||||
TimerID_AutoDismiss = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
Toast(HWND hwnd, std::shared_ptr<NotificationData>* data);
|
Toast(HWND hwnd, std::shared_ptr<NotificationData>* data);
|
||||||
~Toast();
|
~Toast();
|
||||||
|
|
||||||
void UpdateBufferSize();
|
void UpdateBufferSize();
|
||||||
void UpdateScaledImage(const SIZE& size);
|
void UpdateScaledImage(const SIZE& size);
|
||||||
void Draw();
|
void Draw();
|
||||||
void Invalidate();
|
void Invalidate();
|
||||||
bool IsRedrawNeeded() const;
|
bool IsRedrawNeeded() const;
|
||||||
void UpdateContents();
|
void UpdateContents();
|
||||||
|
|
||||||
void AutoDismiss();
|
void AutoDismiss();
|
||||||
void CancelDismiss();
|
void CancelDismiss();
|
||||||
void ScheduleDismissal();
|
void ScheduleDismissal();
|
||||||
|
|
||||||
void StartEaseIn();
|
void StartEaseIn();
|
||||||
void StartEaseOut();
|
void StartEaseOut();
|
||||||
bool IsStackCollapseActive() const;
|
bool IsStackCollapseActive() const;
|
||||||
|
|
||||||
float AnimateEaseIn();
|
float AnimateEaseIn();
|
||||||
float AnimateEaseOut();
|
float AnimateEaseOut();
|
||||||
float AnimateStackCollapse();
|
float AnimateStackCollapse();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr const TCHAR class_name_[] =
|
static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationToast");
|
||||||
TEXT("DesktopNotificationToast");
|
|
||||||
|
|
||||||
const HWND hwnd_;
|
const HWND hwnd_;
|
||||||
HDC hdc_;
|
HDC hdc_;
|
||||||
HBITMAP bitmap_ = NULL;
|
HBITMAP bitmap_ = NULL;
|
||||||
|
|
||||||
const std::shared_ptr<NotificationData> data_; // never null
|
const std::shared_ptr<NotificationData> data_; // never null
|
||||||
|
|
||||||
SIZE toast_size_ = {};
|
SIZE toast_size_ = {};
|
||||||
SIZE margin_ = {};
|
SIZE margin_ = {};
|
||||||
RECT close_button_rect_ = {};
|
RECT close_button_rect_ = {};
|
||||||
HBITMAP scaled_image_ = NULL;
|
HBITMAP scaled_image_ = NULL;
|
||||||
|
|
||||||
int vertical_pos_ = 0;
|
int vertical_pos_ = 0;
|
||||||
int vertical_pos_target_ = 0;
|
int vertical_pos_target_ = 0;
|
||||||
bool is_non_interactive_ = false;
|
bool is_non_interactive_ = false;
|
||||||
bool ease_in_active_ = false;
|
bool ease_in_active_ = false;
|
||||||
bool ease_out_active_ = false;
|
bool ease_out_active_ = false;
|
||||||
bool is_content_updated_ = false;
|
bool is_content_updated_ = false;
|
||||||
bool is_highlighted_ = false;
|
bool is_highlighted_ = false;
|
||||||
bool is_close_hot_ = false;
|
bool is_close_hot_ = false;
|
||||||
DWORD ease_in_start_, ease_out_start_, stack_collapse_start_;
|
DWORD ease_in_start_, ease_out_start_, stack_collapse_start_;
|
||||||
float ease_in_pos_ = 0, ease_out_pos_ = 0, stack_collapse_pos_ = 0;
|
float ease_in_pos_ = 0, ease_out_pos_ = 0, stack_collapse_pos_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -11,50 +11,50 @@
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
|
||||||
void Win32Notification::Show(const NotificationOptions& options) {
|
void Win32Notification::Show(const NotificationOptions& options) {
|
||||||
auto presenter = static_cast<NotificationPresenterWin7*>(this->presenter());
|
auto presenter = static_cast<NotificationPresenterWin7*>(this->presenter());
|
||||||
if (!presenter) return;
|
if (!presenter)
|
||||||
|
return;
|
||||||
|
|
||||||
HBITMAP image = NULL;
|
HBITMAP image = NULL;
|
||||||
|
|
||||||
if (!options.icon.drawsNothing()) {
|
if (!options.icon.drawsNothing()) {
|
||||||
if (options.icon.colorType() == kBGRA_8888_SkColorType) {
|
if (options.icon.colorType() == kBGRA_8888_SkColorType) {
|
||||||
BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) };
|
BITMAPINFOHEADER bmi = {sizeof(BITMAPINFOHEADER)};
|
||||||
bmi.biWidth = options.icon.width();
|
bmi.biWidth = options.icon.width();
|
||||||
bmi.biHeight = -options.icon.height();
|
bmi.biHeight = -options.icon.height();
|
||||||
bmi.biPlanes = 1;
|
bmi.biPlanes = 1;
|
||||||
bmi.biBitCount = 32;
|
bmi.biBitCount = 32;
|
||||||
bmi.biCompression = BI_RGB;
|
bmi.biCompression = BI_RGB;
|
||||||
|
|
||||||
HDC hdcScreen = GetDC(NULL);
|
HDC hdcScreen = GetDC(NULL);
|
||||||
image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT,
|
image =
|
||||||
options.icon.getPixels(),
|
CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, options.icon.getPixels(),
|
||||||
reinterpret_cast<BITMAPINFO*>(&bmi),
|
reinterpret_cast<BITMAPINFO*>(&bmi), DIB_RGB_COLORS);
|
||||||
DIB_RGB_COLORS);
|
ReleaseDC(NULL, hdcScreen);
|
||||||
ReleaseDC(NULL, hdcScreen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Win32Notification* existing = nullptr;
|
Win32Notification* existing = nullptr;
|
||||||
if (!options.tag.empty())
|
if (!options.tag.empty())
|
||||||
existing = presenter->GetNotificationObjectByTag(options.tag);
|
existing = presenter->GetNotificationObjectByTag(options.tag);
|
||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
existing->tag_.clear();
|
existing->tag_.clear();
|
||||||
this->notification_ref_ = std::move(existing->notification_ref_);
|
this->notification_ref_ = std::move(existing->notification_ref_);
|
||||||
this->notification_ref_.Set(options.title, options.msg, image);
|
this->notification_ref_.Set(options.title, options.msg, image);
|
||||||
} else {
|
} else {
|
||||||
this->notification_ref_ = presenter->AddNotification(options.title,
|
this->notification_ref_ =
|
||||||
options.msg,
|
presenter->AddNotification(options.title, options.msg, image);
|
||||||
image);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this->tag_ = options.tag;
|
this->tag_ = options.tag;
|
||||||
|
|
||||||
if (image) DeleteObject(image);
|
if (image)
|
||||||
|
DeleteObject(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Win32Notification::Dismiss() {
|
void Win32Notification::Dismiss() {
|
||||||
notification_ref_.Close();
|
notification_ref_.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -6,26 +6,23 @@ namespace brightray {
|
||||||
|
|
||||||
class Win32Notification : public brightray::Notification {
|
class Win32Notification : public brightray::Notification {
|
||||||
public:
|
public:
|
||||||
Win32Notification(NotificationDelegate* delegate,
|
Win32Notification(NotificationDelegate* delegate,
|
||||||
NotificationPresenterWin7* presenter) :
|
NotificationPresenterWin7* presenter)
|
||||||
Notification(delegate, presenter) {
|
: Notification(delegate, presenter) {}
|
||||||
}
|
void Show(const NotificationOptions& options) override;
|
||||||
void Show(const NotificationOptions& options) override;
|
void Dismiss() override;
|
||||||
void Dismiss() override;
|
|
||||||
|
|
||||||
const DesktopNotificationController::Notification& GetRef() const {
|
const DesktopNotificationController::Notification& GetRef() const {
|
||||||
return notification_ref_;
|
return notification_ref_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& GetTag() const {
|
const std::string& GetTag() const { return tag_; }
|
||||||
return tag_;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DesktopNotificationController::Notification notification_ref_;
|
DesktopNotificationController::Notification notification_ref_;
|
||||||
std::string tag_;
|
std::string tag_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(Win32Notification);
|
DISALLOW_COPY_AND_ASSIGN(Win32Notification);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -81,9 +81,8 @@ WindowsToastNotification::~WindowsToastNotification() {
|
||||||
|
|
||||||
void WindowsToastNotification::Show(const NotificationOptions& options) {
|
void WindowsToastNotification::Show(const NotificationOptions& options) {
|
||||||
auto presenter_win = static_cast<NotificationPresenterWin*>(presenter());
|
auto presenter_win = static_cast<NotificationPresenterWin*>(presenter());
|
||||||
std::wstring icon_path = presenter_win->SaveIconToFilesystem(
|
std::wstring icon_path =
|
||||||
options.icon,
|
presenter_win->SaveIconToFilesystem(options.icon, options.icon_url);
|
||||||
options.icon_url);
|
|
||||||
|
|
||||||
ComPtr<IXmlDocument> toast_xml;
|
ComPtr<IXmlDocument> toast_xml;
|
||||||
if (FAILED(GetToastXml(toast_manager_.Get(), options.title, options.msg,
|
if (FAILED(GetToastXml(toast_manager_.Get(), options.title, options.msg,
|
||||||
|
@ -123,14 +122,16 @@ void WindowsToastNotification::Show(const NotificationOptions& options) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsDebuggingNotifications()) LOG(INFO) << "Notification created";
|
if (IsDebuggingNotifications())
|
||||||
|
LOG(INFO) << "Notification created";
|
||||||
|
|
||||||
if (delegate())
|
if (delegate())
|
||||||
delegate()->NotificationDisplayed();
|
delegate()->NotificationDisplayed();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowsToastNotification::Dismiss() {
|
void WindowsToastNotification::Dismiss() {
|
||||||
if (IsDebuggingNotifications()) LOG(INFO) << "Hiding notification";
|
if (IsDebuggingNotifications())
|
||||||
|
LOG(INFO) << "Hiding notification";
|
||||||
toast_notifier_->Hide(toast_notification_.Get());
|
toast_notifier_->Hide(toast_notification_.Get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,7 +408,8 @@ IFACEMETHODIMP ToastEventHandler::Invoke(
|
||||||
content::BrowserThread::PostTask(
|
content::BrowserThread::PostTask(
|
||||||
content::BrowserThread::UI, FROM_HERE,
|
content::BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(&Notification::NotificationClicked, notification_));
|
base::Bind(&Notification::NotificationClicked, notification_));
|
||||||
if (IsDebuggingNotifications()) LOG(INFO) << "Notification clicked";
|
if (IsDebuggingNotifications())
|
||||||
|
LOG(INFO) << "Notification clicked";
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
@ -418,7 +420,8 @@ IFACEMETHODIMP ToastEventHandler::Invoke(
|
||||||
content::BrowserThread::PostTask(
|
content::BrowserThread::PostTask(
|
||||||
content::BrowserThread::UI, FROM_HERE,
|
content::BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(&Notification::NotificationDismissed, notification_));
|
base::Bind(&Notification::NotificationDismissed, notification_));
|
||||||
if (IsDebuggingNotifications()) LOG(INFO) << "Notification dismissed";
|
if (IsDebuggingNotifications())
|
||||||
|
LOG(INFO) << "Notification dismissed";
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
@ -429,7 +432,8 @@ IFACEMETHODIMP ToastEventHandler::Invoke(
|
||||||
content::BrowserThread::PostTask(
|
content::BrowserThread::PostTask(
|
||||||
content::BrowserThread::UI, FROM_HERE,
|
content::BrowserThread::UI, FROM_HERE,
|
||||||
base::Bind(&Notification::NotificationFailed, notification_));
|
base::Bind(&Notification::NotificationFailed, notification_));
|
||||||
if (IsDebuggingNotifications()) LOG(INFO) << "Notification failed";
|
if (IsDebuggingNotifications())
|
||||||
|
LOG(INFO) << "Notification failed";
|
||||||
|
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ namespace brightray {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
base::string16 g_app_user_model_id;
|
base::string16 g_app_user_model_id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const wchar_t kAppUserModelIDFormat[] = L"electron.app.$1";
|
const wchar_t kAppUserModelIDFormat[] = L"electron.app.$1";
|
||||||
|
@ -49,7 +48,7 @@ PCWSTR GetRawAppUserModelID() {
|
||||||
} else {
|
} else {
|
||||||
std::string name = GetApplicationName();
|
std::string name = GetApplicationName();
|
||||||
base::string16 generated_app_id = base::ReplaceStringPlaceholders(
|
base::string16 generated_app_id = base::ReplaceStringPlaceholders(
|
||||||
kAppUserModelIDFormat, base::UTF8ToUTF16(name), nullptr);
|
kAppUserModelIDFormat, base::UTF8ToUTF16(name), nullptr);
|
||||||
SetAppUserModelID(generated_app_id);
|
SetAppUserModelID(generated_app_id);
|
||||||
}
|
}
|
||||||
CoTaskMemFree(current_app_id);
|
CoTaskMemFree(current_app_id);
|
||||||
|
|
|
@ -16,19 +16,17 @@ namespace brightray {
|
||||||
std::string GetProductInternal() {
|
std::string GetProductInternal() {
|
||||||
auto name = GetApplicationName();
|
auto name = GetApplicationName();
|
||||||
base::RemoveChars(name, base::kWhitespaceASCII, &name);
|
base::RemoveChars(name, base::kWhitespaceASCII, &name);
|
||||||
return base::StringPrintf("%s/%s",
|
return base::StringPrintf("%s/%s", name.c_str(),
|
||||||
name.c_str(), GetApplicationVersion().c_str());
|
GetApplicationVersion().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetBrightrayUserAgent() {
|
std::string GetBrightrayUserAgent() {
|
||||||
return content::BuildUserAgentFromProduct(GetProductInternal());
|
return content::BuildUserAgentFromProduct(GetProductInternal());
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentClient::ContentClient() {
|
ContentClient::ContentClient() {}
|
||||||
}
|
|
||||||
|
|
||||||
ContentClient::~ContentClient() {
|
ContentClient::~ContentClient() {}
|
||||||
}
|
|
||||||
|
|
||||||
std::string ContentClient::GetProduct() const {
|
std::string ContentClient::GetProduct() const {
|
||||||
return GetProductInternal();
|
return GetProductInternal();
|
||||||
|
@ -43,7 +41,8 @@ base::string16 ContentClient::GetLocalizedString(int message_id) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
base::StringPiece ContentClient::GetDataResource(
|
base::StringPiece ContentClient::GetDataResource(
|
||||||
int resource_id, ui::ScaleFactor scale_factor) const {
|
int resource_id,
|
||||||
|
ui::ScaleFactor scale_factor) const {
|
||||||
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
|
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
|
||||||
resource_id, scale_factor);
|
resource_id, scale_factor);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@ bool SubprocessNeedsResourceBundle(const std::string& process_type) {
|
||||||
process_type == switches::kZygoteProcess ||
|
process_type == switches::kZygoteProcess ||
|
||||||
#endif
|
#endif
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
// Mac needs them too for scrollbar related images and for sandbox
|
// Mac needs them too for scrollbar related images and for sandbox
|
||||||
// profiles.
|
// profiles.
|
||||||
#if !defined(DISABLE_NACL)
|
#if !defined(DISABLE_NACL)
|
||||||
process_type == switches::kNaClLoaderProcess ||
|
process_type == switches::kNaClLoaderProcess ||
|
||||||
#endif
|
#endif
|
||||||
|
@ -48,7 +48,7 @@ void LoadResourceBundle(const std::string& locale) {
|
||||||
ui::ResourceBundle::CleanupSharedInstance();
|
ui::ResourceBundle::CleanupSharedInstance();
|
||||||
|
|
||||||
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
||||||
locale, nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
|
locale, nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES);
|
||||||
|
|
||||||
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
|
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
|
||||||
bundle.ReloadLocaleResources(locale);
|
bundle.ReloadLocaleResources(locale);
|
||||||
|
@ -82,11 +82,9 @@ void LoadResourceBundle(const std::string& locale) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
MainDelegate::MainDelegate() {
|
MainDelegate::MainDelegate() {}
|
||||||
}
|
|
||||||
|
|
||||||
MainDelegate::~MainDelegate() {
|
MainDelegate::~MainDelegate() {}
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<ContentClient> MainDelegate::CreateContentClient() {
|
std::unique_ptr<ContentClient> MainDelegate::CreateContentClient() {
|
||||||
return std::unique_ptr<ContentClient>(new ContentClient);
|
return std::unique_ptr<ContentClient>(new ContentClient);
|
||||||
|
|
Loading…
Reference in a new issue