diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index fce7dfc1ad37..b3c4e92e6fde 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -82,8 +82,11 @@ ['libchromiumcontent_component', { 'link_settings': { 'libraries': [ - # libgtk2ui is always linked statically. + # Following libraries are always linked statically. '<(libchromiumcontent_dir)/libgtk2ui.a', + '<(libchromiumcontent_dir)/libdevtools_discovery.a', + '<(libchromiumcontent_dir)/libdevtools_http_handler.a', + '<(libchromiumcontent_dir)/libhttp_server.a', ], }, }, { @@ -112,10 +115,19 @@ ], }, 'conditions': [ - # Link with system frameworks. - ['libchromiumcontent_component==0', { + ['libchromiumcontent_component', { 'link_settings': { 'libraries': [ + # Following libraries are always linked statically. + '<(libchromiumcontent_dir)/libdevtools_discovery.a', + '<(libchromiumcontent_dir)/libdevtools_http_handler.a', + '<(libchromiumcontent_dir)/libhttp_server.a', + ], + }, + }, { + 'link_settings': { + 'libraries': [ + # Link with system frameworks. # ui_base.gypi: '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', # net.gypi: @@ -152,19 +164,21 @@ ['OS=="win"', { 'conditions': [ ['libchromiumcontent_component', { - # sandbox and base_static are always linked statically. + # sandbox, base_static, devtools_discovery, devtools_http_handler, + # http_server are always linked statically. 'link_settings': { 'libraries': [ '<(libchromiumcontent_dir)/base_static.lib', '<(libchromiumcontent_dir)/sandbox.lib', + '<(libchromiumcontent_dir)/devtools_discovery.lib', + '<(libchromiumcontent_dir)/devtools_http_handler.lib', + '<(libchromiumcontent_dir)/http_server.lib', ], }, }, { # Link with system libraries. 'link_settings': { 'libraries': [ - # ffmpegsumo.lib is required for linking with ffmpegsumo.dll - '<(libchromiumcontent_dir)/ffmpegsumo.lib', # content_browser.gypi: '-lsensorsapi.lib', '-lportabledeviceguids.lib', @@ -184,6 +198,7 @@ 'AdditionalDependencies': [ 'advapi32.lib', 'dbghelp.lib', + 'delayimp.lib', 'dwmapi.lib', 'gdi32.lib', 'netapi32.lib', @@ -195,7 +210,6 @@ 'winspool.lib', ], 'DelayLoadDLLs': [ - 'ffmpegsumo.dll', # content_common.gypi: 'd3d9.dll', 'dxva2.dll', diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index d03703ba4a36..32189ab93a82 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -40,6 +40,7 @@ '-Wextra', '-Wno-unused-parameter', '-Wno-missing-field-initializers', + '-Wno-unneeded-internal-declaration', ], }, 'msvs_configuration_attributes': { diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 493e896366fa..18b5fd855e25 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -10,11 +10,8 @@ #include "browser/media/media_capture_devices_dispatcher.h" #include "browser/platform_notification_service_impl.h" -#include "base/base_paths.h" #include "base/path_service.h" -#include "content/public/common/content_descriptors.h" #include "content/public/common/url_constants.h" -#include "gin/public/isolate_holder.h" namespace brightray { @@ -32,11 +29,6 @@ BrowserClient::BrowserClient() : browser_main_parts_(nullptr) { DCHECK(!g_browser_client); g_browser_client = this; - -#if defined(OS_POSIX) && !defined(OS_MACOSX) - v8_natives_fd_.reset(-1); - v8_snapshot_fd_.reset(-1); -#endif // OS_POSIX && !OS_MACOSX } BrowserClient::~BrowserClient() { @@ -63,7 +55,9 @@ net::URLRequestContextGetter* BrowserClient::CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors) { auto context = static_cast(browser_context); - return context->CreateRequestContext(protocol_handlers, protocol_interceptors.Pass()); + return context->CreateRequestContext(static_cast(GetNetLog()), + protocol_handlers, + protocol_interceptors.Pass()); } content::MediaObserver* BrowserClient::GetMediaObserver() { @@ -81,7 +75,7 @@ void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( } net::NetLog* BrowserClient::GetNetLog() { - return browser_context()->GetNetLog(); + return &net_log_; } base::FilePath BrowserClient::GetDefaultDownloadDirectory() { @@ -97,31 +91,4 @@ content::DevToolsManagerDelegate* BrowserClient::GetDevToolsManagerDelegate() { return new DevToolsManagerDelegate; } -#if defined(OS_POSIX) && !defined(OS_MACOSX) -void BrowserClient::GetAdditionalMappedFilesForChildProcess( - const base::CommandLine& command_line, - int child_process_id, - content::FileDescriptorInfo* mappings) { - if (v8_snapshot_fd_.get() == -1 && v8_natives_fd_.get() == -1) { - base::FilePath v8_data_path; - PathService::Get(gin::IsolateHolder::kV8SnapshotBasePathKey, &v8_data_path); - DCHECK(!v8_data_path.empty()); - - int file_flags = base::File::FLAG_OPEN | base::File::FLAG_READ; - base::FilePath v8_natives_data_path = - v8_data_path.AppendASCII(gin::IsolateHolder::kNativesFileName); - base::FilePath v8_snapshot_data_path = - v8_data_path.AppendASCII(gin::IsolateHolder::kSnapshotFileName); - base::File v8_natives_data_file(v8_natives_data_path, file_flags); - base::File v8_snapshot_data_file(v8_snapshot_data_path, file_flags); - DCHECK(v8_natives_data_file.IsValid()); - DCHECK(v8_snapshot_data_file.IsValid()); - v8_natives_fd_.reset(v8_natives_data_file.TakePlatformFile()); - v8_snapshot_fd_.reset(v8_snapshot_data_file.TakePlatformFile()); - } - mappings->Share(kV8NativesDataDescriptor, v8_natives_fd_.get()); - mappings->Share(kV8SnapshotDataDescriptor, v8_snapshot_fd_.get()); -} -#endif - } // namespace brightray diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index f9b0f0d05852..f69b017e5e10 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -5,12 +5,14 @@ #ifndef BRIGHTRAY_BROWSER_BROWSER_CLIENT_H_ #define BRIGHTRAY_BROWSER_BROWSER_CLIENT_H_ +#include "browser/net_log.h" #include "content/public/browser/content_browser_client.h" namespace brightray { class BrowserContext; class BrowserMainParts; +class NetLog; class BrowserClient : public content::ContentBrowserClient { public: @@ -35,8 +37,6 @@ class BrowserClient : public content::ContentBrowserClient { content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors) override; - - private: content::BrowserMainParts* CreateBrowserMainParts( const content::MainFunctionParams&) override; content::MediaObserver* GetMediaObserver() override; @@ -47,19 +47,8 @@ class BrowserClient : public content::ContentBrowserClient { base::FilePath GetDefaultDownloadDirectory() override; content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override; -#if defined(OS_POSIX) && !defined(OS_MACOSX) - void GetAdditionalMappedFilesForChildProcess( - const base::CommandLine& command_line, - int child_process_id, - content::FileDescriptorInfo* mappings) override; -#endif - BrowserMainParts* browser_main_parts_; - -#if defined(OS_POSIX) && !defined(OS_MACOSX) - base::ScopedFD v8_natives_fd_; - base::ScopedFD v8_snapshot_fd_; -#endif // OS_POSIX && !OS_MACOSX + NetLog net_log_; DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index ec41caed2558..c490de4fe276 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -100,11 +100,13 @@ void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { } net::URLRequestContextGetter* BrowserContext::CreateRequestContext( + NetLog* net_log, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors) { DCHECK(!url_request_getter_.get()); url_request_getter_ = new URLRequestContextGetter( this, + net_log, GetPath(), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), @@ -114,10 +116,6 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( return url_request_getter_.get(); } -net::NetLog* BrowserContext::GetNetLog() { - return url_request_getter_->net_log(); -} - net::NetworkDelegate* BrowserContext::CreateNetworkDelegate() { return new NetworkDelegate; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 9244ac40c2f6..6b0ca300b2a1 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -46,9 +46,9 @@ class BrowserContext : public content::BrowserContext, content::PermissionManager* GetPermissionManager() override; net::URLRequestContextGetter* CreateRequestContext( + NetLog* net_log, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors); - net::NetLog* GetNetLog(); net::URLRequestContextGetter* url_request_context_getter() const { return url_request_getter_.get(); diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 807e50224979..fe6a42b93690 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -10,7 +10,7 @@ #include "base/command_line.h" #include "base/strings/string_number_conversions.h" -#include "content/public/browser/devtools_http_handler.h" +#include "components/devtools_http_handler/devtools_http_handler.h" #include "content/public/common/content_switches.h" #include "net/proxy/proxy_resolver_v8.h" diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index e8d7c323c78a..d5ae8f1b7f2a 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -9,7 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" -namespace content { +namespace devtools_http_handler { class DevToolsHttpHandler; } @@ -58,7 +58,7 @@ class BrowserMainParts : public content::BrowserMainParts { scoped_ptr browser_context_; scoped_ptr web_ui_controller_factory_; - scoped_ptr devtools_http_handler_; + scoped_ptr devtools_http_handler_; #if defined(TOOLKIT_VIEWS) scoped_ptr views_delegate_; diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index cb44ec16d860..2a4b38176595 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -195,6 +195,11 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend( d->RegisterHandler("recordActionUMA", &Delegate::RecordActionUMA, delegate); d->RegisterHandlerWithCallback("sendJsonRequest", &Delegate::SendJsonRequest, delegate); + d->RegisterHandlerWithCallback("getPreferences", + &Delegate::GetPreferences, delegate); + d->RegisterHandler("setPreference", &Delegate::SetPreference, delegate); + d->RegisterHandler("removePreference", &Delegate::RemovePreference, delegate); + d->RegisterHandler("clearPreferences", &Delegate::ClearPreferences, delegate); return d; } diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index 851a2f490586..46f54dfbf2ce 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -73,6 +73,11 @@ class DevToolsEmbedderMessageDispatcher { virtual void SendJsonRequest(const DispatchCallback& callback, const std::string& browser_id, const std::string& url) = 0; + virtual void GetPreferences(const DispatchCallback& callback) = 0; + virtual void SetPreference(const std::string& name, + const std::string& value) = 0; + virtual void RemovePreference(const std::string& name) = 0; + virtual void ClearPreferences() = 0; }; using DispatchCallback = Delegate::DispatchCallback; diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index ec660d08ce03..89c3469fc0d7 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -12,27 +12,22 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "browser/browser_context.h" +#include "common/content_client.h" +#include "components/devtools_discovery/basic_target_descriptor.h" +#include "components/devtools_discovery/devtools_discovery_manager.h" +#include "components/devtools_http_handler/devtools_http_handler.h" #include "content/public/browser/devtools_agent_host.h" -#include "content/public/browser/devtools_http_handler.h" -#include "content/public/browser/devtools_target.h" +#include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/favicon_status.h" #include "content/public/browser/navigation_entry.h" -#include "content/public/browser/render_view_host.h" -#include "content/public/browser/web_contents.h" #include "content/public/common/content_switches.h" #include "content/public/common/url_constants.h" #include "content/public/common/user_agent.h" +#include "net/base/net_errors.h" #include "net/socket/tcp_server_socket.h" #include "net/socket/stream_socket.h" #include "ui/base/resource/resource_bundle.h" -using content::DevToolsAgentHost; -using content::RenderViewHost; -using content::WebContents; -using content::BrowserContext; -using content::DevToolsTarget; -using content::DevToolsHttpHandler; namespace brightray { @@ -43,12 +38,8 @@ namespace { // since libcontentchromium doesn't expose content_shell resources. const int kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE = 25500; -const char kTargetTypePage[] = "page"; -const char kTargetTypeServiceWorker[] = "service_worker"; -const char kTargetTypeOther[] = "other"; - class TCPServerSocketFactory - : public content::DevToolsHttpHandler::ServerSocketFactory { + : public devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory { public: TCPServerSocketFactory(const std::string& address, int port) : address_(address), port_(port) { @@ -71,7 +62,7 @@ class TCPServerSocketFactory DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); }; -scoped_ptr +scoped_ptr CreateSocketFactory() { auto& command_line = *base::CommandLine::ForCurrentProcess(); // See if the user specified a port on the command line (useful for @@ -88,77 +79,24 @@ CreateSocketFactory() { DLOG(WARNING) << "Invalid http debugger port number " << temp_port; } } - return scoped_ptr( - new TCPServerSocketFactory("127.0.0.1", port)); + return scoped_ptr< + devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory>( + new TCPServerSocketFactory("127.0.0.1", port)); } -class Target : public content::DevToolsTarget { - public: - explicit Target(scoped_refptr agent_host); - - std::string GetId() const override { return agent_host_->GetId(); } - std::string GetParentId() const override { return std::string(); } - std::string GetType() const override { - switch (agent_host_->GetType()) { - case DevToolsAgentHost::TYPE_WEB_CONTENTS: - return kTargetTypePage; - case DevToolsAgentHost::TYPE_SERVICE_WORKER: - return kTargetTypeServiceWorker; - default: - break; - } - return kTargetTypeOther; - } - std::string GetTitle() const override { return agent_host_->GetTitle(); } - std::string GetDescription() const override { return std::string(); } - GURL GetURL() const override { return agent_host_->GetURL(); } - GURL GetFaviconURL() const override { return favicon_url_; } - base::TimeTicks GetLastActivityTime() const override { - return last_activity_time_; - } - bool IsAttached() const override { return agent_host_->IsAttached(); } - scoped_refptr GetAgentHost() const override { - return agent_host_; - } - bool Activate() const override; - bool Close() const override; - - private: - scoped_refptr agent_host_; - GURL favicon_url_; - base::TimeTicks last_activity_time_; -}; - -Target::Target(scoped_refptr agent_host) - : agent_host_(agent_host) { - if (WebContents* web_contents = agent_host_->GetWebContents()) { - content::NavigationController& controller = web_contents->GetController(); - content::NavigationEntry* entry = controller.GetActiveEntry(); - if (entry != NULL && entry->GetURL().is_valid()) - favicon_url_ = entry->GetFavicon().url; - last_activity_time_ = web_contents->GetLastActiveTime(); - } -} - -bool Target::Activate() const { - return agent_host_->Activate(); -} - -bool Target::Close() const { - return agent_host_->Close(); -} // DevToolsDelegate -------------------------------------------------------- -class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { +class DevToolsDelegate : + public devtools_http_handler::DevToolsHttpHandlerDelegate { public: DevToolsDelegate(); virtual ~DevToolsDelegate(); - // content::DevToolsHttpHandlerDelegate. + // devtools_http_handler::DevToolsHttpHandlerDelegate. std::string GetDiscoveryPageHTML() override; - bool BundlesFrontendResources() override; - base::FilePath GetDebugFrontendDir() override; + std::string GetFrontendResource(const std::string& path) override; + std::string GetPageThumbnailData(const GURL& url) override; private: DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); @@ -175,12 +113,14 @@ std::string DevToolsDelegate::GetDiscoveryPageHTML() { kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); } -bool DevToolsDelegate::BundlesFrontendResources() { - return true; + +std::string DevToolsDelegate::GetFrontendResource( + const std::string& path) { + return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); } -base::FilePath DevToolsDelegate::GetDebugFrontendDir() { - return base::FilePath(); +std::string DevToolsDelegate::GetPageThumbnailData(const GURL& url) { + return std::string(); } } // namespace @@ -188,15 +128,25 @@ base::FilePath DevToolsDelegate::GetDebugFrontendDir() { // DevToolsManagerDelegate --------------------------------------------------- // static -content::DevToolsHttpHandler* +devtools_http_handler::DevToolsHttpHandler* DevToolsManagerDelegate::CreateHttpHandler() { - return DevToolsHttpHandler::Start(CreateSocketFactory(), - std::string(), - new DevToolsDelegate, - base::FilePath()); + return new devtools_http_handler::DevToolsHttpHandler( + CreateSocketFactory(), + std::string(), + new DevToolsDelegate, + base::FilePath(), + base::FilePath(), + std::string(), + GetBrightrayUserAgent()); } DevToolsManagerDelegate::DevToolsManagerDelegate() { + // NB(zcbenz): This call does nothing, the only purpose is to make sure the + // devtools_discovery module is linked into the final executable on Linux. + // Though it is possible to achieve this by modifying the gyp settings, it + // would greatly increase gyp file's complexity, so I chose to instead do + // this hack. + devtools_discovery::DevToolsDiscoveryManager::GetInstance(); } DevToolsManagerDelegate::~DevToolsManagerDelegate() { @@ -208,22 +158,4 @@ base::DictionaryValue* DevToolsManagerDelegate::HandleCommand( return NULL; } -std::string DevToolsManagerDelegate::GetPageThumbnailData( - const GURL& url) { - return std::string(); -} - -scoped_ptr -DevToolsManagerDelegate::CreateNewTarget(const GURL& url) { - return scoped_ptr(); -} - -void DevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) { - TargetList targets; - for (const auto& agent_host : DevToolsAgentHost::GetOrCreateAll()) { - targets.push_back(new Target(agent_host)); - } - callback.Run(targets); -} - } // namespace brightray diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h index 529f1ff7b895..154ea9ccbf75 100644 --- a/brightray/browser/devtools_manager_delegate.h +++ b/brightray/browser/devtools_manager_delegate.h @@ -7,10 +7,10 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "content/public/browser/devtools_http_handler_delegate.h" +#include "components/devtools_http_handler/devtools_http_handler_delegate.h" #include "content/public/browser/devtools_manager_delegate.h" -namespace content { +namespace devtools_http_handler { class DevToolsHttpHandler; } @@ -18,7 +18,7 @@ namespace brightray { class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { public: - static content::DevToolsHttpHandler* CreateHttpHandler(); + static devtools_http_handler::DevToolsHttpHandler* CreateHttpHandler(); DevToolsManagerDelegate(); virtual ~DevToolsManagerDelegate(); @@ -30,9 +30,6 @@ class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { bool attached) override {} base::DictionaryValue* HandleCommand(content::DevToolsAgentHost* agent_host, base::DictionaryValue* command) override; - scoped_ptr CreateNewTarget(const GURL& url) override; - void EnumerateTargets(TargetCallback callback) override; - std::string GetPageThumbnailData(const GURL& url) override; private: DISALLOW_COPY_AND_ASSIGN(DevToolsManagerDelegate); diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 9b5eba7d6fc2..c5df7e027641 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -11,11 +11,10 @@ #include "base/memory/ref_counted_memory.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" -#include "content/public/browser/devtools_http_handler.h" +#include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/url_data_source.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" -#include "ui/base/resource/resource_bundle.h" using content::WebContents; @@ -64,17 +63,10 @@ class BundledDataSource : public content::URLDataSource { int render_view_id, const GotDataCallback& callback) override { std::string filename = PathWithoutParams(path); - - int resource_id = - content::DevToolsHttpHandler::GetFrontendResourceId(filename); - - DLOG_IF(WARNING, resource_id == -1) - << "Unable to find dev tool resource: " << filename - << ". If you compiled with debug_devtools=1, try running with " - "--debug-devtools."; - const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - scoped_refptr bytes(rb.LoadDataResourceBytes( - resource_id)); + base::StringPiece resource = + content::DevToolsFrontendHost::GetFrontendResource(filename); + scoped_refptr bytes( + new base::RefCountedStaticMemory(resource.data(), resource.length())); callback.Run(bytes.get()); } diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c3df837943e9..6d2f24fae4cf 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -17,11 +17,11 @@ #include "base/metrics/histogram.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" +#include "base/prefs/scoped_user_pref_update.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/host_zoom_map.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" @@ -45,6 +45,7 @@ const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?" "experiments=true"; const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; const char kDevToolsZoomPref[] = "brightray.devtools.zoom"; +const char kDevToolsPreferences[] = "brightray.devtools.preferences"; const char kFrontendHostId[] = "id"; const char kFrontendHostMethod[] = "method"; @@ -161,6 +162,7 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get()); registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release()); registry->RegisterDoublePref(kDevToolsZoomPref, 0.); + registry->RegisterDictionaryPref(kDevToolsPreferences); } InspectableWebContentsImpl::InspectableWebContentsImpl( @@ -364,7 +366,7 @@ void InspectableWebContentsImpl::LoadNetworkResource( auto browser_context = static_cast(devtools_web_contents_->GetBrowserContext()); net::URLFetcher* fetcher = - net::URLFetcher::Create(gurl, net::URLFetcher::GET, this); + (net::URLFetcher::Create(gurl, net::URLFetcher::GET, this)).release(); pending_requests_[fetcher] = callback; fetcher->SetRequestContext(browser_context->url_request_context_getter()); fetcher->SetExtraRequestHeaders(headers); @@ -470,6 +472,29 @@ void InspectableWebContentsImpl::SendJsonRequest(const DispatchCallback& callbac callback.Run(nullptr); } +void InspectableWebContentsImpl::GetPreferences( + const DispatchCallback& callback) { + const base::DictionaryValue* prefs = pref_service_->GetDictionary( + kDevToolsPreferences); + callback.Run(prefs); +} + +void InspectableWebContentsImpl::SetPreference(const std::string& name, + const std::string& value) { + DictionaryPrefUpdate update(pref_service_, kDevToolsPreferences); + update.Get()->SetStringWithoutPathExpansion(name, value); +} + +void InspectableWebContentsImpl::RemovePreference(const std::string& name) { + DictionaryPrefUpdate update(pref_service_, kDevToolsPreferences); + update.Get()->RemoveWithoutPathExpansion(name, nullptr); +} + +void InspectableWebContentsImpl::ClearPreferences() { + DictionaryPrefUpdate update(pref_service_, kDevToolsPreferences); + update.Get()->Clear(); +} + void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::string& message) { std::string method; base::ListValue empty_params; @@ -577,8 +602,7 @@ void InspectableWebContentsImpl::CloseContents(content::WebContents* source) { CloseDevTools(); } -void InspectableWebContentsImpl::WebContentsFocused( - content::WebContents* contents) { +void InspectableWebContentsImpl::OnWebContentsFocused() { if (view_->GetDelegate()) view_->GetDelegate()->DevToolsFocused(); } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 2b3ce59ff9d1..62cfffec4f62 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -110,6 +110,11 @@ class InspectableWebContentsImpl : void SendJsonRequest(const DispatchCallback& callback, const std::string& browser_id, const std::string& url) override; + void GetPreferences(const DispatchCallback& callback) override; + void SetPreference(const std::string& name, + const std::string& value) override; + void RemovePreference(const std::string& name) override; + void ClearPreferences() override; // content::DevToolsFrontendHostDelegate: void HandleMessageFromDevToolsFrontend(const std::string& message) override; @@ -125,6 +130,7 @@ class InspectableWebContentsImpl : void AboutToNavigateRenderFrame(content::RenderFrameHost* old_host, content::RenderFrameHost* new_host) override; void WebContentsDestroyed() override; + void OnWebContentsFocused() override; // content::WebContentsDelegate: bool AddMessageToConsole(content::WebContents* source, @@ -144,7 +150,6 @@ class InspectableWebContentsImpl : void HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent&) override; void CloseContents(content::WebContents* source) override; - void WebContentsFocused(content::WebContents* contents) override; // net::URLFetcherDelegate: void OnURLFetchComplete(const net::URLFetcher* source) override; diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index 6a2b9c3d76f8..594474363561 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -4,14 +4,13 @@ #include "browser/net_log.h" -#include "browser/browser_context.h" #include "base/command_line.h" -#include "base/files/file_util.h" -#include "base/json/json_writer.h" -#include "base/logging.h" +#include "base/files/file_path.h" +#include "base/values.h" #include "content/public/common/content_switches.h" #include "net/log/net_log_util.h" -#include "net/url_request/url_request_context.h" + +namespace brightray { namespace { @@ -30,62 +29,34 @@ scoped_ptr GetConstants() { } // namespace -namespace brightray { - -NetLog::NetLog(net::URLRequestContext* context) - : added_events_(false), - context_(context) { +NetLog::NetLog() { auto command_line = base::CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kLogNetLog)) { - base::FilePath log_path = - command_line->GetSwitchValuePath(switches::kLogNetLog); + if (!command_line->HasSwitch(switches::kLogNetLog)) + return; - #if defined(OS_WIN) - log_file_.reset(_wfopen(log_path.value().c_str(), L"w")); - #elif defined(OS_POSIX) - log_file_.reset(fopen(log_path.value().c_str(), "w")); - #endif + base::FilePath log_path = command_line->GetSwitchValuePath(switches::kLogNetLog); +#if defined(OS_WIN) + log_file_.reset(_wfopen(log_path.value().c_str(), L"w")); +#elif defined(OS_POSIX) + log_file_.reset(fopen(log_path.value().c_str(), "w")); +#endif - if (!log_file_) { - LOG(ERROR) << "Could not open file: " << log_path.value() - << "for net logging"; - } else { - std::string json; - scoped_ptr constants(GetConstants().Pass()); - base::JSONWriter::Write(constants.get(), &json); - fprintf(log_file_.get(), "{\"constants\": %s, \n", json.c_str()); - fprintf(log_file_.get(), "\"events\": [\n"); - - if (context_) { - DCHECK(context_->CalledOnValidThread()); - - std::set contexts; - contexts.insert(context_); - - net::CreateNetLogEntriesForActiveObjects(contexts, this); - } - - DeprecatedAddObserver(this, net::NetLog::LogLevel::LOG_STRIP_PRIVATE_DATA); - } + if (!log_file_) { + LOG(ERROR) << "Could not open file: " << log_path.value() + << "for net logging"; + return; } } NetLog::~NetLog() { - if (log_file_) { - DeprecatedRemoveObserver(this); - - // Ending events array. - fprintf(log_file_.get(), "]}"); - log_file_.reset(); - } } -void NetLog::OnAddEntry(const net::NetLog::Entry& entry) { - std::string json; - base::JSONWriter::Write(entry.ToValue(), &json); +void NetLog::StartLogging(net::URLRequestContext* url_request_context) { + if (!log_file_) + return; - fprintf(log_file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str()); - added_events_ = true; + scoped_ptr constants(GetConstants()); + write_to_file_observer_.StartObserving(this, log_file_.Pass(), constants.get(), url_request_context); } } // namespace brightray diff --git a/brightray/browser/net_log.h b/brightray/browser/net_log.h index 4aade754f354..e62c335350c7 100644 --- a/brightray/browser/net_log.h +++ b/brightray/browser/net_log.h @@ -5,29 +5,22 @@ #ifndef BROWSER_NET_LOG_H_ #define BROWSER_NET_LOG_H_ -#include "base/files/file_path.h" #include "base/files/scoped_file.h" #include "net/log/net_log.h" - -namespace net { -class URLRequestContext; -} +#include "net/log/write_to_file_net_log_observer.h" namespace brightray { -class NetLog : public net::NetLog, - public net::NetLog::ThreadSafeObserver { +class NetLog : public net::NetLog { public: - explicit NetLog(net::URLRequestContext* context); + NetLog(); ~NetLog() override; - void OnAddEntry(const net::NetLog::Entry& entry) override; + void StartLogging(net::URLRequestContext* url_request_context); private: - bool added_events_; - // We use raw pointer to prevent reference cycle. - net::URLRequestContext* const context_; base::ScopedFILE log_file_; + net::WriteToFileNetLogObserver write_to_file_observer_; DISALLOW_COPY_AND_ASSIGN(NetLog); }; diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index 20cbee20e842..768bf2b6f1a2 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -6,10 +6,13 @@ #ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ -#import "browser/notification_presenter.h" +#include "browser/notification_presenter.h" -#import "base/mac/scoped_nsobject.h" -#import +#include + +#import + +#include "base/mac/scoped_nsobject.h" @class BRYUserNotificationCenterDelegate; diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 60abc6af76d8..81527772ffb6 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -13,8 +13,6 @@ #include "content/public/browser/desktop_notification_delegate.h" #include "skia/ext/skia_utils_mac.h" -#import - @interface BRYUserNotificationCenterDelegate : NSObject { @private brightray::NotificationPresenterMac* presenter_; diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service_impl.cc index b613dc2ad226..d2b0f679a6c7 100644 --- a/brightray/browser/platform_notification_service_impl.cc +++ b/brightray/browser/platform_notification_service_impl.cc @@ -63,7 +63,13 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification( void PlatformNotificationServiceImpl::ClosePersistentNotification( content::BrowserContext* browser_context, - const std::string& persistent_notification_id) { + int64_t persistent_notification_id) { +} + +bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( + content::BrowserContext* browser_context, + std::set* displayed_notifications) { + return false; } } // namespace brightray diff --git a/brightray/browser/platform_notification_service_impl.h b/brightray/browser/platform_notification_service_impl.h index 4b0d4fa96c7f..da1e2ad81eba 100644 --- a/brightray/browser/platform_notification_service_impl.h +++ b/brightray/browser/platform_notification_service_impl.h @@ -51,7 +51,10 @@ class PlatformNotificationServiceImpl const content::PlatformNotificationData& notification_data) override; void ClosePersistentNotification( content::BrowserContext* browser_context, - const std::string& persistent_notification_id) override; + int64_t persistent_notification_id) override; + bool GetDisplayedPersistentNotifications( + content::BrowserContext* browser_context, + std::set* displayed_notifications) override; scoped_ptr notification_presenter_; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 9f796a7a9f0c..2896c49ae46a 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -119,12 +119,14 @@ URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(const base::Fil URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, + NetLog* net_log, const base::FilePath& base_path, base::MessageLoop* io_loop, base::MessageLoop* file_loop, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors) : delegate_(delegate), + net_log_(net_log), base_path_(base_path), io_loop_(io_loop), file_loop_(file_loop), @@ -157,8 +159,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { url_request_context_.reset(new net::URLRequestContext); // --log-net-log - net_log_.reset(new NetLog(url_request_context_.get())); - url_request_context_->set_net_log(net_log_.get()); + net_log_->StartLogging(url_request_context_.get()); + url_request_context_->set_net_log(net_log_); network_delegate_.reset(delegate_->CreateNetworkDelegate()); url_request_context_->set_network_delegate(network_delegate_.get()); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index afab504c3f22..376f69c9a2f6 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -17,7 +17,6 @@ class MessageLoop; } namespace net { -class NetLog; class HostMappingRules; class HostResolver; class NetworkDelegate; @@ -28,6 +27,8 @@ class URLRequestJobFactory; namespace brightray { +class NetLog; + class URLRequestContextGetter : public net::URLRequestContextGetter { public: class Delegate { @@ -46,6 +47,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { URLRequestContextGetter( Delegate* delegate, + NetLog* net_log, const base::FilePath& base_path, base::MessageLoop* io_loop, base::MessageLoop* file_loop, @@ -58,17 +60,16 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { scoped_refptr GetNetworkTaskRunner() const override; net::HostResolver* host_resolver(); - net::NetLog* net_log() { return net_log_.get(); } private: Delegate* delegate_; + NetLog* net_log_; base::FilePath base_path_; base::MessageLoop* io_loop_; base::MessageLoop* file_loop_; scoped_ptr proxy_config_service_; - scoped_ptr net_log_; scoped_ptr network_delegate_; scoped_ptr storage_; scoped_ptr url_request_context_; diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index 3867ed6fe3fb..b13fc73ef900 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -14,6 +14,17 @@ namespace brightray { +std::string GetProductInternal() { + auto name = GetApplicationName(); + base::RemoveChars(name, base::kWhitespaceASCII, &name); + return base::StringPrintf("%s/%s", + name.c_str(), GetApplicationVersion().c_str()); +} + +std::string GetBrightrayUserAgent() { + return content::BuildUserAgentFromProduct(GetProductInternal()); +} + ContentClient::ContentClient() { } @@ -21,14 +32,11 @@ ContentClient::~ContentClient() { } std::string ContentClient::GetProduct() const { - auto name = GetApplicationName(); - base::RemoveChars(name, base::kWhitespaceASCII, &name); - return base::StringPrintf("%s/%s", - name.c_str(), GetApplicationVersion().c_str()); + return GetProductInternal(); } std::string ContentClient::GetUserAgent() const { - return content::BuildUserAgentFromProduct(GetProduct()); + return GetBrightrayUserAgent(); } base::string16 ContentClient::GetLocalizedString(int message_id) const { diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index f0e4449e251d..d54cf5df7301 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -10,6 +10,8 @@ namespace brightray { +std::string GetBrightrayUserAgent(); + class ContentClient : public content::ContentClient { public: ContentClient(); diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 534e0fbaaca6..cf133b8ebfeb 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 534e0fbaaca61a7b8d57578b2646d47cf4237d2a +Subproject commit cf133b8ebfeb3579032d3092351c801a3112aa7c