From b85c3b5e7fc8da5bc376f7f68220ef22bb5ffe54 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sat, 9 Jul 2016 22:24:40 +0200 Subject: [PATCH 1/8] Remove unused using decls. --- brightray/browser/devtools_ui.cc | 1 - brightray/browser/net/devtools_network_protocol_handler.cc | 1 - 2 files changed, 2 deletions(-) diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 6f5bdc7bfa5b..855474d93bb2 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -14,7 +14,6 @@ #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" -using content::WebContents; namespace brightray { diff --git a/brightray/browser/net/devtools_network_protocol_handler.cc b/brightray/browser/net/devtools_network_protocol_handler.cc index 60a3a15a0a39..584840533be9 100644 --- a/brightray/browser/net/devtools_network_protocol_handler.cc +++ b/brightray/browser/net/devtools_network_protocol_handler.cc @@ -12,7 +12,6 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/devtools_agent_host.h" -using content::BrowserThread; namespace brightray { From 7474e5ec281f3d0c3c3b9b025cb4c864016451db Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sun, 10 Jul 2016 11:56:02 +0200 Subject: [PATCH 2/8] Modernize to C++11 : NULL => nullptr --- brightray/browser/media/media_capture_devices_dispatcher.cc | 6 +++--- brightray/browser/media/media_stream_devices_controller.cc | 2 +- brightray/browser/url_request_context_getter.cc | 6 +++--- brightray/browser/web_ui_controller_factory.cc | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index 09c71b82a495..535635159d31 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -26,7 +26,7 @@ const content::MediaStreamDevice* FindDeviceWithId( return &(*iter); } } - return NULL; + return nullptr; } const MediaStreamDevices& EmptyDevices() { @@ -100,7 +100,7 @@ MediaCaptureDevicesDispatcher::GetFirstAvailableAudioDevice() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices(); if (audio_devices.empty()) - return NULL; + return nullptr; return &(*audio_devices.begin()); } @@ -119,7 +119,7 @@ MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices(); if (video_devices.empty()) - return NULL; + return nullptr; return &(*video_devices.begin()); } diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index 103feea369d1..b3548bbe4093 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -73,7 +73,7 @@ void MediaStreamDevicesController::Accept() { if (microphone_requested_ || webcam_requested_) { switch (request_.request_type) { case content::MEDIA_OPEN_DEVICE_PEPPER_ONLY: { - const content::MediaStreamDevice* device = NULL; + const content::MediaStreamDevice* device = nullptr; // For open device request pick the desired device or fall back to the // first available of the given type. if (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index feec4ce6f84f..f24b9b2bde75 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -221,12 +221,12 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { auto cookie_config = content::CookieStoreConfig( base_path_.Append(FILE_PATH_LITERAL("Cookies")), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, - NULL, NULL); + nullptr, nullptr); cookie_store = content::CreateCookieStore(cookie_config); } storage_->set_cookie_store(std::move(cookie_store)); storage_->set_channel_id_service(base::WrapUnique( - new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), + new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr), base::WorkerPool::GetTaskRunner(true)))); std::string accept_lang = l10n_util::GetApplicationLocale(""); @@ -270,7 +270,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { new net::ProxyScriptFetcherImpl(url_request_context_.get()), dhcp_factory.Create(url_request_context_.get()), host_resolver.get(), - NULL, + nullptr, url_request_context_->network_delegate())); } diff --git a/brightray/browser/web_ui_controller_factory.cc b/brightray/browser/web_ui_controller_factory.cc index 3313d3a6c632..c59e5bb0c667 100644 --- a/brightray/browser/web_ui_controller_factory.cc +++ b/brightray/browser/web_ui_controller_factory.cc @@ -54,7 +54,7 @@ content::WebUIController* WebUIControllerFactory::CreateWebUIControllerForURL( auto browser_context = web_ui->GetWebContents()->GetBrowserContext(); return new DevToolsUI(browser_context, web_ui); } - return NULL; + return nullptr; } } // namespace brightray From 0cf7454d4ba359dbb57d0fd6d8ccc3ec4d2b4ab9 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sun, 10 Jul 2016 13:12:33 +0200 Subject: [PATCH 3/8] Modernize to C++11 : use auto. --- brightray/browser/devtools_embedder_message_dispatcher.cc | 4 ++-- brightray/browser/devtools_file_system_indexer.cc | 2 +- brightray/browser/inspectable_web_contents_impl.cc | 6 +++--- brightray/browser/media/media_capture_devices_dispatcher.cc | 4 ++-- brightray/browser/net/devtools_network_controller.cc | 2 +- brightray/browser/net_log.cc | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index f45d90d753fb..9df6a08b6de0 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -121,7 +121,7 @@ class DispatcherImpl : public DevToolsEmbedderMessageDispatcher { bool Dispatch(const DispatchCallback& callback, const std::string& method, const base::ListValue* params) override { - HandlerMap::iterator it = handlers_.find(method); + auto it = handlers_.find(method); return it != handlers_.end() && it->second.Run(callback, *params); } @@ -156,7 +156,7 @@ class DispatcherImpl : public DevToolsEmbedderMessageDispatcher { DevToolsEmbedderMessageDispatcher* DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend( Delegate* delegate) { - DispatcherImpl* d = new DispatcherImpl(); + auto* d = new DispatcherImpl(); d->RegisterHandler("bringToFront", &Delegate::ActivateWindow, delegate); d->RegisterHandler("closeWindow", &Delegate::CloseWindow, delegate); diff --git a/brightray/browser/devtools_file_system_indexer.cc b/brightray/browser/devtools_file_system_indexer.cc index 788db1fa6303..f9841441ad21 100644 --- a/brightray/browser/devtools_file_system_indexer.cc +++ b/brightray/browser/devtools_file_system_indexer.cc @@ -160,7 +160,7 @@ void Index::SetTrigramsForFile(const FilePath& file_path, const Time& time) { DCHECK_CURRENTLY_ON(BrowserThread::FILE); FileId file_id = GetFileId(file_path); - vector::const_iterator it = index.begin(); + auto it = index.begin(); for (; it != index.end(); ++it) { Trigram trigram = *it; index_[trigram].push_back(file_id); diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 70119c15582c..c6f6eb5b46a4 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -167,7 +167,7 @@ int ResponseWriter::Initialize(const net::CompletionCallback& callback) { int ResponseWriter::Write(net::IOBuffer* buffer, int num_bytes, const net::CompletionCallback& callback) { - base::FundamentalValue* id = new base::FundamentalValue(stream_id_); + auto* id = new base::FundamentalValue(stream_id_); base::StringValue* chunk = new base::StringValue(std::string(buffer->data(), num_bytes)); @@ -683,11 +683,11 @@ void InspectableWebContentsImpl::DidStartNavigationToPendingEntry( void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) { DCHECK(source); - PendingRequestsMap::iterator it = pending_requests_.find(source); + auto it = pending_requests_.find(source); DCHECK(it != pending_requests_.end()); base::DictionaryValue response; - base::DictionaryValue* headers = new base::DictionaryValue(); + auto* headers = new base::DictionaryValue(); net::HttpResponseHeaders* rh = source->GetResponseHeaders(); response.SetInteger("statusCode", rh ? rh->response_code() : 200); response.Set("headers", headers); diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index 535635159d31..44b781fafaf2 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -20,7 +20,7 @@ namespace { const content::MediaStreamDevice* FindDeviceWithId( const content::MediaStreamDevices& devices, const std::string& device_id) { - content::MediaStreamDevices::const_iterator iter = devices.begin(); + auto iter = devices.begin(); for (; iter != devices.end(); ++iter) { if (iter->id == device_id) { return &(*iter); @@ -30,7 +30,7 @@ const content::MediaStreamDevice* FindDeviceWithId( } const MediaStreamDevices& EmptyDevices() { - static MediaStreamDevices* devices = new MediaStreamDevices; + static auto* devices = new MediaStreamDevices; return *devices; } diff --git a/brightray/browser/net/devtools_network_controller.cc b/brightray/browser/net/devtools_network_controller.cc index cb2f92ba222b..cfa4e2347123 100644 --- a/brightray/browser/net/devtools_network_controller.cc +++ b/brightray/browser/net/devtools_network_controller.cc @@ -47,7 +47,7 @@ void DevToolsNetworkController::SetNetworkState( } bool has_offline_interceptors = false; - InterceptorMap::iterator it = interceptors_.begin(); + auto it = interceptors_.begin(); for (; it != interceptors_.end(); ++it) { if (it->second->IsOffline()) { has_offline_interceptors = true; diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index 9876b49418b3..f141c7ef2e43 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -18,7 +18,7 @@ std::unique_ptr GetConstants() { std::unique_ptr constants = net::GetNetConstants(); // Adding client information to constants dictionary. - base::DictionaryValue* client_info = new base::DictionaryValue(); + auto* client_info = new base::DictionaryValue(); client_info->SetString( "command_line", base::CommandLine::ForCurrentProcess()->GetCommandLineString()); From 3e041b2c916b4e4e96288ab1857cfe894fdaf59e Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sun, 10 Jul 2016 13:22:54 +0200 Subject: [PATCH 4/8] Modernize C++11: Use override. --- brightray/browser/devtools_manager_delegate.cc | 2 +- brightray/browser/devtools_ui.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index 1464362f3ad7..368ac3a60731 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -89,7 +89,7 @@ class DevToolsDelegate : public devtools_http_handler::DevToolsHttpHandlerDelegate { public: DevToolsDelegate(); - virtual ~DevToolsDelegate(); + ~DevToolsDelegate() override; // devtools_http_handler::DevToolsHttpHandlerDelegate. std::string GetDiscoveryPageHTML() override; diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 6f5bdc7bfa5b..e3452fa8b79f 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -114,7 +114,7 @@ class BundledDataSource : public content::URLDataSource { } private: - virtual ~BundledDataSource() {} + ~BundledDataSource() override {} DISALLOW_COPY_AND_ASSIGN(BundledDataSource); }; From 1d1dd6301ab4d6c235788b4c6ecccc1f46abf0d0 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sun, 10 Jul 2016 15:38:34 +0200 Subject: [PATCH 5/8] Don't use auto to static variables. --- brightray/browser/media/media_capture_devices_dispatcher.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index 44b781fafaf2..4a0a71c7c3f8 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -30,7 +30,7 @@ const content::MediaStreamDevice* FindDeviceWithId( } const MediaStreamDevices& EmptyDevices() { - static auto* devices = new MediaStreamDevices; + static MediaStreamDevices* devices = new MediaStreamDevices; return *devices; } From f6171c53cafbed86c397db13be5fc4268fbbaf24 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 11 Jul 2016 15:08:39 +0900 Subject: [PATCH 6/8] Allow devtools window to show on other screens --- brightray/browser/inspectable_web_contents_impl.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c6f6eb5b46a4..dfb46ff0124d 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -91,6 +91,14 @@ bool IsPointInRect(const gfx::Point& point, const gfx::Rect& rect) { point.y() > rect.y() && point.y() < (rect.height() + rect.y()); } +bool IsPointInScreen(const gfx::Point& point) { + for (const auto& display : gfx::Screen::GetScreen()->GetAllDisplays()) { + if (IsPointInRect(point, display.bounds())) + return true; + } + return false; +} + void SetZoomLevelForWebContents(content::WebContents* web_contents, double level) { content::HostZoomMap::SetZoomLevel(web_contents, level); @@ -214,9 +222,9 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( devtools_bounds_.set_height(600); devtools_bounds_.set_width(800); } - gfx::Rect display = gfx::Screen::GetScreen() - ->GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); - if (!IsPointInRect(devtools_bounds_.origin(), display)) { + if (!IsPointInScreen(devtools_bounds_.origin())) { + gfx::Rect display = gfx::Screen::GetScreen()-> + GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); devtools_bounds_.set_x(display.x() + (display.width() - devtools_bounds_.width()) / 2); devtools_bounds_.set_y(display.y() + (display.height() - devtools_bounds_.height()) / 2); } From 6413a4c516c7108fd4a6a5ccc546f9124cfdfc11 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 12 Jul 2016 21:39:23 +0900 Subject: [PATCH 7/8] Move the ability to create BrowserContext to embedder --- brightray/browser/browser_context.cc | 10 +++++----- brightray/browser/browser_context.h | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 236a8f5c1f21..91928d9e367b 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -85,16 +85,13 @@ class BrowserContext::ResourceContext : public content::ResourceContext { BrowserContext::BrowserContextMap BrowserContext::browser_context_map_; // static -scoped_refptr BrowserContext::From( +scoped_refptr BrowserContext::Get( const std::string& partition, bool in_memory) { PartitionKey key(partition, in_memory); if (browser_context_map_[key].get()) return make_scoped_refptr(browser_context_map_[key].get()); - auto browser_context = BrowserContext::Create(partition, in_memory); - browser_context->InitPrefs(); - browser_context_map_[key] = browser_context->weak_factory_.GetWeakPtr(); - return browser_context; + return nullptr; } BrowserContext::BrowserContext(const std::string& partition, bool in_memory) @@ -112,7 +109,10 @@ BrowserContext::BrowserContext(const std::string& partition, bool in_memory) path_ = path_.Append(FILE_PATH_LITERAL("Partitions")) .Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition))); + InitPrefs(); content::BrowserContext::Initialize(this, path_); + + browser_context_map_[PartitionKey(partition, in_memory)] = GetWeakPtr(); } void BrowserContext::InitPrefs() { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 421ef51f43ce..7ae9b2692090 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -30,13 +30,14 @@ class BrowserContext : public base::RefCounted, public content::BrowserContext, public brightray::URLRequestContextGetter::Delegate { public: - // Get or Create the BrowserContext according to its |partition| and |in_memory|. - static scoped_refptr From( + // Get the BrowserContext according to its |partition| and |in_memory|, + // empty pointer when be returned when there is no matching BrowserContext. + static scoped_refptr Get( const std::string& partition, bool in_memory); - // Create a new BrowserContext, embedders should implement it on their own. - static scoped_refptr Create( - const std::string& partition, bool in_memory); + base::WeakPtr GetWeakPtr() { + return weak_factory_.GetWeakPtr(); + } // content::BrowserContext: std::unique_ptr CreateZoomLevelDelegate( From 22b3b69e175dc85bde966ecc6948641c33954ae5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 12 Jul 2016 14:03:02 -0700 Subject: [PATCH 8/8] Return focus state of window web view when available --- .../browser/views/inspectable_web_contents_view_views.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 09c9ab6f8012..1a438f200e3a 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -142,7 +142,9 @@ bool InspectableWebContentsViewViews::IsDevToolsViewShowing() { } bool InspectableWebContentsViewViews::IsDevToolsViewFocused() { - if (devtools_web_view_) + if (devtools_window_web_view_) + return devtools_window_web_view_->HasFocus(); + else if (devtools_web_view_) return devtools_web_view_->HasFocus(); else return false;