From e451d9212179197b88abeb752602de3859bb1765 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 13 Mar 2013 15:12:05 -0400 Subject: [PATCH 0001/1195] Initial commit --- brightray/.gitignore | 2 + brightray/.gitmodules | 3 + brightray/LICENSE | 19 ++ brightray/LICENSE-CHROMIUM | 27 ++ brightray/README.md | 34 +++ brightray/brightray.gyp | 47 +++ brightray/brightray.gypi | 39 +++ brightray/browser/browser_client.cc | 35 +++ brightray/browser/browser_client.h | 39 +++ brightray/browser/browser_context.cc | 106 +++++++ brightray/browser/browser_context.h | 46 +++ brightray/browser/browser_main_parts.cc | 21 ++ brightray/browser/browser_main_parts.h | 38 +++ brightray/browser/browser_main_parts_mac.mm | 21 ++ brightray/browser/mac/bry_application.h | 7 + brightray/browser/mac/bry_application.mm | 19 ++ brightray/browser/network_delegate.cc | 105 +++++++ brightray/browser/network_delegate.h | 41 +++ .../browser/url_request_context_getter.cc | 137 +++++++++ .../browser/url_request_context_getter.h | 54 ++++ brightray/common/main_delegate.cc | 29 ++ brightray/common/main_delegate.h | 31 ++ brightray/common/main_delegate_mac.mm | 59 ++++ brightray/script/bootstrap | 26 ++ brightray/script/build | 8 + brightray/tools/mac/change_mach_o_flags.py | 273 ++++++++++++++++++ brightray/tools/mac/make_more_helpers.sh | 91 ++++++ brightray/vendor/.gitignore | 1 + brightray/vendor/libchromiumcontent | 1 + 29 files changed, 1359 insertions(+) create mode 100644 brightray/.gitignore create mode 100644 brightray/.gitmodules create mode 100644 brightray/LICENSE create mode 100644 brightray/LICENSE-CHROMIUM create mode 100644 brightray/README.md create mode 100644 brightray/brightray.gyp create mode 100644 brightray/brightray.gypi create mode 100644 brightray/browser/browser_client.cc create mode 100644 brightray/browser/browser_client.h create mode 100644 brightray/browser/browser_context.cc create mode 100644 brightray/browser/browser_context.h create mode 100644 brightray/browser/browser_main_parts.cc create mode 100644 brightray/browser/browser_main_parts.h create mode 100644 brightray/browser/browser_main_parts_mac.mm create mode 100644 brightray/browser/mac/bry_application.h create mode 100644 brightray/browser/mac/bry_application.mm create mode 100644 brightray/browser/network_delegate.cc create mode 100644 brightray/browser/network_delegate.h create mode 100644 brightray/browser/url_request_context_getter.cc create mode 100644 brightray/browser/url_request_context_getter.h create mode 100644 brightray/common/main_delegate.cc create mode 100644 brightray/common/main_delegate.h create mode 100644 brightray/common/main_delegate_mac.mm create mode 100755 brightray/script/bootstrap create mode 100755 brightray/script/build create mode 100755 brightray/tools/mac/change_mach_o_flags.py create mode 100755 brightray/tools/mac/make_more_helpers.sh create mode 100644 brightray/vendor/.gitignore create mode 160000 brightray/vendor/libchromiumcontent diff --git a/brightray/.gitignore b/brightray/.gitignore new file mode 100644 index 00000000000..dde2688146f --- /dev/null +++ b/brightray/.gitignore @@ -0,0 +1,2 @@ +/brightray.xcodeproj/ +/build/ diff --git a/brightray/.gitmodules b/brightray/.gitmodules new file mode 100644 index 00000000000..3579d1eb607 --- /dev/null +++ b/brightray/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/libchromiumcontent"] + path = vendor/libchromiumcontent + url = https://github.com/aroben/libchromiumcontent diff --git a/brightray/LICENSE b/brightray/LICENSE new file mode 100644 index 00000000000..4fb14d4add8 --- /dev/null +++ b/brightray/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2013 Adam Roben + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/brightray/LICENSE-CHROMIUM b/brightray/LICENSE-CHROMIUM new file mode 100644 index 00000000000..3d0f7d3edfd --- /dev/null +++ b/brightray/LICENSE-CHROMIUM @@ -0,0 +1,27 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/brightray/README.md b/brightray/README.md new file mode 100644 index 00000000000..725a4718af3 --- /dev/null +++ b/brightray/README.md @@ -0,0 +1,34 @@ +# Brightray + +Brightray is a static library that makes +[libchromiumcontent](https://github.com/aroben/libchromiumcontent) easier to +use in applications. + +## Using it in your app + +See [brightray_example](https://github.com/aroben/brightray_example) for a +sample application written using Brightray. + +## Development + +### One-time setup + +You must previously have built and uploaded libchromiumcontent using its +`script/upload` script. + + $ script/bootstrap http://base.url.com/used/by/script/upload + +### Building + + $ script/build + +Building Brightray on its own isn’t all that interesting, since it’s just a +static library. Building it into an application (like +[brightray_example](https://github.com/aroben/brightray_example)) is the only +way to test it. + +## License + +In general, everything is covered by the [`LICENSE`](LICENSE) file. Some files +specify at the top that they are covered by the +[`LICENSE-CHROMIUM`](LICENSE-CHROMIUM) file instead. diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp new file mode 100644 index 00000000000..0e19a903cb2 --- /dev/null +++ b/brightray/brightray.gyp @@ -0,0 +1,47 @@ +{ + 'includes': [ + 'brightray.gypi', + ], + 'targets': [ + { + 'target_name': 'brightray', + 'type': 'static_library', + 'include_dirs': [ + '<(libchromiumcontent_include_dir)', + ], + 'direct_dependent_settings': { + 'include_dirs': [ + '<(libchromiumcontent_include_dir)', + ], + }, + 'sources': [ + 'browser/browser_client.cc', + 'browser/browser_client.h', + 'browser/browser_context.cc', + 'browser/browser_context.h', + 'browser/browser_main_parts.cc', + 'browser/browser_main_parts.h', + 'browser/browser_main_parts_mac.mm', + 'browser/mac/bry_application.h', + 'browser/mac/bry_application.mm', + 'browser/network_delegate.cc', + 'browser/network_delegate.h', + 'browser/url_request_context_getter.cc', + 'browser/url_request_context_getter.h', + 'common/main_delegate.cc', + 'common/main_delegate.h', + 'common/main_delegate_mac.mm', + ], + 'conditions': [ + ['OS=="mac"', { + 'link_settings': { + 'libraries': [ + 'libchromiumcontent.dylib', + '$(SDKROOT)/System/Library/Frameworks/AppKit.framework', + ], + }, + }], + ], + }, + ], +} diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi new file mode 100644 index 00000000000..ecd35a269e0 --- /dev/null +++ b/brightray/brightray.gypi @@ -0,0 +1,39 @@ +{ + 'variables': { + 'libchromiumcontent_dir': 'vendor/download/libchromiumcontent', + 'libchromiumcontent_library_dir': '<(libchromiumcontent_dir)/Release', + 'libchromiumcontent_include_dir': '<(libchromiumcontent_dir)/include', + 'libchromiumcontent_resources_dir': '<(libchromiumcontent_library_dir)', + }, + 'target_defaults': { + 'defines': [ + 'NDEBUG', + ], + 'xcode_settings': { + 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11', + 'CLANG_CXX_LIBRARY': 'libstdc++', + 'COMBINE_HIDPI_IMAGES': 'YES', + 'GCC_ENABLE_CPP_RTTI': 'NO', + 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', + 'MACOSX_DEPLOYMENT_TARGET': '10.7', + 'RUN_CLANG_STATIC_ANALYZER': 'YES', + 'SDKROOT': 'macosx10.7', + 'WARNING_CFLAGS': [ + '-Wall', + '-Wextra', + '-Wno-unused-parameter', + '-Wno-missing-field-initializers', + ], + }, + 'configurations': { + 'Debug': { + 'xcode_settings': { + 'COPY_PHASE_STRIP': 'NO', + 'GCC_OPTIMIZATION_LEVEL': '0', + }, + }, + 'Release': { + }, + }, + }, +} diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc new file mode 100644 index 00000000000..b9115fe1ebc --- /dev/null +++ b/brightray/browser/browser_client.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser_client.h" + +#include "browser_context.h" +#include "browser_main_parts.h" + +namespace brightray { + +BrowserClient::BrowserClient() { +} + +BrowserClient::~BrowserClient() { +} + +BrowserContext* BrowserClient::browser_context() { + return browser_main_parts_->browser_context(); +} + +BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts(const content::MainFunctionParams&) { + return new BrowserMainParts; +} + +content::BrowserMainParts* BrowserClient::CreateBrowserMainParts(const content::MainFunctionParams& parameters) { + browser_main_parts_.reset(OverrideCreateBrowserMainParts(parameters)); + return browser_main_parts_.get(); +} + +net::URLRequestContextGetter* BrowserClient::CreateRequestContext(content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers) { + return static_cast(browser_context)->CreateRequestContext(protocol_handlers); +} + +} diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h new file mode 100644 index 00000000000..ac5412233f6 --- /dev/null +++ b/brightray/browser/browser_client.h @@ -0,0 +1,39 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef __brightray__browser_client__ +#define __brightray__browser_client__ + +#include "content/public/browser/content_browser_client.h" + +namespace brightray { + +class BrowserContext; +class BrowserMainParts; + +class BrowserClient : public content::ContentBrowserClient { +public: + BrowserClient(); + ~BrowserClient(); + + BrowserContext* browser_context(); + BrowserMainParts* browser_main_parts() { return browser_main_parts_.get(); } + +protected: + // Subclasses should override this to provide their own BrowserMainParts implementation. The + // lifetime of the returned instance is managed by the caller. + virtual BrowserMainParts* OverrideCreateBrowserMainParts(const content::MainFunctionParams&); + +private: + virtual content::BrowserMainParts* CreateBrowserMainParts(const content::MainFunctionParams&) OVERRIDE; + virtual net::URLRequestContextGetter* CreateRequestContext(content::BrowserContext*, content::ProtocolHandlerMap*) OVERRIDE; + + scoped_ptr browser_main_parts_; + + DISALLOW_COPY_AND_ASSIGN(BrowserClient); +}; + +} + +#endif /* defined(__brightray__browser_client__) */ diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc new file mode 100644 index 00000000000..51778133996 --- /dev/null +++ b/brightray/browser/browser_context.cc @@ -0,0 +1,106 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser_context.h" + +#include "base/files/file_path.h" +#include "base/path_service.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/resource_context.h" +#include "content/public/browser/storage_partition.h" +#include "net/base/host_resolver.h" +#include "url_request_context_getter.h" + +namespace brightray { + +class BrowserContext::ResourceContext : public content::ResourceContext { +public: + ResourceContext() : getter_(nullptr) {} + + void set_url_request_context_getter(URLRequestContextGetter* getter) { + getter_ = getter; + } + +private: + virtual net::HostResolver* GetHostResolver() OVERRIDE { + return getter_->host_resolver(); + } + + virtual net::URLRequestContext* GetRequestContext() OVERRIDE { + return getter_->GetURLRequestContext(); + } + + URLRequestContextGetter* getter_; + scoped_ptr host_resolver_; +}; + +BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { +} + +BrowserContext::~BrowserContext() { +} + +net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::ProtocolHandlerMap* protocol_handlers) { + DCHECK(!url_request_getter_); + url_request_getter_.reset(new URLRequestContextGetter( + GetPath(), + content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::IO), + content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::FILE), + protocol_handlers)); + resource_context_->set_url_request_context_getter(url_request_getter_.get()); + return url_request_getter_.get(); +} + +base::FilePath BrowserContext::GetPath() { + // FIXME: This should be an application-specific path. + base::FilePath path; + CHECK(PathService::Get(base::DIR_APP_DATA, &path)); + return path.Append("Brightray"); +} + +bool BrowserContext::IsOffTheRecord() const { + return false; +} + +net::URLRequestContextGetter* BrowserContext::GetRequestContext() { + return GetDefaultStoragePartition(this)->GetURLRequestContext(); +} + +net::URLRequestContextGetter* BrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) { + return GetRequestContext(); +} + +net::URLRequestContextGetter* BrowserContext::GetMediaRequestContext() { + return GetRequestContext(); +} + +net::URLRequestContextGetter* BrowserContext::GetMediaRequestContextForRenderProcess(int renderer_child_id) { + return GetRequestContext(); +} + +net::URLRequestContextGetter* BrowserContext::GetMediaRequestContextForStoragePartition(const base::FilePath& partition_path, bool in_memory) { + return GetRequestContext(); +} + +content::ResourceContext* BrowserContext::GetResourceContext() { + return resource_context_.get(); +} + +content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() { + return nullptr; +} + +content::GeolocationPermissionContext* BrowserContext::GetGeolocationPermissionContext() { + return nullptr; +} + +content::SpeechRecognitionPreferences* BrowserContext::GetSpeechRecognitionPreferences() { + return nullptr; +} + +quota::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() { + return nullptr; +} + +} diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h new file mode 100644 index 00000000000..2b2c603c696 --- /dev/null +++ b/brightray/browser/browser_context.h @@ -0,0 +1,46 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef __brightray__browser_context__ +#define __brightray__browser_context__ + +#include "content/public/browser/browser_context.h" +#include "content/public/browser/content_browser_client.h" + +namespace brightray { + +class URLRequestContextGetter; + +class BrowserContext : public content::BrowserContext { +public: + BrowserContext(); + ~BrowserContext(); + + net::URLRequestContextGetter* CreateRequestContext(content::ProtocolHandlerMap*); + +private: + class ResourceContext; + + virtual base::FilePath GetPath() OVERRIDE; + virtual bool IsOffTheRecord() const OVERRIDE; + virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; + virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(int renderer_child_id); + virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE; + virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(int renderer_child_id) OVERRIDE; + virtual net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition(const base::FilePath& partition_path, bool in_memory); + virtual content::ResourceContext* GetResourceContext() OVERRIDE; + virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; + virtual content::GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; + virtual content::SpeechRecognitionPreferences* GetSpeechRecognitionPreferences() OVERRIDE; + virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; + + scoped_ptr resource_context_; + scoped_ptr url_request_getter_; + + DISALLOW_COPY_AND_ASSIGN(BrowserContext); +}; + +} + +#endif /* defined(__brightray__browser_context__) */ diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc new file mode 100644 index 00000000000..87847948850 --- /dev/null +++ b/brightray/browser/browser_main_parts.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser_main_parts.h" + +#include "browser_context.h" + +namespace brightray { + +BrowserMainParts::BrowserMainParts() { +} + +BrowserMainParts::~BrowserMainParts() { +} + +void BrowserMainParts::PreMainMessageLoopRun() { + browser_context_.reset(new BrowserContext); +} + +} diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h new file mode 100644 index 00000000000..5e8194aa093 --- /dev/null +++ b/brightray/browser/browser_main_parts.h @@ -0,0 +1,38 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef __brightray__main_parts__ +#define __brightray__main_parts__ + +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/browser_main_parts.h" + +namespace brightray { + +class BrowserContext; + +class BrowserMainParts : public content::BrowserMainParts { +public: + BrowserMainParts(); + ~BrowserMainParts(); + + BrowserContext* browser_context() { return browser_context_.get(); } + +protected: +#if defined(OS_MACOSX) + virtual void PreMainMessageLoopStart() OVERRIDE; +#endif + + virtual void PreMainMessageLoopRun() OVERRIDE; + +private: + scoped_ptr browser_context_; + + DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); +}; + +} + +#endif /* defined(__brightray__main_parts__) */ diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm new file mode 100644 index 00000000000..c3fb162fe1b --- /dev/null +++ b/brightray/browser/browser_main_parts_mac.mm @@ -0,0 +1,21 @@ +#import "browser_main_parts.h" + +#import "base/mac/bundle_locations.h" +#import + +namespace brightray { + +// Replicates NSApplicationMain, but doesn't start a run loop. +void BrowserMainParts::PreMainMessageLoopStart() { + auto infoDictionary = base::mac::OuterBundle().infoDictionary; + + auto principalClass = NSClassFromString([infoDictionary objectForKey:@"NSPrincipalClass"]); + auto application = [principalClass sharedApplication]; + + NSString *mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"]; + auto mainNib = [[NSNib alloc] initWithNibNamed:mainNibName bundle:base::mac::FrameworkBundle()]; + [mainNib instantiateNibWithOwner:application topLevelObjects:nil]; + [mainNib release]; +} + +} diff --git a/brightray/browser/mac/bry_application.h b/brightray/browser/mac/bry_application.h new file mode 100644 index 00000000000..f64d5db4e36 --- /dev/null +++ b/brightray/browser/mac/bry_application.h @@ -0,0 +1,7 @@ +#import "base/mac/scoped_sending_event.h" + +@interface BRYApplication : NSApplication { + BOOL _handlingSendEvent; +} + +@end diff --git a/brightray/browser/mac/bry_application.mm b/brightray/browser/mac/bry_application.mm new file mode 100644 index 00000000000..aca8392bc35 --- /dev/null +++ b/brightray/browser/mac/bry_application.mm @@ -0,0 +1,19 @@ +#import "bry_application.h" + +@interface BRYApplication () + +@property (nonatomic, assign, getter = isHandlingSendEvent) BOOL handlingSendEvent; + +@end + +@implementation BRYApplication + +@synthesize handlingSendEvent = _handlingSendEvent; + +- (void)sendEvent:(NSEvent *)theEvent +{ + base::mac::ScopedSendingEvent scopedSendingEvent; + [super sendEvent:theEvent]; +} + +@end diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc new file mode 100644 index 00000000000..8213a744edb --- /dev/null +++ b/brightray/browser/network_delegate.cc @@ -0,0 +1,105 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "network_delegate.h" + +#include "net/base/net_errors.h" + +namespace brightray { + +NetworkDelegate::NetworkDelegate() { +} + +NetworkDelegate::~NetworkDelegate() { +} + +int NetworkDelegate::OnBeforeURLRequest( + net::URLRequest* request, + const net::CompletionCallback& callback, + GURL* new_url) { + return net::OK; +} + +int NetworkDelegate::OnBeforeSendHeaders( + net::URLRequest* request, + const net::CompletionCallback& callback, + net::HttpRequestHeaders* headers) { + return net::OK; +} + +void NetworkDelegate::OnSendHeaders( + net::URLRequest* request, + const net::HttpRequestHeaders& headers) { +} + +int NetworkDelegate::OnHeadersReceived( + net::URLRequest* request, + const net::CompletionCallback& callback, + const net::HttpResponseHeaders* original_response_headers, + scoped_refptr* override_response_headers) { + return net::OK; +} + +void NetworkDelegate::OnBeforeRedirect(net::URLRequest* request, + const GURL& new_location) { +} + +void NetworkDelegate::OnResponseStarted(net::URLRequest* request) { +} + +void NetworkDelegate::OnRawBytesRead(const net::URLRequest& request, + int bytes_read) { +} + +void NetworkDelegate::OnCompleted(net::URLRequest* request, bool started) { +} + +void NetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { +} + +void NetworkDelegate::OnPACScriptError(int line_number, + const string16& error) { +} + +NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired( + net::URLRequest* request, + const net::AuthChallengeInfo& auth_info, + const AuthCallback& callback, + net::AuthCredentials* credentials) { + return AUTH_REQUIRED_RESPONSE_NO_ACTION; +} + +bool NetworkDelegate::OnCanGetCookies(const net::URLRequest& request, + const net::CookieList& cookie_list) { + return true; +} + +bool NetworkDelegate::OnCanSetCookie(const net::URLRequest& request, + const std::string& cookie_line, + net::CookieOptions* options) { + return true; +} + +bool NetworkDelegate::OnCanAccessFile(const net::URLRequest& request, + const base::FilePath& path) const { + return true; +} + +bool NetworkDelegate::OnCanThrottleRequest( + const net::URLRequest& request) const { + return false; +} + +int NetworkDelegate::OnBeforeSocketStreamConnect( + net::SocketStream* socket, + const net::CompletionCallback& callback) { + return net::OK; +} + +void NetworkDelegate::OnRequestWaitStateChange( + const net::URLRequest& request, + RequestWaitState waiting) { +} + +} diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h new file mode 100644 index 00000000000..54c98dca31e --- /dev/null +++ b/brightray/browser/network_delegate.h @@ -0,0 +1,41 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef __brightray__network_delegate__ +#define __brightray__network_delegate__ + +#include "net/base/network_delegate.h" + +namespace brightray { + +class NetworkDelegate : public net::NetworkDelegate { +public: + NetworkDelegate(); + virtual ~NetworkDelegate(); + +private: + virtual int OnBeforeURLRequest(net::URLRequest* request, const net::CompletionCallback& callback, GURL* new_url) OVERRIDE; + virtual int OnBeforeSendHeaders(net::URLRequest* request, const net::CompletionCallback& callback, net::HttpRequestHeaders* headers) OVERRIDE; + virtual void OnSendHeaders(net::URLRequest* request, const net::HttpRequestHeaders& headers) OVERRIDE; + virtual int OnHeadersReceived(net::URLRequest* request, const net::CompletionCallback& callback, const net::HttpResponseHeaders* original_response_headers, scoped_refptr* override_response_headers) OVERRIDE; + virtual void OnBeforeRedirect(net::URLRequest* request, const GURL& new_location) OVERRIDE; + virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; + virtual void OnRawBytesRead(const net::URLRequest& request, int bytes_read) OVERRIDE; + virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE; + virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE; + virtual void OnPACScriptError(int line_number, const string16& error) OVERRIDE; + virtual AuthRequiredResponse OnAuthRequired(net::URLRequest* request, const net::AuthChallengeInfo& auth_info, const AuthCallback& callback, net::AuthCredentials* credentials) OVERRIDE; + virtual bool OnCanGetCookies(const net::URLRequest& request, const net::CookieList& cookie_list) OVERRIDE; + virtual bool OnCanSetCookie(const net::URLRequest& request, const std::string& cookie_line, net::CookieOptions* options) OVERRIDE; + virtual bool OnCanAccessFile(const net::URLRequest& request, const base::FilePath& path) const OVERRIDE; + virtual bool OnCanThrottleRequest(const net::URLRequest& request) const OVERRIDE; + virtual int OnBeforeSocketStreamConnect(net::SocketStream* stream, const net::CompletionCallback& callback) OVERRIDE; + virtual void OnRequestWaitStateChange(const net::URLRequest& request, RequestWaitState state) OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(NetworkDelegate); +}; + +} + +#endif /* defined(__brightray__network_delegate__) */ diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc new file mode 100644 index 00000000000..137d6a90f8a --- /dev/null +++ b/brightray/browser/url_request_context_getter.cc @@ -0,0 +1,137 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "url_request_context_getter.h" + +#include "network_delegate.h" +#include "base/string_util.h" +#include "base/threading/worker_pool.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/common/url_constants.h" +#include "net/base/cert_verifier.h" +#include "net/base/default_server_bound_cert_store.h" +#include "net/base/server_bound_cert_service.h" +#include "net/base/ssl_config_service_defaults.h" +#include "net/cookies/cookie_monster.h" +#include "net/http/http_auth_handler_factory.h" +#include "net/http/http_cache.h" +#include "net/http/http_server_properties_impl.h" +#include "net/proxy/proxy_service.h" +#include "net/url_request/static_http_user_agent_settings.h" +#include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_context_storage.h" +#include "net/url_request/url_request_job_factory_impl.h" + +namespace brightray { + +URLRequestContextGetter::URLRequestContextGetter( + const base::FilePath& base_path, + MessageLoop* io_loop, + MessageLoop* file_loop, + content::ProtocolHandlerMap* protocol_handlers) + : base_path_(base_path), + io_loop_(io_loop), + file_loop_(file_loop) { + // Must first be created on the UI thread. + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + + std::swap(protocol_handlers_, *protocol_handlers); + + proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService(io_loop_->message_loop_proxy(), file_loop_)); +} + +URLRequestContextGetter::~URLRequestContextGetter() { +} + +net::HostResolver* URLRequestContextGetter::host_resolver() { + return url_request_context_->host_resolver(); +} + +net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() +{ + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); + + if (!url_request_context_.get()) { + url_request_context_.reset(new net::URLRequestContext()); + network_delegate_.reset(new NetworkDelegate); + url_request_context_->set_network_delegate(network_delegate_.get()); + storage_.reset( + new net::URLRequestContextStorage(url_request_context_.get())); + storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); + storage_->set_server_bound_cert_service(new net::ServerBoundCertService( + new net::DefaultServerBoundCertStore(NULL), + base::WorkerPool::GetTaskRunner(true))); + storage_->set_http_user_agent_settings( + new net::StaticHttpUserAgentSettings( + "en-us,en", "iso-8859-1,*,utf-8", EmptyString())); + + scoped_ptr host_resolver( + net::HostResolver::CreateDefaultResolver(NULL)); + + storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); + // TODO(jam): use v8 if possible, look at chrome code. + storage_->set_proxy_service( + net::ProxyService::CreateUsingSystemProxyResolver( + proxy_config_service_.release(), + 0, + NULL)); + storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); + storage_->set_http_auth_handler_factory( + net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); + storage_->set_http_server_properties(new net::HttpServerPropertiesImpl); + + base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); + net::HttpCache::DefaultBackend* main_backend = + new net::HttpCache::DefaultBackend( + net::DISK_CACHE, + cache_path, + 0, + content::BrowserThread::GetMessageLoopProxyForThread( + content::BrowserThread::CACHE)); + + net::HttpNetworkSession::Params network_session_params; + network_session_params.cert_verifier = + url_request_context_->cert_verifier(); + network_session_params.server_bound_cert_service = + url_request_context_->server_bound_cert_service(); + network_session_params.proxy_service = + url_request_context_->proxy_service(); + network_session_params.ssl_config_service = + url_request_context_->ssl_config_service(); + network_session_params.http_auth_handler_factory = + url_request_context_->http_auth_handler_factory(); + network_session_params.network_delegate = + url_request_context_->network_delegate(); + network_session_params.http_server_properties = + url_request_context_->http_server_properties(); + network_session_params.ignore_certificate_errors = false; + + // Give |storage_| ownership at the end in case it's |mapped_host_resolver|. + storage_->set_host_resolver(host_resolver.Pass()); + network_session_params.host_resolver = + url_request_context_->host_resolver(); + + net::HttpCache* main_cache = new net::HttpCache( + network_session_params, main_backend); + storage_->set_http_transaction_factory(main_cache); + + scoped_ptr job_factory( + new net::URLRequestJobFactoryImpl()); + for (auto& it : protocol_handlers_) { + bool set_protocol = job_factory->SetProtocolHandler(it.first, it.second.release()); + DCHECK(set_protocol); + } + protocol_handlers_.clear(); + storage_->set_job_factory(job_factory.release()); + } + + return url_request_context_.get(); +} + +scoped_refptr URLRequestContextGetter::GetNetworkTaskRunner() const +{ + return content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::IO); +} + +} diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h new file mode 100644 index 00000000000..89db0ec5b7d --- /dev/null +++ b/brightray/browser/url_request_context_getter.h @@ -0,0 +1,54 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef __brightray__url_request_context_getter__ +#define __brightray__url_request_context_getter__ + +#include "base/files/file_path.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/content_browser_client.h" +#include "net/url_request/url_request_context_getter.h" + +class MessageLoop; + +namespace net { +class HostResolver; +class NetworkDelegate; +class ProxyConfigService; +class URLRequestContextStorage; +} + +namespace brightray { + +class URLRequestContextGetter : public net::URLRequestContextGetter { +public: + URLRequestContextGetter( + const base::FilePath& base_path, + MessageLoop* io_loop, + MessageLoop* file_loop, + content::ProtocolHandlerMap*); + virtual ~URLRequestContextGetter(); + + net::HostResolver* host_resolver(); + virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; + +private: + virtual scoped_refptr GetNetworkTaskRunner() const OVERRIDE; + + base::FilePath base_path_; + MessageLoop* io_loop_; + MessageLoop* file_loop_; + + scoped_ptr proxy_config_service_; + scoped_ptr network_delegate_; + scoped_ptr storage_; + scoped_ptr url_request_context_; + content::ProtocolHandlerMap protocol_handlers_; + + DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter); +}; + +} + +#endif /* defined(__brightray__url_request_context_getter__) */ diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc new file mode 100644 index 00000000000..2eb3141a219 --- /dev/null +++ b/brightray/common/main_delegate.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "main_delegate.h" + +#include "browser_client.h" +#include "base/command_line.h" +#include "content/public/common/content_switches.h" + +namespace brightray { + +MainDelegate::MainDelegate() { +} + +MainDelegate::~MainDelegate() { +} + +void MainDelegate::PreSandboxStartup() { + // FIXME: We don't currently support running sandboxed. + CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNoSandbox); + +#if defined(OS_MACOSX) + OverrideChildProcessPath(); + OverrideFrameworkBundlePath(); +#endif +} + +} diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h new file mode 100644 index 00000000000..9b56a7939e5 --- /dev/null +++ b/brightray/common/main_delegate.h @@ -0,0 +1,31 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef __brightray__main_delegate__ +#define __brightray__main_delegate__ + +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "content/public/app/content_main_delegate.h" + +namespace brightray { + +class MainDelegate : public content::ContentMainDelegate { +public: + MainDelegate(); + ~MainDelegate(); + +private: +#if defined(OS_MACOSX) + static void OverrideChildProcessPath(); + static void OverrideFrameworkBundlePath(); +#endif + + virtual void PreSandboxStartup() OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(MainDelegate); +}; + +} +#endif /* defined(__brightray__main_delegate__) */ diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm new file mode 100644 index 00000000000..e91312ef442 --- /dev/null +++ b/brightray/common/main_delegate_mac.mm @@ -0,0 +1,59 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Adam Roben . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#import "main_delegate.h" + +#include "base/mac/bundle_locations.h" +#include "base/mac/foundation_util.h" +#include "base/path_service.h" +#include "content/public/common/content_paths.h" + +namespace brightray { + +namespace { + +base::FilePath GetFrameworksPath() { + // Start out with the path to the running executable. + base::FilePath path; + PathService::Get(base::FILE_EXE, &path); + + // Up to Contents. + if (base::mac::IsBackgroundOnlyProcess()) { + // The running executable is the helper. Go up five steps: + // Contents/Frameworks/Helper.app/Contents/MacOS/Helper + // ^ to here ^ from here + path = path.DirName().DirName().DirName().DirName().DirName(); + } else { + // One step up to MacOS, another to Contents. + path = path.DirName().DirName(); + } + DCHECK_EQ(path.BaseName().value(), "Contents"); + + // Go into the frameworks directory. + return path.Append("Frameworks"); +} + +std::string OuterBundleName() { + return [[base::mac::OuterBundle().infoDictionary objectForKey:base::mac::CFToNSCast(kCFBundleNameKey)] UTF8String]; +} + +} + +void MainDelegate::OverrideFrameworkBundlePath() { + base::FilePath helper_path = GetFrameworksPath().Append(OuterBundleName() + ".framework"); + + base::mac::SetOverrideFrameworkBundlePath(helper_path); +} + +void MainDelegate::OverrideChildProcessPath() { + base::FilePath helper_path = GetFrameworksPath().Append(OuterBundleName() + " Helper.app") + .Append("Contents") + .Append("MacOS") + .Append(OuterBundleName() + " Helper"); + + PathService::Override(content::CHILD_PROCESS_EXE, helper_path); +} + +} diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap new file mode 100755 index 00000000000..057a65f314a --- /dev/null +++ b/brightray/script/bootstrap @@ -0,0 +1,26 @@ +#!/bin/sh +#/ Usage: bootstrap https://base.url.com/from/libchromiumcontent/script/upload +#/ Bootstrap this project. + +set -e + +usage() { + grep '^#/' <"$0"| cut -c4- +} + +BASE_URL="${1}" + +if [ -z "${BASE_URL}" ]; then + usage + exit 1 +fi + +cd "$(dirname "$0")/.." + +git submodule sync --quiet +git submodule update --init --recursive + +SOURCE_ROOT="$(pwd -P)" +DOWNLOAD_DIR="${SOURCE_ROOT}/vendor/download" +mkdir -p "${DOWNLOAD_DIR}" +vendor/libchromiumcontent/script/download "${BASE_URL}" "${DOWNLOAD_DIR}/libchromiumcontent" diff --git a/brightray/script/build b/brightray/script/build new file mode 100755 index 00000000000..515feb65f03 --- /dev/null +++ b/brightray/script/build @@ -0,0 +1,8 @@ +#!/bin/sh + +set -e + +cd "$(dirname "$0")/.." + +gyp --depth . brightray.gyp +xcodebuild diff --git a/brightray/tools/mac/change_mach_o_flags.py b/brightray/tools/mac/change_mach_o_flags.py new file mode 100755 index 00000000000..4547cb75f7a --- /dev/null +++ b/brightray/tools/mac/change_mach_o_flags.py @@ -0,0 +1,273 @@ +#!/usr/bin/env python +# Copyright (c) 2011 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE-CHROMIUM file. + +"""Usage: change_mach_o_flags.py [--executable-heap] [--no-pie] + +Arranges for the executable at |executable_path| to have its data (heap) +pages protected to prevent execution on Mac OS X 10.7 ("Lion"), and to have +the PIE (position independent executable) bit set to enable ASLR (address +space layout randomization). With --executable-heap or --no-pie, the +respective bits are cleared instead of set, making the heap executable or +disabling PIE/ASLR. + +This script is able to operate on thin (single-architecture) Mach-O files +and fat (universal, multi-architecture) files. When operating on fat files, +it will set or clear the bits for each architecture contained therein. + +NON-EXECUTABLE HEAP + +Traditionally in Mac OS X, 32-bit processes did not have data pages set to +prohibit execution. Although user programs could call mprotect and +mach_vm_protect to deny execution of code in data pages, the kernel would +silently ignore such requests without updating the page tables, and the +hardware would happily execute code on such pages. 64-bit processes were +always given proper hardware protection of data pages. This behavior was +controllable on a system-wide level via the vm.allow_data_exec sysctl, which +is set by default to 1. The bit with value 1 (set by default) allows code +execution on data pages for 32-bit processes, and the bit with value 2 +(clear by default) does the same for 64-bit processes. + +In Mac OS X 10.7, executables can "opt in" to having hardware protection +against code execution on data pages applied. This is done by setting a new +bit in the |flags| field of an executable's |mach_header|. When +MH_NO_HEAP_EXECUTION is set, proper protections will be applied, regardless +of the setting of vm.allow_data_exec. See xnu-1699.22.73/osfmk/vm/vm_map.c +override_nx and xnu-1699.22.73/bsd/kern/mach_loader.c load_machfile. + +The Apple toolchain has been revised to set the MH_NO_HEAP_EXECUTION when +producing executables, provided that -allow_heap_execute is not specified +at link time. Only linkers shipping with Xcode 4.0 and later (ld64-123.2 and +later) have this ability. See ld64-123.2.1/src/ld/Options.cpp +Options::reconfigureDefaults() and +ld64-123.2.1/src/ld/HeaderAndLoadCommands.hpp +HeaderAndLoadCommandsAtom::flags(). + +This script sets the MH_NO_HEAP_EXECUTION bit on Mach-O executables. It is +intended for use with executables produced by a linker that predates Apple's +modifications to set this bit itself. It is also useful for setting this bit +for non-i386 executables, including x86_64 executables. Apple's linker only +sets it for 32-bit i386 executables, presumably under the assumption that +the value of vm.allow_data_exec is set in stone. However, if someone were to +change vm.allow_data_exec to 2 or 3, 64-bit x86_64 executables would run +without hardware protection against code execution on data pages. This +script can set the bit for x86_64 executables, guaranteeing that they run +with appropriate protection even when vm.allow_data_exec has been tampered +with. + +POSITION-INDEPENDENT EXECUTABLES/ADDRESS SPACE LAYOUT RANDOMIZATION + +This script sets or clears the MH_PIE bit in an executable's Mach-O header, +enabling or disabling position independence on Mac OS X 10.5 and later. +Processes running position-independent executables have varying levels of +ASLR protection depending on the OS release. The main executable's load +address, shared library load addresess, and the heap and stack base +addresses may be randomized. Position-independent executables are produced +by supplying the -pie flag to the linker (or defeated by supplying -no_pie). +Executables linked with a deployment target of 10.7 or higher have PIE on +by default. + +This script is never strictly needed during the build to enable PIE, as all +linkers used are recent enough to support -pie. However, it's used to +disable the PIE bit as needed on already-linked executables. +""" + +import optparse +import os +import struct +import sys + + +# +FAT_MAGIC = 0xcafebabe +FAT_CIGAM = 0xbebafeca + +# +MH_MAGIC = 0xfeedface +MH_CIGAM = 0xcefaedfe +MH_MAGIC_64 = 0xfeedfacf +MH_CIGAM_64 = 0xcffaedfe +MH_EXECUTE = 0x2 +MH_PIE = 0x00200000 +MH_NO_HEAP_EXECUTION = 0x01000000 + + +class MachOError(Exception): + """A class for exceptions thrown by this module.""" + + pass + + +def CheckedSeek(file, offset): + """Seeks the file-like object at |file| to offset |offset| and raises a + MachOError if anything funny happens.""" + + file.seek(offset, os.SEEK_SET) + new_offset = file.tell() + if new_offset != offset: + raise MachOError, \ + 'seek: expected offset %d, observed %d' % (offset, new_offset) + + +def CheckedRead(file, count): + """Reads |count| bytes from the file-like |file| object, raising a + MachOError if any other number of bytes is read.""" + + bytes = file.read(count) + if len(bytes) != count: + raise MachOError, \ + 'read: expected length %d, observed %d' % (count, len(bytes)) + + return bytes + + +def ReadUInt32(file, endian): + """Reads an unsinged 32-bit integer from the file-like |file| object, + treating it as having endianness specified by |endian| (per the |struct| + module), and returns it as a number. Raises a MachOError if the proper + length of data can't be read from |file|.""" + + bytes = CheckedRead(file, 4) + + (uint32,) = struct.unpack(endian + 'I', bytes) + return uint32 + + +def ReadMachHeader(file, endian): + """Reads an entire |mach_header| structure () from the + file-like |file| object, treating it as having endianness specified by + |endian| (per the |struct| module), and returns a 7-tuple of its members + as numbers. Raises a MachOError if the proper length of data can't be read + from |file|.""" + + bytes = CheckedRead(file, 28) + + magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags = \ + struct.unpack(endian + '7I', bytes) + return magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags + + +def ReadFatArch(file): + """Reads an entire |fat_arch| structure () from the file-like + |file| object, treating it as having endianness specified by |endian| + (per the |struct| module), and returns a 5-tuple of its members as numbers. + Raises a MachOError if the proper length of data can't be read from + |file|.""" + + bytes = CheckedRead(file, 20) + + cputype, cpusubtype, offset, size, align = struct.unpack('>5I', bytes) + return cputype, cpusubtype, offset, size, align + + +def WriteUInt32(file, uint32, endian): + """Writes |uint32| as an unsinged 32-bit integer to the file-like |file| + object, treating it as having endianness specified by |endian| (per the + |struct| module).""" + + bytes = struct.pack(endian + 'I', uint32) + assert len(bytes) == 4 + + file.write(bytes) + + +def HandleMachOFile(file, options, offset=0): + """Seeks the file-like |file| object to |offset|, reads its |mach_header|, + and rewrites the header's |flags| field if appropriate. The header's + endianness is detected. Both 32-bit and 64-bit Mach-O headers are supported + (mach_header and mach_header_64). Raises MachOError if used on a header that + does not have a known magic number or is not of type MH_EXECUTE. The + MH_PIE and MH_NO_HEAP_EXECUTION bits are set or cleared in the |flags| field + according to |options| and written to |file| if any changes need to be made. + If already set or clear as specified by |options|, nothing is written.""" + + CheckedSeek(file, offset) + magic = ReadUInt32(file, '<') + if magic == MH_MAGIC or magic == MH_MAGIC_64: + endian = '<' + elif magic == MH_CIGAM or magic == MH_CIGAM_64: + endian = '>' + else: + raise MachOError, \ + 'Mach-O file at offset %d has illusion of magic' % offset + + CheckedSeek(file, offset) + magic, cputype, cpusubtype, filetype, ncmds, sizeofcmds, flags = \ + ReadMachHeader(file, endian) + assert magic == MH_MAGIC or magic == MH_MAGIC_64 + if filetype != MH_EXECUTE: + raise MachOError, \ + 'Mach-O file at offset %d is type 0x%x, expected MH_EXECUTE' % \ + (offset, filetype) + + original_flags = flags + + if options.no_heap_execution: + flags |= MH_NO_HEAP_EXECUTION + else: + flags &= ~MH_NO_HEAP_EXECUTION + + if options.pie: + flags |= MH_PIE + else: + flags &= ~MH_PIE + + if flags != original_flags: + CheckedSeek(file, offset + 24) + WriteUInt32(file, flags, endian) + + +def HandleFatFile(file, options, fat_offset=0): + """Seeks the file-like |file| object to |offset| and loops over its + |fat_header| entries, calling HandleMachOFile for each.""" + + CheckedSeek(file, fat_offset) + magic = ReadUInt32(file, '>') + assert magic == FAT_MAGIC + + nfat_arch = ReadUInt32(file, '>') + + for index in xrange(0, nfat_arch): + cputype, cpusubtype, offset, size, align = ReadFatArch(file) + assert size >= 28 + + # HandleMachOFile will seek around. Come back here after calling it, in + # case it sought. + fat_arch_offset = file.tell() + HandleMachOFile(file, options, offset) + CheckedSeek(file, fat_arch_offset) + + +def main(me, args): + parser = optparse.OptionParser('%prog [options] ') + parser.add_option('--executable-heap', action='store_false', + dest='no_heap_execution', default=True, + help='Clear the MH_NO_HEAP_EXECUTION bit') + parser.add_option('--no-pie', action='store_false', + dest='pie', default=True, + help='Clear the MH_PIE bit') + (options, loose_args) = parser.parse_args(args) + if len(loose_args) != 1: + parser.print_usage() + return 1 + + executable_path = loose_args[0] + executable_file = open(executable_path, 'rb+') + + magic = ReadUInt32(executable_file, '<') + if magic == FAT_CIGAM: + # Check FAT_CIGAM and not FAT_MAGIC because the read was little-endian. + HandleFatFile(executable_file, options) + elif magic == MH_MAGIC or magic == MH_CIGAM or \ + magic == MH_MAGIC_64 or magic == MH_CIGAM_64: + HandleMachOFile(executable_file, options) + else: + raise MachOError, '%s is not a Mach-O or fat file' % executable_file + + executable_file.close() + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[0], sys.argv[1:])) diff --git a/brightray/tools/mac/make_more_helpers.sh b/brightray/tools/mac/make_more_helpers.sh new file mode 100755 index 00000000000..ee4f21105b4 --- /dev/null +++ b/brightray/tools/mac/make_more_helpers.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE-CHROMIUM file. + +# Usage: make_more_helpers.sh +# +# This script creates additional helper .app bundles for Chromium, based on +# the existing helper .app bundle, changing their Mach-O header's flags to +# enable and disable various features. Based on Chromium Helper.app, it will +# create Chromium Helper EH.app, which has the MH_NO_HEAP_EXECUTION bit +# cleared to support Chromium child processes that require an executable heap, +# and Chromium Helper NP.app, which has the MH_PIE bit cleared to support +# Chromium child processes that cannot tolerate ASLR. +# +# This script expects to be called from the chrome_exe target as a postbuild, +# and operates directly within the built-up browser app's versioned directory. +# +# Each helper is adjusted by giving it the proper bundle name, renaming the +# executable, adjusting several Info.plist keys, and changing the executable's +# Mach-O flags. + +set -eu + +make_helper() { + local containing_dir="${1}" + local app_name="${2}" + local feature="${3}" + local flags="${4}" + + local helper_name="${app_name} Helper" + local helper_stem="${containing_dir}/${helper_name}" + local original_helper="${helper_stem}.app" + if [[ ! -d "${original_helper}" ]]; then + echo "${0}: error: ${original_helper} is a required directory" >& 2 + exit 1 + fi + local original_helper_exe="${original_helper}/Contents/MacOS/${helper_name}" + if [[ ! -f "${original_helper_exe}" ]]; then + echo "${0}: error: ${original_helper_exe} is a required file" >& 2 + exit 1 + fi + + local feature_helper="${helper_stem} ${feature}.app" + + rsync -acC --delete --include '*.so' "${original_helper}/" "${feature_helper}" + + local helper_feature="${helper_name} ${feature}" + local helper_feature_exe="${feature_helper}/Contents/MacOS/${helper_feature}" + mv "${feature_helper}/Contents/MacOS/${helper_name}" "${helper_feature_exe}" + + local change_flags="$(dirname "${0}")/change_mach_o_flags.py" + "${change_flags}" ${flags} "${helper_feature_exe}" + + local feature_info="${feature_helper}/Contents/Info" + local feature_info_plist="${feature_info}.plist" + + defaults write "${feature_info}" "CFBundleDisplayName" "${helper_feature}" + defaults write "${feature_info}" "CFBundleExecutable" "${helper_feature}" + + cfbundleid="$(defaults read "${feature_info}" "CFBundleIdentifier")" + feature_cfbundleid="${cfbundleid}.${feature}" + defaults write "${feature_info}" "CFBundleIdentifier" "${feature_cfbundleid}" + + cfbundlename="$(defaults read "${feature_info}" "CFBundleName")" + feature_cfbundlename="${cfbundlename} ${feature}" + defaults write "${feature_info}" "CFBundleName" "${feature_cfbundlename}" + + # As usual, defaults might have put the plist into whatever format excites + # it, but Info.plists get converted back to the expected XML format. + plutil -convert xml1 "${feature_info_plist}" + + # `defaults` also changes the file permissions, so make the file + # world-readable again. + chmod a+r "${feature_info_plist}" +} + +if [[ ${#} -ne 2 ]]; then + echo "usage: ${0} " >& 2 + exit 1 +fi + +DIRECTORY_WITHIN_CONTENTS="${1}" +APP_NAME="${2}" + +CONTENTS_DIR="${BUILT_PRODUCTS_DIR}/${CONTENTS_FOLDER_PATH}" +CONTAINING_DIR="${CONTENTS_DIR}/${DIRECTORY_WITHIN_CONTENTS}" + +make_helper "${CONTAINING_DIR}" "${APP_NAME}" "EH" "--executable-heap" +make_helper "${CONTAINING_DIR}" "${APP_NAME}" "NP" "--no-pie" diff --git a/brightray/vendor/.gitignore b/brightray/vendor/.gitignore new file mode 100644 index 00000000000..0920e14cbc0 --- /dev/null +++ b/brightray/vendor/.gitignore @@ -0,0 +1 @@ +/download/ diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent new file mode 160000 index 00000000000..3f6f01c46be --- /dev/null +++ b/brightray/vendor/libchromiumcontent @@ -0,0 +1 @@ +Subproject commit 3f6f01c46be61f36b4e25456bf2c0539ef4d77f3 From 65dd011fa379d4c92248ed92f0d341444e40d0d7 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 13 Mar 2013 15:42:16 -0400 Subject: [PATCH 0002/1195] Use Google-style header guards everywhere --- brightray/browser/browser_client.h | 6 +++--- brightray/browser/browser_context.h | 6 +++--- brightray/browser/browser_main_parts.h | 6 +++--- brightray/browser/network_delegate.h | 6 +++--- brightray/browser/url_request_context_getter.h | 6 +++--- brightray/common/main_delegate.h | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index ac5412233f6..9d7c1aebb9a 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#ifndef __brightray__browser_client__ -#define __brightray__browser_client__ +#ifndef BRIGHTRAY_BROWSER_BROWSER_CLIENT_H_ +#define BRIGHTRAY_BROWSER_BROWSER_CLIENT_H_ #include "content/public/browser/content_browser_client.h" @@ -36,4 +36,4 @@ private: } -#endif /* defined(__brightray__browser_client__) */ +#endif diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 2b2c603c696..3418e901cf9 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#ifndef __brightray__browser_context__ -#define __brightray__browser_context__ +#ifndef BRIGHTRAY_BROWSER_BROWSER_CONTEXT_H_ +#define BRIGHTRAY_BROWSER_BROWSER_CONTEXT_H_ #include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" @@ -43,4 +43,4 @@ private: } -#endif /* defined(__brightray__browser_context__) */ +#endif diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 5e8194aa093..f86dd832686 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#ifndef __brightray__main_parts__ -#define __brightray__main_parts__ +#ifndef BRIGHTRAY_BROWSER_BROWSER_MAIN_PARTS_H_ +#define BRIGHTRAY_BROWSER_BROWSER_MAIN_PARTS_H_ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" @@ -35,4 +35,4 @@ private: } -#endif /* defined(__brightray__main_parts__) */ +#endif diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 54c98dca31e..1d2645532f4 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#ifndef __brightray__network_delegate__ -#define __brightray__network_delegate__ +#ifndef BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_ +#define BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_ #include "net/base/network_delegate.h" @@ -38,4 +38,4 @@ private: } -#endif /* defined(__brightray__network_delegate__) */ +#endif diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 89db0ec5b7d..cb3c4edcb22 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#ifndef __brightray__url_request_context_getter__ -#define __brightray__url_request_context_getter__ +#ifndef BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_ +#define BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_ #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" @@ -51,4 +51,4 @@ private: } -#endif /* defined(__brightray__url_request_context_getter__) */ +#endif diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 9b56a7939e5..0edc3f8cb9c 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#ifndef __brightray__main_delegate__ -#define __brightray__main_delegate__ +#ifndef BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ +#define BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" @@ -28,4 +28,4 @@ private: }; } -#endif /* defined(__brightray__main_delegate__) */ +#endif From e1b5e5e1bfc82c950a14cdb3c0fb6bc92ecde17c Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 13 Mar 2013 16:45:00 -0400 Subject: [PATCH 0003/1195] Store the disk cache in an app-specific location We deduce the name of the application from the CFBundleName of the .app bundle and use a path based on that. Similar logic should be implementable for other platforms. Fixes #3. --- brightray/brightray.gyp | 3 +++ brightray/browser/browser_context.cc | 5 +++-- brightray/common/application_name.h | 12 ++++++++++++ brightray/common/application_name_mac.mm | 12 ++++++++++++ brightray/common/main_delegate_mac.mm | 11 ++++------- 5 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 brightray/common/application_name.h create mode 100644 brightray/common/application_name_mac.mm diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 0e19a903cb2..2eec6db9940 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -7,6 +7,7 @@ 'target_name': 'brightray', 'type': 'static_library', 'include_dirs': [ + '.', '<(libchromiumcontent_include_dir)', ], 'direct_dependent_settings': { @@ -28,6 +29,8 @@ 'browser/network_delegate.h', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', + 'common/application_name.h', + 'common/application_name_mac.mm', 'common/main_delegate.cc', 'common/main_delegate.h', 'common/main_delegate_mac.mm', diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 51778133996..1b06fe0b1cf 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -4,6 +4,8 @@ #include "browser_context.h" +#include "common/application_name.h" + #include "base/files/file_path.h" #include "base/path_service.h" #include "content/public/browser/browser_thread.h" @@ -53,10 +55,9 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::Prot } base::FilePath BrowserContext::GetPath() { - // FIXME: This should be an application-specific path. base::FilePath path; CHECK(PathService::Get(base::DIR_APP_DATA, &path)); - return path.Append("Brightray"); + return path.Append(GetApplicationName()); } bool BrowserContext::IsOffTheRecord() const { diff --git a/brightray/common/application_name.h b/brightray/common/application_name.h new file mode 100644 index 00000000000..c00ea71aa02 --- /dev/null +++ b/brightray/common/application_name.h @@ -0,0 +1,12 @@ +#ifndef BRIGHTRAY_COMMON_APPLICATION_NAME_H_ +#define BRIGHTRAY_COMMON_APPLICATION_NAME_H_ + +#include + +namespace brightray { + +std::string GetApplicationName(); + +} + +#endif diff --git a/brightray/common/application_name_mac.mm b/brightray/common/application_name_mac.mm new file mode 100644 index 00000000000..48bac02b6f8 --- /dev/null +++ b/brightray/common/application_name_mac.mm @@ -0,0 +1,12 @@ +#import "common/application_name.h" + +#import "base/mac/bundle_locations.h" +#import "base/mac/foundation_util.h" + +namespace brightray { + +std::string GetApplicationName() { + return [[base::mac::OuterBundle().infoDictionary objectForKey:base::mac::CFToNSCast(kCFBundleNameKey)] UTF8String]; +} + +} diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index e91312ef442..f53bc7866f0 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -5,6 +5,7 @@ #import "main_delegate.h" +#include "common/application_name.h" #include "base/mac/bundle_locations.h" #include "base/mac/foundation_util.h" #include "base/path_service.h" @@ -35,23 +36,19 @@ base::FilePath GetFrameworksPath() { return path.Append("Frameworks"); } -std::string OuterBundleName() { - return [[base::mac::OuterBundle().infoDictionary objectForKey:base::mac::CFToNSCast(kCFBundleNameKey)] UTF8String]; -} - } void MainDelegate::OverrideFrameworkBundlePath() { - base::FilePath helper_path = GetFrameworksPath().Append(OuterBundleName() + ".framework"); + base::FilePath helper_path = GetFrameworksPath().Append(GetApplicationName() + ".framework"); base::mac::SetOverrideFrameworkBundlePath(helper_path); } void MainDelegate::OverrideChildProcessPath() { - base::FilePath helper_path = GetFrameworksPath().Append(OuterBundleName() + " Helper.app") + base::FilePath helper_path = GetFrameworksPath().Append(GetApplicationName() + " Helper.app") .Append("Contents") .Append("MacOS") - .Append(OuterBundleName() + " Helper"); + .Append(GetApplicationName() + " Helper"); PathService::Override(content::CHILD_PROCESS_EXE, helper_path); } From b2a79856ef9cddc654f1cdc80912eddc2a5d401b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 14 Mar 2013 09:03:50 -0400 Subject: [PATCH 0004/1195] Add InspectableWebContents This class can be used to create a content::WebContents that can be inspected by the Chrome Dev Tools. This requires embedding applications to copy content_shell.pak into their resource bundle. Right now the dev tools are always docked to the bottom of the view; we don't yet support undocking or changing the docked side. Fixes #1. --- brightray/brightray.gyp | 16 ++++ brightray/browser/browser_main_parts.cc | 16 +++- brightray/browser/browser_main_parts.h | 6 ++ brightray/browser/devtools_delegate.cc | 39 +++++++++ brightray/browser/devtools_delegate.h | 28 +++++++ brightray/browser/devtools_frontend.cc | 84 +++++++++++++++++++ brightray/browser/devtools_frontend.h | 52 ++++++++++++ brightray/browser/inspectable_web_contents.cc | 11 +++ brightray/browser/inspectable_web_contents.h | 23 +++++ .../browser/inspectable_web_contents_impl.cc | 33 ++++++++ .../browser/inspectable_web_contents_impl.h | 32 +++++++ .../browser/inspectable_web_contents_view.h | 19 +++++ .../inspectable_web_contents_view_mac.h | 34 ++++++++ .../inspectable_web_contents_view_mac.mm | 28 +++++++ .../mac/bry_inspectable_web_contents_view.h | 12 +++ .../mac/bry_inspectable_web_contents_view.mm | 77 +++++++++++++++++ ...ry_inspectable_web_contents_view_private.h | 12 +++ brightray/common/content_client.cc | 28 +++++++ brightray/common/content_client.h | 27 ++++++ brightray/common/main_delegate.cc | 15 +++- brightray/common/main_delegate.h | 6 ++ brightray/common/main_delegate_mac.mm | 8 ++ 22 files changed, 601 insertions(+), 5 deletions(-) create mode 100644 brightray/browser/devtools_delegate.cc create mode 100644 brightray/browser/devtools_delegate.h create mode 100644 brightray/browser/devtools_frontend.cc create mode 100644 brightray/browser/devtools_frontend.h create mode 100644 brightray/browser/inspectable_web_contents.cc create mode 100644 brightray/browser/inspectable_web_contents.h create mode 100644 brightray/browser/inspectable_web_contents_impl.cc create mode 100644 brightray/browser/inspectable_web_contents_impl.h create mode 100644 brightray/browser/inspectable_web_contents_view.h create mode 100644 brightray/browser/inspectable_web_contents_view_mac.h create mode 100644 brightray/browser/inspectable_web_contents_view_mac.mm create mode 100644 brightray/browser/mac/bry_inspectable_web_contents_view.h create mode 100644 brightray/browser/mac/bry_inspectable_web_contents_view.mm create mode 100644 brightray/browser/mac/bry_inspectable_web_contents_view_private.h create mode 100644 brightray/common/content_client.cc create mode 100644 brightray/common/content_client.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 2eec6db9940..f233b9e7bb9 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -23,14 +23,30 @@ 'browser/browser_main_parts.cc', 'browser/browser_main_parts.h', 'browser/browser_main_parts_mac.mm', + 'browser/devtools_delegate.cc', + 'browser/devtools_delegate.h', + 'browser/devtools_frontend.cc', + 'browser/devtools_frontend.h', + 'browser/inspectable_web_contents.cc', + 'browser/inspectable_web_contents.h', + 'browser/inspectable_web_contents_impl.cc', + 'browser/inspectable_web_contents_impl.h', + 'browser/inspectable_web_contents_view.h', + 'browser/inspectable_web_contents_view_mac.h', + 'browser/inspectable_web_contents_view_mac.mm', 'browser/mac/bry_application.h', 'browser/mac/bry_application.mm', + 'browser/mac/bry_inspectable_web_contents_view.h', + 'browser/mac/bry_inspectable_web_contents_view.mm', + 'browser/mac/bry_inspectable_web_contents_view_private.h', 'browser/network_delegate.cc', 'browser/network_delegate.h', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', 'common/application_name.h', 'common/application_name_mac.mm', + 'common/content_client.cc', + 'common/content_client.h', 'common/main_delegate.cc', 'common/main_delegate.h', 'common/main_delegate_mac.mm', diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 87847948850..fcfb82af6d8 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -2,9 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include "browser_main_parts.h" +#include "browser/browser_main_parts.h" -#include "browser_context.h" +#include "browser/browser_context.h" +#include "browser/devtools_delegate.h" + +#include "content/public/browser/devtools_http_handler.h" +#include "net/base/tcp_listen_socket.h" namespace brightray { @@ -12,10 +16,18 @@ BrowserMainParts::BrowserMainParts() { } BrowserMainParts::~BrowserMainParts() { + devtools_http_handler_->Stop(); + devtools_http_handler_ = nullptr; } void BrowserMainParts::PreMainMessageLoopRun() { browser_context_.reset(new BrowserContext); + + // These two objects are owned by devtools_http_handler_. + auto delegate = new DevToolsDelegate; + auto factory = new net::TCPListenSocketFactory("127.0.0.1", 0); + + devtools_http_handler_ = content::DevToolsHttpHandler::Start(factory, std::string(), delegate); } } diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index f86dd832686..0268dc04022 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -9,6 +9,10 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" +namespace content { +class DevToolsHttpHandler; +} + namespace brightray { class BrowserContext; @@ -19,6 +23,7 @@ public: ~BrowserMainParts(); BrowserContext* browser_context() { return browser_context_.get(); } + content::DevToolsHttpHandler* devtools_http_handler() { return devtools_http_handler_; } protected: #if defined(OS_MACOSX) @@ -29,6 +34,7 @@ protected: private: scoped_ptr browser_context_; + content::DevToolsHttpHandler* devtools_http_handler_; DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); }; diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_delegate.cc new file mode 100644 index 00000000000..3542a6da694 --- /dev/null +++ b/brightray/browser/devtools_delegate.cc @@ -0,0 +1,39 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "devtools_delegate.h" + +namespace brightray { + +DevToolsDelegate::DevToolsDelegate() { +} + +DevToolsDelegate::~DevToolsDelegate() { +} + +std::string DevToolsDelegate::GetDiscoveryPageHTML() { + return std::string(); +} + +bool DevToolsDelegate::BundlesFrontendResources() { + return true; +} + +base::FilePath DevToolsDelegate::GetDebugFrontendDir() { + return base::FilePath(); +} + +std::string DevToolsDelegate::GetPageThumbnailData(const GURL&) { + return std::string(); +} + +content::RenderViewHost* DevToolsDelegate::CreateNewTarget() { + return nullptr; +} + +content::DevToolsHttpHandlerDelegate::TargetType DevToolsDelegate::GetTargetType(content::RenderViewHost*) { + return kTargetTypeTab; +} + +} diff --git a/brightray/browser/devtools_delegate.h b/brightray/browser/devtools_delegate.h new file mode 100644 index 00000000000..e237222c4c1 --- /dev/null +++ b/brightray/browser/devtools_delegate.h @@ -0,0 +1,28 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_DEVTOOLS_DELEGATE_H_ +#define BRIGHTRAY_BROWSER_DEVTOOLS_DELEGATE_H_ + +#include "content/public/browser/devtools_http_handler_delegate.h" + +namespace brightray { + +class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { +public: + DevToolsDelegate(); + ~DevToolsDelegate(); + +private: + virtual std::string GetDiscoveryPageHTML() OVERRIDE; + virtual bool BundlesFrontendResources() OVERRIDE; + virtual base::FilePath GetDebugFrontendDir() OVERRIDE; + virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE; + virtual content::RenderViewHost* CreateNewTarget() OVERRIDE; + virtual TargetType GetTargetType(content::RenderViewHost*) OVERRIDE; +}; + +} + +#endif diff --git a/brightray/browser/devtools_frontend.cc b/brightray/browser/devtools_frontend.cc new file mode 100644 index 00000000000..773c1c9a915 --- /dev/null +++ b/brightray/browser/devtools_frontend.cc @@ -0,0 +1,84 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "devtools_frontend.h" + +#include "browser/browser_client.h" +#include "browser/browser_main_parts.h" + +#include "content/public/browser/devtools_agent_host.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_http_handler.h" +#include "content/public/browser/devtools_manager.h" +#include "content/public/browser/web_contents.h" + +namespace brightray { + +content::WebContents* DevToolsFrontend::Show(content::WebContents* inspected_contents) { + // frontend will delete itself when the WebContents closes. + auto frontend = new DevToolsFrontend(inspected_contents); + + return frontend->web_contents(); +} + +DevToolsFrontend::DevToolsFrontend(content::WebContents* inspected_contents) + : WebContentsObserver(content::WebContents::Create(content::WebContents::CreateParams(inspected_contents->GetBrowserContext()))), + agent_host_(content::DevToolsAgentHost::GetFor(inspected_contents->GetRenderViewHost())), + frontend_host_(content::DevToolsClientHost::CreateDevToolsFrontendHost(web_contents(), this)) { + auto client = static_cast(content::GetContentClient()->browser()); + auto handler = client->browser_main_parts()->devtools_http_handler(); + auto url = handler->GetFrontendURL(nullptr); + web_contents()->GetController().LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); +} + +DevToolsFrontend::~DevToolsFrontend() { +} + +void DevToolsFrontend::ActivateWindow() { +} + +void DevToolsFrontend::ChangeAttachedWindowHeight(unsigned height) { +} + +void DevToolsFrontend::CloseWindow() { +} + +void DevToolsFrontend::MoveWindow(int x, int y) { +} + +void DevToolsFrontend::SetDockSide(const std::string& side) { +} + +void DevToolsFrontend::OpenInNewTab(const std::string& url) { +} + +void DevToolsFrontend::SaveToFile(const std::string& url, const std::string& content, bool save_as) { +} + +void DevToolsFrontend::AppendToFile(const std::string& url, const std::string& content) { +} + +void DevToolsFrontend::RequestFileSystems() { +} + +void DevToolsFrontend::AddFileSystem() { +} + +void DevToolsFrontend::RemoveFileSystem(const std::string& file_system_path) { +} + +void DevToolsFrontend::InspectedContentsClosing() { +} + +void DevToolsFrontend::RenderViewCreated(content::RenderViewHost* render_view_host) { + content::DevToolsClientHost::SetupDevToolsFrontendClient(web_contents()->GetRenderViewHost()); + content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get()); +} + +void DevToolsFrontend::WebContentsDestroyed(content::WebContents*) { + content::DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get()); + delete this; +} + +} diff --git a/brightray/browser/devtools_frontend.h b/brightray/browser/devtools_frontend.h new file mode 100644 index 00000000000..07772f42ea2 --- /dev/null +++ b/brightray/browser/devtools_frontend.h @@ -0,0 +1,52 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_DEVTOOLS_FRONTEND_H_ +#define BRIGHTRAY_BROWSER_DEVTOOLS_FRONTEND_H_ + +#include "base/memory/scoped_ptr.h" +#include "content/public/browser/devtools_frontend_host_delegate.h" +#include "content/public/browser/web_contents_observer.h" + +namespace content { +class DevToolsAgentHost; +class DevToolsClientHost; +} + +namespace brightray { + +class DevToolsFrontend : content::DevToolsFrontendHostDelegate, content::WebContentsObserver { +public: + static content::WebContents* Show(content::WebContents* inspected_contents); + +private: + DevToolsFrontend(content::WebContents* inspected_contents); + ~DevToolsFrontend(); + + virtual void ActivateWindow() OVERRIDE; + virtual void ChangeAttachedWindowHeight(unsigned height) OVERRIDE; + virtual void CloseWindow() OVERRIDE; + virtual void MoveWindow(int x, int y) OVERRIDE; + virtual void SetDockSide(const std::string& side) OVERRIDE; + virtual void OpenInNewTab(const std::string& url) OVERRIDE; + virtual void SaveToFile(const std::string& url, + const std::string& content, + bool save_as) OVERRIDE; + virtual void AppendToFile(const std::string& url, + const std::string& content) OVERRIDE; + virtual void RequestFileSystems() OVERRIDE; + virtual void AddFileSystem() OVERRIDE; + virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; + virtual void InspectedContentsClosing() OVERRIDE; + + virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE; + virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE; + + scoped_refptr agent_host_; + scoped_ptr frontend_host_; +}; + +} + +#endif diff --git a/brightray/browser/inspectable_web_contents.cc b/brightray/browser/inspectable_web_contents.cc new file mode 100644 index 00000000000..64f840e77fe --- /dev/null +++ b/brightray/browser/inspectable_web_contents.cc @@ -0,0 +1,11 @@ +#include "browser/inspectable_web_contents.h" + +#include "browser/inspectable_web_contents_impl.h" + +namespace brightray { + +InspectableWebContents* InspectableWebContents::Create(const content::WebContents::CreateParams& create_params) { + return new InspectableWebContentsImpl(create_params); +} + +} diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h new file mode 100644 index 00000000000..f515d062543 --- /dev/null +++ b/brightray/browser/inspectable_web_contents.h @@ -0,0 +1,23 @@ +#ifndef BRIGHTRAY_INSPECTABLE_WEB_CONTENTS_H_ +#define BRIGHTRAY_INSPECTABLE_WEB_CONTENTS_H_ + +#include "content/public/browser/web_contents.h" + +namespace brightray { + +class InspectableWebContentsView; + +class InspectableWebContents { +public: + static InspectableWebContents* Create(const content::WebContents::CreateParams&); + virtual ~InspectableWebContents() {} + + virtual InspectableWebContentsView* GetView() const = 0; + virtual content::WebContents* GetWebContents() const = 0; + + virtual void ShowDevTools() = 0; +}; + +} + +#endif diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc new file mode 100644 index 00000000000..77a62c88730 --- /dev/null +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -0,0 +1,33 @@ +#include "browser/inspectable_web_contents_impl.h" + +#include "browser/devtools_frontend.h" +#include "browser/inspectable_web_contents_view.h" + +namespace brightray { + +// Implemented separately on each platform. +InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl*); + +InspectableWebContentsImpl::InspectableWebContentsImpl(const content::WebContents::CreateParams& create_params) + : web_contents_(content::WebContents::Create(create_params)) { + view_.reset(CreateInspectableContentsView(this)); +} + +InspectableWebContentsImpl::~InspectableWebContentsImpl() { +} + +InspectableWebContentsView* InspectableWebContentsImpl::GetView() const { + return view_.get(); +} + +content::WebContents* InspectableWebContentsImpl::GetWebContents() const { + return web_contents_.get(); +} + +void InspectableWebContentsImpl::ShowDevTools() { + if (!devtools_web_contents_) + devtools_web_contents_.reset(DevToolsFrontend::Show(web_contents_.get())); + view_->ShowDevTools(); +} + +} diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h new file mode 100644 index 00000000000..88326425def --- /dev/null +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -0,0 +1,32 @@ +#ifndef BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_IMPL_H_ +#define BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_IMPL_H_ + +#include "browser/inspectable_web_contents.h" + +namespace brightray { + +class InspectableWebContentsView; + +class InspectableWebContentsImpl : public InspectableWebContents { +public: + InspectableWebContentsImpl(const content::WebContents::CreateParams&); + virtual ~InspectableWebContentsImpl() OVERRIDE; + + virtual InspectableWebContentsView* GetView() const OVERRIDE; + virtual content::WebContents* GetWebContents() const OVERRIDE; + + virtual void ShowDevTools() OVERRIDE; + + content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); } + +private: + scoped_ptr web_contents_; + scoped_ptr devtools_web_contents_; + scoped_ptr view_; + + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); +}; + +} + +#endif diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h new file mode 100644 index 00000000000..c64dd36d739 --- /dev/null +++ b/brightray/browser/inspectable_web_contents_view.h @@ -0,0 +1,19 @@ +#ifndef BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_H_ +#define BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_H_ + +#include "ui/gfx/native_widget_types.h" + +namespace brightray { + +class InspectableWebContentsView { +public: + virtual ~InspectableWebContentsView() {} + + virtual gfx::NativeView GetNativeView() const = 0; + + virtual void ShowDevTools() = 0; +}; + +} + +#endif diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h new file mode 100644 index 00000000000..ebe4699e1be --- /dev/null +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -0,0 +1,34 @@ +#ifndef BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_MAC_H_ +#define BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_MAC_H_ + +#import "browser/inspectable_web_contents_view.h" + +#import "base/memory/scoped_nsobject.h" + +@class BRYInspectableWebContentsView; + +namespace brightray { + +class InspectableWebContentsImpl; + +class InspectableWebContentsViewMac : public InspectableWebContentsView { +public: + InspectableWebContentsViewMac(InspectableWebContentsImpl*); + + virtual gfx::NativeView GetNativeView() const OVERRIDE; + virtual void ShowDevTools() OVERRIDE; + + InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; } + +private: + // Owns us. + InspectableWebContentsImpl* inspectable_web_contents_; + + scoped_nsobject view_; + + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewMac); +}; + +} + +#endif diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm new file mode 100644 index 00000000000..bb75bc9cb7b --- /dev/null +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -0,0 +1,28 @@ +#import "browser/inspectable_web_contents_view_mac.h" + +#import "browser/inspectable_web_contents.h" +#import "browser/mac/bry_inspectable_web_contents_view_private.h" + +#import "content/public/browser/web_contents_view.h" +#import + +namespace brightray { + +InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { + return new InspectableWebContentsViewMac(inspectable_web_contents); +} + +InspectableWebContentsViewMac::InspectableWebContentsViewMac(InspectableWebContentsImpl* inspectable_web_contents) + : inspectable_web_contents_(inspectable_web_contents), + view_([[BRYInspectableWebContentsView alloc] initWithInspectableWebContentsViewMac:this]) { +} + +gfx::NativeView InspectableWebContentsViewMac::GetNativeView() const { + return view_.get(); +} + +void InspectableWebContentsViewMac::ShowDevTools() { + [view_ setDevToolsVisible:YES]; +} + +} diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h new file mode 100644 index 00000000000..99f70a57b91 --- /dev/null +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -0,0 +1,12 @@ +#import + +@class BRYInspectableWebContentsViewPrivate; + +@interface BRYInspectableWebContentsView : NSView { +@private + BRYInspectableWebContentsViewPrivate *_private; +} + +- (IBAction)showDevTools:(id)sender; + +@end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm new file mode 100644 index 00000000000..6ebc238e6f5 --- /dev/null +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -0,0 +1,77 @@ +#import "browser/mac/bry_inspectable_web_contents_view.h" + +#import "browser/inspectable_web_contents_impl.h" +#import "browser/inspectable_web_contents_view_mac.h" +#import "browser/mac/bry_inspectable_web_contents_view_private.h" + +#import "content/public/browser/web_contents_view.h" + +using namespace brightray; + +@interface BRYInspectableWebContentsViewPrivate : NSObject { +@public + InspectableWebContentsViewMac *inspectableWebContentsView; + NSSplitView *splitView; +} +@end + +@implementation BRYInspectableWebContentsView + +- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac *)inspectableWebContentsView { + self = [super init]; + if (!self) + return nil; + + _private = [[BRYInspectableWebContentsViewPrivate alloc] init]; + _private->inspectableWebContentsView = inspectableWebContentsView; + _private->splitView = [[NSSplitView alloc] init]; + + [self addSubview:_private->splitView]; + _private->splitView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; + _private->splitView.dividerStyle = NSSplitViewDividerStyleThin; + [_private->splitView addSubview:inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView()]; + + return self; +} + +- (void)dealloc { + [_private release]; + _private = nil; + + [super dealloc]; +} + +- (IBAction)showDevTools:(id)sender { + _private->inspectableWebContentsView->inspectable_web_contents()->ShowDevTools(); +} + +- (void)setDevToolsVisible:(BOOL)visible { + BOOL wasVisible = _private->splitView.subviews.count == 2; + if (wasVisible == visible) + return; + + auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); + auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); + + if (visible) { + auto inspectedView = _private->inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView(); + CGRect frame = NSRectToCGRect(inspectedView.frame); + CGRect inspectedViewFrame; + CGRect devToolsFrame; + CGRectDivide(frame, &inspectedViewFrame, &devToolsFrame, CGRectGetHeight(frame) * 2 / 3, CGRectMaxYEdge); + + inspectedView.frame = NSRectFromCGRect(inspectedViewFrame); + devToolsView.frame = NSRectFromCGRect(devToolsFrame); + + [_private->splitView addSubview:devToolsView]; + } else { + [devToolsView removeFromSuperview]; + } + + [_private->splitView adjustSubviews]; +} + +@end + +@implementation BRYInspectableWebContentsViewPrivate +@end \ No newline at end of file diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view_private.h b/brightray/browser/mac/bry_inspectable_web_contents_view_private.h new file mode 100644 index 00000000000..5fce3da9cc4 --- /dev/null +++ b/brightray/browser/mac/bry_inspectable_web_contents_view_private.h @@ -0,0 +1,12 @@ +#import "browser/mac/bry_inspectable_web_contents_view.h" + +namespace brightray { +class InspectableWebContentsViewMac; +} + +@interface BRYInspectableWebContentsView (Private) + +- (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac *)inspectableWebContentsView; +- (void)setDevToolsVisible:(BOOL)visible; + +@end \ No newline at end of file diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc new file mode 100644 index 00000000000..e824ee916bb --- /dev/null +++ b/brightray/common/content_client.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "common/content_client.h" + +#include "common/application_name.h" + +#include "ui/base/resource/resource_bundle.h" +#include "webkit/user_agent/user_agent_util.h" + +namespace brightray { + +ContentClient::ContentClient() { +} + +ContentClient::~ContentClient() { +} + +std::string ContentClient::GetUserAgent() const { + return webkit_glue::BuildUserAgentFromProduct(GetApplicationName()); +} + +base::StringPiece ContentClient::GetDataResource(int resource_id, ui::ScaleFactor scale_factor) const { + return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(resource_id, scale_factor); +} + +} \ No newline at end of file diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h new file mode 100644 index 00000000000..d322b03526c --- /dev/null +++ b/brightray/common/content_client.h @@ -0,0 +1,27 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_COMMON_CONTENT_CLIENT_H_ +#define BRIGHTRAY_COMMON_CONTENT_CLIENT_H_ + +#include "base/compiler_specific.h" +#include "content/public/common/content_client.h" + +namespace brightray { + +class ContentClient : public content::ContentClient { +public: + ContentClient(); + ~ContentClient(); + +private: + virtual std::string GetUserAgent() const OVERRIDE; + virtual base::StringPiece GetDataResource(int resource_id, ui::ScaleFactor) const OVERRIDE; + + DISALLOW_COPY_AND_ASSIGN(ContentClient); +}; + +} + +#endif diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 2eb3141a219..9b850500e1b 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -2,20 +2,28 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include "main_delegate.h" +#include "common/main_delegate.h" + +#include "browser/browser_client.h" +#include "common/content_client.h" -#include "browser_client.h" #include "base/command_line.h" #include "content/public/common/content_switches.h" namespace brightray { -MainDelegate::MainDelegate() { +MainDelegate::MainDelegate() + : content_client_(new ContentClient) { } MainDelegate::~MainDelegate() { } +bool MainDelegate::BasicStartupComplete(int* exit_code) { + SetContentClient(content_client_.get()); + return false; +} + void MainDelegate::PreSandboxStartup() { // FIXME: We don't currently support running sandboxed. CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNoSandbox); @@ -24,6 +32,7 @@ void MainDelegate::PreSandboxStartup() { OverrideChildProcessPath(); OverrideFrameworkBundlePath(); #endif + InitializeResourceBundle(); } } diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 0edc3f8cb9c..4795cfdeb65 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -11,19 +11,25 @@ namespace brightray { +class ContentClient; + class MainDelegate : public content::ContentMainDelegate { public: MainDelegate(); ~MainDelegate(); private: + static void InitializeResourceBundle(); #if defined(OS_MACOSX) static void OverrideChildProcessPath(); static void OverrideFrameworkBundlePath(); #endif + virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; virtual void PreSandboxStartup() OVERRIDE; + scoped_ptr content_client_; + DISALLOW_COPY_AND_ASSIGN(MainDelegate); }; diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index f53bc7866f0..e8dd7f1d97f 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -6,10 +6,12 @@ #import "main_delegate.h" #include "common/application_name.h" + #include "base/mac/bundle_locations.h" #include "base/mac/foundation_util.h" #include "base/path_service.h" #include "content/public/common/content_paths.h" +#include "ui/base/resource/resource_bundle.h" namespace brightray { @@ -38,6 +40,12 @@ base::FilePath GetFrameworksPath() { } +void MainDelegate::InitializeResourceBundle() { + auto path = [base::mac::FrameworkBundle() pathForResource:@"content_shell" ofType:@"pak"]; + + ui::ResourceBundle::InitSharedInstanceWithPakPath(base::mac::NSStringToFilePath(path)); +} + void MainDelegate::OverrideFrameworkBundlePath() { base::FilePath helper_path = GetFrameworksPath().Append(GetApplicationName() + ".framework"); From fe35a92de51776a6b2bd5ad6c6ec3292c72a6a53 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 14 Mar 2013 13:05:01 -0400 Subject: [PATCH 0005/1195] Get the linen background painting during elastic scrolling We weren't setting the location of the resource bundle correctly in the renderer process. It turns out base::mac::OuterBundle() returns the helper app's bundle in the renderer process. So now we have MainApplicationBundle() to give us the bundle of the main app. --- brightray/brightray.gyp | 2 + brightray/common/application_name_mac.mm | 5 ++- .../common/mac/main_application_bundle.h | 20 +++++++++ .../common/mac/main_application_bundle.mm | 42 +++++++++++++++++++ brightray/common/main_delegate_mac.mm | 20 +-------- 5 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 brightray/common/mac/main_application_bundle.h create mode 100644 brightray/common/mac/main_application_bundle.mm diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index f233b9e7bb9..2a776b24fa9 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -47,6 +47,8 @@ 'common/application_name_mac.mm', 'common/content_client.cc', 'common/content_client.h', + 'common/mac/main_application_bundle.h', + 'common/mac/main_application_bundle.mm', 'common/main_delegate.cc', 'common/main_delegate.h', 'common/main_delegate_mac.mm', diff --git a/brightray/common/application_name_mac.mm b/brightray/common/application_name_mac.mm index 48bac02b6f8..eecccefd3fa 100644 --- a/brightray/common/application_name_mac.mm +++ b/brightray/common/application_name_mac.mm @@ -1,12 +1,13 @@ #import "common/application_name.h" -#import "base/mac/bundle_locations.h" +#import "common/mac/main_application_bundle.h" + #import "base/mac/foundation_util.h" namespace brightray { std::string GetApplicationName() { - return [[base::mac::OuterBundle().infoDictionary objectForKey:base::mac::CFToNSCast(kCFBundleNameKey)] UTF8String]; + return [[MainApplicationBundle().infoDictionary objectForKey:base::mac::CFToNSCast(kCFBundleNameKey)] UTF8String]; } } diff --git a/brightray/common/mac/main_application_bundle.h b/brightray/common/mac/main_application_bundle.h new file mode 100644 index 00000000000..61f19adadd7 --- /dev/null +++ b/brightray/common/mac/main_application_bundle.h @@ -0,0 +1,20 @@ +#ifndef BRIGHTRAY_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ +#define BRIGHTRAY_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ + +@class NSBundle; + +namespace base { +class FilePath; +} + +namespace brightray { + +// The "main" application bundle is the outermost bundle for this logical application. E.g., if you +// have MyApp.app and MyApp.app/Contents/Frameworks/MyApp Helper.app, the main application bundle is +// MyApp.app, no matter which executable is currently running. +NSBundle* MainApplicationBundle(); +base::FilePath MainApplicationBundlePath(); + +} + +#endif diff --git a/brightray/common/mac/main_application_bundle.mm b/brightray/common/mac/main_application_bundle.mm new file mode 100644 index 00000000000..14173241e8f --- /dev/null +++ b/brightray/common/mac/main_application_bundle.mm @@ -0,0 +1,42 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Adam Roben . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#import "common/mac/main_application_bundle.h" + +#import "base/files/file_path.h" +#import "base/mac/foundation_util.h" +#import "base/path_service.h" + +namespace brightray { + +base::FilePath MainApplicationBundlePath() { + // Start out with the path to the running executable. + base::FilePath path; + PathService::Get(base::FILE_EXE, &path); + + // Up to Contents. + if (base::mac::IsBackgroundOnlyProcess()) { + // The running executable is the helper. Go up five steps: + // Contents/Frameworks/Helper.app/Contents/MacOS/Helper + // ^ to here ^ from here + path = path.DirName().DirName().DirName().DirName().DirName(); + } else { + // One step up to MacOS, another to Contents. + path = path.DirName().DirName(); + } + DCHECK_EQ(path.BaseName().value(), "Contents"); + + // Up one more level to the .app. + path = path.DirName(); + DCHECK_EQ(path.BaseName().Extension(), ".app"); + + return path; +} + +NSBundle* MainApplicationBundle() { + return [NSBundle bundleWithPath:base::mac::FilePathToNSString(MainApplicationBundlePath())]; +} + +} diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index e8dd7f1d97f..ec04e0f1702 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -6,6 +6,7 @@ #import "main_delegate.h" #include "common/application_name.h" +#include "common/mac/main_application_bundle.h" #include "base/mac/bundle_locations.h" #include "base/mac/foundation_util.h" @@ -18,24 +19,7 @@ namespace brightray { namespace { base::FilePath GetFrameworksPath() { - // Start out with the path to the running executable. - base::FilePath path; - PathService::Get(base::FILE_EXE, &path); - - // Up to Contents. - if (base::mac::IsBackgroundOnlyProcess()) { - // The running executable is the helper. Go up five steps: - // Contents/Frameworks/Helper.app/Contents/MacOS/Helper - // ^ to here ^ from here - path = path.DirName().DirName().DirName().DirName().DirName(); - } else { - // One step up to MacOS, another to Contents. - path = path.DirName().DirName(); - } - DCHECK_EQ(path.BaseName().value(), "Contents"); - - // Go into the frameworks directory. - return path.Append("Frameworks"); + return MainApplicationBundlePath().Append("Contents").Append("Frameworks"); } } From 4bff7a592aa50887eefdc81a158bc6c7e3ee95ea Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 14 Mar 2013 13:06:17 -0400 Subject: [PATCH 0006/1195] Enforce better header hygiene Apple recommends disabling ALWAYS_SEARCH_USER_PATHS, so we now do. And we also disable USE_HEADER_MAP to match other platforms more closely. --- brightray/brightray.gypi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index ecd35a269e0..938fab03912 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -10,6 +10,7 @@ 'NDEBUG', ], 'xcode_settings': { + 'ALWAYS_SEARCH_USER_PATHS': 'NO', 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11', 'CLANG_CXX_LIBRARY': 'libstdc++', 'COMBINE_HIDPI_IMAGES': 'YES', @@ -18,6 +19,7 @@ 'MACOSX_DEPLOYMENT_TARGET': '10.7', 'RUN_CLANG_STATIC_ANALYZER': 'YES', 'SDKROOT': 'macosx10.7', + 'USE_HEADER_MAP': 'NO', 'WARNING_CFLAGS': [ '-Wall', '-Wextra', From 561fc9a342f62edd1f56c9ad137c0dbdaa651dac Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 14 Mar 2013 13:06:58 -0400 Subject: [PATCH 0007/1195] Fix a NSSplitView leak --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 6ebc238e6f5..2a141c3129f 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -35,6 +35,7 @@ using namespace brightray; } - (void)dealloc { + [_private->splitView release]; [_private release]; _private = nil; From be6d990a97ea3bda10359448c7ce39b46e3e7bc3 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 14 Mar 2013 13:48:17 -0400 Subject: [PATCH 0008/1195] Make keyboard shortcuts work on Mac When the renderer doesn't handle a key event, we pass it off to the main menu to see if it can handle it. Part of #2. --- brightray/brightray.gyp | 3 +++ .../browser/default_web_contents_delegate.cc | 11 ++++++++++ .../browser/default_web_contents_delegate.h | 21 +++++++++++++++++++ .../default_web_contents_delegate_mac.mm | 15 +++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 brightray/browser/default_web_contents_delegate.cc create mode 100644 brightray/browser/default_web_contents_delegate.h create mode 100644 brightray/browser/default_web_contents_delegate_mac.mm diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 2a776b24fa9..28fcf6603e8 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -23,6 +23,9 @@ 'browser/browser_main_parts.cc', 'browser/browser_main_parts.h', 'browser/browser_main_parts_mac.mm', + 'browser/default_web_contents_delegate.cc', + 'browser/default_web_contents_delegate.h', + 'browser/default_web_contents_delegate_mac.mm', 'browser/devtools_delegate.cc', 'browser/devtools_delegate.h', 'browser/devtools_frontend.cc', diff --git a/brightray/browser/default_web_contents_delegate.cc b/brightray/browser/default_web_contents_delegate.cc new file mode 100644 index 00000000000..967881efb7a --- /dev/null +++ b/brightray/browser/default_web_contents_delegate.cc @@ -0,0 +1,11 @@ +#include "browser/default_web_contents_delegate.h" + +namespace brightray { + +DefaultWebContentsDelegate::DefaultWebContentsDelegate() { +} + +DefaultWebContentsDelegate::~DefaultWebContentsDelegate() { +} + +} diff --git a/brightray/browser/default_web_contents_delegate.h b/brightray/browser/default_web_contents_delegate.h new file mode 100644 index 00000000000..8ec70c316b6 --- /dev/null +++ b/brightray/browser/default_web_contents_delegate.h @@ -0,0 +1,21 @@ +#ifndef BRIGHTRAY_BROWSER_DEFAULT_WEB_CONTENTS_DELEGATE_H_ +#define BRIGHTRAY_BROWSER_DEFAULT_WEB_CONTENTS_DELEGATE_H_ + +#include "content/public/browser/web_contents_delegate.h" + +namespace brightray { + +// This class provides some sane default behaviors to any content::WebContents instance (e.g., +// keyboard shortcut handling on Mac). +class DefaultWebContentsDelegate : public content::WebContentsDelegate { +public: + DefaultWebContentsDelegate(); + ~DefaultWebContentsDelegate(); + +protected: + virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; +}; + +} + +#endif diff --git a/brightray/browser/default_web_contents_delegate_mac.mm b/brightray/browser/default_web_contents_delegate_mac.mm new file mode 100644 index 00000000000..78760614cbf --- /dev/null +++ b/brightray/browser/default_web_contents_delegate_mac.mm @@ -0,0 +1,15 @@ +#import "browser/default_web_contents_delegate.h" + +#import "content/public/browser/native_web_keyboard_event.h" +#import + +namespace brightray { + +void DefaultWebContentsDelegate::HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent& event) { + if (event.skip_in_browser) + return; + + [[NSApp mainMenu] performKeyEquivalent:event.os_event]; +} + +} \ No newline at end of file From 4ca59ba27904c52b5c63b6533028cacdcb38a200 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 14 Mar 2013 13:48:42 -0400 Subject: [PATCH 0009/1195] Make keyboard shortcuts work when the dev tools are focused We just pass unhandled key events from dev tools along to the main WebContentsDelegate. Part of #2. --- brightray/browser/devtools_frontend.cc | 8 ++++++++ brightray/browser/devtools_frontend.h | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/brightray/browser/devtools_frontend.cc b/brightray/browser/devtools_frontend.cc index 773c1c9a915..097e28c9ff1 100644 --- a/brightray/browser/devtools_frontend.cc +++ b/brightray/browser/devtools_frontend.cc @@ -24,8 +24,10 @@ content::WebContents* DevToolsFrontend::Show(content::WebContents* inspected_con DevToolsFrontend::DevToolsFrontend(content::WebContents* inspected_contents) : WebContentsObserver(content::WebContents::Create(content::WebContents::CreateParams(inspected_contents->GetBrowserContext()))), + inspected_web_contents_(inspected_contents), agent_host_(content::DevToolsAgentHost::GetFor(inspected_contents->GetRenderViewHost())), frontend_host_(content::DevToolsClientHost::CreateDevToolsFrontendHost(web_contents(), this)) { + web_contents()->SetDelegate(this); auto client = static_cast(content::GetContentClient()->browser()); auto handler = client->browser_main_parts()->devtools_http_handler(); auto url = handler->GetFrontendURL(nullptr); @@ -81,4 +83,10 @@ void DevToolsFrontend::WebContentsDestroyed(content::WebContents*) { delete this; } +void DevToolsFrontend::HandleKeyboardEvent(content::WebContents* source, const content::NativeWebKeyboardEvent& event) { + auto delegate = inspected_web_contents_->GetDelegate(); + if (delegate) + delegate->HandleKeyboardEvent(source, event); +} + } diff --git a/brightray/browser/devtools_frontend.h b/brightray/browser/devtools_frontend.h index 07772f42ea2..051b86b2b84 100644 --- a/brightray/browser/devtools_frontend.h +++ b/brightray/browser/devtools_frontend.h @@ -7,6 +7,7 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/devtools_frontend_host_delegate.h" +#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" namespace content { @@ -16,7 +17,7 @@ class DevToolsClientHost; namespace brightray { -class DevToolsFrontend : content::DevToolsFrontendHostDelegate, content::WebContentsObserver { +class DevToolsFrontend : content::DevToolsFrontendHostDelegate, content::WebContentsObserver, content::WebContentsDelegate { public: static content::WebContents* Show(content::WebContents* inspected_contents); @@ -24,6 +25,8 @@ private: DevToolsFrontend(content::WebContents* inspected_contents); ~DevToolsFrontend(); + // content::DevToolsFrontendHostDelegate + virtual void ActivateWindow() OVERRIDE; virtual void ChangeAttachedWindowHeight(unsigned height) OVERRIDE; virtual void CloseWindow() OVERRIDE; @@ -40,9 +43,16 @@ private: virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; virtual void InspectedContentsClosing() OVERRIDE; + // content::WebContentsObserver + virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE; virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE; + // content::WebContentsDelegate + + virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; + + content::WebContents* inspected_web_contents_; scoped_refptr agent_host_; scoped_ptr frontend_host_; }; From 909b3cd18f8eaae8394445c36a00218157ea081b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 14 Mar 2013 14:00:52 -0400 Subject: [PATCH 0010/1195] Stop disabling the sandbox Now that we have the resources bundle hooked up correctly, the sandbox functions just fine. Fixes #4. --- brightray/common/main_delegate.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 9b850500e1b..13ace6f6321 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -25,9 +25,6 @@ bool MainDelegate::BasicStartupComplete(int* exit_code) { } void MainDelegate::PreSandboxStartup() { - // FIXME: We don't currently support running sandboxed. - CommandLine::ForCurrentProcess()->AppendSwitch(switches::kNoSandbox); - #if defined(OS_MACOSX) OverrideChildProcessPath(); OverrideFrameworkBundlePath(); From 3cda49b894283d08ce2c964e12c19541c2fca411 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 21 Mar 2013 15:09:00 -0400 Subject: [PATCH 0011/1195] Update to latest libchromiumcontent --- brightray/browser/browser_context.cc | 2 -- brightray/browser/devtools_delegate.cc | 4 ++++ brightray/browser/devtools_delegate.h | 1 + brightray/browser/devtools_frontend.cc | 2 +- brightray/browser/url_request_context_getter.cc | 8 ++++---- brightray/vendor/libchromiumcontent | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 1b06fe0b1cf..2747ad9f781 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -11,7 +11,6 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" -#include "net/base/host_resolver.h" #include "url_request_context_getter.h" namespace brightray { @@ -34,7 +33,6 @@ private: } URLRequestContextGetter* getter_; - scoped_ptr host_resolver_; }; BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_delegate.cc index 3542a6da694..ed9f9a47b8a 100644 --- a/brightray/browser/devtools_delegate.cc +++ b/brightray/browser/devtools_delegate.cc @@ -36,4 +36,8 @@ content::DevToolsHttpHandlerDelegate::TargetType DevToolsDelegate::GetTargetType return kTargetTypeTab; } +std::string DevToolsDelegate::GetViewDescription(content::RenderViewHost*) { + return std::string(); +} + } diff --git a/brightray/browser/devtools_delegate.h b/brightray/browser/devtools_delegate.h index e237222c4c1..3fb345e2ebe 100644 --- a/brightray/browser/devtools_delegate.h +++ b/brightray/browser/devtools_delegate.h @@ -21,6 +21,7 @@ private: virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE; virtual content::RenderViewHost* CreateNewTarget() OVERRIDE; virtual TargetType GetTargetType(content::RenderViewHost*) OVERRIDE; + virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE; }; } diff --git a/brightray/browser/devtools_frontend.cc b/brightray/browser/devtools_frontend.cc index 097e28c9ff1..b8a9004b628 100644 --- a/brightray/browser/devtools_frontend.cc +++ b/brightray/browser/devtools_frontend.cc @@ -25,7 +25,7 @@ content::WebContents* DevToolsFrontend::Show(content::WebContents* inspected_con DevToolsFrontend::DevToolsFrontend(content::WebContents* inspected_contents) : WebContentsObserver(content::WebContents::Create(content::WebContents::CreateParams(inspected_contents->GetBrowserContext()))), inspected_web_contents_(inspected_contents), - agent_host_(content::DevToolsAgentHost::GetFor(inspected_contents->GetRenderViewHost())), + agent_host_(content::DevToolsAgentHost::GetOrCreateFor(inspected_contents->GetRenderViewHost())), frontend_host_(content::DevToolsClientHost::CreateDevToolsFrontendHost(web_contents(), this)) { web_contents()->SetDelegate(this); auto client = static_cast(content::GetContentClient()->browser()); diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 137d6a90f8a..e865f8ce224 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -10,14 +10,14 @@ #include "content/public/browser/browser_thread.h" #include "content/public/common/url_constants.h" #include "net/base/cert_verifier.h" -#include "net/base/default_server_bound_cert_store.h" -#include "net/base/server_bound_cert_service.h" -#include "net/base/ssl_config_service_defaults.h" #include "net/cookies/cookie_monster.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_cache.h" #include "net/http/http_server_properties_impl.h" #include "net/proxy/proxy_service.h" +#include "net/ssl/default_server_bound_cert_store.h" +#include "net/ssl/server_bound_cert_service.h" +#include "net/ssl/ssl_config_service_defaults.h" #include "net/url_request/static_http_user_agent_settings.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_storage.h" @@ -64,7 +64,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() base::WorkerPool::GetTaskRunner(true))); storage_->set_http_user_agent_settings( new net::StaticHttpUserAgentSettings( - "en-us,en", "iso-8859-1,*,utf-8", EmptyString())); + "en-us,en", EmptyString())); scoped_ptr host_resolver( net::HostResolver::CreateDefaultResolver(NULL)); diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 3f6f01c46be..8a81d74a567 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 3f6f01c46be61f36b4e25456bf2c0539ef4d77f3 +Subproject commit 8a81d74a56712c112cad1956fdd8ed836532a378 From 5c0323cf237ed9166c3bc005eebc26bb17f31cc5 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 25 Mar 2013 12:23:37 -0400 Subject: [PATCH 0012/1195] Allow overwriting vendor/download/libchromiumcontent when its version changes --- brightray/script/bootstrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index 057a65f314a..c5ca741a412 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -23,4 +23,4 @@ git submodule update --init --recursive SOURCE_ROOT="$(pwd -P)" DOWNLOAD_DIR="${SOURCE_ROOT}/vendor/download" mkdir -p "${DOWNLOAD_DIR}" -vendor/libchromiumcontent/script/download "${BASE_URL}" "${DOWNLOAD_DIR}/libchromiumcontent" +vendor/libchromiumcontent/script/download -f "${BASE_URL}" "${DOWNLOAD_DIR}/libchromiumcontent" From 5120887571441e27b616abb771fc78e55e8d1c4a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 25 Mar 2013 12:28:30 -0400 Subject: [PATCH 0013/1195] Update libchromiumcontent to pull in more headers --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 8a81d74a567..915259576de 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 8a81d74a56712c112cad1956fdd8ed836532a378 +Subproject commit 915259576de45b0ffe83faf3700691bdcc8af7f9 From 3d3b9898068709af146a3ff39cf1e5062a66a69b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 25 Mar 2013 12:53:30 -0400 Subject: [PATCH 0014/1195] Update libchromiumcontent to pull in more headers * vendor/libchromiumcontent 9152595...cf87e4d (1): > Export webkit/plugins headers --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 915259576de..cf87e4d6deb 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 915259576de45b0ffe83faf3700691bdcc8af7f9 +Subproject commit cf87e4d6deb086dac396711efd4ee391dbe686c8 From 115eef52a323192f28baa389144df015d966d0e2 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 26 Mar 2013 16:30:32 -0400 Subject: [PATCH 0015/1195] Update libchromiumcontent * vendor/libchromiumcontent cf87e4d...3944c1c (1): > Compile and export SQLitePersistentCookieStore --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index cf87e4d6deb..3944c1c0055 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit cf87e4d6deb086dac396711efd4ee391dbe686c8 +Subproject commit 3944c1c0055d1de3d8f0647087acc0f6244113d6 From 4fc0fed0810419ea71f9439570c89230c107c91a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 27 Mar 2013 08:53:35 -0400 Subject: [PATCH 0016/1195] Persist cookies to disk We use Chrome's SQLitePersistentCookieStore to save cookies to a file called "Cookies" within the application support directory. Fixes #5. --- brightray/browser/url_request_context_getter.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index e865f8ce224..cfaa9a1a194 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include "url_request_context_getter.h" +#include "browser/url_request_context_getter.h" #include "network_delegate.h" #include "base/string_util.h" #include "base/threading/worker_pool.h" +#include "chrome/browser/net/sqlite_persistent_cookie_store.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/url_constants.h" #include "net/base/cert_verifier.h" @@ -58,7 +59,14 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() url_request_context_->set_network_delegate(network_delegate_.get()); storage_.reset( new net::URLRequestContextStorage(url_request_context_.get())); - storage_->set_cookie_store(new net::CookieMonster(NULL, NULL)); + storage_->set_cookie_store(new net::CookieMonster( + new SQLitePersistentCookieStore( + base_path_.Append(FILE_PATH_LITERAL("Cookies")), + content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::IO), + content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::DB), + false, + nullptr), + NULL)); storage_->set_server_bound_cert_service(new net::ServerBoundCertService( new net::DefaultServerBoundCertStore(NULL), base::WorkerPool::GetTaskRunner(true))); From 90691e394fdfd0b7370a895b03e7a9b2bc845bbc Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 27 Mar 2013 08:53:53 -0400 Subject: [PATCH 0017/1195] Fix lifetime management of URLRequestContextGetter I noticed this bug while adding persistent cookie storage. --- brightray/browser/browser_context.cc | 4 ++-- brightray/browser/browser_context.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 2747ad9f781..0b6aaee7011 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -43,11 +43,11 @@ BrowserContext::~BrowserContext() { net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::ProtocolHandlerMap* protocol_handlers) { DCHECK(!url_request_getter_); - url_request_getter_.reset(new URLRequestContextGetter( + url_request_getter_ = new URLRequestContextGetter( GetPath(), content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::IO), content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::FILE), - protocol_handlers)); + protocol_handlers); resource_context_->set_url_request_context_getter(url_request_getter_.get()); return url_request_getter_.get(); } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 3418e901cf9..a57023af1b3 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -36,7 +36,7 @@ private: virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; scoped_ptr resource_context_; - scoped_ptr url_request_getter_; + scoped_refptr url_request_getter_; DISALLOW_COPY_AND_ASSIGN(BrowserContext); }; From 881a203b571c6ce0a8359ca3a9f87a390948a2f2 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 27 Mar 2013 08:54:19 -0400 Subject: [PATCH 0018/1195] Fix double-delete of BrowserMainParts The caller of BrowserClient::CreateBrowserMainParts handles destroying the BrowserMainParts instance we return. --- brightray/browser/browser_client.cc | 5 +++-- brightray/browser/browser_client.h | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index b9115fe1ebc..61f173d6434 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -24,8 +24,9 @@ BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts(const content::M } content::BrowserMainParts* BrowserClient::CreateBrowserMainParts(const content::MainFunctionParams& parameters) { - browser_main_parts_.reset(OverrideCreateBrowserMainParts(parameters)); - return browser_main_parts_.get(); + DCHECK(!browser_main_parts_); + browser_main_parts_ = OverrideCreateBrowserMainParts(parameters); + return browser_main_parts_; } net::URLRequestContextGetter* BrowserClient::CreateRequestContext(content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers) { diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 9d7c1aebb9a..ebf7a80a198 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -18,7 +18,7 @@ public: ~BrowserClient(); BrowserContext* browser_context(); - BrowserMainParts* browser_main_parts() { return browser_main_parts_.get(); } + BrowserMainParts* browser_main_parts() { return browser_main_parts_; } protected: // Subclasses should override this to provide their own BrowserMainParts implementation. The @@ -29,7 +29,7 @@ private: virtual content::BrowserMainParts* CreateBrowserMainParts(const content::MainFunctionParams&) OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContext(content::BrowserContext*, content::ProtocolHandlerMap*) OVERRIDE; - scoped_ptr browser_main_parts_; + BrowserMainParts* browser_main_parts_; DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; From d20ecc0e2b8af013934d5377fbd39837dc938794 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 27 Mar 2013 10:33:00 -0400 Subject: [PATCH 0019/1195] Merge InspectableWebContentsImpl and DevToolsFrontend While this prevents clients from easily implementing their own devtools windows, it gives us much easier control over the devtools experience. --- brightray/brightray.gyp | 2 - brightray/browser/devtools_frontend.cc | 92 ------------------- brightray/browser/devtools_frontend.h | 62 ------------- .../browser/inspectable_web_contents_impl.cc | 84 ++++++++++++++++- .../browser/inspectable_web_contents_impl.h | 44 ++++++++- 5 files changed, 124 insertions(+), 160 deletions(-) delete mode 100644 brightray/browser/devtools_frontend.cc delete mode 100644 brightray/browser/devtools_frontend.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 28fcf6603e8..95ffe02810c 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -28,8 +28,6 @@ 'browser/default_web_contents_delegate_mac.mm', 'browser/devtools_delegate.cc', 'browser/devtools_delegate.h', - 'browser/devtools_frontend.cc', - 'browser/devtools_frontend.h', 'browser/inspectable_web_contents.cc', 'browser/inspectable_web_contents.h', 'browser/inspectable_web_contents_impl.cc', diff --git a/brightray/browser/devtools_frontend.cc b/brightray/browser/devtools_frontend.cc deleted file mode 100644 index b8a9004b628..00000000000 --- a/brightray/browser/devtools_frontend.cc +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE-CHROMIUM file. - -#include "devtools_frontend.h" - -#include "browser/browser_client.h" -#include "browser/browser_main_parts.h" - -#include "content/public/browser/devtools_agent_host.h" -#include "content/public/browser/devtools_client_host.h" -#include "content/public/browser/devtools_http_handler.h" -#include "content/public/browser/devtools_manager.h" -#include "content/public/browser/web_contents.h" - -namespace brightray { - -content::WebContents* DevToolsFrontend::Show(content::WebContents* inspected_contents) { - // frontend will delete itself when the WebContents closes. - auto frontend = new DevToolsFrontend(inspected_contents); - - return frontend->web_contents(); -} - -DevToolsFrontend::DevToolsFrontend(content::WebContents* inspected_contents) - : WebContentsObserver(content::WebContents::Create(content::WebContents::CreateParams(inspected_contents->GetBrowserContext()))), - inspected_web_contents_(inspected_contents), - agent_host_(content::DevToolsAgentHost::GetOrCreateFor(inspected_contents->GetRenderViewHost())), - frontend_host_(content::DevToolsClientHost::CreateDevToolsFrontendHost(web_contents(), this)) { - web_contents()->SetDelegate(this); - auto client = static_cast(content::GetContentClient()->browser()); - auto handler = client->browser_main_parts()->devtools_http_handler(); - auto url = handler->GetFrontendURL(nullptr); - web_contents()->GetController().LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); -} - -DevToolsFrontend::~DevToolsFrontend() { -} - -void DevToolsFrontend::ActivateWindow() { -} - -void DevToolsFrontend::ChangeAttachedWindowHeight(unsigned height) { -} - -void DevToolsFrontend::CloseWindow() { -} - -void DevToolsFrontend::MoveWindow(int x, int y) { -} - -void DevToolsFrontend::SetDockSide(const std::string& side) { -} - -void DevToolsFrontend::OpenInNewTab(const std::string& url) { -} - -void DevToolsFrontend::SaveToFile(const std::string& url, const std::string& content, bool save_as) { -} - -void DevToolsFrontend::AppendToFile(const std::string& url, const std::string& content) { -} - -void DevToolsFrontend::RequestFileSystems() { -} - -void DevToolsFrontend::AddFileSystem() { -} - -void DevToolsFrontend::RemoveFileSystem(const std::string& file_system_path) { -} - -void DevToolsFrontend::InspectedContentsClosing() { -} - -void DevToolsFrontend::RenderViewCreated(content::RenderViewHost* render_view_host) { - content::DevToolsClientHost::SetupDevToolsFrontendClient(web_contents()->GetRenderViewHost()); - content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get()); -} - -void DevToolsFrontend::WebContentsDestroyed(content::WebContents*) { - content::DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get()); - delete this; -} - -void DevToolsFrontend::HandleKeyboardEvent(content::WebContents* source, const content::NativeWebKeyboardEvent& event) { - auto delegate = inspected_web_contents_->GetDelegate(); - if (delegate) - delegate->HandleKeyboardEvent(source, event); -} - -} diff --git a/brightray/browser/devtools_frontend.h b/brightray/browser/devtools_frontend.h deleted file mode 100644 index 051b86b2b84..00000000000 --- a/brightray/browser/devtools_frontend.h +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE-CHROMIUM file. - -#ifndef BRIGHTRAY_BROWSER_DEVTOOLS_FRONTEND_H_ -#define BRIGHTRAY_BROWSER_DEVTOOLS_FRONTEND_H_ - -#include "base/memory/scoped_ptr.h" -#include "content/public/browser/devtools_frontend_host_delegate.h" -#include "content/public/browser/web_contents_delegate.h" -#include "content/public/browser/web_contents_observer.h" - -namespace content { -class DevToolsAgentHost; -class DevToolsClientHost; -} - -namespace brightray { - -class DevToolsFrontend : content::DevToolsFrontendHostDelegate, content::WebContentsObserver, content::WebContentsDelegate { -public: - static content::WebContents* Show(content::WebContents* inspected_contents); - -private: - DevToolsFrontend(content::WebContents* inspected_contents); - ~DevToolsFrontend(); - - // content::DevToolsFrontendHostDelegate - - virtual void ActivateWindow() OVERRIDE; - virtual void ChangeAttachedWindowHeight(unsigned height) OVERRIDE; - virtual void CloseWindow() OVERRIDE; - virtual void MoveWindow(int x, int y) OVERRIDE; - virtual void SetDockSide(const std::string& side) OVERRIDE; - virtual void OpenInNewTab(const std::string& url) OVERRIDE; - virtual void SaveToFile(const std::string& url, - const std::string& content, - bool save_as) OVERRIDE; - virtual void AppendToFile(const std::string& url, - const std::string& content) OVERRIDE; - virtual void RequestFileSystems() OVERRIDE; - virtual void AddFileSystem() OVERRIDE; - virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; - virtual void InspectedContentsClosing() OVERRIDE; - - // content::WebContentsObserver - - virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE; - virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE; - - // content::WebContentsDelegate - - virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; - - content::WebContents* inspected_web_contents_; - scoped_refptr agent_host_; - scoped_ptr frontend_host_; -}; - -} - -#endif diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 77a62c88730..f2657915840 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -1,8 +1,19 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Adam Roben . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + #include "browser/inspectable_web_contents_impl.h" -#include "browser/devtools_frontend.h" +#include "browser/browser_client.h" +#include "browser/browser_main_parts.h" #include "browser/inspectable_web_contents_view.h" +#include "content/public/browser/devtools_agent_host.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_http_handler.h" +#include "content/public/browser/devtools_manager.h" + namespace brightray { // Implemented separately on each platform. @@ -25,9 +36,76 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const { } void InspectableWebContentsImpl::ShowDevTools() { - if (!devtools_web_contents_) - devtools_web_contents_.reset(DevToolsFrontend::Show(web_contents_.get())); + if (!devtools_web_contents_) { + devtools_web_contents_.reset(content::WebContents::Create(content::WebContents::CreateParams(web_contents_->GetBrowserContext()))); + Observe(devtools_web_contents_.get()); + devtools_web_contents_->SetDelegate(this); + + agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_->GetRenderViewHost()); + frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(devtools_web_contents_.get(), this)); + + auto client = static_cast(content::GetContentClient()->browser()); + auto handler = client->browser_main_parts()->devtools_http_handler(); + auto url = handler->GetFrontendURL(nullptr); + devtools_web_contents_->GetController().LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); + } + view_->ShowDevTools(); } +void InspectableWebContentsImpl::ActivateWindow() { +} + +void InspectableWebContentsImpl::ChangeAttachedWindowHeight(unsigned height) { +} + +void InspectableWebContentsImpl::CloseWindow() { +} + +void InspectableWebContentsImpl::MoveWindow(int x, int y) { +} + +void InspectableWebContentsImpl::SetDockSide(const std::string& side) { +} + +void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) { +} + +void InspectableWebContentsImpl::SaveToFile(const std::string& url, const std::string& content, bool save_as) { +} + +void InspectableWebContentsImpl::AppendToFile(const std::string& url, const std::string& content) { +} + +void InspectableWebContentsImpl::RequestFileSystems() { +} + +void InspectableWebContentsImpl::AddFileSystem() { +} + +void InspectableWebContentsImpl::RemoveFileSystem(const std::string& file_system_path) { +} + +void InspectableWebContentsImpl::InspectedContentsClosing() { +} + +void InspectableWebContentsImpl::RenderViewCreated(content::RenderViewHost* render_view_host) { + content::DevToolsClientHost::SetupDevToolsFrontendClient(web_contents()->GetRenderViewHost()); + content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get()); +} + +void InspectableWebContentsImpl::WebContentsDestroyed(content::WebContents*) { + content::DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get()); + Observe(nullptr); + agent_host_ = nullptr; + frontend_host_.reset(); + devtools_web_contents_.reset(); +} + +void InspectableWebContentsImpl::HandleKeyboardEvent(content::WebContents* source, const content::NativeWebKeyboardEvent& event) { + auto delegate = web_contents_->GetDelegate(); + if (delegate) + delegate->HandleKeyboardEvent(source, event); +} + } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 88326425def..aa6cf1754ff 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -3,11 +3,24 @@ #include "browser/inspectable_web_contents.h" +#include "content/public/browser/devtools_frontend_host_delegate.h" +#include "content/public/browser/web_contents_delegate.h" +#include "content/public/browser/web_contents_observer.h" + +namespace content { +class DevToolsAgentHost; +class DevToolsClientHost; +} + namespace brightray { class InspectableWebContentsView; -class InspectableWebContentsImpl : public InspectableWebContents { +class InspectableWebContentsImpl : + public InspectableWebContents, + content::DevToolsFrontendHostDelegate, + content::WebContentsObserver, + content::WebContentsDelegate { public: InspectableWebContentsImpl(const content::WebContents::CreateParams&); virtual ~InspectableWebContentsImpl() OVERRIDE; @@ -20,9 +33,38 @@ public: content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); } private: + // content::DevToolsFrontendHostDelegate + + virtual void ActivateWindow() OVERRIDE; + virtual void ChangeAttachedWindowHeight(unsigned height) OVERRIDE; + virtual void CloseWindow() OVERRIDE; + virtual void MoveWindow(int x, int y) OVERRIDE; + virtual void SetDockSide(const std::string& side) OVERRIDE; + virtual void OpenInNewTab(const std::string& url) OVERRIDE; + virtual void SaveToFile(const std::string& url, + const std::string& content, + bool save_as) OVERRIDE; + virtual void AppendToFile(const std::string& url, + const std::string& content) OVERRIDE; + virtual void RequestFileSystems() OVERRIDE; + virtual void AddFileSystem() OVERRIDE; + virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; + virtual void InspectedContentsClosing() OVERRIDE; + + // content::WebContentsObserver + + virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE; + virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE; + + // content::WebContentsDelegate + + virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; + scoped_ptr web_contents_; scoped_ptr devtools_web_contents_; scoped_ptr view_; + scoped_refptr agent_host_; + scoped_ptr frontend_host_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); }; From 001d0197de17c07fbde127100b2a78e81871262d Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 27 Mar 2013 10:59:40 -0400 Subject: [PATCH 0020/1195] Make the devtools close button work --- brightray/browser/inspectable_web_contents_impl.cc | 5 ++++- brightray/browser/inspectable_web_contents_view.h | 1 + brightray/browser/inspectable_web_contents_view_mac.h | 1 + brightray/browser/inspectable_web_contents_view_mac.mm | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index f2657915840..594a0c1fdd0 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -13,6 +13,7 @@ #include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_manager.h" +#include "content/public/browser/web_contents_view.h" namespace brightray { @@ -60,6 +61,9 @@ void InspectableWebContentsImpl::ChangeAttachedWindowHeight(unsigned height) { } void InspectableWebContentsImpl::CloseWindow() { + view_->CloseDevTools(); + devtools_web_contents_.reset(); + web_contents_->GetView()->Focus(); } void InspectableWebContentsImpl::MoveWindow(int x, int y) { @@ -99,7 +103,6 @@ void InspectableWebContentsImpl::WebContentsDestroyed(content::WebContents*) { Observe(nullptr); agent_host_ = nullptr; frontend_host_.reset(); - devtools_web_contents_.reset(); } void InspectableWebContentsImpl::HandleKeyboardEvent(content::WebContents* source, const content::NativeWebKeyboardEvent& event) { diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index c64dd36d739..0d68b4cabee 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -12,6 +12,7 @@ public: virtual gfx::NativeView GetNativeView() const = 0; virtual void ShowDevTools() = 0; + virtual void CloseDevTools() = 0; }; } diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index ebe4699e1be..6a35ac46c3b 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -17,6 +17,7 @@ public: virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; + virtual void CloseDevTools() OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; } diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index bb75bc9cb7b..49e4ad70c7f 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -25,4 +25,8 @@ void InspectableWebContentsViewMac::ShowDevTools() { [view_ setDevToolsVisible:YES]; } +void InspectableWebContentsViewMac::CloseDevTools() { + [view_ setDevToolsVisible:NO]; +} + } From c22d1cca79c713c9c8610cf66f790d5f4e4dae40 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 27 Mar 2013 11:19:15 -0400 Subject: [PATCH 0021/1195] Support docking the devtools on the right side of the window --- brightray/browser/inspectable_web_contents_impl.cc | 8 ++++++++ brightray/browser/inspectable_web_contents_view.h | 1 + .../browser/inspectable_web_contents_view_mac.h | 1 + .../browser/inspectable_web_contents_view_mac.mm | 4 ++++ .../mac/bry_inspectable_web_contents_view.mm | 13 +++++++++++++ .../mac/bry_inspectable_web_contents_view_private.h | 1 + 6 files changed, 28 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 594a0c1fdd0..1c91fa7ff96 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -9,11 +9,14 @@ #include "browser/browser_main_parts.h" #include "browser/inspectable_web_contents_view.h" +#include "base/stringprintf.h" +#include "base/utf_string_conversions.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_manager.h" #include "content/public/browser/web_contents_view.h" +#include "content/public/browser/render_view_host.h" namespace brightray { @@ -70,6 +73,11 @@ void InspectableWebContentsImpl::MoveWindow(int x, int y) { } void InspectableWebContentsImpl::SetDockSide(const std::string& side) { + if (!view_->SetDockSide(side)) + return; + + auto javascript = base::StringPrintf("InspectorFrontendAPI.setDockSide(\"%s\")", side.c_str()); + devtools_web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(javascript)); } void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) { diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 0d68b4cabee..3964cc682c0 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -13,6 +13,7 @@ public: virtual void ShowDevTools() = 0; virtual void CloseDevTools() = 0; + virtual bool SetDockSide(const std::string& side) = 0; }; } diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 6a35ac46c3b..a03ccaf6361 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -18,6 +18,7 @@ public: virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; + virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; } diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index 49e4ad70c7f..c9cc215591c 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -29,4 +29,8 @@ void InspectableWebContentsViewMac::CloseDevTools() { [view_ setDevToolsVisible:NO]; } +bool InspectableWebContentsViewMac::SetDockSide(const std::string& side) { + return [view_ setDockSide:side]; +} + } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 2a141c3129f..9bf5f4fdcd5 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -72,6 +72,19 @@ using namespace brightray; [_private->splitView adjustSubviews]; } +- (BOOL)setDockSide:(const std::string&)side { + if (side == "right") { + _private->splitView.vertical = YES; + } else if (side == "bottom") { + _private->splitView.vertical = NO; + } else { + return NO; + } + + [_private->splitView adjustSubviews]; + return YES; +} + @end @implementation BRYInspectableWebContentsViewPrivate diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view_private.h b/brightray/browser/mac/bry_inspectable_web_contents_view_private.h index 5fce3da9cc4..ef8c50cc8b6 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view_private.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view_private.h @@ -8,5 +8,6 @@ class InspectableWebContentsViewMac; - (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac *)inspectableWebContentsView; - (void)setDevToolsVisible:(BOOL)visible; +- (BOOL)setDockSide:(const std::string&)side; @end \ No newline at end of file From fa9a1d7b3567b588f03e8b46b6427f1caff3cb84 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 27 Mar 2013 12:15:46 -0400 Subject: [PATCH 0022/1195] Support undocking the devtools view into its own window --- .../mac/bry_inspectable_web_contents_view.h | 2 +- .../mac/bry_inspectable_web_contents_view.mm | 66 ++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 99f70a57b91..87abc98c354 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -2,7 +2,7 @@ @class BRYInspectableWebContentsViewPrivate; -@interface BRYInspectableWebContentsView : NSView { +@interface BRYInspectableWebContentsView : NSView { @private BRYInspectableWebContentsViewPrivate *_private; } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 9bf5f4fdcd5..b6c377dcc4c 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -12,9 +12,19 @@ using namespace brightray; @public InspectableWebContentsViewMac *inspectableWebContentsView; NSSplitView *splitView; + NSWindow *window; } @end +namespace { + +NSRect devtoolsWindowFrame(NSView *referenceView) { + auto screenFrame = [referenceView.window convertRectToScreen:[referenceView convertRect:referenceView.bounds toView:nil]]; + return NSInsetRect(screenFrame, NSWidth(screenFrame) / 6, NSHeight(screenFrame) / 6); +} + +} + @implementation BRYInspectableWebContentsView - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac *)inspectableWebContentsView { @@ -35,6 +45,7 @@ using namespace brightray; } - (void)dealloc { + [_private->window release]; [_private->splitView release]; [_private release]; _private = nil; @@ -54,6 +65,15 @@ using namespace brightray; auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); + if (_private->window && devToolsView.window == _private->window) { + if (visible) { + [_private->window makeKeyAndOrderFront:nil]; + } else { + [_private->window orderOut:nil]; + } + return; + } + if (visible) { auto inspectedView = _private->inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView(); CGRect frame = NSRectToCGRect(inspectedView.frame); @@ -75,16 +95,60 @@ using namespace brightray; - (BOOL)setDockSide:(const std::string&)side { if (side == "right") { _private->splitView.vertical = YES; + [self moveToSplitView]; } else if (side == "bottom") { _private->splitView.vertical = NO; + [self moveToSplitView]; + } else if (side == "undocked") { + [self moveToWindow]; } else { return NO; } - [_private->splitView adjustSubviews]; return YES; } +- (void)moveToWindow { + if (!_private->window) { + auto styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask | NSTexturedBackgroundWindowMask | NSUnifiedTitleAndToolbarWindowMask; + auto contentRect = [NSWindow contentRectForFrameRect:devtoolsWindowFrame(_private->splitView) styleMask:styleMask]; + _private->window = [[NSWindow alloc] initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:YES]; + _private->window.delegate = self; + _private->window.releasedWhenClosed = NO; + _private->window.title = @"Developer Tools"; + [_private->window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; + [_private->window setContentBorderThickness:24 forEdge:NSMaxYEdge]; + } + + auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); + auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); + + NSView *contentView = _private->window.contentView; + devToolsView.frame = contentView.bounds; + devToolsView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; + + [contentView addSubview:devToolsView]; + [_private->window makeKeyAndOrderFront:nil]; + [_private->splitView adjustSubviews]; +} + +- (void)moveToSplitView { + [_private->window orderOut:nil]; + + auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); + auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); + + [_private->splitView addSubview:devToolsView]; + [_private->splitView adjustSubviews]; +} + +#pragma mark - NSWindowDelegate + +- (BOOL)windowShouldClose:(id)sender { + [_private->window orderOut:nil]; + return NO; +} + @end @implementation BRYInspectableWebContentsViewPrivate From 93d9b612153922e0a91aef863fc6071590cbfa1b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 28 Mar 2013 12:34:49 -0400 Subject: [PATCH 0023/1195] Allow overriding MainDelegate::BasicStartupComplete --- brightray/common/main_delegate.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 4795cfdeb65..19d1306191c 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -18,6 +18,10 @@ public: MainDelegate(); ~MainDelegate(); +protected: + virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; + virtual void PreSandboxStartup() OVERRIDE; + private: static void InitializeResourceBundle(); #if defined(OS_MACOSX) @@ -25,9 +29,6 @@ private: static void OverrideFrameworkBundlePath(); #endif - virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; - virtual void PreSandboxStartup() OVERRIDE; - scoped_ptr content_client_; DISALLOW_COPY_AND_ASSIGN(MainDelegate); From e4e4cb6ec4ca8bebb653ce27b1bbda66953f983a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 28 Mar 2013 15:56:35 -0400 Subject: [PATCH 0024/1195] Allow embedders to customize the deployment target and base SDK --- brightray/brightray.gypi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 938fab03912..7014dd6cbf9 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -4,6 +4,8 @@ 'libchromiumcontent_library_dir': '<(libchromiumcontent_dir)/Release', 'libchromiumcontent_include_dir': '<(libchromiumcontent_dir)/include', 'libchromiumcontent_resources_dir': '<(libchromiumcontent_library_dir)', + 'mac_deployment_target%': '10.7', + 'mac_sdkroot%': 'macosx10.7', }, 'target_defaults': { 'defines': [ @@ -16,9 +18,9 @@ 'COMBINE_HIDPI_IMAGES': 'YES', 'GCC_ENABLE_CPP_RTTI': 'NO', 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', - 'MACOSX_DEPLOYMENT_TARGET': '10.7', + 'MACOSX_DEPLOYMENT_TARGET': '<(mac_deployment_target)', 'RUN_CLANG_STATIC_ANALYZER': 'YES', - 'SDKROOT': 'macosx10.7', + 'SDKROOT': '<(mac_sdkroot)', 'USE_HEADER_MAP': 'NO', 'WARNING_CFLAGS': [ '-Wall', From 1a1fecf42394682d608d90841ad9e4a162157c92 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 28 Mar 2013 17:16:35 -0400 Subject: [PATCH 0025/1195] Bump the base SDK and deployment target to 10.8 This required working around an incompatibility in base/mac/foundation_util.h. --- brightray/brightray.gyp | 1 + brightray/brightray.gypi | 4 ++-- brightray/browser/browser_main_parts_mac.mm | 2 +- brightray/common/application_name_mac.mm | 3 +-- brightray/common/mac/foundation_util.h | 15 +++++++++++++++ brightray/common/mac/main_application_bundle.mm | 3 ++- brightray/common/main_delegate_mac.mm | 2 +- 7 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 brightray/common/mac/foundation_util.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 95ffe02810c..8e53f38dde7 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -48,6 +48,7 @@ 'common/application_name_mac.mm', 'common/content_client.cc', 'common/content_client.h', + 'common/mac/foundation_util.h', 'common/mac/main_application_bundle.h', 'common/mac/main_application_bundle.mm', 'common/main_delegate.cc', diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 7014dd6cbf9..4245e8c6aa0 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -4,8 +4,8 @@ 'libchromiumcontent_library_dir': '<(libchromiumcontent_dir)/Release', 'libchromiumcontent_include_dir': '<(libchromiumcontent_dir)/include', 'libchromiumcontent_resources_dir': '<(libchromiumcontent_library_dir)', - 'mac_deployment_target%': '10.7', - 'mac_sdkroot%': 'macosx10.7', + 'mac_deployment_target%': '10.8', + 'mac_sdkroot%': 'macosx', }, 'target_defaults': { 'defines': [ diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm index c3fb162fe1b..373280ca444 100644 --- a/brightray/browser/browser_main_parts_mac.mm +++ b/brightray/browser/browser_main_parts_mac.mm @@ -14,7 +14,7 @@ void BrowserMainParts::PreMainMessageLoopStart() { NSString *mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"]; auto mainNib = [[NSNib alloc] initWithNibNamed:mainNibName bundle:base::mac::FrameworkBundle()]; - [mainNib instantiateNibWithOwner:application topLevelObjects:nil]; + [mainNib instantiateWithOwner:application topLevelObjects:nil]; [mainNib release]; } diff --git a/brightray/common/application_name_mac.mm b/brightray/common/application_name_mac.mm index eecccefd3fa..6a781189c3d 100644 --- a/brightray/common/application_name_mac.mm +++ b/brightray/common/application_name_mac.mm @@ -1,9 +1,8 @@ #import "common/application_name.h" +#import "common/mac/foundation_util.h" #import "common/mac/main_application_bundle.h" -#import "base/mac/foundation_util.h" - namespace brightray { std::string GetApplicationName() { diff --git a/brightray/common/mac/foundation_util.h b/brightray/common/mac/foundation_util.h new file mode 100644 index 00000000000..509c635b04f --- /dev/null +++ b/brightray/common/mac/foundation_util.h @@ -0,0 +1,15 @@ +#ifndef BRIGHTRAY_COMMON_MAC_FOUNDATION_UTIL_H_ +#define BRIGHTRAY_COMMON_MAC_FOUNDATION_UTIL_H_ + +// This header exists to work around incompatibilities between +// base/mac/foundation_util.h and the 10.8 SDK. + +#import + +// base/mac/foundation_util.h contains an incompatible declaration of NSSearchPathDirectory, +// so here we #define it to be something else. +#define NSSearchPathDirectory NSSearchPathDirectory___PRE_10_8 +#import "base/mac/foundation_util.h" +#undef NSSearchPathDirectory + +#endif diff --git a/brightray/common/mac/main_application_bundle.mm b/brightray/common/mac/main_application_bundle.mm index 14173241e8f..730eb36207b 100644 --- a/brightray/common/mac/main_application_bundle.mm +++ b/brightray/common/mac/main_application_bundle.mm @@ -5,8 +5,9 @@ #import "common/mac/main_application_bundle.h" +#import "common/mac/foundation_util.h" + #import "base/files/file_path.h" -#import "base/mac/foundation_util.h" #import "base/path_service.h" namespace brightray { diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index ec04e0f1702..e676402f889 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -6,10 +6,10 @@ #import "main_delegate.h" #include "common/application_name.h" +#include "common/mac/foundation_util.h" #include "common/mac/main_application_bundle.h" #include "base/mac/bundle_locations.h" -#include "base/mac/foundation_util.h" #include "base/path_service.h" #include "content/public/common/content_paths.h" #include "ui/base/resource/resource_bundle.h" From 08932531885d90c1641bfaf783d4070c8f400962 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 28 Mar 2013 17:17:46 -0400 Subject: [PATCH 0026/1195] Add bare-bones HTML notifications support Calling Notification.show() now works. But Notification.close() does nothing, and none of the notification's events fire. --- brightray/brightray.gyp | 1 + brightray/browser/browser_client.h | 5 +++++ brightray/browser/browser_client_mac.mm | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 brightray/browser/browser_client_mac.mm diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 8e53f38dde7..0f115eb1f32 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -18,6 +18,7 @@ 'sources': [ 'browser/browser_client.cc', 'browser/browser_client.h', + 'browser/browser_client_mac.mm', 'browser/browser_context.cc', 'browser/browser_context.h', 'browser/browser_main_parts.cc', diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index ebf7a80a198..0605d4afd5f 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -28,6 +28,11 @@ protected: private: virtual content::BrowserMainParts* CreateBrowserMainParts(const content::MainFunctionParams&) OVERRIDE; virtual net::URLRequestContextGetter* CreateRequestContext(content::BrowserContext*, content::ProtocolHandlerMap*) OVERRIDE; + virtual void ShowDesktopNotification( + const content::ShowDesktopNotificationHostMsgParams&, + int render_process_id, + int render_view_id, + bool worker) OVERRIDE; BrowserMainParts* browser_main_parts_; diff --git a/brightray/browser/browser_client_mac.mm b/brightray/browser/browser_client_mac.mm new file mode 100644 index 00000000000..8cc4b5cd3e5 --- /dev/null +++ b/brightray/browser/browser_client_mac.mm @@ -0,0 +1,23 @@ +#import "browser/browser_client.h" + +#import "base/strings/sys_string_conversions.h" +#import "content/public/common/show_desktop_notification_params.h" + +#import + +namespace brightray { + +void BrowserClient::ShowDesktopNotification( + const content::ShowDesktopNotificationHostMsgParams& params, + int render_process_id, + int render_view_id, + bool worker) { + auto notification = [[NSUserNotification alloc] init]; + notification.title = base::SysUTF16ToNSString(params.title); + notification.informativeText = base::SysUTF16ToNSString(params.body); + + [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; + [notification release]; +} + +} From 1328c85eefff7f15b61da86a0356d6166ea05ae7 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 28 Mar 2013 17:20:06 -0400 Subject: [PATCH 0027/1195] Fire a `show` event when a notification is shown --- brightray/browser/browser_client_mac.mm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightray/browser/browser_client_mac.mm b/brightray/browser/browser_client_mac.mm index 8cc4b5cd3e5..f3b235e0ace 100644 --- a/brightray/browser/browser_client_mac.mm +++ b/brightray/browser/browser_client_mac.mm @@ -1,6 +1,7 @@ #import "browser/browser_client.h" #import "base/strings/sys_string_conversions.h" +#import "content/public/browser/render_view_host.h" #import "content/public/common/show_desktop_notification_params.h" #import @@ -18,6 +19,12 @@ void BrowserClient::ShowDesktopNotification( [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; [notification release]; + + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); + if (!host) + return; + + host->DesktopNotificationPostDisplay(params.notification_id); } } From 3c41af84a107f41dba302249d5bee4d99fd45b3a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 28 Mar 2013 17:49:29 -0400 Subject: [PATCH 0028/1195] Move notification-related code into a new NotificationPresenter class --- brightray/brightray.gyp | 4 +++- brightray/browser/browser_client.cc | 15 ++++++++++++ brightray/browser/browser_client.h | 3 +++ brightray/browser/notification_presenter.cc | 11 +++++++++ brightray/browser/notification_presenter.h | 23 +++++++++++++++++++ ...t_mac.mm => notification_presenter_mac.mm} | 7 +++--- 6 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 brightray/browser/notification_presenter.cc create mode 100644 brightray/browser/notification_presenter.h rename brightray/browser/{browser_client_mac.mm => notification_presenter_mac.mm} (86%) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 0f115eb1f32..052f04863cd 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -18,7 +18,6 @@ 'sources': [ 'browser/browser_client.cc', 'browser/browser_client.h', - 'browser/browser_client_mac.mm', 'browser/browser_context.cc', 'browser/browser_context.h', 'browser/browser_main_parts.cc', @@ -43,6 +42,9 @@ 'browser/mac/bry_inspectable_web_contents_view_private.h', 'browser/network_delegate.cc', 'browser/network_delegate.h', + 'browser/notification_presenter.cc', + 'browser/notification_presenter.h', + 'browser/notification_presenter_mac.mm', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', 'common/application_name.h', diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 61f173d6434..7c6aa89381a 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -6,6 +6,7 @@ #include "browser_context.h" #include "browser_main_parts.h" +#include "notification_presenter.h" namespace brightray { @@ -19,6 +20,12 @@ BrowserContext* BrowserClient::browser_context() { return browser_main_parts_->browser_context(); } +NotificationPresenter* BrowserClient::notification_presenter() { + if (!notification_presenter_) + notification_presenter_.reset(new NotificationPresenter); + return notification_presenter_.get(); +} + BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts(const content::MainFunctionParams&) { return new BrowserMainParts; } @@ -33,4 +40,12 @@ net::URLRequestContextGetter* BrowserClient::CreateRequestContext(content::Brows return static_cast(browser_context)->CreateRequestContext(protocol_handlers); } +void BrowserClient::ShowDesktopNotification( + const content::ShowDesktopNotificationHostMsgParams& params, + int render_process_id, + int render_view_id, + bool worker) { + notification_presenter()->ShowNotification(params, render_process_id, render_view_id); +} + } diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 0605d4afd5f..38983dd47fb 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -11,6 +11,7 @@ namespace brightray { class BrowserContext; class BrowserMainParts; +class NotificationPresenter; class BrowserClient : public content::ContentBrowserClient { public: @@ -19,6 +20,7 @@ public: BrowserContext* browser_context(); BrowserMainParts* browser_main_parts() { return browser_main_parts_; } + NotificationPresenter* notification_presenter(); protected: // Subclasses should override this to provide their own BrowserMainParts implementation. The @@ -35,6 +37,7 @@ private: bool worker) OVERRIDE; BrowserMainParts* browser_main_parts_; + scoped_ptr notification_presenter_; DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; diff --git a/brightray/browser/notification_presenter.cc b/brightray/browser/notification_presenter.cc new file mode 100644 index 00000000000..152a10c3b8a --- /dev/null +++ b/brightray/browser/notification_presenter.cc @@ -0,0 +1,11 @@ +#include "browser/notification_presenter.h" + +namespace brightray { + +NotificationPresenter::NotificationPresenter() { +} + +NotificationPresenter::~NotificationPresenter() { +} + +} diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h new file mode 100644 index 00000000000..1ef7e3d5cd0 --- /dev/null +++ b/brightray/browser/notification_presenter.h @@ -0,0 +1,23 @@ +#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_ +#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_ + +namespace content { +struct ShowDesktopNotificationHostMsgParams; +} + +namespace brightray { + +class NotificationPresenter { + public: + NotificationPresenter(); + ~NotificationPresenter(); + + void ShowNotification( + const content::ShowDesktopNotificationHostMsgParams&, + int render_process_id, + int render_view_id); +}; + +} + +#endif diff --git a/brightray/browser/browser_client_mac.mm b/brightray/browser/notification_presenter_mac.mm similarity index 86% rename from brightray/browser/browser_client_mac.mm rename to brightray/browser/notification_presenter_mac.mm index f3b235e0ace..b348d0c1bc0 100644 --- a/brightray/browser/browser_client_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -1,4 +1,4 @@ -#import "browser/browser_client.h" +#import "browser/notification_presenter.h" #import "base/strings/sys_string_conversions.h" #import "content/public/browser/render_view_host.h" @@ -8,11 +8,10 @@ namespace brightray { -void BrowserClient::ShowDesktopNotification( +void NotificationPresenter::ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, int render_process_id, - int render_view_id, - bool worker) { + int render_view_id) { auto notification = [[NSUserNotification alloc] init]; notification.title = base::SysUTF16ToNSString(params.title); notification.informativeText = base::SysUTF16ToNSString(params.body); From 651ab18a21d49cb4c2c50836ef0b213783ac1084 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 28 Mar 2013 18:03:58 -0400 Subject: [PATCH 0029/1195] Turn NotificationPresenter into an abstract base class This will allow us to have Mac-specific member variables without a bunch of ifdefs. --- brightray/brightray.gyp | 2 +- brightray/browser/browser_client.cc | 2 +- brightray/browser/notification_presenter.cc | 11 --------- brightray/browser/notification_presenter.h | 9 ++++---- .../browser/notification_presenter_mac.h | 23 +++++++++++++++++++ .../browser/notification_presenter_mac.mm | 14 +++++++++-- 6 files changed, 42 insertions(+), 19 deletions(-) delete mode 100644 brightray/browser/notification_presenter.cc create mode 100644 brightray/browser/notification_presenter_mac.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 052f04863cd..a00cfa0d3dc 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -42,8 +42,8 @@ 'browser/mac/bry_inspectable_web_contents_view_private.h', 'browser/network_delegate.cc', 'browser/network_delegate.h', - 'browser/notification_presenter.cc', 'browser/notification_presenter.h', + 'browser/notification_presenter_mac.h', 'browser/notification_presenter_mac.mm', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 7c6aa89381a..63fb78257bf 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -22,7 +22,7 @@ BrowserContext* BrowserClient::browser_context() { NotificationPresenter* BrowserClient::notification_presenter() { if (!notification_presenter_) - notification_presenter_.reset(new NotificationPresenter); + notification_presenter_.reset(NotificationPresenter::Create()); return notification_presenter_.get(); } diff --git a/brightray/browser/notification_presenter.cc b/brightray/browser/notification_presenter.cc deleted file mode 100644 index 152a10c3b8a..00000000000 --- a/brightray/browser/notification_presenter.cc +++ /dev/null @@ -1,11 +0,0 @@ -#include "browser/notification_presenter.h" - -namespace brightray { - -NotificationPresenter::NotificationPresenter() { -} - -NotificationPresenter::~NotificationPresenter() { -} - -} diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index 1ef7e3d5cd0..f2b6e7ea44c 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -9,13 +9,14 @@ namespace brightray { class NotificationPresenter { public: - NotificationPresenter(); - ~NotificationPresenter(); + virtual ~NotificationPresenter() {}; - void ShowNotification( + static NotificationPresenter* Create(); + + virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams&, int render_process_id, - int render_view_id); + int render_view_id) = 0; }; } diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h new file mode 100644 index 00000000000..3334c5f3c6b --- /dev/null +++ b/brightray/browser/notification_presenter_mac.h @@ -0,0 +1,23 @@ +#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ +#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ + +#import "browser/notification_presenter.h" + +#import "base/compiler_specific.h" + +namespace brightray { + +class NotificationPresenterMac : public NotificationPresenter { + public: + NotificationPresenterMac(); + ~NotificationPresenterMac(); + + virtual void ShowNotification( + const content::ShowDesktopNotificationHostMsgParams&, + int render_process_id, + int render_view_id) OVERRIDE; +}; + +} + +#endif diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index b348d0c1bc0..2b07ae90627 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -1,4 +1,4 @@ -#import "browser/notification_presenter.h" +#import "browser/notification_presenter_mac.h" #import "base/strings/sys_string_conversions.h" #import "content/public/browser/render_view_host.h" @@ -8,7 +8,17 @@ namespace brightray { -void NotificationPresenter::ShowNotification( +NotificationPresenter* NotificationPresenter::Create() { + return new NotificationPresenterMac; +} + +NotificationPresenterMac::NotificationPresenterMac() { +} + +NotificationPresenterMac::~NotificationPresenterMac() { +} + +void NotificationPresenterMac::ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, int render_process_id, int render_view_id) { From 08f393437e0d3050881144bbb8adc8a2e6bf4bc8 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 28 Mar 2013 18:08:34 -0400 Subject: [PATCH 0030/1195] Show notifications even when the app is focused It's a little icky to be taking over global state (NSUserNotificationCenter's delegate) like this, but until we have evidence that it gets in someone's way it's the pragmatic thing to do. --- brightray/browser/notification_presenter_mac.h | 7 ++++++- brightray/browser/notification_presenter_mac.mm | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index 3334c5f3c6b..77da8cf0766 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -3,7 +3,9 @@ #import "browser/notification_presenter.h" -#import "base/compiler_specific.h" +#import "base/memory/scoped_nsobject.h" + +@class BRYUserNotificationCenterDelegate; namespace brightray { @@ -16,6 +18,9 @@ class NotificationPresenterMac : public NotificationPresenter { const content::ShowDesktopNotificationHostMsgParams&, int render_process_id, int render_view_id) OVERRIDE; + + private: + scoped_nsobject delegate_; }; } diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 2b07ae90627..dc914bb9352 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -6,13 +6,18 @@ #import +@interface BRYUserNotificationCenterDelegate : NSObject +@end + namespace brightray { NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterMac; } -NotificationPresenterMac::NotificationPresenterMac() { +NotificationPresenterMac::NotificationPresenterMac() + : delegate_([[BRYUserNotificationCenterDelegate alloc] init]) { + NSUserNotificationCenter.defaultUserNotificationCenter.delegate = delegate_; } NotificationPresenterMac::~NotificationPresenterMac() { @@ -37,3 +42,12 @@ void NotificationPresenterMac::ShowNotification( } } + +@implementation BRYUserNotificationCenterDelegate + +- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification { + // Display notifications even if the app is active. + return YES; +} + +@end From e592f3ffa17be280cf8b9d9a8f5522da9eedcf62 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 29 Mar 2013 08:32:00 -0400 Subject: [PATCH 0031/1195] Add CreateUserNotification helper function --- .../browser/notification_presenter_mac.mm | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index dc914bb9352..a8e07fbfeaf 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -11,6 +11,20 @@ namespace brightray { +namespace { + +scoped_nsobject CreateUserNotification( + const content::ShowDesktopNotificationHostMsgParams& params, + int render_process_id, + int render_view_id) { + auto notification = [[NSUserNotification alloc] init]; + notification.title = base::SysUTF16ToNSString(params.title); + notification.informativeText = base::SysUTF16ToNSString(params.body); + return scoped_nsobject(notification); +} + +} + NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterMac; } @@ -27,12 +41,8 @@ void NotificationPresenterMac::ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, int render_process_id, int render_view_id) { - auto notification = [[NSUserNotification alloc] init]; - notification.title = base::SysUTF16ToNSString(params.title); - notification.informativeText = base::SysUTF16ToNSString(params.body); - + auto notification = CreateUserNotification(params, render_process_id, render_view_id); [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; - [notification release]; auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (!host) From c1463f9799f99ffc4aeebd9ca6ee173e3c2737f6 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 29 Mar 2013 08:59:21 -0400 Subject: [PATCH 0032/1195] Don't fire the `show` event until the notification is actually shown --- .../browser/notification_presenter_mac.mm | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index a8e07fbfeaf..a52da634203 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -13,6 +13,16 @@ namespace brightray { namespace { +struct NotificationID { + int render_process_id; + int render_view_id; + int notification_id; +}; + +NSString * const kRenderProcessIDKey = @"RenderProcessID"; +NSString * const kRenderViewIDKey = @"RenderViewID"; +NSString * const kNotificationIDKey = @"NotificationID"; + scoped_nsobject CreateUserNotification( const content::ShowDesktopNotificationHostMsgParams& params, int render_process_id, @@ -20,9 +30,23 @@ scoped_nsobject CreateUserNotification( auto notification = [[NSUserNotification alloc] init]; notification.title = base::SysUTF16ToNSString(params.title); notification.informativeText = base::SysUTF16ToNSString(params.body); + notification.userInfo = @{ + kRenderProcessIDKey: @(render_process_id), + kRenderViewIDKey: @(render_view_id), + kNotificationIDKey: @(params.notification_id), + }; + return scoped_nsobject(notification); } +NotificationID GetID(NSUserNotification* notification) { + NotificationID ID; + ID.render_process_id = [[notification.userInfo objectForKey:kRenderProcessIDKey] intValue]; + ID.render_view_id = [[notification.userInfo objectForKey:kRenderViewIDKey] intValue]; + ID.notification_id = [[notification.userInfo objectForKey:kNotificationIDKey] intValue]; + return ID; +} + } NotificationPresenter* NotificationPresenter::Create() { @@ -43,18 +67,22 @@ void NotificationPresenterMac::ShowNotification( int render_view_id) { auto notification = CreateUserNotification(params, render_process_id, render_view_id); [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; - - auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); - if (!host) - return; - - host->DesktopNotificationPostDisplay(params.notification_id); } } @implementation BRYUserNotificationCenterDelegate +- (void)userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification { + auto ID = brightray::GetID(notification); + + auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id); + if (!host) + return; + + host->DesktopNotificationPostDisplay(ID.notification_id); +} + - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification { // Display notifications even if the app is active. return YES; From e59c549e62929d99d7190bc04a53d7077d10ea88 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 29 Mar 2013 09:02:40 -0400 Subject: [PATCH 0033/1195] Fire a `click` event when a notification is clicked --- brightray/browser/notification_presenter_mac.mm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index a52da634203..4c27f48f015 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -83,6 +83,16 @@ void NotificationPresenterMac::ShowNotification( host->DesktopNotificationPostDisplay(ID.notification_id); } +- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification { + auto ID = brightray::GetID(notification); + + auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id); + if (!host) + return; + + host->DesktopNotificationPostClick(ID.notification_id); +} + - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification { // Display notifications even if the app is active. return YES; From dde3c3f78f27a227f46074ce065dd1d2338d612c Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 29 Mar 2013 09:23:10 -0400 Subject: [PATCH 0034/1195] Make NotificationID more useful --- .../browser/notification_presenter_mac.mm | 49 ++++++++++++------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 4c27f48f015..49a33561459 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -13,16 +13,39 @@ namespace brightray { namespace { +NSString * const kRenderProcessIDKey = @"RenderProcessID"; +NSString * const kRenderViewIDKey = @"RenderViewID"; +NSString * const kNotificationIDKey = @"NotificationID"; + struct NotificationID { + NotificationID( + const content::ShowDesktopNotificationHostMsgParams& params, + int render_process_id, + int render_view_id) + : render_process_id(render_process_id), + render_view_id(render_view_id), + notification_id(params.notification_id) { + } + + NotificationID(NSUserNotification* notification) + : render_process_id([[notification.userInfo objectForKey:kRenderProcessIDKey] intValue]), + render_view_id([[notification.userInfo objectForKey:kRenderViewIDKey] intValue]), + notification_id([[notification.userInfo objectForKey:kNotificationIDKey] intValue]) { + } + + NSDictionary* GetUserInfo() { + return @{ + kRenderProcessIDKey: @(render_process_id), + kRenderViewIDKey: @(render_view_id), + kNotificationIDKey: @(notification_id), + }; + } + int render_process_id; int render_view_id; int notification_id; }; -NSString * const kRenderProcessIDKey = @"RenderProcessID"; -NSString * const kRenderViewIDKey = @"RenderViewID"; -NSString * const kNotificationIDKey = @"NotificationID"; - scoped_nsobject CreateUserNotification( const content::ShowDesktopNotificationHostMsgParams& params, int render_process_id, @@ -30,23 +53,11 @@ scoped_nsobject CreateUserNotification( auto notification = [[NSUserNotification alloc] init]; notification.title = base::SysUTF16ToNSString(params.title); notification.informativeText = base::SysUTF16ToNSString(params.body); - notification.userInfo = @{ - kRenderProcessIDKey: @(render_process_id), - kRenderViewIDKey: @(render_view_id), - kNotificationIDKey: @(params.notification_id), - }; + notification.userInfo = NotificationID(params, render_process_id, render_view_id).GetUserInfo(); return scoped_nsobject(notification); } -NotificationID GetID(NSUserNotification* notification) { - NotificationID ID; - ID.render_process_id = [[notification.userInfo objectForKey:kRenderProcessIDKey] intValue]; - ID.render_view_id = [[notification.userInfo objectForKey:kRenderViewIDKey] intValue]; - ID.notification_id = [[notification.userInfo objectForKey:kNotificationIDKey] intValue]; - return ID; -} - } NotificationPresenter* NotificationPresenter::Create() { @@ -74,7 +85,7 @@ void NotificationPresenterMac::ShowNotification( @implementation BRYUserNotificationCenterDelegate - (void)userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification { - auto ID = brightray::GetID(notification); + brightray::NotificationID ID(notification); auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id); if (!host) @@ -84,7 +95,7 @@ void NotificationPresenterMac::ShowNotification( } - (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification { - auto ID = brightray::GetID(notification); + brightray::NotificationID ID(notification); auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id); if (!host) From 080d9f59e98a40154117371addf4e111297a1462 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 29 Mar 2013 09:36:07 -0400 Subject: [PATCH 0035/1195] Implement Notification.close() --- brightray/browser/browser_client.cc | 7 +++ brightray/browser/browser_client.h | 4 ++ brightray/browser/notification_presenter.h | 4 ++ .../browser/notification_presenter_mac.h | 11 +++++ .../browser/notification_presenter_mac.mm | 48 +++++++++++++++++-- 5 files changed, 70 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 63fb78257bf..2d02e826dda 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -48,4 +48,11 @@ void BrowserClient::ShowDesktopNotification( notification_presenter()->ShowNotification(params, render_process_id, render_view_id); } +void BrowserClient::CancelDesktopNotification( + int render_process_id, + int render_view_id, + int notification_id) { + notification_presenter()->CancelNotification(render_process_id, render_view_id, notification_id); +} + } diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 38983dd47fb..33fea3dea32 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -35,6 +35,10 @@ private: int render_process_id, int render_view_id, bool worker) OVERRIDE; + virtual void CancelDesktopNotification( + int render_process_id, + int render_view_id, + int notification_id) OVERRIDE; BrowserMainParts* browser_main_parts_; scoped_ptr notification_presenter_; diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index f2b6e7ea44c..a106edab208 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -17,6 +17,10 @@ class NotificationPresenter { const content::ShowDesktopNotificationHostMsgParams&, int render_process_id, int render_view_id) = 0; + virtual void CancelNotification( + int render_process_id, + int render_view_id, + int notification_id) = 0; }; } diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index 77da8cf0766..5cd2c87e40a 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -1,9 +1,15 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Adam Roben . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + #ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ #import "browser/notification_presenter.h" #import "base/memory/scoped_nsobject.h" +#import @class BRYUserNotificationCenterDelegate; @@ -18,8 +24,13 @@ class NotificationPresenterMac : public NotificationPresenter { const content::ShowDesktopNotificationHostMsgParams&, int render_process_id, int render_view_id) OVERRIDE; + virtual void CancelNotification( + int render_process_id, + int render_view_id, + int notification_id) OVERRIDE; private: + std::map> notification_map_; scoped_nsobject delegate_; }; diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 49a33561459..02ca2927fe3 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -1,5 +1,11 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Adam Roben . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + #import "browser/notification_presenter_mac.h" +#import "base/stringprintf.h" #import "base/strings/sys_string_conversions.h" #import "content/public/browser/render_view_host.h" #import "content/public/common/show_desktop_notification_params.h" @@ -19,12 +25,12 @@ NSString * const kNotificationIDKey = @"NotificationID"; struct NotificationID { NotificationID( - const content::ShowDesktopNotificationHostMsgParams& params, int render_process_id, - int render_view_id) + int render_view_id, + int notification_id) : render_process_id(render_process_id), render_view_id(render_view_id), - notification_id(params.notification_id) { + notification_id(notification_id) { } NotificationID(NSUserNotification* notification) @@ -33,6 +39,10 @@ struct NotificationID { notification_id([[notification.userInfo objectForKey:kNotificationIDKey] intValue]) { } + std::string GetID() { + return base::StringPrintf("%d:%d:%d", render_process_id, render_view_id, notification_id); + } + NSDictionary* GetUserInfo() { return @{ kRenderProcessIDKey: @(render_process_id), @@ -53,7 +63,7 @@ scoped_nsobject CreateUserNotification( auto notification = [[NSUserNotification alloc] init]; notification.title = base::SysUTF16ToNSString(params.title); notification.informativeText = base::SysUTF16ToNSString(params.body); - notification.userInfo = NotificationID(params, render_process_id, render_view_id).GetUserInfo(); + notification.userInfo = NotificationID(render_process_id, render_view_id, params.notification_id).GetUserInfo(); return scoped_nsobject(notification); } @@ -77,9 +87,39 @@ void NotificationPresenterMac::ShowNotification( int render_process_id, int render_view_id) { auto notification = CreateUserNotification(params, render_process_id, render_view_id); + notification_map_.insert(std::make_pair(NotificationID(notification).GetID(), notification)); [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; } +void NotificationPresenterMac::CancelNotification( + int render_process_id, + int render_view_id, + int notification_id) { + auto found = notification_map_.find(NotificationID(render_process_id, render_view_id, notification_id).GetID()); + if (found == notification_map_.end()) + return; + + auto notification = found->second; + + notification_map_.erase(found); + + // Notifications in -deliveredNotifications aren't the same objects we passed to + // -deliverNotification:, but they will respond YES to -isEqual:. + auto center = NSUserNotificationCenter.defaultUserNotificationCenter; + for (NSUserNotification* deliveredNotification in center.deliveredNotifications) { + if (![notification isEqual:deliveredNotification]) + continue; + [center removeDeliveredNotification:deliveredNotification]; + } + + NotificationID ID(notification); + auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id); + if (!host) + return; + + host->DesktopNotificationPostClose(ID.notification_id, false); +} + } @implementation BRYUserNotificationCenterDelegate From 3cef0dd98c783729cea3ec58b0795eb4f24e4f03 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 1 Apr 2013 20:10:00 -0400 Subject: [PATCH 0036/1195] Allow embedders to provide their own BrowserContext implementation --- brightray/browser/browser_main_parts.cc | 6 +++++- brightray/browser/browser_main_parts.h | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index fcfb82af6d8..cb58d93be30 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -21,7 +21,7 @@ BrowserMainParts::~BrowserMainParts() { } void BrowserMainParts::PreMainMessageLoopRun() { - browser_context_.reset(new BrowserContext); + browser_context_.reset(CreateBrowserContext()); // These two objects are owned by devtools_http_handler_. auto delegate = new DevToolsDelegate; @@ -30,4 +30,8 @@ void BrowserMainParts::PreMainMessageLoopRun() { devtools_http_handler_ = content::DevToolsHttpHandler::Start(factory, std::string(), delegate); } +BrowserContext* BrowserMainParts::CreateBrowserContext() { + return new BrowserContext; +} + } diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 0268dc04022..7120c619b0b 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -26,6 +26,10 @@ public: content::DevToolsHttpHandler* devtools_http_handler() { return devtools_http_handler_; } protected: + // Subclasses should override this to provide their own BrowserContxt implementation. The caller + // takes ownership of the returned object. + virtual BrowserContext* CreateBrowserContext(); + #if defined(OS_MACOSX) virtual void PreMainMessageLoopStart() OVERRIDE; #endif From d2c04779e4f19a92c5bb733037a473eb9b1ead01 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 8 Apr 2013 12:41:30 -0400 Subject: [PATCH 0037/1195] Include the application's version number in the user agent string --- brightray/brightray.gyp | 4 ++-- brightray/browser/browser_context.cc | 2 +- brightray/common/application_info.h | 13 ++++++++++++ brightray/common/application_info_mac.mm | 26 ++++++++++++++++++++++++ brightray/common/application_name.h | 12 ----------- brightray/common/application_name_mac.mm | 12 ----------- brightray/common/content_client.cc | 9 ++++++-- brightray/common/content_client.h | 1 + brightray/common/main_delegate_mac.mm | 2 +- 9 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 brightray/common/application_info.h create mode 100644 brightray/common/application_info_mac.mm delete mode 100644 brightray/common/application_name.h delete mode 100644 brightray/common/application_name_mac.mm diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index a00cfa0d3dc..aefa2305f83 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -47,8 +47,8 @@ 'browser/notification_presenter_mac.mm', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', - 'common/application_name.h', - 'common/application_name_mac.mm', + 'common/application_info.h', + 'common/application_info_mac.mm', 'common/content_client.cc', 'common/content_client.h', 'common/mac/foundation_util.h', diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 0b6aaee7011..3f247bd5105 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -4,7 +4,7 @@ #include "browser_context.h" -#include "common/application_name.h" +#include "common/application_info.h" #include "base/files/file_path.h" #include "base/path_service.h" diff --git a/brightray/common/application_info.h b/brightray/common/application_info.h new file mode 100644 index 00000000000..25b02c0d239 --- /dev/null +++ b/brightray/common/application_info.h @@ -0,0 +1,13 @@ +#ifndef BRIGHTRAY_COMMON_APPLICATION_INFO_H_ +#define BRIGHTRAY_COMMON_APPLICATION_INFO_H_ + +#include + +namespace brightray { + +std::string GetApplicationName(); +std::string GetApplicationVersion(); + +} + +#endif diff --git a/brightray/common/application_info_mac.mm b/brightray/common/application_info_mac.mm new file mode 100644 index 00000000000..be5568a987c --- /dev/null +++ b/brightray/common/application_info_mac.mm @@ -0,0 +1,26 @@ +#import "common/application_info.h" + +#import "common/mac/foundation_util.h" +#import "common/mac/main_application_bundle.h" + +#import "base/sys_string_conversions.h" + +namespace brightray { + +namespace { + +std::string ApplicationInfoDictionaryValue(CFStringRef key) { + return base::SysNSStringToUTF8([MainApplicationBundle().infoDictionary objectForKey:base::mac::CFToNSCast(key)]); +} + +} + +std::string GetApplicationName() { + return ApplicationInfoDictionaryValue(kCFBundleNameKey); +} + +std::string GetApplicationVersion() { + return ApplicationInfoDictionaryValue(kCFBundleVersionKey); +} + +} diff --git a/brightray/common/application_name.h b/brightray/common/application_name.h deleted file mode 100644 index c00ea71aa02..00000000000 --- a/brightray/common/application_name.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef BRIGHTRAY_COMMON_APPLICATION_NAME_H_ -#define BRIGHTRAY_COMMON_APPLICATION_NAME_H_ - -#include - -namespace brightray { - -std::string GetApplicationName(); - -} - -#endif diff --git a/brightray/common/application_name_mac.mm b/brightray/common/application_name_mac.mm deleted file mode 100644 index 6a781189c3d..00000000000 --- a/brightray/common/application_name_mac.mm +++ /dev/null @@ -1,12 +0,0 @@ -#import "common/application_name.h" - -#import "common/mac/foundation_util.h" -#import "common/mac/main_application_bundle.h" - -namespace brightray { - -std::string GetApplicationName() { - return [[MainApplicationBundle().infoDictionary objectForKey:base::mac::CFToNSCast(kCFBundleNameKey)] UTF8String]; -} - -} diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index e824ee916bb..5e9877da5aa 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -4,8 +4,9 @@ #include "common/content_client.h" -#include "common/application_name.h" +#include "common/application_info.h" +#include "base/stringprintf.h" #include "ui/base/resource/resource_bundle.h" #include "webkit/user_agent/user_agent_util.h" @@ -17,8 +18,12 @@ ContentClient::ContentClient() { ContentClient::~ContentClient() { } +std::string ContentClient::GetProduct() const { + return base::StringPrintf("%s/%s", GetApplicationName().c_str(), GetApplicationVersion().c_str()); +} + std::string ContentClient::GetUserAgent() const { - return webkit_glue::BuildUserAgentFromProduct(GetApplicationName()); + return webkit_glue::BuildUserAgentFromProduct(GetProduct()); } base::StringPiece ContentClient::GetDataResource(int resource_id, ui::ScaleFactor scale_factor) const { diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index d322b03526c..b58dfe70f80 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -16,6 +16,7 @@ public: ~ContentClient(); private: + virtual std::string GetProduct() const OVERRIDE; virtual std::string GetUserAgent() const OVERRIDE; virtual base::StringPiece GetDataResource(int resource_id, ui::ScaleFactor) const OVERRIDE; diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index e676402f889..18647a05dab 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -5,7 +5,7 @@ #import "main_delegate.h" -#include "common/application_name.h" +#include "common/application_info.h" #include "common/mac/foundation_util.h" #include "common/mac/main_application_bundle.h" From 5db043f7d430f573ff61c84ebbb25d9caa8687f7 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 8 Apr 2013 12:42:37 -0400 Subject: [PATCH 0038/1195] Strip whitespace from the application name in the user agent Having whitespace in the application name makes the user agent hard to parse. --- brightray/common/content_client.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index 5e9877da5aa..e976cdb03ad 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -7,6 +7,7 @@ #include "common/application_info.h" #include "base/stringprintf.h" +#include "base/string_util.h" #include "ui/base/resource/resource_bundle.h" #include "webkit/user_agent/user_agent_util.h" @@ -19,7 +20,9 @@ ContentClient::~ContentClient() { } std::string ContentClient::GetProduct() const { - return base::StringPrintf("%s/%s", GetApplicationName().c_str(), GetApplicationVersion().c_str()); + auto name = GetApplicationName(); + RemoveChars(name, kWhitespaceASCII, &name); + return base::StringPrintf("%s/%s", name.c_str(), GetApplicationVersion().c_str()); } std::string ContentClient::GetUserAgent() const { From a2a2cd19361e313a746a2eb79fc051f597dc2e00 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 29 Mar 2013 17:28:49 -0400 Subject: [PATCH 0039/1195] Add preferences support for embedding applications Applications can use brightray::BrowserContext::prefs to get access to preferences that are persisted between launches. brightray::BrowserContext::RegisterPrefs must be used to register preferences before they're accessed. Updated libchromiumcontent to pull in preferences support. * vendor/libchromiumcontent 3944c1c...b6a0d85 (2): > Actually compile the base/prefs code > Export symbols from base/prefs --- brightray/browser/browser_context.cc | 13 +++++++++++++ brightray/browser/browser_context.h | 10 ++++++++++ brightray/vendor/libchromiumcontent | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 3f247bd5105..4a2d0cb49e2 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -8,6 +8,10 @@ #include "base/files/file_path.h" #include "base/path_service.h" +#include "base/prefs/json_pref_store.h" +#include "base/prefs/pref_registry_simple.h" +#include "base/prefs/pref_service.h" +#include "base/prefs/pref_service_builder.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" @@ -36,6 +40,15 @@ private: }; BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { + auto prefs_path = GetPath().Append("Preferences"); + PrefServiceBuilder builder; + builder.WithUserFilePrefs(prefs_path, + JsonPrefStore::GetTaskRunnerForFile(prefs_path, content::BrowserThread::GetBlockingPool())); + + auto registry = make_scoped_refptr(new PrefRegistrySimple); + RegisterPrefs(registry); + + prefs_.reset(builder.Create(registry)); } BrowserContext::~BrowserContext() { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index a57023af1b3..950a4a28d06 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -8,6 +8,9 @@ #include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" +class PrefRegistrySimple; +class PrefService; + namespace brightray { class URLRequestContextGetter; @@ -19,6 +22,12 @@ public: net::URLRequestContextGetter* CreateRequestContext(content::ProtocolHandlerMap*); + PrefService* prefs() { return prefs_.get(); } + +protected: + // Subclasses should override this to register custom preferences. + virtual void RegisterPrefs(PrefRegistrySimple*) {} + private: class ResourceContext; @@ -37,6 +46,7 @@ private: scoped_ptr resource_context_; scoped_refptr url_request_getter_; + scoped_ptr prefs_; DISALLOW_COPY_AND_ASSIGN(BrowserContext); }; diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 3944c1c0055..b6a0d851db2 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 3944c1c0055d1de3d8f0647087acc0f6244113d6 +Subproject commit b6a0d851db2e4f1bf181e05d3e9c2d8fe6ef7f0c From 3c513d6ae847a5c820d18fbae8b0331e95f98838 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 8 Apr 2013 13:53:53 -0400 Subject: [PATCH 0040/1195] Remember where the dev tools were docked between launches --- brightray/browser/browser_context.cc | 6 +++ brightray/browser/browser_context.h | 2 + .../browser/inspectable_web_contents_impl.cc | 37 ++++++++++++++++++- .../browser/inspectable_web_contents_impl.h | 16 ++++++++ .../mac/bry_inspectable_web_contents_view.mm | 5 ++- 5 files changed, 62 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 4a2d0cb49e2..2b214476198 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -4,6 +4,7 @@ #include "browser_context.h" +#include "browser/inspectable_web_contents_impl.h" #include "common/application_info.h" #include "base/files/file_path.h" @@ -46,6 +47,7 @@ BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { JsonPrefStore::GetTaskRunnerForFile(prefs_path, content::BrowserThread::GetBlockingPool())); auto registry = make_scoped_refptr(new PrefRegistrySimple); + RegisterInternalPrefs(registry); RegisterPrefs(registry); prefs_.reset(builder.Create(registry)); @@ -54,6 +56,10 @@ BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { BrowserContext::~BrowserContext() { } +void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { + InspectableWebContentsImpl::RegisterPrefs(registry); +} + net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::ProtocolHandlerMap* protocol_handlers) { DCHECK(!url_request_getter_); url_request_getter_ = new URLRequestContextGetter( diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 950a4a28d06..47feccd042c 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -31,6 +31,8 @@ protected: private: class ResourceContext; + void RegisterInternalPrefs(PrefRegistrySimple*); + virtual base::FilePath GetPath() OVERRIDE; virtual bool IsOffTheRecord() const OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 1c91fa7ff96..144a2b58724 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -6,9 +6,12 @@ #include "browser/inspectable_web_contents_impl.h" #include "browser/browser_client.h" +#include "browser/browser_context.h" #include "browser/browser_main_parts.h" #include "browser/inspectable_web_contents_view.h" +#include "base/prefs/pref_registry_simple.h" +#include "base/prefs/pref_service.h" #include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "content/public/browser/devtools_agent_host.h" @@ -20,11 +23,24 @@ namespace brightray { +namespace { + +const char kDockSidePref[] = "brightray.devtools.dockside"; + +} + // Implemented separately on each platform. InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl*); +void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { + registry->RegisterStringPref(kDockSidePref, "bottom"); +} + InspectableWebContentsImpl::InspectableWebContentsImpl(const content::WebContents::CreateParams& create_params) : web_contents_(content::WebContents::Create(create_params)) { + auto context = static_cast(web_contents_->GetBrowserContext()); + dock_side_ = context->prefs()->GetString(kDockSidePref); + view_.reset(CreateInspectableContentsView(this)); } @@ -54,9 +70,15 @@ void InspectableWebContentsImpl::ShowDevTools() { devtools_web_contents_->GetController().LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); } + view_->SetDockSide(dock_side_); view_->ShowDevTools(); } +void InspectableWebContentsImpl::UpdateFrontendDockSide() { + auto javascript = base::StringPrintf("InspectorFrontendAPI.setDockSide(\"%s\")", dock_side_.c_str()); + devtools_web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(javascript)); +} + void InspectableWebContentsImpl::ActivateWindow() { } @@ -76,8 +98,12 @@ void InspectableWebContentsImpl::SetDockSide(const std::string& side) { if (!view_->SetDockSide(side)) return; - auto javascript = base::StringPrintf("InspectorFrontendAPI.setDockSide(\"%s\")", side.c_str()); - devtools_web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(javascript)); + dock_side_ = side; + + auto context = static_cast(web_contents_->GetBrowserContext()); + context->prefs()->SetString(kDockSidePref, side); + + UpdateFrontendDockSide(); } void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) { @@ -106,6 +132,13 @@ void InspectableWebContentsImpl::RenderViewCreated(content::RenderViewHost* rend content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get()); } +void InspectableWebContentsImpl::DidFinishLoad(int64, const GURL&, bool is_main_frame, content::RenderViewHost*) { + if (!is_main_frame) + return; + + UpdateFrontendDockSide(); +} + void InspectableWebContentsImpl::WebContentsDestroyed(content::WebContents*) { content::DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get()); Observe(nullptr); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index aa6cf1754ff..ddddc7e1f0a 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -1,3 +1,8 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Adam Roben . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + #ifndef BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_IMPL_H_ #define BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_IMPL_H_ @@ -7,6 +12,8 @@ #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" +class PrefRegistrySimple; + namespace content { class DevToolsAgentHost; class DevToolsClientHost; @@ -22,6 +29,8 @@ class InspectableWebContentsImpl : content::WebContentsObserver, content::WebContentsDelegate { public: + static void RegisterPrefs(PrefRegistrySimple*); + InspectableWebContentsImpl(const content::WebContents::CreateParams&); virtual ~InspectableWebContentsImpl() OVERRIDE; @@ -33,6 +42,8 @@ public: content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); } private: + void UpdateFrontendDockSide(); + // content::DevToolsFrontendHostDelegate virtual void ActivateWindow() OVERRIDE; @@ -54,6 +65,10 @@ private: // content::WebContentsObserver virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE; + virtual void DidFinishLoad(int64 frame_id, + const GURL& validated_url, + bool is_main_frame, + content::RenderViewHost*) OVERRIDE; virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE; // content::WebContentsDelegate @@ -65,6 +80,7 @@ private: scoped_ptr view_; scoped_refptr agent_host_; scoped_ptr frontend_host_; + std::string dock_side_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); }; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index b6c377dcc4c..81f7f3921d3 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -13,6 +13,7 @@ using namespace brightray; InspectableWebContentsViewMac *inspectableWebContentsView; NSSplitView *splitView; NSWindow *window; + BOOL visible; } @end @@ -58,9 +59,9 @@ NSRect devtoolsWindowFrame(NSView *referenceView) { } - (void)setDevToolsVisible:(BOOL)visible { - BOOL wasVisible = _private->splitView.subviews.count == 2; - if (wasVisible == visible) + if (_private->visible == visible) return; + _private->visible = visible; auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); From d9df9bcf47e7e1c92a51dc8b8adc2324ac5d306b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 9 Apr 2013 15:11:16 -0400 Subject: [PATCH 0041/1195] Send focus/blur events when an InspectableWebContents's window gains/loses focus We listen for key window chages and inform content::RenderWidgetHostView as appropriate. --- .../mac/bry_inspectable_web_contents_view.mm | 66 +++++++++++++++++-- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 81f7f3921d3..460cb830b1e 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -4,6 +4,7 @@ #import "browser/inspectable_web_contents_view_mac.h" #import "browser/mac/bry_inspectable_web_contents_view_private.h" +#import "content/public/browser/render_widget_host_view.h" #import "content/public/browser/web_contents_view.h" using namespace brightray; @@ -24,6 +25,14 @@ NSRect devtoolsWindowFrame(NSView *referenceView) { return NSInsetRect(screenFrame, NSWidth(screenFrame) / 6, NSHeight(screenFrame) / 6); } +void SetActive(content::WebContents* web_contents, bool active) { + auto render_widget_host_view = web_contents->GetRenderWidgetHostView(); + if (!render_widget_host_view) + return; + + render_widget_host_view->SetActive(active); +} + } @implementation BRYInspectableWebContentsView @@ -63,10 +72,7 @@ NSRect devtoolsWindowFrame(NSView *referenceView) { return; _private->visible = visible; - auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); - auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); - - if (_private->window && devToolsView.window == _private->window) { + if ([self isDocked]) { if (visible) { [_private->window makeKeyAndOrderFront:nil]; } else { @@ -75,6 +81,9 @@ NSRect devtoolsWindowFrame(NSView *referenceView) { return; } + auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); + auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); + if (visible) { auto inspectedView = _private->inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView(); CGRect frame = NSRectToCGRect(inspectedView.frame); @@ -143,6 +152,47 @@ NSRect devtoolsWindowFrame(NSView *referenceView) { [_private->splitView adjustSubviews]; } +- (BOOL)isDocked { + auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); + if (!devToolsWebContents) + return NO; + auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); + + return _private->window && devToolsView.window == _private->window; +} + +- (void)window:(NSWindow *)window didBecomeActive:(BOOL)active { + auto inspectable_contents = _private->inspectableWebContentsView->inspectable_web_contents(); + + // Changes to the active state of the window we create only affects the dev tools contents. + if (window == _private->window) { + SetActive(inspectable_contents->devtools_web_contents(), active); + return; + } + + // Changes the window that hosts us always affect our main web contents. If the dev tools are also + // hosted in this window, they are affected too. + SetActive(inspectable_contents->GetWebContents(), active); + if (![self isDocked]) + return; + SetActive(inspectable_contents->devtools_web_contents(), active); +} + +#pragma mark - NSView + +- (void)viewWillMoveToWindow:(NSWindow *)newWindow { + if (self.window) { + [NSNotificationCenter.defaultCenter removeObserver:self name:NSWindowDidBecomeKeyNotification object:self.window]; + [NSNotificationCenter.defaultCenter removeObserver:self name:NSWindowDidResignKeyNotification object:self.window]; + } + + if (!newWindow) + return; + + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:newWindow]; + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:newWindow]; +} + #pragma mark - NSWindowDelegate - (BOOL)windowShouldClose:(id)sender { @@ -150,6 +200,14 @@ NSRect devtoolsWindowFrame(NSView *referenceView) { return NO; } +- (void)windowDidBecomeKey:(NSNotification *)notification { + [self window:notification.object didBecomeActive:YES]; +} + +- (void)windowDidResignKey:(NSNotification *)notification { + [self window:notification.object didBecomeActive:NO]; +} + @end @implementation BRYInspectableWebContentsViewPrivate From 0b5ab8e43dc07f2bc72ec5c37ea19d4c9a9be423 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 16 Apr 2013 21:06:07 -0400 Subject: [PATCH 0042/1195] Size dev tools correctly when starting out docked to the right --- .../browser/mac/bry_inspectable_web_contents_view.mm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 460cb830b1e..09b5c863b02 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -89,7 +89,16 @@ void SetActive(content::WebContents* web_contents, bool active) { CGRect frame = NSRectToCGRect(inspectedView.frame); CGRect inspectedViewFrame; CGRect devToolsFrame; - CGRectDivide(frame, &inspectedViewFrame, &devToolsFrame, CGRectGetHeight(frame) * 2 / 3, CGRectMaxYEdge); + CGFloat amount; + CGRectEdge edge; + if ([_private->splitView isVertical]) { + amount = CGRectGetWidth(frame) * 2 / 3; + edge = CGRectMaxXEdge; + } else { + amount = CGRectGetHeight(frame) * 2 / 3; + edge = CGRectMaxYEdge; + } + CGRectDivide(frame, &inspectedViewFrame, &devToolsFrame, amount, edge); inspectedView.frame = NSRectFromCGRect(inspectedViewFrame); devToolsView.frame = NSRectFromCGRect(devToolsFrame); From 80cb76355c8f9940ba7fb03e15063f3c3e24c904 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 17 Apr 2013 23:27:53 -0400 Subject: [PATCH 0043/1195] Update to latest libchromiumcontent * vendor/libchromiumcontent b6a0d85...0d607ee (3): > Stop trying to compile SQLitePersistentCookieStore separately > Update to latest Chromium trunk revision > Merge pull request #4 from aroben/atom --- brightray/browser/browser_client.cc | 12 ++++++++++++ brightray/browser/browser_client.h | 2 ++ brightray/browser/browser_main_parts.cc | 2 +- brightray/browser/devtools_delegate.cc | 6 ++++++ brightray/browser/devtools_delegate.h | 3 +++ .../browser/inspectable_web_contents_impl.cc | 3 +-- brightray/browser/url_request_context_getter.cc | 17 +++++++---------- brightray/browser/url_request_context_getter.h | 10 ++++++---- brightray/common/application_info_mac.mm | 2 +- brightray/vendor/libchromiumcontent | 2 +- 10 files changed, 40 insertions(+), 19 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 2d02e826dda..4de5d7c1ce0 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -10,7 +10,19 @@ namespace brightray { +namespace { + +BrowserClient* g_browser_client; + +} + +BrowserClient* BrowserClient::Get() { + return g_browser_client; +} + BrowserClient::BrowserClient() { + DCHECK(!g_browser_client); + g_browser_client = this; } BrowserClient::~BrowserClient() { diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 33fea3dea32..9a4f3a3bb52 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -15,6 +15,8 @@ class NotificationPresenter; class BrowserClient : public content::ContentBrowserClient { public: + static BrowserClient* Get(); + BrowserClient(); ~BrowserClient(); diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index cb58d93be30..04e67f24fb1 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -8,7 +8,7 @@ #include "browser/devtools_delegate.h" #include "content/public/browser/devtools_http_handler.h" -#include "net/base/tcp_listen_socket.h" +#include "net/socket/tcp_listen_socket.h" namespace brightray { diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_delegate.cc index ed9f9a47b8a..ccbcd362aa9 100644 --- a/brightray/browser/devtools_delegate.cc +++ b/brightray/browser/devtools_delegate.cc @@ -40,4 +40,10 @@ std::string DevToolsDelegate::GetViewDescription(content::RenderViewHost*) { return std::string(); } +scoped_refptr DevToolsDelegate::CreateSocketForTethering( + net::StreamListenSocket::Delegate*, + std::string* name) { + return nullptr; +} + } diff --git a/brightray/browser/devtools_delegate.h b/brightray/browser/devtools_delegate.h index 3fb345e2ebe..12dd2087ee7 100644 --- a/brightray/browser/devtools_delegate.h +++ b/brightray/browser/devtools_delegate.h @@ -22,6 +22,9 @@ private: virtual content::RenderViewHost* CreateNewTarget() OVERRIDE; virtual TargetType GetTargetType(content::RenderViewHost*) OVERRIDE; virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE; + virtual scoped_refptr CreateSocketForTethering( + net::StreamListenSocket::Delegate*, + std::string* name) OVERRIDE; }; } diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 144a2b58724..22bddf411c4 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -64,8 +64,7 @@ void InspectableWebContentsImpl::ShowDevTools() { agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_->GetRenderViewHost()); frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(devtools_web_contents_.get(), this)); - auto client = static_cast(content::GetContentClient()->browser()); - auto handler = client->browser_main_parts()->devtools_http_handler(); + auto handler = BrowserClient::Get()->browser_main_parts()->devtools_http_handler(); auto url = handler->GetFrontendURL(nullptr); devtools_web_contents_->GetController().LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); } diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index cfaa9a1a194..58a251c239e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -7,10 +7,10 @@ #include "network_delegate.h" #include "base/string_util.h" #include "base/threading/worker_pool.h" -#include "chrome/browser/net/sqlite_persistent_cookie_store.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/cookie_store_factory.h" #include "content/public/common/url_constants.h" -#include "net/base/cert_verifier.h" +#include "net/cert/cert_verifier.h" #include "net/cookies/cookie_monster.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_cache.h" @@ -59,14 +59,11 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() url_request_context_->set_network_delegate(network_delegate_.get()); storage_.reset( new net::URLRequestContextStorage(url_request_context_.get())); - storage_->set_cookie_store(new net::CookieMonster( - new SQLitePersistentCookieStore( - base_path_.Append(FILE_PATH_LITERAL("Cookies")), - content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::IO), - content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::DB), - false, - nullptr), - NULL)); + storage_->set_cookie_store(content::CreatePersistentCookieStore( + base_path_.Append(FILE_PATH_LITERAL("Cookies")), + false, + nullptr, + nullptr)); storage_->set_server_bound_cert_service(new net::ServerBoundCertService( new net::DefaultServerBoundCertStore(NULL), base::WorkerPool::GetTaskRunner(true))); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index cb3c4edcb22..026778e4dc5 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -10,7 +10,9 @@ #include "content/public/browser/content_browser_client.h" #include "net/url_request/url_request_context_getter.h" +namespace base { class MessageLoop; +} namespace net { class HostResolver; @@ -25,8 +27,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { public: URLRequestContextGetter( const base::FilePath& base_path, - MessageLoop* io_loop, - MessageLoop* file_loop, + base::MessageLoop* io_loop, + base::MessageLoop* file_loop, content::ProtocolHandlerMap*); virtual ~URLRequestContextGetter(); @@ -37,8 +39,8 @@ private: virtual scoped_refptr GetNetworkTaskRunner() const OVERRIDE; base::FilePath base_path_; - MessageLoop* io_loop_; - MessageLoop* file_loop_; + base::MessageLoop* io_loop_; + base::MessageLoop* file_loop_; scoped_ptr proxy_config_service_; scoped_ptr network_delegate_; diff --git a/brightray/common/application_info_mac.mm b/brightray/common/application_info_mac.mm index be5568a987c..c6df34e5582 100644 --- a/brightray/common/application_info_mac.mm +++ b/brightray/common/application_info_mac.mm @@ -3,7 +3,7 @@ #import "common/mac/foundation_util.h" #import "common/mac/main_application_bundle.h" -#import "base/sys_string_conversions.h" +#import "base/strings/sys_string_conversions.h" namespace brightray { diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index b6a0d851db2..0d607ee56be 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit b6a0d851db2e4f1bf181e05d3e9c2d8fe6ef7f0c +Subproject commit 0d607ee56be77990ba3a929aa4016c1633bad208 From 082aa618700a85cb551ac26a51343e1e485a45cc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 20 Apr 2013 13:24:45 +0800 Subject: [PATCH 0044/1195] InspectableWebContents should be able to accept existing WebContents. --- brightray/browser/inspectable_web_contents.cc | 6 +++++- brightray/browser/inspectable_web_contents.h | 1 + brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- brightray/browser/inspectable_web_contents_impl.h | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.cc b/brightray/browser/inspectable_web_contents.cc index 64f840e77fe..a1e67adf0ab 100644 --- a/brightray/browser/inspectable_web_contents.cc +++ b/brightray/browser/inspectable_web_contents.cc @@ -5,7 +5,11 @@ namespace brightray { InspectableWebContents* InspectableWebContents::Create(const content::WebContents::CreateParams& create_params) { - return new InspectableWebContentsImpl(create_params); + return new InspectableWebContentsImpl(content::WebContents::Create(create_params)); +} + +InspectableWebContents* InspectableWebContents::Create(content::WebContents* web_contents) { + return new InspectableWebContentsImpl(web_contents); } } diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index f515d062543..70b860cc744 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -10,6 +10,7 @@ class InspectableWebContentsView; class InspectableWebContents { public: static InspectableWebContents* Create(const content::WebContents::CreateParams&); + static InspectableWebContents* Create(content::WebContents*); virtual ~InspectableWebContents() {} virtual InspectableWebContentsView* GetView() const = 0; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 22bddf411c4..7f694ad54ff 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -36,8 +36,8 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { registry->RegisterStringPref(kDockSidePref, "bottom"); } -InspectableWebContentsImpl::InspectableWebContentsImpl(const content::WebContents::CreateParams& create_params) - : web_contents_(content::WebContents::Create(create_params)) { +InspectableWebContentsImpl::InspectableWebContentsImpl(content::WebContents* web_contents) + : web_contents_(web_contents) { auto context = static_cast(web_contents_->GetBrowserContext()); dock_side_ = context->prefs()->GetString(kDockSidePref); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index ddddc7e1f0a..7a9bcd4eedc 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -31,7 +31,7 @@ class InspectableWebContentsImpl : public: static void RegisterPrefs(PrefRegistrySimple*); - InspectableWebContentsImpl(const content::WebContents::CreateParams&); + InspectableWebContentsImpl(content::WebContents*); virtual ~InspectableWebContentsImpl() OVERRIDE; virtual InspectableWebContentsView* GetView() const OVERRIDE; From a5e1c46674eda02ec54765965544731a9a17af1a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 22 Apr 2013 20:41:58 +0800 Subject: [PATCH 0045/1195] :lipstick: --- brightray/browser/inspectable_web_contents.cc | 2 +- brightray/browser/inspectable_web_contents.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents.cc b/brightray/browser/inspectable_web_contents.cc index a1e67adf0ab..ca3bded4a48 100644 --- a/brightray/browser/inspectable_web_contents.cc +++ b/brightray/browser/inspectable_web_contents.cc @@ -5,7 +5,7 @@ namespace brightray { InspectableWebContents* InspectableWebContents::Create(const content::WebContents::CreateParams& create_params) { - return new InspectableWebContentsImpl(content::WebContents::Create(create_params)); + return Create(content::WebContents::Create(create_params)); } InspectableWebContents* InspectableWebContents::Create(content::WebContents* web_contents) { diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 70b860cc744..0a585146866 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -10,7 +10,10 @@ class InspectableWebContentsView; class InspectableWebContents { public: static InspectableWebContents* Create(const content::WebContents::CreateParams&); + + // The returned InspectableWebContents takes ownership of the passed-in WebContents. static InspectableWebContents* Create(content::WebContents*); + virtual ~InspectableWebContents() {} virtual InspectableWebContentsView* GetView() const = 0; From 67081a64b0c1ec9f7920f33a5003d6a2123943f8 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 23 Apr 2013 13:27:29 -0400 Subject: [PATCH 0046/1195] Pull in latest libchromiumcontent to get gtest * vendor/libchromiumcontent 0d607ee...4ae397b (1): > Build and distribute libgtest.a --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 0d607ee56be..4ae397b0e77 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 0d607ee56be77990ba3a929aa4016c1633bad208 +Subproject commit 4ae397b0e77d5ade62c9e963a4ce759f82edf59c From 48878af0db76979d4677eacdaa3220bf83d24324 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 23 Apr 2013 15:50:17 -0400 Subject: [PATCH 0047/1195] Let embedders add their own protocol handlers --- brightray/browser/browser_client.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 9a4f3a3bb52..cb8143b71c9 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -29,9 +29,12 @@ protected: // lifetime of the returned instance is managed by the caller. virtual BrowserMainParts* OverrideCreateBrowserMainParts(const content::MainFunctionParams&); + // Subclasses that override this (e.g., to provide their own protocol handlers) should call this + // implementation after doing their own work. + virtual net::URLRequestContextGetter* CreateRequestContext(content::BrowserContext*, content::ProtocolHandlerMap*) OVERRIDE; + private: virtual content::BrowserMainParts* CreateBrowserMainParts(const content::MainFunctionParams&) OVERRIDE; - virtual net::URLRequestContextGetter* CreateRequestContext(content::BrowserContext*, content::ProtocolHandlerMap*) OVERRIDE; virtual void ShowDesktopNotification( const content::ShowDesktopNotificationHostMsgParams&, int render_process_id, From 94d7b383c5f73d17fd19b6a18c972b06704ed05e Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 24 Apr 2013 10:54:53 -0400 Subject: [PATCH 0048/1195] Fix DCHECK() assertion in BrowserClient --- brightray/browser/browser_client.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 4de5d7c1ce0..9dc99f18a3b 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -20,7 +20,8 @@ BrowserClient* BrowserClient::Get() { return g_browser_client; } -BrowserClient::BrowserClient() { +BrowserClient::BrowserClient() + : browser_main_parts_() { DCHECK(!g_browser_client); g_browser_client = this; } From c27ac7996962f527994a1f3c904c8eb5db42ec9b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 24 Apr 2013 15:56:43 -0400 Subject: [PATCH 0049/1195] Update to latest libchromiumcontent * vendor/libchromiumcontent 4ae397b...d5cef3b (1): > Add libtest_support_chromiumcontent.a --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 4ae397b0e77..d5cef3b0fe5 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 4ae397b0e77d5ade62c9e963a4ce759f82edf59c +Subproject commit d5cef3b0fe5d3cf4360febbde1183447fc906aad From 3b879a6178ba94eed512bff6e1ddcdb211a2951d Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 24 Apr 2013 18:30:47 -0400 Subject: [PATCH 0050/1195] Allow embedders to provide their own ContentClient subclass --- brightray/common/main_delegate.cc | 8 ++++++-- brightray/common/main_delegate.h | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 13ace6f6321..7c1fa903bcb 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -12,14 +12,18 @@ namespace brightray { -MainDelegate::MainDelegate() - : content_client_(new ContentClient) { +MainDelegate::MainDelegate() { } MainDelegate::~MainDelegate() { } +scoped_ptr MainDelegate::CreateContentClient() { + return make_scoped_ptr(new ContentClient).Pass(); +} + bool MainDelegate::BasicStartupComplete(int* exit_code) { + content_client_ = CreateContentClient().Pass(); SetContentClient(content_client_.get()); return false; } diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 19d1306191c..6037ab3eaf3 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -19,6 +19,9 @@ public: ~MainDelegate(); protected: + // Subclasses can override this to provide their own ContentClient implementation. + virtual scoped_ptr CreateContentClient(); + virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; virtual void PreSandboxStartup() OVERRIDE; From 6908eecd0cb6c8274fffb0c141fa29db7eeb7a2f Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 26 Apr 2013 11:04:51 -0400 Subject: [PATCH 0051/1195] Allow embedders to specify extra .pak files --- brightray/common/main_delegate.h | 10 +++++++++- brightray/common/main_delegate_mac.mm | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 6037ab3eaf3..34ebfef9d7f 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -8,6 +8,11 @@ #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "content/public/app/content_main_delegate.h" +#include + +namespace base { +class FilePath; +} namespace brightray { @@ -22,11 +27,14 @@ protected: // Subclasses can override this to provide their own ContentClient implementation. virtual scoped_ptr CreateContentClient(); + // Subclasses can override this to provide additional .pak files to be included in the ui::ResourceBundle. + virtual void AddPakPaths(std::vector* pak_paths) {} + virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; virtual void PreSandboxStartup() OVERRIDE; private: - static void InitializeResourceBundle(); + void InitializeResourceBundle(); #if defined(OS_MACOSX) static void OverrideChildProcessPath(); static void OverrideFrameworkBundlePath(); diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index 18647a05dab..72ae553ff88 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -28,6 +28,11 @@ void MainDelegate::InitializeResourceBundle() { auto path = [base::mac::FrameworkBundle() pathForResource:@"content_shell" ofType:@"pak"]; ui::ResourceBundle::InitSharedInstanceWithPakPath(base::mac::NSStringToFilePath(path)); + + std::vector pak_paths; + AddPakPaths(&pak_paths); + for (const auto& path : pak_paths) + ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(path, ui::SCALE_FACTOR_NONE); } void MainDelegate::OverrideFrameworkBundlePath() { From 73d467d657e0009ee70287673c43b024acad454c Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 26 Apr 2013 14:13:45 -0400 Subject: [PATCH 0052/1195] Turn off C++ exceptions We weren't using them anyway, and don't intend to. This matches Chromium. --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 4245e8c6aa0..85416178df1 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -16,6 +16,7 @@ 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11', 'CLANG_CXX_LIBRARY': 'libstdc++', 'COMBINE_HIDPI_IMAGES': 'YES', + 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', 'GCC_ENABLE_CPP_RTTI': 'NO', 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', 'MACOSX_DEPLOYMENT_TARGET': '<(mac_deployment_target)', From 676e92e322fd90ee6a53b36087d08b1a265e75ef Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 26 Apr 2013 22:49:24 -0400 Subject: [PATCH 0053/1195] Fix crashes when dragging links Turns out we needed to implement ContentClient::GetNativeImageNamed, which is called to get the default drag image. --- brightray/common/content_client.cc | 6 +++++- brightray/common/content_client.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index e976cdb03ad..87cc07abfee 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -33,4 +33,8 @@ base::StringPiece ContentClient::GetDataResource(int resource_id, ui::ScaleFacto return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(resource_id, scale_factor); } -} \ No newline at end of file +gfx::Image& ContentClient::GetNativeImageNamed(int resource_id) const { + return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); +} + +} diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index b58dfe70f80..8a93771018e 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -19,6 +19,7 @@ private: virtual std::string GetProduct() const OVERRIDE; virtual std::string GetUserAgent() const OVERRIDE; virtual base::StringPiece GetDataResource(int resource_id, ui::ScaleFactor) const OVERRIDE; + virtual gfx::Image& GetNativeImageNamed(int resource_id) const OVERRIDE; DISALLOW_COPY_AND_ASSIGN(ContentClient); }; From 082f88ed3c795ad886f5a04e3ae14fe3f825ff2c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 1 May 2013 22:00:20 +0800 Subject: [PATCH 0054/1195] frontend_host_ should be destructed after devtools_web_contents_. --- brightray/browser/inspectable_web_contents_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 7a9bcd4eedc..8efde3c25d9 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -76,10 +76,10 @@ private: virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; scoped_ptr web_contents_; + scoped_ptr frontend_host_; scoped_ptr devtools_web_contents_; scoped_ptr view_; scoped_refptr agent_host_; - scoped_ptr frontend_host_; std::string dock_side_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); From 0526aa45e7f51dd4534aa57a62778d620e255455 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 13 May 2013 18:57:03 -0400 Subject: [PATCH 0055/1195] Update libchromiumcontent to get its Python scripts * vendor/libchromiumcontent 3f6f01c...588f368 (17): > Merge pull request #8 from aroben/menu-controller > Merge pull request #6 from aroben/shell_dialogs > Fix typo in script/create-dist > Merge pull request #5 from aroben/python > Add libtest_support_chromiumcontent.a > Build and distribute libgtest.a > Stop trying to compile SQLitePersistentCookieStore separately > Update to latest Chromium trunk revision > Merge pull request #4 from aroben/atom > Actually compile the base/prefs code > Export symbols from base/prefs > Compile and export SQLitePersistentCookieStore > Export webkit/plugins headers > Export skia/ext headers > Export ui/surface headers, too > Export Skia symbols from libchromiumcontent > Update to match chrome/trunk --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index d5cef3b0fe5..588f36848bc 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit d5cef3b0fe5d3cf4360febbde1183447fc906aad +Subproject commit 588f36848bced9ff4f780d26d070a53443a5f230 From c29074ff943be188b8789537d9c02acb4460ea92 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 13 May 2013 18:53:23 -0400 Subject: [PATCH 0056/1195] Rewrite script/boostrap in Python This is the first step toward supporting Windows. --- brightray/script/bootstrap | 64 +++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index c5ca741a412..57e28b33997 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -1,26 +1,52 @@ -#!/bin/sh -#/ Usage: bootstrap https://base.url.com/from/libchromiumcontent/script/upload -#/ Bootstrap this project. +#!/usr/bin/env python -set -e +import argparse +import errno +import os +import subprocess +import sys -usage() { - grep '^#/' <"$0"| cut -c4- -} -BASE_URL="${1}" +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor') +DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download') -if [ -z "${BASE_URL}" ]; then - usage - exit 1 -fi -cd "$(dirname "$0")/.." +def main(): + args = parse_args() + update_submodules() + download_libchromiumcontent(args.url) -git submodule sync --quiet -git submodule update --init --recursive -SOURCE_ROOT="$(pwd -P)" -DOWNLOAD_DIR="${SOURCE_ROOT}/vendor/download" -mkdir -p "${DOWNLOAD_DIR}" -vendor/libchromiumcontent/script/download -f "${BASE_URL}" "${DOWNLOAD_DIR}/libchromiumcontent" +def parse_args(): + parser = argparse.ArgumentParser(description='Bootstrap this project') + parser.add_argument('url', help='The base URL from which to download ' + 'libchromiumcontent (i.e., the URL you passed to ' + 'libchromiumcontent\'s script/upload script') + return parser.parse_args() + + +def update_submodules(): + subprocess.check_call(['git', 'submodule', 'sync', '--quiet']) + subprocess.check_call(['git', 'submodule', 'update', '--init', + '--recursive']) + + +def download_libchromiumcontent(url): + mkdir_p(DOWNLOAD_DIR) + download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', + 'download') + subprocess.check_call([sys.executable, download, '-f', url, + os.path.join(DOWNLOAD_DIR, 'libchromiumcontent')]) + + +def mkdir_p(path): + try: + os.makedirs(path) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + +if __name__ == '__main__': + sys.exit(main()) From 46c887b62d6bff11634f9cf0ea9952738b3f13fd Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 13 May 2013 18:55:10 -0400 Subject: [PATCH 0057/1195] Rewrite script/build in Python The script is still Mac-specific, but this will make it easier to add Windows support later. --- brightray/script/build | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/brightray/script/build b/brightray/script/build index 515feb65f03..773b847aee0 100755 --- a/brightray/script/build +++ b/brightray/script/build @@ -1,8 +1,18 @@ -#!/bin/sh +#!/usr/bin/env python -set -e +import os +import subprocess -cd "$(dirname "$0")/.." -gyp --depth . brightray.gyp -xcodebuild +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) + + +def main(): + os.chdir(SOURCE_ROOT) + subprocess.check_call(['gyp', '--depth', '.', 'brightray.gyp']) + subprocess.check_call(['xcodebuild']) + + +if __name__ == '__main__': + import sys + sys.exit(main()) From de9b0a008b8126288fc9edd1ad92f764b0bc968c Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 08:31:10 -0400 Subject: [PATCH 0058/1195] Fix script/bootstrap * vendor/libchromiumcontent 588f368...e70a88f (1): > Make script/download work when we're a submodule --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 588f36848bc..e70a88f3323 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 588f36848bced9ff4f780d26d070a53443a5f230 +Subproject commit e70a88f3323aaf1a24e36bd5449b3e1bab5c57a3 From a922d8a529b81bacd1e6c164dad7f3fbbbd7f196 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 09:26:40 -0400 Subject: [PATCH 0059/1195] Update for libchromiumcontent repo transfer --- brightray/.gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/.gitmodules b/brightray/.gitmodules index 3579d1eb607..b5a3d92f902 100644 --- a/brightray/.gitmodules +++ b/brightray/.gitmodules @@ -1,3 +1,3 @@ [submodule "vendor/libchromiumcontent"] path = vendor/libchromiumcontent - url = https://github.com/aroben/libchromiumcontent + url = https://github.com/brightray/libchromiumcontent From 33d4b7398a9fbc533485a7e637cc1e002f808fb1 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 09:31:20 -0400 Subject: [PATCH 0060/1195] Add script/cibuild This just ensures that we can bootstrap and build. --- brightray/script/cibuild | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 brightray/script/cibuild diff --git a/brightray/script/cibuild b/brightray/script/cibuild new file mode 100755 index 00000000000..2ca4394f31c --- /dev/null +++ b/brightray/script/cibuild @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +import os +import subprocess +import sys + + +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +# We're in JENKINS_ROOT/workspace/brightray. Walk up to JENKINS_ROOT. +JENKINS_ROOT = os.path.dirname(os.path.dirname(SOURCE_ROOT)) +S3_CREDENTIALS_FILE = os.path.join(JENKINS_ROOT, 'config', 's3credentials') + + +def main(): + if not os.path.isfile(S3_CREDENTIALS_FILE): + return 'Error: Can\'t find {0}'.format(S3_CREDENTIALS_FILE) + copy_to_environment(S3_CREDENTIALS_FILE) + + run_script('bootstrap', 'https://{0}.s3.amazonaws.com/libchromiumcontent'.format(os.environ['JANKY_ARTIFACTS_S3_BUCKET'])) + run_script('build') + + +def copy_to_environment(credentials_file): + with open(credentials_file, 'r') as f: + for line in f: + key, value = line.strip().split('=') + value = value.strip("'") + os.environ[key] = value + + +def run_script(script, *args): + script = os.path.join('script', script) + sys.stderr.write('+ {0}\n'.format(script)) + sys.stderr.flush() + subprocess.check_call([sys.executable, script] + list(args)) + + +if __name__ == '__main__': + sys.exit(main()) From 90e1370d7f22e14765bfaa36df0e4051b6d66ff5 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 13:09:57 +0000 Subject: [PATCH 0061/1195] Update libchromiumcontent for Windows support * vendor/libchromiumcontent e70a88f...4aae27b (2): > Merge pull request #11 from brightray/windows-build > Merge pull request #10 from brightray/windows-scripts --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index e70a88f3323..4aae27b02c4 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit e70a88f3323aaf1a24e36bd5449b3e1bab5c57a3 +Subproject commit 4aae27b02c48decf86ad8656530d52632d6dd169 From 39f0694cceac90f017291ddeb90544cd0777ff6a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 16 May 2013 09:08:39 -0400 Subject: [PATCH 0062/1195] Add prerequisites to the README --- brightray/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/brightray/README.md b/brightray/README.md index 725a4718af3..16569743d0c 100644 --- a/brightray/README.md +++ b/brightray/README.md @@ -11,6 +11,15 @@ sample application written using Brightray. ## Development +### Prerequisites + +* Python 2.7 +* gyp +* Mac: + * Xcode +* Windows: + * Visual Studio 2010 SP1 + ### One-time setup You must previously have built and uploaded libchromiumcontent using its From 0dfd5ec3206380f6c7741fda516ae338a84a7556 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 16 May 2013 08:59:24 -0400 Subject: [PATCH 0063/1195] Ensure consistent line endings in all files --- brightray/.gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 brightray/.gitattributes diff --git a/brightray/.gitattributes b/brightray/.gitattributes new file mode 100644 index 00000000000..dfe0770424b --- /dev/null +++ b/brightray/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto From fd6e43baf9f9b62ed74513f6d26d081813e76392 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 15:21:03 +0000 Subject: [PATCH 0064/1195] Make script/build actually run gyp on Windows We don't yet build, but we're getting closer. --- brightray/script/build | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/brightray/script/build b/brightray/script/build index 773b847aee0..709af93ab01 100755 --- a/brightray/script/build +++ b/brightray/script/build @@ -2,17 +2,20 @@ import os import subprocess +import sys SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) - +GYP = { + 'darwin': 'gyp', + 'win32': 'gyp.bat', +}[sys.platform] def main(): os.chdir(SOURCE_ROOT) - subprocess.check_call(['gyp', '--depth', '.', 'brightray.gyp']) + subprocess.check_call([GYP, '--depth', '.', 'brightray.gyp']) subprocess.check_call(['xcodebuild']) if __name__ == '__main__': - import sys sys.exit(main()) From 3d83416c0466dff481db7ff4eb3ecc49e3c70670 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 15:21:16 +0000 Subject: [PATCH 0065/1195] Ignore .sln/.vcxproj files created by gyp --- brightray/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/.gitignore b/brightray/.gitignore index dde2688146f..c3ee68b0b54 100644 --- a/brightray/.gitignore +++ b/brightray/.gitignore @@ -1,2 +1,4 @@ +/brightray.sln +/brightray.vcxproj* /brightray.xcodeproj/ /build/ From a5b118ce348e669997a43a38c30f68c7c82dbe75 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 17:29:35 +0000 Subject: [PATCH 0066/1195] Use MSBuild to build on Windows --- brightray/script/build | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/brightray/script/build b/brightray/script/build index 709af93ab01..6463d9d1d90 100755 --- a/brightray/script/build +++ b/brightray/script/build @@ -11,10 +11,25 @@ GYP = { 'win32': 'gyp.bat', }[sys.platform] + def main(): os.chdir(SOURCE_ROOT) + run_gyp() + build() + + +def run_gyp(): subprocess.check_call([GYP, '--depth', '.', 'brightray.gyp']) - subprocess.check_call(['xcodebuild']) + + +def build(): + if sys.platform == 'darwin': + subprocess.check_call(['xcodebuild']) + return + + assert sys.platform == 'win32', sys.platform + msbuild = os.path.join(os.environ['windir'], 'Microsoft.NET', 'Framework', 'v4.0.30319', 'MSBuild.exe') + subprocess.check_call([msbuild, 'brightray.sln']) if __name__ == '__main__': From 689496afb8b9ab9fcd68e4baeab1d79c16b15147 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 14:13:09 -0400 Subject: [PATCH 0067/1195] Make sure sk_stdint.h is in the include path --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index aefa2305f83..71f73b98b5c 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -9,10 +9,12 @@ 'include_dirs': [ '.', '<(libchromiumcontent_include_dir)', + '<(libchromiumcontent_include_dir)/third_party/skia/include/config', ], 'direct_dependent_settings': { 'include_dirs': [ '<(libchromiumcontent_include_dir)', + '<(libchromiumcontent_include_dir)/third_party/skia/include/config', ], }, 'sources': [ From ae7331da8260ca79aea4839207e5ff531d5ab326 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 13:50:31 -0400 Subject: [PATCH 0068/1195] Add some build defaults for Windows These came from Chromium's build/common.gypi file. --- brightray/brightray.gypi | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 85416178df1..bc07c9da192 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -31,14 +31,58 @@ ], }, 'configurations': { + 'Common_Base': { + 'abstract': 1, + 'msvs_configuration_attributes': { + 'OutputDirectory': '<(DEPTH)\\build\\$(ConfigurationName)', + 'IntermediateDirectory': '$(OutDir)\\obj\\$(ProjectName)', + 'CharacterSet': '1', + }, + }, 'Debug': { + 'inherit_from': [ + 'Common_Base', + ], 'xcode_settings': { 'COPY_PHASE_STRIP': 'NO', 'GCC_OPTIMIZATION_LEVEL': '0', }, }, 'Release': { + 'inherit_from': [ + 'Common_Base', + ], }, }, }, + 'conditions': [ + ['OS=="win"', { + 'target_defaults': { + 'defines': [ + '_WIN32_WINNT=0x0602', + 'WINVER=0x0602', + 'WIN32', + '_WINDOWS', + 'NOMINMAX', + 'PSAPI_VERSION=1', + '_CRT_RAND_S', + 'CERT_CHAIN_PARA_HAS_EXTRA_FIELDS', + 'WIN32_LEAN_AND_MEAN', + '_ATL_NO_OPENGL', + ], + }, + 'msvs_settings': { + 'VCCLCompilerTool': { + 'AdditionalOptions': ['/MP'], + 'MinimalRebuild': 'false', + 'BufferSecurityCheck': 'true', + 'EnableFunctionLevelLinking': 'true', + 'RuntimeTypeInfo': 'false', + 'WarningLevel': '4', + 'WarnAsError': 'true', + 'DebugInformationFormat': '3', + }, + }, + }], + ], } From 35199ba31fe119b39fa435026fe41dac168166cb Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 14:41:50 -0400 Subject: [PATCH 0069/1195] MSVC doesn't allow `override` on destructors --- brightray/browser/inspectable_web_contents_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 8efde3c25d9..95293e062bd 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -32,7 +32,7 @@ public: static void RegisterPrefs(PrefRegistrySimple*); InspectableWebContentsImpl(content::WebContents*); - virtual ~InspectableWebContentsImpl() OVERRIDE; + virtual ~InspectableWebContentsImpl(); virtual InspectableWebContentsView* GetView() const OVERRIDE; virtual content::WebContents* GetWebContents() const OVERRIDE; From a6c5cb04f7739165ce25593836ac658c73713a52 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 14:43:42 -0400 Subject: [PATCH 0070/1195] Use FILE_PATH_LITERAL to fix build errors --- brightray/browser/browser_context.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 2b214476198..f4ab576e09b 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -41,7 +41,7 @@ private: }; BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { - auto prefs_path = GetPath().Append("Preferences"); + auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); PrefServiceBuilder builder; builder.WithUserFilePrefs(prefs_path, JsonPrefStore::GetTaskRunnerForFile(prefs_path, content::BrowserThread::GetBlockingPool())); From 5fa005d5da7aaf3be314cf2468c5f1b82bf688d6 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 14:47:33 -0400 Subject: [PATCH 0071/1195] Fix Windows build error about passing std::string to base::FilePath::Append --- brightray/browser/browser_context.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index f4ab576e09b..c8b923977d3 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -74,7 +74,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::Prot base::FilePath BrowserContext::GetPath() { base::FilePath path; CHECK(PathService::Get(base::DIR_APP_DATA, &path)); - return path.Append(GetApplicationName()); + return path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); } bool BrowserContext::IsOffTheRecord() const { From d07c45080d6debda5336b548d07aaca153480bf1 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 14 May 2013 14:50:24 -0400 Subject: [PATCH 0072/1195] Don't use range-based for loops VS2010 doesn't support them :-( --- brightray/browser/url_request_context_getter.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 58a251c239e..5726500f6c8 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -123,8 +123,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() scoped_ptr job_factory( new net::URLRequestJobFactoryImpl()); - for (auto& it : protocol_handlers_) { - bool set_protocol = job_factory->SetProtocolHandler(it.first, it.second.release()); + for (auto it = protocol_handlers_.begin(), + end = protocol_handlers_.end(); it != end; ++it) { + bool set_protocol = job_factory->SetProtocolHandler(it->first, it->second.release()); DCHECK(set_protocol); } protocol_handlers_.clear(); From e531f46a4b7b2dac0f4ca2926da7100048838ace Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 16 May 2013 09:16:29 -0400 Subject: [PATCH 0073/1195] Ignore files created by Visual Studio --- brightray/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/.gitignore b/brightray/.gitignore index c3ee68b0b54..4f725781672 100644 --- a/brightray/.gitignore +++ b/brightray/.gitignore @@ -1,3 +1,5 @@ +/brightray.opensdf +/brightray.sdf /brightray.sln /brightray.vcxproj* /brightray.xcodeproj/ From d6b4e430f8575adcc3a746211cfac2b1c87911c6 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 21 May 2013 14:57:52 -0400 Subject: [PATCH 0074/1195] Update links after move to brightray org --- brightray/README.md | 6 +++--- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/brightray/README.md b/brightray/README.md index 16569743d0c..ad939344c4d 100644 --- a/brightray/README.md +++ b/brightray/README.md @@ -1,12 +1,12 @@ # Brightray Brightray is a static library that makes -[libchromiumcontent](https://github.com/aroben/libchromiumcontent) easier to +[libchromiumcontent](https://github.com/brightray/libchromiumcontent) easier to use in applications. ## Using it in your app -See [brightray_example](https://github.com/aroben/brightray_example) for a +See [brightray_example](https://github.com/brightray/brightray_example) for a sample application written using Brightray. ## Development @@ -33,7 +33,7 @@ You must previously have built and uploaded libchromiumcontent using its Building Brightray on its own isn’t all that interesting, since it’s just a static library. Building it into an application (like -[brightray_example](https://github.com/aroben/brightray_example)) is the only +[brightray_example](https://github.com/brightray/brightray_example)) is the only way to test it. ## License diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 4aae27b02c4..ad588f54dc3 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 4aae27b02c48decf86ad8656530d52632d6dd169 +Subproject commit ad588f54dc342716e55fd23ce69d6e2c176a1df7 From f387535eae6f5d52754e209e817b1e96d413158d Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 11:59:06 -0400 Subject: [PATCH 0075/1195] Beef up .gitignore --- brightray/.gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/.gitignore b/brightray/.gitignore index 4f725781672..4ee8ba8eacf 100644 --- a/brightray/.gitignore +++ b/brightray/.gitignore @@ -4,3 +4,6 @@ /brightray.vcxproj* /brightray.xcodeproj/ /build/ + +# Vim +*.swp From 3cf6e5eda22ab5a68ea3cbc80848740249e0ac10 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 12:14:29 -0400 Subject: [PATCH 0076/1195] Make sure dependents can #include "brightray/foo.h" --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 71f73b98b5c..48ad90d6bea 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -13,6 +13,7 @@ ], 'direct_dependent_settings': { 'include_dirs': [ + '..', '<(libchromiumcontent_include_dir)', '<(libchromiumcontent_include_dir)/third_party/skia/include/config', ], From 35f4dfe4b0204b77c82f5f65ada60ee001b61e22 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 11:15:04 -0400 Subject: [PATCH 0077/1195] Add some more default build settings for Windows --- brightray/brightray.gypi | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index bc07c9da192..965ad51fd6a 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -6,6 +6,26 @@ 'libchromiumcontent_resources_dir': '<(libchromiumcontent_library_dir)', 'mac_deployment_target%': '10.8', 'mac_sdkroot%': 'macosx', + + 'win_release_RuntimeLibrary%': '0', # /MT (nondebug static) + 'win_debug_RuntimeLibrary%': '1', # /MTd (debug static) + + # See http://msdn.microsoft.com/en-us/library/aa652360(VS.71).aspx + 'win_release_Optimization%': '2', # 2 = /Os + 'win_debug_Optimization%': '0', # 0 = /Od + + # See http://msdn.microsoft.com/en-us/library/2kxx5t2c(v=vs.80).aspx + # Tri-state: blank is default, 1 on, 0 off + 'win_release_OmitFramePointers%': '0', + # Tri-state: blank is default, 1 on, 0 off + 'win_debug_OmitFramePointers%': '', + + # See http://msdn.microsoft.com/en-us/library/8wtf2dfz(VS.71).aspx + 'win_debug_RuntimeChecks%': '3', # 3 = all checks enabled, 0 = off + + # See http://msdn.microsoft.com/en-us/library/47238hez(VS.71).aspx + 'win_debug_InlineFunctionExpansion%': '', # empty = default, 0 = off, + 'win_release_InlineFunctionExpansion%': '2', # 1 = only __inline, 2 = max }, 'target_defaults': { 'defines': [ @@ -43,6 +63,41 @@ 'inherit_from': [ 'Common_Base', ], + 'msvs_settings': { + 'VCCLCompilerTool': { + 'Optimization': '<(win_debug_Optimization)', + 'PreprocessorDefinitions': ['_DEBUG'], + 'BasicRuntimeChecks': '<(win_debug_RuntimeChecks)', + # We use Release to match the version of chromiumcontent.dll we + # link against. + 'RuntimeLibrary': '<(win_release_RuntimeLibrary)', + 'conditions': [ + # According to MSVS, InlineFunctionExpansion=0 means + # "default inlining", not "/Ob0". + # Thus, we have to handle InlineFunctionExpansion==0 separately. + ['win_debug_InlineFunctionExpansion==0', { + 'AdditionalOptions': ['/Ob0'], + }], + ['win_debug_InlineFunctionExpansion!=""', { + 'InlineFunctionExpansion': + '<(win_debug_InlineFunctionExpansion)', + }], + # if win_debug_OmitFramePointers is blank, leave as default + ['win_debug_OmitFramePointers==1', { + 'OmitFramePointers': 'true', + }], + ['win_debug_OmitFramePointers==0', { + 'OmitFramePointers': 'false', + # The above is not sufficient (http://crbug.com/106711): it + # simply eliminates an explicit "/Oy", but both /O2 and /Ox + # perform FPO regardless, so we must explicitly disable. + # We still want the false setting above to avoid having + # "/Oy /Oy-" and warnings about overriding. + 'AdditionalOptions': ['/Oy-'], + }], + ], + }, + }, 'xcode_settings': { 'COPY_PHASE_STRIP': 'NO', 'GCC_OPTIMIZATION_LEVEL': '0', @@ -52,6 +107,37 @@ 'inherit_from': [ 'Common_Base', ], + 'msvs_settings': { + 'VCCLCompilerTool': { + 'Optimization': '<(win_release_Optimization)', + 'RuntimeLibrary': '<(win_release_RuntimeLibrary)', + 'conditions': [ + # According to MSVS, InlineFunctionExpansion=0 means + # "default inlining", not "/Ob0". + # Thus, we have to handle InlineFunctionExpansion==0 separately. + ['win_release_InlineFunctionExpansion==0', { + 'AdditionalOptions': ['/Ob0'], + }], + ['win_release_InlineFunctionExpansion!=""', { + 'InlineFunctionExpansion': + '<(win_release_InlineFunctionExpansion)', + }], + # if win_release_OmitFramePointers is blank, leave as default + ['win_release_OmitFramePointers==1', { + 'OmitFramePointers': 'true', + }], + ['win_release_OmitFramePointers==0', { + 'OmitFramePointers': 'false', + # The above is not sufficient (http://crbug.com/106711): it + # simply eliminates an explicit "/Oy", but both /O2 and /Ox + # perform FPO regardless, so we must explicitly disable. + # We still want the false setting above to avoid having + # "/Oy /Oy-" and warnings about overriding. + 'AdditionalOptions': ['/Oy-'], + }], + ], + }, + }, }, }, }, From 7b65fe49488080710cee26620eee1c35927144c5 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 13:46:55 -0400 Subject: [PATCH 0078/1195] Link against chromiumcontent.dll * vendor/libchromiumcontent 4aae27b...15ada44 (3): > Include chromiumcontent.dll's import library > Export sandbox/ headers > Mention that Python is required to build --- brightray/brightray.gyp | 7 +++++++ brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 48ad90d6bea..92554d1d8bf 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -70,6 +70,13 @@ ], }, }], + ['OS=="win"', { + 'link_settings': { + 'libraries': [ + '<(libchromiumcontent_library_dir)/chromiumcontent.dll.lib', + ], + }, + }], ], }, ], diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index ad588f54dc3..15ada44da42 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit ad588f54dc342716e55fd23ce69d6e2c176a1df7 +Subproject commit 15ada44da42eec88400ca978fdd73213488a04bc From 4c0765b413fea09ea2d517df2c3ae9d781a53d01 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 21 May 2013 14:49:49 -0400 Subject: [PATCH 0079/1195] Use __declspec(dllimport) for functions from chromiumcontent.dll --- brightray/brightray.gypi | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 965ad51fd6a..8985019011b 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -28,9 +28,6 @@ 'win_release_InlineFunctionExpansion%': '2', # 1 = only __inline, 2 = max }, 'target_defaults': { - 'defines': [ - 'NDEBUG', - ], 'xcode_settings': { 'ALWAYS_SEARCH_USER_PATHS': 'NO', 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11', @@ -53,6 +50,14 @@ 'configurations': { 'Common_Base': { 'abstract': 1, + 'defines': [ + 'COMPONENT_BUILD', + 'GURL_DLL', + 'SKIA_DLL', + 'NDEBUG', + 'USING_V8_SHARED', + 'WEBKIT_DLL', + ], 'msvs_configuration_attributes': { 'OutputDirectory': '<(DEPTH)\\build\\$(ConfigurationName)', 'IntermediateDirectory': '$(OutDir)\\obj\\$(ProjectName)', From 7f463b896244caa2a87536948f6a7f77a042df6f Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 21 May 2013 11:28:44 -0400 Subject: [PATCH 0080/1195] Give clients access to libchromiumcontent's src directory * vendor/libchromiumcontent 15ada44...65b85bf (2): > Export content/app/startup_helper_win.cc to clients > Rename dist/include to dist/src --- brightray/brightray.gypi | 3 ++- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 8985019011b..3cf7d500090 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -2,8 +2,9 @@ 'variables': { 'libchromiumcontent_dir': 'vendor/download/libchromiumcontent', 'libchromiumcontent_library_dir': '<(libchromiumcontent_dir)/Release', - 'libchromiumcontent_include_dir': '<(libchromiumcontent_dir)/include', + 'libchromiumcontent_include_dir': '<(libchromiumcontent_dir)/src', 'libchromiumcontent_resources_dir': '<(libchromiumcontent_library_dir)', + 'libchromiumcontent_src_dir': '<(libchromiumcontent_dir)/src', 'mac_deployment_target%': '10.8', 'mac_sdkroot%': 'macosx', diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 15ada44da42..65b85bf315a 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 15ada44da42eec88400ca978fdd73213488a04bc +Subproject commit 65b85bf315a9db754a590a6e484f6f705c837583 From 2813bef7411ef1dbf56611160062e1e4226a417b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 13:48:08 -0400 Subject: [PATCH 0081/1195] Link against sandbox_static.lib * vendor/libchromiumcontent 15ada44...c973a7c (3): > Create and export sandbox_static.lib for Windows clients > Export content/app/startup_helper_win.cc to clients > Rename dist/include to dist/src --- brightray/brightray.gyp | 1 + brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 92554d1d8bf..c1dd0c0e0b2 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -74,6 +74,7 @@ 'link_settings': { 'libraries': [ '<(libchromiumcontent_library_dir)/chromiumcontent.dll.lib', + '<(libchromiumcontent_library_dir)/sandbox_static.lib', ], }, }], diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 65b85bf315a..c973a7c3937 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 65b85bf315a9db754a590a6e484f6f705c837583 +Subproject commit c973a7c3937fd31183e2fcf6809dc7182c5fe0ec From 12773cff6ed32e7472764f375e9a33b3eefd967e Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 21 May 2013 11:30:43 -0400 Subject: [PATCH 0082/1195] Fix linker errors about missing registry APIs --- brightray/brightray.gypi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 3cf7d500090..4d74515ef57 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -64,6 +64,13 @@ 'IntermediateDirectory': '$(OutDir)\\obj\\$(ProjectName)', 'CharacterSet': '1', }, + 'msvs_settings': { + 'VCLinkerTool': { + 'AdditionalDependencies': [ + 'advapi32.lib', + ], + }, + }, }, 'Debug': { 'inherit_from': [ From 12d01e4fd58aee3947f7c49c67319a4a92516ad2 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 21 May 2013 11:39:25 -0400 Subject: [PATCH 0083/1195] ifdef out a bunch of Mac-specific code This is a hacky solution but helps us deal with other compiler/linker errors. --- brightray/browser/browser_client.cc | 2 ++ brightray/browser/inspectable_web_contents_impl.cc | 2 ++ brightray/common/main_delegate.cc | 2 +- brightray/common/main_delegate.h | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 9dc99f18a3b..72626a5226b 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -34,8 +34,10 @@ BrowserContext* BrowserClient::browser_context() { } NotificationPresenter* BrowserClient::notification_presenter() { +#if defined(OS_MACOSX) if (!notification_presenter_) notification_presenter_.reset(NotificationPresenter::Create()); +#endif return notification_presenter_.get(); } diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 7f694ad54ff..c6c6f00f4cd 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -41,7 +41,9 @@ InspectableWebContentsImpl::InspectableWebContentsImpl(content::WebContents* web auto context = static_cast(web_contents_->GetBrowserContext()); dock_side_ = context->prefs()->GetString(kDockSidePref); +#if defined(OS_MACOSX) view_.reset(CreateInspectableContentsView(this)); +#endif } InspectableWebContentsImpl::~InspectableWebContentsImpl() { diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 7c1fa903bcb..09cc8bc1038 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -32,8 +32,8 @@ void MainDelegate::PreSandboxStartup() { #if defined(OS_MACOSX) OverrideChildProcessPath(); OverrideFrameworkBundlePath(); -#endif InitializeResourceBundle(); +#endif } } diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 34ebfef9d7f..b695c7c326c 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -34,8 +34,8 @@ protected: virtual void PreSandboxStartup() OVERRIDE; private: - void InitializeResourceBundle(); #if defined(OS_MACOSX) + void InitializeResourceBundle(); static void OverrideChildProcessPath(); static void OverrideFrameworkBundlePath(); #endif From 7e03f93dcdf5a24257d4b4e3b675ce7bc9959b50 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 21 May 2013 11:40:49 -0400 Subject: [PATCH 0084/1195] Add a stub application_info_win.cc --- brightray/brightray.gyp | 1 + brightray/common/application_info_win.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 brightray/common/application_info_win.cc diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index c1dd0c0e0b2..8064aeeb154 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -52,6 +52,7 @@ 'browser/url_request_context_getter.h', 'common/application_info.h', 'common/application_info_mac.mm', + 'common/application_info_win.cc', 'common/content_client.cc', 'common/content_client.h', 'common/mac/foundation_util.h', diff --git a/brightray/common/application_info_win.cc b/brightray/common/application_info_win.cc new file mode 100644 index 00000000000..11333015860 --- /dev/null +++ b/brightray/common/application_info_win.cc @@ -0,0 +1,13 @@ +#include "common/application_info.h" + +namespace brightray { + +std::string GetApplicationName() { + return std::string(); +} + +std::string GetApplicationVersion() { + return std::string(); +} + +} From 6a8ee865f4ceb00cd041666135ffaa69e9f755bd Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 21 May 2013 11:42:26 -0400 Subject: [PATCH 0085/1195] Fix linker errors about missing Win32 APIs --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 4d74515ef57..e443dde45aa 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -68,6 +68,7 @@ 'VCLinkerTool': { 'AdditionalDependencies': [ 'advapi32.lib', + 'user32.lib', ], }, }, From 18b64f375cfe4b81b6be08b4206cdfc3df0d0289 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 21 May 2013 14:49:19 -0400 Subject: [PATCH 0086/1195] Link client apps against base_static.lib This is required to get base::win::PEImage, which is required by sandboxing code. * vendor/libchromiumcontent c973a7c...04ccdd8 (1): > Export base_static.lib for Windows clients --- brightray/brightray.gyp | 1 + brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 8064aeeb154..9676795690e 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -74,6 +74,7 @@ ['OS=="win"', { 'link_settings': { 'libraries': [ + '<(libchromiumcontent_library_dir)/base_static.lib', '<(libchromiumcontent_library_dir)/chromiumcontent.dll.lib', '<(libchromiumcontent_library_dir)/sandbox_static.lib', ], diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index c973a7c3937..04ccdd8d3c9 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit c973a7c3937fd31183e2fcf6809dc7182c5fe0ec +Subproject commit 04ccdd8d3c9938eeff3764f77c955ac08553c960 From 1ec7280663cd2db472ae007f0fbcc072e7b6aeef Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 11:16:56 -0400 Subject: [PATCH 0087/1195] Link against the DLL version of the CRT * vendor/libchromiumcontent 04ccdd8...31efc77 (3): > Use the DLL version of the CRT > Generate libchromiumcontent-symbols.zip on Windows > Fix exporting of WebKit symbols --- brightray/brightray.gypi | 4 ++-- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index e443dde45aa..3f426666d9b 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -8,8 +8,8 @@ 'mac_deployment_target%': '10.8', 'mac_sdkroot%': 'macosx', - 'win_release_RuntimeLibrary%': '0', # /MT (nondebug static) - 'win_debug_RuntimeLibrary%': '1', # /MTd (debug static) + 'win_release_RuntimeLibrary%': '2', # /MD (nondebug DLL) + 'win_debug_RuntimeLibrary%': '3', # /MTd (debug DLL) # See http://msdn.microsoft.com/en-us/library/aa652360(VS.71).aspx 'win_release_Optimization%': '2', # 2 = /Os diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 04ccdd8d3c9..31efc77a0e7 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 04ccdd8d3c9938eeff3764f77c955ac08553c960 +Subproject commit 31efc77a0e71c7dfcf62010fed51ab4acf74fc01 From 3713ea6403be28bb0d345245149a56e9c5a0853d Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 11:37:42 -0400 Subject: [PATCH 0088/1195] Exclude platform-specific files from other platforms --- brightray/brightray.gyp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 9676795690e..2732d5c9a1d 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -70,6 +70,11 @@ '$(SDKROOT)/System/Library/Frameworks/AppKit.framework', ], }, + }, { + 'sources/': [ + ['exclude', '/mac/'], + ['exclude', '_mac\.(mm|h)$'], + ], }], ['OS=="win"', { 'link_settings': { @@ -79,6 +84,11 @@ '<(libchromiumcontent_library_dir)/sandbox_static.lib', ], }, + }, { + 'sources/': [ + ['exclude', '/win/'], + ['exclude', '_win\.(cc|h)$'], + ], }], ], }, From f2909b0d90a11c95c8c350107fc5e4e4f5e66549 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 11:40:43 -0400 Subject: [PATCH 0089/1195] Set up the resource bundle on Windows --- brightray/common/main_delegate.cc | 22 +++++++++++++++++++++- brightray/common/main_delegate.h | 3 ++- brightray/common/main_delegate_mac.mm | 11 ++--------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 09cc8bc1038..5578fc7c3af 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -8,7 +8,9 @@ #include "common/content_client.h" #include "base/command_line.h" +#include "base/path_service.h" #include "content/public/common/content_switches.h" +#include "ui/base/resource/resource_bundle.h" namespace brightray { @@ -32,8 +34,26 @@ void MainDelegate::PreSandboxStartup() { #if defined(OS_MACOSX) OverrideChildProcessPath(); OverrideFrameworkBundlePath(); - InitializeResourceBundle(); #endif + InitializeResourceBundle(); +} + +void MainDelegate::InitializeResourceBundle() { + base::FilePath path; +#if defined(OS_MACOSX) + path = GetResourcesPakFilePath(); +#else + base::FilePath pak_dir; + PathService::Get(base::DIR_MODULE, &pak_dir); + path = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); +#endif + + ui::ResourceBundle::InitSharedInstanceWithPakPath(path); + + std::vector pak_paths; + AddPakPaths(&pak_paths); + for (auto it = pak_paths.begin(), end = pak_paths.end(); it != end; ++it) + ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(*it, ui::SCALE_FACTOR_NONE); } } diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index b695c7c326c..f5cbe88d4e8 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -34,8 +34,9 @@ protected: virtual void PreSandboxStartup() OVERRIDE; private: -#if defined(OS_MACOSX) void InitializeResourceBundle(); +#if defined(OS_MACOSX) + static base::FilePath GetResourcesPakFilePath(); static void OverrideChildProcessPath(); static void OverrideFrameworkBundlePath(); #endif diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index 72ae553ff88..aa7bf0f4625 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -12,7 +12,6 @@ #include "base/mac/bundle_locations.h" #include "base/path_service.h" #include "content/public/common/content_paths.h" -#include "ui/base/resource/resource_bundle.h" namespace brightray { @@ -24,15 +23,9 @@ base::FilePath GetFrameworksPath() { } -void MainDelegate::InitializeResourceBundle() { +base::FilePath MainDelegate::GetResourcesPakFilePath() { auto path = [base::mac::FrameworkBundle() pathForResource:@"content_shell" ofType:@"pak"]; - - ui::ResourceBundle::InitSharedInstanceWithPakPath(base::mac::NSStringToFilePath(path)); - - std::vector pak_paths; - AddPakPaths(&pak_paths); - for (const auto& path : pak_paths) - ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(path, ui::SCALE_FACTOR_NONE); + return base::mac::NSStringToFilePath(path); } void MainDelegate::OverrideFrameworkBundlePath() { From d54f4e2bdddff25bca59f5b36870c5bff85a4f6b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 11:48:54 -0400 Subject: [PATCH 0090/1195] Update libchromiumcontent to get icudt.dll * vendor/libchromiumcontent 31efc77...e436974 (2): > Export icudt.dll for Windows clients > Export libGLESv2.dll on Windows --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 31efc77a0e7..e436974fc1a 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 31efc77a0e71c7dfcf62010fed51ab4acf74fc01 +Subproject commit e436974fc1a470311879056b93f9bf0c3e2408fc From b970e9d5c330f8f9870a5ae5b6c492158d0770d2 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 16:08:40 -0400 Subject: [PATCH 0091/1195] Only compile HandleKeyboardEvent on Mac --- brightray/browser/default_web_contents_delegate.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/browser/default_web_contents_delegate.h b/brightray/browser/default_web_contents_delegate.h index 8ec70c316b6..c6ce2ee23ff 100644 --- a/brightray/browser/default_web_contents_delegate.h +++ b/brightray/browser/default_web_contents_delegate.h @@ -13,7 +13,9 @@ public: ~DefaultWebContentsDelegate(); protected: +#if defined(OS_MACOSX) virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; +#endif }; } From cf14f0922827f1c28a8101746f39c25a6d3f7298 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 16:57:32 -0400 Subject: [PATCH 0092/1195] Stub out InspectableWebContentsViewWin This class doesn't implement any devtools behavior yet. Right now it's just a glorified wrapper around a content::WebContents. But it's enough to show web content on screen on Windows! --- brightray/brightray.gyp | 2 ++ .../browser/inspectable_web_contents_impl.cc | 2 -- .../win/inspectable_web_contents_view_win.cc | 34 +++++++++++++++++++ .../win/inspectable_web_contents_view_win.h | 33 ++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 brightray/browser/win/inspectable_web_contents_view_win.cc create mode 100644 brightray/browser/win/inspectable_web_contents_view_win.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 2732d5c9a1d..e8adbc15fcc 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -50,6 +50,8 @@ 'browser/notification_presenter_mac.mm', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', + 'browser/win/inspectable_web_contents_view_win.cc', + 'browser/win/inspectable_web_contents_view_win.h', 'common/application_info.h', 'common/application_info_mac.mm', 'common/application_info_win.cc', diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c6c6f00f4cd..7f694ad54ff 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -41,9 +41,7 @@ InspectableWebContentsImpl::InspectableWebContentsImpl(content::WebContents* web auto context = static_cast(web_contents_->GetBrowserContext()); dock_side_ = context->prefs()->GetString(kDockSidePref); -#if defined(OS_MACOSX) view_.reset(CreateInspectableContentsView(this)); -#endif } InspectableWebContentsImpl::~InspectableWebContentsImpl() { diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc new file mode 100644 index 00000000000..deab04590c0 --- /dev/null +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -0,0 +1,34 @@ +#include "browser/win/inspectable_web_contents_view_win.h" + +#include "browser/inspectable_web_contents_impl.h" + +#include "content/public/browser/web_contents_view.h" + +namespace brightray { + +InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { + return new InspectableWebContentsViewWin(inspectable_web_contents); +} + +InspectableWebContentsViewWin::InspectableWebContentsViewWin(InspectableWebContentsImpl* inspectable_web_contents) + : inspectable_web_contents_(inspectable_web_contents) { +} + +InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { +} + +gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { + return inspectable_web_contents_->GetWebContents()->GetView()->GetNativeView(); +} + +void InspectableWebContentsViewWin::ShowDevTools() { +} + +void InspectableWebContentsViewWin::CloseDevTools() { +} + +bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { + return false; +} + +} diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h new file mode 100644 index 00000000000..801eb931360 --- /dev/null +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -0,0 +1,33 @@ +#ifndef BRIGHTRAY_BROWSER_WIN_INSPECTABLE_WEB_CONTENTS_VIEW_WIN_H_ +#define BRIGHTRAY_BROWSER_WIN_INSPECTABLE_WEB_CONTENTS_VIEW_WIN_H_ + +#include "browser/inspectable_web_contents_view.h" + +#include "base/compiler_specific.h" + +namespace brightray { + +class InspectableWebContentsImpl; + +class InspectableWebContentsViewWin : public InspectableWebContentsView { +public: + InspectableWebContentsViewWin(InspectableWebContentsImpl*); + ~InspectableWebContentsViewWin(); + + virtual gfx::NativeView GetNativeView() const OVERRIDE; + virtual void ShowDevTools() OVERRIDE; + virtual void CloseDevTools() OVERRIDE; + virtual bool SetDockSide(const std::string& side) OVERRIDE; + + InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; } + +private: + // Owns us. + InspectableWebContentsImpl* inspectable_web_contents_; + + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewWin); +}; + +} + +#endif From 51cb56e604fe44420b59a956b6ca2069f2412c8a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 22 May 2013 16:58:59 -0400 Subject: [PATCH 0093/1195] Get libchromiumcontent back on master --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index e436974fc1a..3cbc11e5d7b 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit e436974fc1a470311879056b93f9bf0c3e2408fc +Subproject commit 3cbc11e5d7bcfe48445c4bbc5f3653bd1b11f112 From 37d847c416712e9b8ed0468538456a552fa77881 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 28 May 2013 11:55:25 -0400 Subject: [PATCH 0094/1195] Fix linker errors about __imp___CrtDbgReportW We were linking against the release CRT but defining _DEBUG, which should only be defined when using the debug CRT. --- brightray/brightray.gypi | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 3f426666d9b..14d10cc7a16 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -80,7 +80,6 @@ 'msvs_settings': { 'VCCLCompilerTool': { 'Optimization': '<(win_debug_Optimization)', - 'PreprocessorDefinitions': ['_DEBUG'], 'BasicRuntimeChecks': '<(win_debug_RuntimeChecks)', # We use Release to match the version of chromiumcontent.dll we # link against. From 3f40456161edfb15975c962bdff6844cb2dcf4bd Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 28 May 2013 11:56:17 -0400 Subject: [PATCH 0095/1195] Make our Windows build settings actually take effect We need to put them inside the target_defaults dictionary. Now that these settings are turned on, we need to ignore some warnings that Chromium ignores. --- brightray/brightray.gypi | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 14d10cc7a16..989e34d929e 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -169,18 +169,30 @@ 'WIN32_LEAN_AND_MEAN', '_ATL_NO_OPENGL', ], - }, - 'msvs_settings': { - 'VCCLCompilerTool': { - 'AdditionalOptions': ['/MP'], - 'MinimalRebuild': 'false', - 'BufferSecurityCheck': 'true', - 'EnableFunctionLevelLinking': 'true', - 'RuntimeTypeInfo': 'false', - 'WarningLevel': '4', - 'WarnAsError': 'true', - 'DebugInformationFormat': '3', + 'msvs_settings': { + 'VCCLCompilerTool': { + 'AdditionalOptions': ['/MP'], + 'MinimalRebuild': 'false', + 'BufferSecurityCheck': 'true', + 'EnableFunctionLevelLinking': 'true', + 'RuntimeTypeInfo': 'false', + 'WarningLevel': '4', + 'WarnAsError': 'true', + 'DebugInformationFormat': '3', + }, }, + 'msvs_disabled_warnings': [ + 4100, # unreferenced formal parameter + 4127, # conditional expression is constant + 4244, # 'initializing' : conversion from 'double' to 'size_t', possible loss of data + 4245, # 'initializing' : conversion from 'int' to 'const net::QuicVersionTag', signed/unsigned mismatch + 4251, # class 'std::xx' needs to have dll-interface. + 4310, # cast truncates constant value + 4480, # nonstandard extension used: specifying underlying type for enum + 4481, # nonstandard extension used: override specifier 'override' + 4512, # assignment operator could not be generated + 4702, # unreachable code + ], }, }], ], From 427ba96062e5811178d4f626618b866d85628e2c Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 28 May 2013 11:56:50 -0400 Subject: [PATCH 0096/1195] Set up linker defaults for Windows These match Chromium's defaults. --- brightray/brightray.gypi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 989e34d929e..abd380a238c 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -180,6 +180,11 @@ 'WarnAsError': 'true', 'DebugInformationFormat': '3', }, + 'VCLinkerTool': { + 'GenerateDebugInformation': 'true', + 'MapFileName': '$(OutDir)\\$(TargetName).map', + 'ImportLibrary': '$(OutDir)\\lib\\$(TargetName).lib', + }, }, 'msvs_disabled_warnings': [ 4100, # unreferenced formal parameter From 70af1f351f6f42270e066db679f0571fb7f74127 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 28 May 2013 14:27:57 -0400 Subject: [PATCH 0097/1195] Automatically exclude platform-specific files for all targets This way embedding applications don't have to do this themselves, as long as they follow our naming conventions. --- brightray/brightray.gyp | 10 ---------- brightray/brightray.gypi | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index e8adbc15fcc..2ac42272200 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -72,11 +72,6 @@ '$(SDKROOT)/System/Library/Frameworks/AppKit.framework', ], }, - }, { - 'sources/': [ - ['exclude', '/mac/'], - ['exclude', '_mac\.(mm|h)$'], - ], }], ['OS=="win"', { 'link_settings': { @@ -86,11 +81,6 @@ '<(libchromiumcontent_library_dir)/sandbox_static.lib', ], }, - }, { - 'sources/': [ - ['exclude', '/win/'], - ['exclude', '_win\.(cc|h)$'], - ], }], ], }, diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index abd380a238c..964eae9de59 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -153,6 +153,20 @@ }, }, }, + 'conditions': [ + ['OS!="mac"', { + 'sources/': [ + ['exclude', '/mac/'], + ['exclude', '_mac\.(mm|h)$'], + ], + }], + ['OS!="win"', { + 'sources/': [ + ['exclude', '/win/'], + ['exclude', '_win\.(cc|h)$'], + ], + }], + ], }, 'conditions': [ ['OS=="win"', { From 54419bbbb1a46a0aaa8dc71c9ac85da4f0896637 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 28 May 2013 15:24:55 -0400 Subject: [PATCH 0098/1195] Set the user agent string correctly on Windows We use the main executable's ProductName and FileVersion resources to build the user agent string. --- brightray/common/application_info_win.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/brightray/common/application_info_win.cc b/brightray/common/application_info_win.cc index 11333015860..c099db02f40 100644 --- a/brightray/common/application_info_win.cc +++ b/brightray/common/application_info_win.cc @@ -1,13 +1,19 @@ #include "common/application_info.h" +#include "base/file_version_info.h" +#include "base/memory/scoped_ptr.h" +#include "base/utf_string_conversions.h" + namespace brightray { std::string GetApplicationName() { - return std::string(); + auto info = make_scoped_ptr(FileVersionInfo::CreateFileVersionInfoForModule(GetModuleHandle(nullptr))); + return UTF16ToUTF8(info->product_name()); } std::string GetApplicationVersion() { - return std::string(); + auto info = make_scoped_ptr(FileVersionInfo::CreateFileVersionInfoForModule(GetModuleHandle(nullptr))); + return UTF16ToUTF8(info->file_version()); } } From a24c3903186857581602ef8ed27ea75a78e1ad68 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 28 May 2013 15:42:52 -0400 Subject: [PATCH 0099/1195] Use the user-visible version number in our user agent string I.e., use CFBundleShortVersionString instead of CFBundleVersion on OS X and ProductVersion instead of FileVersion on Windows. This is generally more useful (although slightly lower granularity) than the machine-readable version number. --- brightray/common/application_info_mac.mm | 8 ++++++-- brightray/common/application_info_win.cc | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/brightray/common/application_info_mac.mm b/brightray/common/application_info_mac.mm index c6df34e5582..ee9f9bbf4c5 100644 --- a/brightray/common/application_info_mac.mm +++ b/brightray/common/application_info_mac.mm @@ -9,8 +9,12 @@ namespace brightray { namespace { +std::string ApplicationInfoDictionaryValue(NSString* key) { + return base::SysNSStringToUTF8([MainApplicationBundle().infoDictionary objectForKey:key]); +} + std::string ApplicationInfoDictionaryValue(CFStringRef key) { - return base::SysNSStringToUTF8([MainApplicationBundle().infoDictionary objectForKey:base::mac::CFToNSCast(key)]); + return ApplicationInfoDictionaryValue(base::mac::CFToNSCast(key)); } } @@ -20,7 +24,7 @@ std::string GetApplicationName() { } std::string GetApplicationVersion() { - return ApplicationInfoDictionaryValue(kCFBundleVersionKey); + return ApplicationInfoDictionaryValue(@"CFBundleShortVersionString"); } } diff --git a/brightray/common/application_info_win.cc b/brightray/common/application_info_win.cc index c099db02f40..8363970ebd8 100644 --- a/brightray/common/application_info_win.cc +++ b/brightray/common/application_info_win.cc @@ -13,7 +13,7 @@ std::string GetApplicationName() { std::string GetApplicationVersion() { auto info = make_scoped_ptr(FileVersionInfo::CreateFileVersionInfoForModule(GetModuleHandle(nullptr))); - return UTF16ToUTF8(info->file_version()); + return UTF16ToUTF8(info->product_version()); } } From f88634fea561b7f7f6636e6ee2f94a87e8abc4e2 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 29 May 2013 13:15:18 -0400 Subject: [PATCH 0100/1195] Pull in libchromiumcontent's Windows test support * vendor/libchromiumcontent 3cbc11e...0d02a8d (1): > Merge pull request #13 from brightray/windows-test-support --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 3cbc11e5d7b..0d02a8d41a1 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 3cbc11e5d7bcfe48445c4bbc5f3653bd1b11f112 +Subproject commit 0d02a8d41a1d6711f196a744126fa5e2eba961ff From 2582e8561ce76541a90bc4f01b1e67bdf8dfcb96 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 30 May 2013 15:04:51 -0400 Subject: [PATCH 0101/1195] Update to Chromium r202921 * vendor/libchromiumcontent 0d02a8d...2f53a96 (1): > Merge pull request #14 from brightray/latest-chromium --- brightray/brightray.gypi | 1 + brightray/browser/url_request_context_getter.cc | 1 + brightray/common/content_client.cc | 2 +- brightray/vendor/libchromiumcontent | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 964eae9de59..69513546df7 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -207,6 +207,7 @@ 4245, # 'initializing' : conversion from 'int' to 'const net::QuicVersionTag', signed/unsigned mismatch 4251, # class 'std::xx' needs to have dll-interface. 4310, # cast truncates constant value + 4355, # 'this' : used in base member initializer list 4480, # nonstandard extension used: specifying underlying type for enum 4481, # nonstandard extension used: override specifier 'override' 4512, # assignment operator could not be generated diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 5726500f6c8..7c5c45111bb 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -90,6 +90,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() net::HttpCache::DefaultBackend* main_backend = new net::HttpCache::DefaultBackend( net::DISK_CACHE, + net::CACHE_BACKEND_DEFAULT, cache_path, 0, content::BrowserThread::GetMessageLoopProxyForThread( diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index 87cc07abfee..fc294f45ec5 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -9,7 +9,7 @@ #include "base/stringprintf.h" #include "base/string_util.h" #include "ui/base/resource/resource_bundle.h" -#include "webkit/user_agent/user_agent_util.h" +#include "webkit/common/user_agent/user_agent_util.h" namespace brightray { diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 0d02a8d41a1..2f53a96fc66 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 0d02a8d41a1d6711f196a744126fa5e2eba961ff +Subproject commit 2f53a96fc665176d7e07b67bac6d861295587ce8 From 3d12cb2c649fa11404e993e03f5fc64690d084b0 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 31 May 2013 08:05:14 -0400 Subject: [PATCH 0102/1195] Don't crash when HTML notifications are used on Windows Eventually we'll implement real support for this, but for now not crashing is more important. --- brightray/browser/browser_client.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 72626a5226b..a42fcea4ccf 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -60,14 +60,20 @@ void BrowserClient::ShowDesktopNotification( int render_process_id, int render_view_id, bool worker) { - notification_presenter()->ShowNotification(params, render_process_id, render_view_id); + auto presenter = notification_presenter(); + if (!presenter) + return; + presenter->ShowNotification(params, render_process_id, render_view_id); } void BrowserClient::CancelDesktopNotification( int render_process_id, int render_view_id, int notification_id) { - notification_presenter()->CancelNotification(render_process_id, render_view_id, notification_id); + auto presenter = notification_presenter(); + if (!presenter) + return; + presenter->CancelNotification(render_process_id, render_view_id, notification_id); } } From 27d55031f44c9c55b3e37f37567de6c4938bde6d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 2 Jun 2013 00:23:59 +0800 Subject: [PATCH 0103/1195] Set file and data protocol handler. --- brightray/browser/url_request_context_getter.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 7c5c45111bb..83a986e495e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -19,6 +19,8 @@ #include "net/ssl/default_server_bound_cert_store.h" #include "net/ssl/server_bound_cert_service.h" #include "net/ssl/ssl_config_service_defaults.h" +#include "net/url_request/data_protocol_handler.h" +#include "net/url_request/file_protocol_handler.h" #include "net/url_request/static_http_user_agent_settings.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_storage.h" @@ -130,6 +132,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() DCHECK(set_protocol); } protocol_handlers_.clear(); + job_factory->SetProtocolHandler(chrome::kDataScheme, new net::DataProtocolHandler); + job_factory->SetProtocolHandler(chrome::kFileScheme, new net::FileProtocolHandler); storage_->set_job_factory(job_factory.release()); } From 4c9870e75333c720018e71c0ed3bea9b548217d5 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 4 Jun 2013 14:17:16 -0400 Subject: [PATCH 0104/1195] Fix debug assertion about performing IO on the UI thread We were querying the application's FILEVERSIONINFO every time we needed to figure out the path for storing BrowserContext data. Now we cache the path the first time we need it, which is during application initialization and before IO prohibitions begin. --- brightray/browser/browser_context.cc | 6 +++++- brightray/browser/browser_context.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index c8b923977d3..17ff9b2269c 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -72,9 +72,13 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::Prot } base::FilePath BrowserContext::GetPath() { + if (!path_.empty()) + return path_; + base::FilePath path; CHECK(PathService::Get(base::DIR_APP_DATA, &path)); - return path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); + path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); + return path_; } bool BrowserContext::IsOffTheRecord() const { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 47feccd042c..a83e016e437 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -46,6 +46,7 @@ private: virtual content::SpeechRecognitionPreferences* GetSpeechRecognitionPreferences() OVERRIDE; virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; + base::FilePath path_; scoped_ptr resource_context_; scoped_refptr url_request_getter_; scoped_ptr prefs_; From 9ad77c4a3803060cef8ec8f21db870075c550076 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 4 Jun 2013 14:31:37 -0400 Subject: [PATCH 0105/1195] Implement undocked dev tools on Windows DevToolsWindow represents a vanilla top-level window that shows the dev tools. It uses ui::WindowImpl to implement window functionality, which requires a newer libchromiumcontent which contains the necessary headers for using that class, and requires some modifications to brightray.gypi to make WTL's headers available. * vendor/libchromiumcontent 2f53a96...fc02d93 (4): > Export third_party/wtl/include headers > Export test_support_base.pdb and test_support_content.pdb > Fix linker errors with test_support_base on Windows > Fix linker errors with base_prefs_test_support on Windows --- brightray/brightray.gyp | 2 + brightray/brightray.gypi | 7 +++ brightray/browser/win/devtools_window.cc | 47 +++++++++++++++++++ brightray/browser/win/devtools_window.h | 36 ++++++++++++++ .../win/inspectable_web_contents_view_win.cc | 25 ++++++++++ .../win/inspectable_web_contents_view_win.h | 4 ++ brightray/vendor/libchromiumcontent | 2 +- 7 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 brightray/browser/win/devtools_window.cc create mode 100644 brightray/browser/win/devtools_window.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 2ac42272200..71616f36a50 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -50,6 +50,8 @@ 'browser/notification_presenter_mac.mm', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', + 'browser/win/devtools_window.cc', + 'browser/win/devtools_window.h', 'browser/win/inspectable_web_contents_view_win.cc', 'browser/win/inspectable_web_contents_view_win.h', 'common/application_info.h', diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 69513546df7..828fc55046d 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -171,6 +171,9 @@ 'conditions': [ ['OS=="win"', { 'target_defaults': { + 'include_dirs': [ + '<(libchromiumcontent_include_dir)/third_party/wtl/include', + ], 'defines': [ '_WIN32_WINNT=0x0602', 'WINVER=0x0602', @@ -182,6 +185,10 @@ 'CERT_CHAIN_PARA_HAS_EXTRA_FIELDS', 'WIN32_LEAN_AND_MEAN', '_ATL_NO_OPENGL', + '_SECURE_ATL', + ], + 'msvs_system_include_dirs': [ + '$(VSInstallDir)/VC/atlmfc/include', ], 'msvs_settings': { 'VCCLCompilerTool': { diff --git a/brightray/browser/win/devtools_window.cc b/brightray/browser/win/devtools_window.cc new file mode 100644 index 00000000000..8bed3e89f7d --- /dev/null +++ b/brightray/browser/win/devtools_window.cc @@ -0,0 +1,47 @@ +#include "browser/win/devtools_window.h" + +#include "browser/inspectable_web_contents_impl.h" +#include "browser/win/inspectable_web_contents_view_win.h" + +#include "content/public/browser/web_contents_view.h" +#include "ui/base/win/hidden_window.h" + +namespace brightray { + +DevToolsWindow* DevToolsWindow::Create(InspectableWebContentsViewWin* controller) { + return new DevToolsWindow(controller); +} + +DevToolsWindow::DevToolsWindow(InspectableWebContentsViewWin* controller) + : controller_(controller) { +} + +DevToolsWindow::~DevToolsWindow() { +} + +LRESULT DevToolsWindow::OnCreate(UINT, WPARAM, LPARAM, BOOL&) { + SetParent(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), hwnd()); + SetWindowText(hwnd(), L"Developer Tools"); + return 0; +} + +LRESULT DevToolsWindow::OnDestroy(UINT, WPARAM, LPARAM, BOOL&) { + SetParent(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), ui::GetHiddenWindow()); + delete this; + return 0; +} + +LRESULT DevToolsWindow::OnSize(UINT, WPARAM, LPARAM, BOOL&) { + RECT rect; + GetClientRect(hwnd(), &rect); + + SetWindowPos(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), + nullptr, + rect.left, rect.top, + rect.right - rect.left, rect.bottom - rect.top, + SWP_NOZORDER | SWP_SHOWWINDOW); + + return 0; +} + +} diff --git a/brightray/browser/win/devtools_window.h b/brightray/browser/win/devtools_window.h new file mode 100644 index 00000000000..7181ab8e4d3 --- /dev/null +++ b/brightray/browser/win/devtools_window.h @@ -0,0 +1,36 @@ +#ifndef BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ +#define BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ + +#include "base/memory/weak_ptr.h" +#include "ui/base/win/window_impl.h" + +namespace brightray { + +class InspectableWebContentsViewWin; + +class DevToolsWindow : public ui::WindowImpl, public base::SupportsWeakPtr { + public: + static DevToolsWindow* Create(InspectableWebContentsViewWin*); + + BEGIN_MSG_MAP_EX(DevToolsWindow) + MESSAGE_HANDLER(WM_CREATE, OnCreate) + MESSAGE_HANDLER(WM_DESTROY, OnDestroy) + MESSAGE_HANDLER(WM_SIZE, OnSize) + END_MSG_MAP() + + private: + DevToolsWindow(InspectableWebContentsViewWin*); + ~DevToolsWindow(); + + LRESULT OnCreate(UINT message, WPARAM, LPARAM, BOOL& handled); + LRESULT OnDestroy(UINT message, WPARAM, LPARAM, BOOL& handled); + LRESULT OnSize(UINT message, WPARAM, LPARAM, BOOL& handled); + + InspectableWebContentsViewWin* controller_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); +}; + +} + +#endif diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index deab04590c0..c6161286c23 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -1,11 +1,20 @@ #include "browser/win/inspectable_web_contents_view_win.h" +#include "browser/browser_client.h" #include "browser/inspectable_web_contents_impl.h" +#include "browser/win/devtools_window.h" #include "content/public/browser/web_contents_view.h" +#include "ui/base/win/hwnd_util.h" namespace brightray { +namespace { + +const int kWindowInset = 100; + +} + InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewWin(inspectable_web_contents); } @@ -15,6 +24,8 @@ InspectableWebContentsViewWin::InspectableWebContentsViewWin(InspectableWebConte } InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { + if (devtools_window_) + DestroyWindow(devtools_window_->hwnd()); } gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { @@ -22,9 +33,23 @@ gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { } void InspectableWebContentsViewWin::ShowDevTools() { + if (!devtools_window_) { + devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr(); + devtools_window_->Init(HWND_DESKTOP, gfx::Rect()); + } + + auto contents_view = inspectable_web_contents_->GetWebContents()->GetView(); + auto size = contents_view->GetContainerSize(); + size.Enlarge(-kWindowInset, -kWindowInset); + ui::CenterAndSizeWindow(contents_view->GetNativeView(), devtools_window_->hwnd(), size); + + ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL); } void InspectableWebContentsViewWin::CloseDevTools() { + if (!devtools_window_) + return; + SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); } bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index 801eb931360..8f5816fb4e7 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -4,9 +4,11 @@ #include "browser/inspectable_web_contents_view.h" #include "base/compiler_specific.h" +#include "base/memory/weak_ptr.h" namespace brightray { +class DevToolsWindow; class InspectableWebContentsImpl; class InspectableWebContentsViewWin : public InspectableWebContentsView { @@ -25,6 +27,8 @@ private: // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; + base::WeakPtr devtools_window_; + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewWin); }; diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 2f53a96fc66..fc02d9380a5 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 2f53a96fc665176d7e07b67bac6d861295587ce8 +Subproject commit fc02d9380a52ed648196ea6a0d9053483f233658 From 496b246405ed7c5ba142c71fd45c37ffdaa65087 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 6 Jun 2013 18:50:37 -0400 Subject: [PATCH 0106/1195] Give BrowserContext subclasses access to GetPath() --- brightray/browser/browser_context.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index a83e016e437..d814be5cdfc 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -28,12 +28,13 @@ protected: // Subclasses should override this to register custom preferences. virtual void RegisterPrefs(PrefRegistrySimple*) {} + virtual base::FilePath GetPath() OVERRIDE; + private: class ResourceContext; void RegisterInternalPrefs(PrefRegistrySimple*); - virtual base::FilePath GetPath() OVERRIDE; virtual bool IsOffTheRecord() const OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(int renderer_child_id); From 3d00cded271d1e09022122fe5c07437035b7f845 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 6 Jun 2013 18:50:55 -0400 Subject: [PATCH 0107/1195] Update to latest libchromiumcontent * vendor/libchromiumcontent fc02d93...f4f8a7e (4): > Include encryptor.lib and its symbols and headers in the distribution > Build encryptor.lib on Windows > Revert all changes before building if any unexpected files are modified > Export headers from cc/ --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index fc02d9380a5..f4f8a7ecad6 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit fc02d9380a52ed648196ea6a0d9053483f233658 +Subproject commit f4f8a7ecad6df079c54ca87cb4a3a0f4d6cf9771 From 5e807cffc87f0f90ddee67cf11ecdbea1f2075bb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 2 Jul 2013 15:12:34 +0800 Subject: [PATCH 0108/1195] Use abusolute path when linking to external libraries. Fixes #22. The ninja generator of gyp behaves strangely on the 'libraries' field of link settings, for example, specifying path to an external library works well on both xcodebuild and msvc generators, but the ninja generator would link to the wrong path (it can neither translate relative path correctly, nor convert the command line parameter to the '-lxxx' form). The only way to make all generators work on all platforms is to use abusolute paths for external libraries. --- brightray/brightray.gyp | 11 +++++++---- brightray/tools/brightray_source_root.py | 9 +++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 brightray/tools/brightray_source_root.py diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 71616f36a50..90759e731f3 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -2,6 +2,9 @@ 'includes': [ 'brightray.gypi', ], + 'variables': { + 'brightray_source_root': ' Date: Tue, 2 Jul 2013 10:07:23 -0400 Subject: [PATCH 0109/1195] Update libchromiumcontent to be based on Chrome 28 * vendor/libchromiumcontent f4f8a7e...929f9c9 (3): > Merge pull request #19 from brightray/chrome-28 > Merge pull request #18 from brightray/encryptor > Merge pull request #17 from brightray/cygwin --- brightray/common/content_client.cc | 2 +- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index fc294f45ec5..87cc07abfee 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -9,7 +9,7 @@ #include "base/stringprintf.h" #include "base/string_util.h" #include "ui/base/resource/resource_bundle.h" -#include "webkit/common/user_agent/user_agent_util.h" +#include "webkit/user_agent/user_agent_util.h" namespace brightray { diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index f4f8a7ecad6..929f9c9b38c 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit f4f8a7ecad6df079c54ca87cb4a3a0f4d6cf9771 +Subproject commit 929f9c9b38cb4f2069944873f4babe3b1bfaad0f From 8e0f5624dd4fee612603fced80f324eaa2c26a67 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jul 2013 11:58:49 +0800 Subject: [PATCH 0110/1195] Some headers are including SkMtrix.h, fix compilation errors for them. --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 90759e731f3..b91e1d9aed1 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -19,6 +19,8 @@ '..', '<(libchromiumcontent_include_dir)', '<(libchromiumcontent_include_dir)/third_party/skia/include/config', + # For SkMatrix.h. + '<(libchromiumcontent_include_dir)/third_party/skia/include/core', ], }, 'sources': [ From 29237e21ce5b687e2045c92b7adaf7a5d5df8dec Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 8 Jul 2013 12:17:48 -0400 Subject: [PATCH 0111/1195] Always build 32-bit in Xcode libchromiumcontent is 32-bit-only, so we need to match. --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 828fc55046d..7d4b1f42073 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -31,6 +31,7 @@ 'target_defaults': { 'xcode_settings': { 'ALWAYS_SEARCH_USER_PATHS': 'NO', + 'ARCHS': '$(ARCHS_STANDARD_32_BIT)', 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11', 'CLANG_CXX_LIBRARY': 'libstdc++', 'COMBINE_HIDPI_IMAGES': 'YES', From 09efd19d2f6dab1351c7b1da04970fa8cdfafa9a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 9 Jul 2013 07:48:17 -0400 Subject: [PATCH 0112/1195] Update to latest libchromiumcontent * vendor/libchromiumcontent 929f9c9...ee4cea0 (2): > Merge pull request #21 from brightray/ui_views > Include all headers from testing/ --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 929f9c9b38c..ee4cea0403a 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 929f9c9b38cb4f2069944873f4babe3b1bfaad0f +Subproject commit ee4cea0403a70d624ab5e37ec10c35ccb8b84b21 From 33b574b43446fc8bf45e300901f6b6bc0b15cc19 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 17 Jul 2013 10:21:33 -0400 Subject: [PATCH 0113/1195] Allow clients to supply their own NetworkDelegate implementation --- brightray/browser/browser_context.cc | 6 ++++++ brightray/browser/browser_context.h | 4 ++++ brightray/browser/network_delegate.h | 5 +++-- brightray/browser/url_request_context_getter.cc | 5 +++-- brightray/browser/url_request_context_getter.h | 6 ++++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 17ff9b2269c..42074e74ce3 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -5,6 +5,7 @@ #include "browser_context.h" #include "browser/inspectable_web_contents_impl.h" +#include "browser/network_delegate.h" #include "common/application_info.h" #include "base/files/file_path.h" @@ -66,11 +67,16 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::Prot GetPath(), content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::IO), content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::FILE), + CreateNetworkDelegate().Pass(), protocol_handlers); resource_context_->set_url_request_context_getter(url_request_getter_.get()); return url_request_getter_.get(); } +scoped_ptr BrowserContext::CreateNetworkDelegate() { + return make_scoped_ptr(new NetworkDelegate).Pass(); +} + base::FilePath BrowserContext::GetPath() { if (!path_.empty()) return path_; diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index d814be5cdfc..4307df0aa3b 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -13,6 +13,7 @@ class PrefService; namespace brightray { +class NetworkDelegate; class URLRequestContextGetter; class BrowserContext : public content::BrowserContext { @@ -28,6 +29,9 @@ protected: // Subclasses should override this to register custom preferences. virtual void RegisterPrefs(PrefRegistrySimple*) {} + // Subclasses should override this to provide a custom NetworkDelegate implementation. + virtual scoped_ptr CreateNetworkDelegate(); + virtual base::FilePath GetPath() OVERRIDE; private: diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 1d2645532f4..aff8e228856 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -10,11 +10,11 @@ namespace brightray { class NetworkDelegate : public net::NetworkDelegate { -public: + public: NetworkDelegate(); virtual ~NetworkDelegate(); -private: + protected: virtual int OnBeforeURLRequest(net::URLRequest* request, const net::CompletionCallback& callback, GURL* new_url) OVERRIDE; virtual int OnBeforeSendHeaders(net::URLRequest* request, const net::CompletionCallback& callback, net::HttpRequestHeaders* headers) OVERRIDE; virtual void OnSendHeaders(net::URLRequest* request, const net::HttpRequestHeaders& headers) OVERRIDE; @@ -33,6 +33,7 @@ private: virtual int OnBeforeSocketStreamConnect(net::SocketStream* stream, const net::CompletionCallback& callback) OVERRIDE; virtual void OnRequestWaitStateChange(const net::URLRequest& request, RequestWaitState state) OVERRIDE; + private: DISALLOW_COPY_AND_ASSIGN(NetworkDelegate); }; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 83a986e495e..e6d73a608f3 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -32,10 +32,12 @@ URLRequestContextGetter::URLRequestContextGetter( const base::FilePath& base_path, MessageLoop* io_loop, MessageLoop* file_loop, + scoped_ptr network_delegate, content::ProtocolHandlerMap* protocol_handlers) : base_path_(base_path), io_loop_(io_loop), - file_loop_(file_loop) { + file_loop_(file_loop), + network_delegate_(network_delegate.Pass()) { // Must first be created on the UI thread. DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); @@ -57,7 +59,6 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext()); - network_delegate_.reset(new NetworkDelegate); url_request_context_->set_network_delegate(network_delegate_.get()); storage_.reset( new net::URLRequestContextStorage(url_request_context_.get())); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 026778e4dc5..7d4efb6c00d 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -16,19 +16,21 @@ class MessageLoop; namespace net { class HostResolver; -class NetworkDelegate; class ProxyConfigService; class URLRequestContextStorage; } namespace brightray { +class NetworkDelegate; + class URLRequestContextGetter : public net::URLRequestContextGetter { public: URLRequestContextGetter( const base::FilePath& base_path, base::MessageLoop* io_loop, base::MessageLoop* file_loop, + scoped_ptr, content::ProtocolHandlerMap*); virtual ~URLRequestContextGetter(); @@ -43,7 +45,7 @@ private: base::MessageLoop* file_loop_; scoped_ptr proxy_config_service_; - scoped_ptr network_delegate_; + scoped_ptr network_delegate_; scoped_ptr storage_; scoped_ptr url_request_context_; content::ProtocolHandlerMap protocol_handlers_; From bacf11d53f9168d3eb2fdd4837c37381e4aaa551 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 17 Jul 2013 11:04:45 -0400 Subject: [PATCH 0114/1195] Rename the Helper process to Renderer/Plug-In Host/Utility as appropriate This matches Chrome. --- brightray/common/main_delegate.cc | 1 + brightray/common/main_delegate.h | 1 + brightray/common/main_delegate_mac.mm | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 5578fc7c3af..b58b2e9d72f 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -34,6 +34,7 @@ void MainDelegate::PreSandboxStartup() { #if defined(OS_MACOSX) OverrideChildProcessPath(); OverrideFrameworkBundlePath(); + SetProcessName(); #endif InitializeResourceBundle(); } diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index f5cbe88d4e8..ba99f5155f0 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -39,6 +39,7 @@ private: static base::FilePath GetResourcesPakFilePath(); static void OverrideChildProcessPath(); static void OverrideFrameworkBundlePath(); + static void SetProcessName(); #endif scoped_ptr content_client_; diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index aa7bf0f4625..c9aaecbede3 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -9,9 +9,14 @@ #include "common/mac/foundation_util.h" #include "common/mac/main_application_bundle.h" +#include "base/command_line.h" #include "base/mac/bundle_locations.h" +#include "base/mac/mac_util.h" #include "base/path_service.h" +#include "base/stringprintf.h" +#include "base/strings/sys_string_conversions.h" #include "content/public/common/content_paths.h" +#include "content/public/common/content_switches.h" namespace brightray { @@ -43,4 +48,21 @@ void MainDelegate::OverrideChildProcessPath() { PathService::Override(content::CHILD_PROCESS_EXE, helper_path); } +void MainDelegate::SetProcessName() { + const auto& command_line = *CommandLine::ForCurrentProcess(); + auto process_type = command_line.GetSwitchValueASCII(switches::kProcessType); + std::string suffix; + if (process_type == switches::kRendererProcess) + suffix = "Renderer"; + else if (process_type == switches::kPluginProcess || process_type == switches::kPpapiPluginProcess) + suffix = "Plug-In Host"; + else if (process_type == switches::kUtilityProcess) + suffix = "Utility"; + else + return; + + auto name = base::SysUTF8ToNSString(base::StringPrintf("%s %s", GetApplicationName().c_str(), suffix.c_str())); + base::mac::SetProcessName(base::mac::NSToCFCast(name)); +} + } From 56b904947bf4be0b3ca80cd65c137a84595f83be Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 24 Jul 2013 07:56:55 -0400 Subject: [PATCH 0115/1195] Avoid a crash when starting a download by disallowing downloads Chromium crashes when starting a download if a content::DownloadManagerDelegate is not provided. We now provide a default implementation of content::DownloadManagerDelegate which disallows all downloads. --- brightray/brightray.gyp | 2 ++ brightray/browser/browser_context.cc | 5 ++++- brightray/browser/browser_context.h | 2 ++ .../browser/download_manager_delegate.cc | 11 +++++++++++ brightray/browser/download_manager_delegate.h | 19 +++++++++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 brightray/browser/download_manager_delegate.cc create mode 100644 brightray/browser/download_manager_delegate.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b91e1d9aed1..d6ba7960b8b 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -36,6 +36,8 @@ 'browser/default_web_contents_delegate_mac.mm', 'browser/devtools_delegate.cc', 'browser/devtools_delegate.h', + 'browser/download_manager_delegate.cc', + 'browser/download_manager_delegate.h', 'browser/inspectable_web_contents.cc', 'browser/inspectable_web_contents.h', 'browser/inspectable_web_contents_impl.cc', diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 42074e74ce3..494f08f6403 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -4,6 +4,7 @@ #include "browser_context.h" +#include "browser/download_manager_delegate.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/network_delegate.h" #include "common/application_info.h" @@ -116,7 +117,9 @@ content::ResourceContext* BrowserContext::GetResourceContext() { } content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() { - return nullptr; + if (!download_manager_delegate_) + download_manager_delegate_.reset(new DownloadManagerDelegate); + return download_manager_delegate_.get(); } content::GeolocationPermissionContext* BrowserContext::GetGeolocationPermissionContext() { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 4307df0aa3b..85f00148c9c 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -13,6 +13,7 @@ class PrefService; namespace brightray { +class DownloadManagerDelegate; class NetworkDelegate; class URLRequestContextGetter; @@ -55,6 +56,7 @@ private: scoped_ptr resource_context_; scoped_refptr url_request_getter_; scoped_ptr prefs_; + scoped_ptr download_manager_delegate_; DISALLOW_COPY_AND_ASSIGN(BrowserContext); }; diff --git a/brightray/browser/download_manager_delegate.cc b/brightray/browser/download_manager_delegate.cc new file mode 100644 index 00000000000..f241f8441bc --- /dev/null +++ b/brightray/browser/download_manager_delegate.cc @@ -0,0 +1,11 @@ +#include "browser/download_manager_delegate.h" + +namespace brightray { + +DownloadManagerDelegate::DownloadManagerDelegate() { +} + +DownloadManagerDelegate::~DownloadManagerDelegate() { +} + +} diff --git a/brightray/browser/download_manager_delegate.h b/brightray/browser/download_manager_delegate.h new file mode 100644 index 00000000000..c25d2e7a16a --- /dev/null +++ b/brightray/browser/download_manager_delegate.h @@ -0,0 +1,19 @@ +#ifndef BRIGHTRAY_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ +#define BRIGHTRAY_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ + +#include "content/public/browser/download_manager_delegate.h" + +namespace brightray { + +class DownloadManagerDelegate : public content::DownloadManagerDelegate { + public: + DownloadManagerDelegate(); + ~DownloadManagerDelegate(); + + private: + DISALLOW_COPY_AND_ASSIGN(DownloadManagerDelegate); +}; + +} + +#endif From d32a2fbc97e412e13efd392bf2880280b56c989f Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 25 Jul 2013 12:22:58 -0400 Subject: [PATCH 0116/1195] Update libchromiumcontent to get ICU headers * vendor/libchromiumcontent ee4cea0...33472d4 (5): > Export ICU headers > When `gclient sync` fails, revert all local changes and try again > Merge pull request #23 from brightray/chromiumviews_pdb > Merge pull request #22 from brightray/cygwin2 > Update to Chrome 28.0.1500.71 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index ee4cea0403a..33472d4dfec 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit ee4cea0403a70d624ab5e37ec10c35ccb8b84b21 +Subproject commit 33472d4dfeca556ce68c126cc71cd1e3f830de8a From bd648ce58f9f66374f0e94d086b752b99dd45ba0 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 25 Jul 2013 12:31:41 -0400 Subject: [PATCH 0117/1195] Put ICU headers on the include path for embedders --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index d6ba7960b8b..85174cab872 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -21,6 +21,7 @@ '<(libchromiumcontent_include_dir)/third_party/skia/include/config', # For SkMatrix.h. '<(libchromiumcontent_include_dir)/third_party/skia/include/core', + '<(libchromiumcontent_include_dir)/third_party/icu/public/common', ], }, 'sources': [ From 259533504509cd91b3be355f1da12228b62cbb66 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 31 Jul 2013 11:08:45 -0700 Subject: [PATCH 0118/1195] Enable navigator.webkitGetUserMedia() The code came from chrome/browser/media, but was simplified to remove dependencies on other parts of chrome/ and to always allow the media stream request. --- brightray/brightray.gyp | 4 + brightray/browser/browser_client.cc | 13 +- brightray/browser/browser_client.h | 1 + .../browser/default_web_contents_delegate.cc | 10 ++ .../browser/default_web_contents_delegate.h | 3 + .../media/media_capture_devices_dispatcher.cc | 161 ++++++++++++++++++ .../media/media_capture_devices_dispatcher.h | 82 +++++++++ .../media/media_stream_devices_controller.cc | 86 ++++++++++ .../media/media_stream_devices_controller.h | 46 +++++ 9 files changed, 402 insertions(+), 4 deletions(-) create mode 100644 brightray/browser/media/media_capture_devices_dispatcher.cc create mode 100644 brightray/browser/media/media_capture_devices_dispatcher.h create mode 100644 brightray/browser/media/media_stream_devices_controller.cc create mode 100644 brightray/browser/media/media_stream_devices_controller.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 85174cab872..b576b273ec7 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -51,6 +51,10 @@ 'browser/mac/bry_inspectable_web_contents_view.h', 'browser/mac/bry_inspectable_web_contents_view.mm', 'browser/mac/bry_inspectable_web_contents_view_private.h', + 'browser/media/media_capture_devices_dispatcher.cc', + 'browser/media/media_capture_devices_dispatcher.h', + 'browser/media/media_stream_devices_controller.cc', + 'browser/media/media_stream_devices_controller.h', 'browser/network_delegate.cc', 'browser/network_delegate.h', 'browser/notification_presenter.h', diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index a42fcea4ccf..1c19f622ef0 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include "browser_client.h" +#include "browser/browser_client.h" -#include "browser_context.h" -#include "browser_main_parts.h" -#include "notification_presenter.h" +#include "browser/browser_context.h" +#include "browser/browser_main_parts.h" +#include "browser/media/media_capture_devices_dispatcher.h" +#include "browser/notification_presenter.h" namespace brightray { @@ -76,4 +77,8 @@ void BrowserClient::CancelDesktopNotification( presenter->CancelNotification(render_process_id, render_view_id, notification_id); } +content::MediaObserver* BrowserClient::GetMediaObserver() { + return MediaCaptureDevicesDispatcher::GetInstance(); +} + } diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index cb8143b71c9..f5bc9d618fe 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -44,6 +44,7 @@ private: int render_process_id, int render_view_id, int notification_id) OVERRIDE; + virtual content::MediaObserver* GetMediaObserver() OVERRIDE; BrowserMainParts* browser_main_parts_; scoped_ptr notification_presenter_; diff --git a/brightray/browser/default_web_contents_delegate.cc b/brightray/browser/default_web_contents_delegate.cc index 967881efb7a..f4e08b84098 100644 --- a/brightray/browser/default_web_contents_delegate.cc +++ b/brightray/browser/default_web_contents_delegate.cc @@ -1,5 +1,7 @@ #include "browser/default_web_contents_delegate.h" +#include "browser/media/media_stream_devices_controller.h" + namespace brightray { DefaultWebContentsDelegate::DefaultWebContentsDelegate() { @@ -8,4 +10,12 @@ DefaultWebContentsDelegate::DefaultWebContentsDelegate() { DefaultWebContentsDelegate::~DefaultWebContentsDelegate() { } +void DefaultWebContentsDelegate::RequestMediaAccessPermission( + content::WebContents*, + const content::MediaStreamRequest& request, + const content::MediaResponseCallback& callback) { + MediaStreamDevicesController controller(request, callback); + controller.TakeAction(); +} + } diff --git a/brightray/browser/default_web_contents_delegate.h b/brightray/browser/default_web_contents_delegate.h index c6ce2ee23ff..b4dabdd03b8 100644 --- a/brightray/browser/default_web_contents_delegate.h +++ b/brightray/browser/default_web_contents_delegate.h @@ -13,6 +13,9 @@ public: ~DefaultWebContentsDelegate(); protected: + virtual void RequestMediaAccessPermission(content::WebContents*, + const content::MediaStreamRequest&, + const content::MediaResponseCallback&) OVERRIDE; #if defined(OS_MACOSX) virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; #endif diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc new file mode 100644 index 00000000000..3c15841c164 --- /dev/null +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -0,0 +1,161 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/media/media_capture_devices_dispatcher.h" + +#include "base/prefs/pref_service.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/media_devices_monitor.h" +#include "content/public/common/media_stream_request.h" + +namespace brightray { + +using content::BrowserThread; +using content::MediaStreamDevices; + +namespace { + +const content::MediaStreamDevice* FindDefaultDeviceWithId( + const content::MediaStreamDevices& devices, + const std::string& device_id) { + if (devices.empty()) + return NULL; + + content::MediaStreamDevices::const_iterator iter = devices.begin(); + for (; iter != devices.end(); ++iter) { + if (iter->id == device_id) { + return &(*iter); + } + } + + return &(*devices.begin()); +}; + +} // namespace + + +MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { + return Singleton::get(); +} + +MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() + : devices_enumerated_(false) {} + +MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {} + +const MediaStreamDevices& +MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (!devices_enumerated_) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&content::EnsureMonitorCaptureDevices)); + devices_enumerated_ = true; + } + return audio_devices_; +} + +const MediaStreamDevices& +MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + if (!devices_enumerated_) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&content::EnsureMonitorCaptureDevices)); + devices_enumerated_ = true; + } + return video_devices_; +} + +void MediaCaptureDevicesDispatcher::GetRequestedDevice( + const std::string& requested_device_id, + bool audio, + bool video, + content::MediaStreamDevices* devices) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + DCHECK(audio || video); + + if (audio) { + const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices(); + const content::MediaStreamDevice* const device = + FindDefaultDeviceWithId(audio_devices, requested_device_id); + if (device) + devices->push_back(*device); + } + if (video) { + const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices(); + const content::MediaStreamDevice* const device = + FindDefaultDeviceWithId(video_devices, requested_device_id); + if (device) + devices->push_back(*device); + } +} + +void MediaCaptureDevicesDispatcher::GetDefaultDevices( + bool audio, + bool video, + content::MediaStreamDevices* devices) { + if (audio) { + GetRequestedDevice(std::string(), true, false, devices); + } + + if (video) { + GetRequestedDevice(std::string(), false, true, devices); + } +} + +void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged( + const content::MediaStreamDevices& devices) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread, + base::Unretained(this), devices)); +} + +void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged( + const content::MediaStreamDevices& devices) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread, + base::Unretained(this), devices)); +} + +void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( + int render_process_id, + int render_view_id, + const content::MediaStreamDevice& device, + content::MediaRequestState state) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind( + &MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread, + base::Unretained(this), render_process_id, render_view_id, device, + state)); +} + +void MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread( + const content::MediaStreamDevices& devices) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + devices_enumerated_ = true; + audio_devices_ = devices; +} + +void MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread( + const content::MediaStreamDevices& devices) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + devices_enumerated_ = true; + video_devices_ = devices; +} + +void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread( + int render_process_id, + int render_view_id, + const content::MediaStreamDevice& device, + content::MediaRequestState state) { +} + +} diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h new file mode 100644 index 00000000000..6edb12b5cf0 --- /dev/null +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -0,0 +1,82 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ +#define BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ + +#include "base/callback.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/singleton.h" +#include "base/observer_list.h" +#include "content/public/browser/media_observer.h" +#include "content/public/common/media_stream_request.h" + +namespace brightray { + +// This singleton is used to receive updates about media events from the content +// layer. +class MediaCaptureDevicesDispatcher : public content::MediaObserver { + public: + static MediaCaptureDevicesDispatcher* GetInstance(); + + // Helper for picking the device that was requested for an OpenDevice request. + // If the device requested is not available it will revert to using the first + // available one instead or will return an empty list if no devices of the + // requested kind are present. + void GetRequestedDevice(const std::string& requested_device_id, + bool audio, + bool video, + content::MediaStreamDevices* devices); + void GetDefaultDevices(bool audio, + bool video, + content::MediaStreamDevices* devices); + + const content::MediaStreamDevices& GetAudioCaptureDevices(); + const content::MediaStreamDevices& GetVideoCaptureDevices(); + + // Overridden from content::MediaObserver: + virtual void OnAudioCaptureDevicesChanged( + const content::MediaStreamDevices& devices) OVERRIDE; + virtual void OnVideoCaptureDevicesChanged( + const content::MediaStreamDevices& devices) OVERRIDE; + virtual void OnMediaRequestStateChanged( + int render_process_id, + int render_view_id, + const content::MediaStreamDevice& device, + content::MediaRequestState state) OVERRIDE; + virtual void OnAudioStreamPlayingChanged( + int render_process_id, + int render_view_id, + int stream_id, + bool playing) OVERRIDE {} + + private: + friend struct DefaultSingletonTraits; + + MediaCaptureDevicesDispatcher(); + virtual ~MediaCaptureDevicesDispatcher(); + + // Called by the MediaObserver() functions, executed on UI thread. + void UpdateAudioDevicesOnUIThread(const content::MediaStreamDevices& devices); + void UpdateVideoDevicesOnUIThread(const content::MediaStreamDevices& devices); + void UpdateMediaRequestStateOnUIThread( + int render_process_id, + int render_view_id, + const content::MediaStreamDevice& device, + content::MediaRequestState state); + + // A list of cached audio capture devices. + content::MediaStreamDevices audio_devices_; + + // A list of cached video capture devices. + content::MediaStreamDevices video_devices_; + + // Flag to indicate if device enumeration has been done/doing. + // Only accessed on UI thread. + bool devices_enumerated_; +}; + +} + +#endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc new file mode 100644 index 00000000000..0aca4805fea --- /dev/null +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -0,0 +1,86 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/media/media_stream_devices_controller.h" + +#include "base/values.h" +#include "browser/media/media_capture_devices_dispatcher.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/common/media_stream_request.h" + +namespace brightray { + +namespace { + +bool HasAnyAvailableDevice() { + const content::MediaStreamDevices& audio_devices = + MediaCaptureDevicesDispatcher::GetInstance()->GetAudioCaptureDevices(); + const content::MediaStreamDevices& video_devices = + MediaCaptureDevicesDispatcher::GetInstance()->GetVideoCaptureDevices(); + + return !audio_devices.empty() || !video_devices.empty(); +}; + +} // namespace + +MediaStreamDevicesController::MediaStreamDevicesController( + const content::MediaStreamRequest& request, + const content::MediaResponseCallback& callback) + : request_(request), + callback_(callback), + microphone_requested_( + request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE), + webcam_requested_( + request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { +} + +MediaStreamDevicesController::~MediaStreamDevicesController() {} + +bool MediaStreamDevicesController::TakeAction() { + // Deny the request if there is no device attached to the OS. + if (!HasAnyAvailableDevice()) { + Deny(); + return true; + } + + Accept(); + return true; +} + +void MediaStreamDevicesController::Accept() { + // Get the default devices for the request. + content::MediaStreamDevices devices; + if (microphone_requested_ || webcam_requested_) { + switch (request_.request_type) { + case content::MEDIA_OPEN_DEVICE: + // For open device request pick the desired device or fall back to the + // first available of the given type. + MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedDevice( + request_.requested_device_id, + microphone_requested_, + webcam_requested_, + &devices); + break; + case content::MEDIA_DEVICE_ACCESS: + case content::MEDIA_GENERATE_STREAM: + case content::MEDIA_ENUMERATE_DEVICES: + // Get the default devices for the request. + MediaCaptureDevicesDispatcher::GetInstance()-> + GetDefaultDevices(microphone_requested_, + webcam_requested_, + &devices); + break; + } + } + + LOG(ERROR) << "Accept"; + callback_.Run(devices, scoped_ptr()); +} + +void MediaStreamDevicesController::Deny() { + callback_.Run(content::MediaStreamDevices(), + scoped_ptr()); +} + +} // namespace atom diff --git a/brightray/browser/media/media_stream_devices_controller.h b/brightray/browser/media/media_stream_devices_controller.h new file mode 100644 index 00000000000..071fa499144 --- /dev/null +++ b/brightray/browser/media/media_stream_devices_controller.h @@ -0,0 +1,46 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ +#define BRIGHTRAY_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ + +#include "content/public/browser/web_contents_delegate.h" + +namespace brightray { + +class MediaStreamDevicesController { + public: + MediaStreamDevicesController(const content::MediaStreamRequest& request, + const content::MediaResponseCallback& callback); + + virtual ~MediaStreamDevicesController(); + + // Public method to be called before creating the MediaStreamInfoBarDelegate. + // This function will check the content settings exceptions and take the + // corresponding action on exception which matches the request. + bool TakeAction(); + + // Public methods to be called by MediaStreamInfoBarDelegate; + bool has_audio() const { return microphone_requested_; } + bool has_video() const { return webcam_requested_; } + void Accept(); + void Deny(); + + private: + // The original request for access to devices. + const content::MediaStreamRequest request_; + + // The callback that needs to be Run to notify WebRTC of whether access to + // audio/video devices was granted or not. + content::MediaResponseCallback callback_; + + bool microphone_requested_; + bool webcam_requested_; + + DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); +}; + +} // namespace atom + +#endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ From c2623d2bdcfbca1a9f3a7d4a86d1c9fae16905aa Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 31 Jul 2013 11:52:21 -0700 Subject: [PATCH 0119/1195] Fix typos --- brightray/browser/media/media_stream_devices_controller.cc | 2 +- brightray/browser/media/media_stream_devices_controller.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index 0aca4805fea..ea53c20fd29 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -83,4 +83,4 @@ void MediaStreamDevicesController::Deny() { scoped_ptr()); } -} // namespace atom +} // namespace brightray diff --git a/brightray/browser/media/media_stream_devices_controller.h b/brightray/browser/media/media_stream_devices_controller.h index 071fa499144..bcf4a0f0049 100644 --- a/brightray/browser/media/media_stream_devices_controller.h +++ b/brightray/browser/media/media_stream_devices_controller.h @@ -41,6 +41,6 @@ class MediaStreamDevicesController { DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); }; -} // namespace atom +} // namespace brightray #endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ From a61fa01c5df9d739c410e2be54e81cbc54926873 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 31 Jul 2013 16:27:00 -0700 Subject: [PATCH 0120/1195] Update libchromiumcontent to get basic Linux support * vendor/libchromiumcontent 33472d4...be71317 (4): > Merge pull request #24 from brightray/linux > Fix gyp syntax > Fix Release linker error on Linux > Make sure we always apply patches in alphabetical order --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 33472d4dfec..be713176cce 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 33472d4dfeca556ce68c126cc71cd1e3f830de8a +Subproject commit be713176cce155601c7ec79f4129f4c7fceae495 From 684180153893af2077adeda399e1a82facecd910 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 6 Aug 2013 16:36:58 -0400 Subject: [PATCH 0121/1195] Spew less when script/bootstrap fails --- brightray/script/bootstrap | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index 57e28b33997..0325f49b0c3 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -14,8 +14,8 @@ DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download') def main(): args = parse_args() - update_submodules() - download_libchromiumcontent(args.url) + return (update_submodules() or + download_libchromiumcontent(args.url)) def parse_args(): @@ -27,17 +27,17 @@ def parse_args(): def update_submodules(): - subprocess.check_call(['git', 'submodule', 'sync', '--quiet']) - subprocess.check_call(['git', 'submodule', 'update', '--init', - '--recursive']) + return (subprocess.call(['git', 'submodule', 'sync', '--quiet']) or + subprocess.call(['git', 'submodule', 'update', '--init', + '--recursive'])) def download_libchromiumcontent(url): mkdir_p(DOWNLOAD_DIR) download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', 'download') - subprocess.check_call([sys.executable, download, '-f', url, - os.path.join(DOWNLOAD_DIR, 'libchromiumcontent')]) + return subprocess.call([sys.executable, download, '-f', url, + os.path.join(DOWNLOAD_DIR, 'libchromiumcontent')]) def mkdir_p(path): From af20c555194573f55d5b910009daf03679c68aec Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 6 Aug 2013 16:41:58 -0400 Subject: [PATCH 0122/1195] Spew less when script/cibuild fails --- brightray/script/cibuild | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/brightray/script/cibuild b/brightray/script/cibuild index 2ca4394f31c..318331ffb3b 100755 --- a/brightray/script/cibuild +++ b/brightray/script/cibuild @@ -16,8 +16,9 @@ def main(): return 'Error: Can\'t find {0}'.format(S3_CREDENTIALS_FILE) copy_to_environment(S3_CREDENTIALS_FILE) - run_script('bootstrap', 'https://{0}.s3.amazonaws.com/libchromiumcontent'.format(os.environ['JANKY_ARTIFACTS_S3_BUCKET'])) - run_script('build') + url = 'https://{0}.s3.amazonaws.com/libchromiumcontent'.format(os.environ['JANKY_ARTIFACTS_S3_BUCKET']) + return (run_script('bootstrap', url) or + run_script('build')) def copy_to_environment(credentials_file): @@ -32,7 +33,7 @@ def run_script(script, *args): script = os.path.join('script', script) sys.stderr.write('+ {0}\n'.format(script)) sys.stderr.flush() - subprocess.check_call([sys.executable, script] + list(args)) + return subprocess.call([sys.executable, script] + list(args)) if __name__ == '__main__': From efad174995b092932152b2222d80c88890501c1a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 6 Aug 2013 16:43:21 -0400 Subject: [PATCH 0123/1195] Update libchromiumcontent to get better Linux support * vendor/libchromiumcontent be71317...5ffcb39 (2): > Delete commented-out code in script/download > Teach script/download about Linux --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index be713176cce..5ffcb396d64 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit be713176cce155601c7ec79f4129f4c7fceae495 +Subproject commit 5ffcb396d64df97a2d0220101e1e52598a661fc8 From b596adc23770f676c1b3ffbf566491e556a881f2 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 6 Aug 2013 16:49:59 -0400 Subject: [PATCH 0124/1195] Start teaching script/build about Linux --- brightray/script/build | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/brightray/script/build b/brightray/script/build index 6463d9d1d90..b308e183787 100755 --- a/brightray/script/build +++ b/brightray/script/build @@ -7,9 +7,8 @@ import sys SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) GYP = { - 'darwin': 'gyp', - 'win32': 'gyp.bat', -}[sys.platform] + 'win32': 'gyp.bat', +}.get(sys.platform, 'gyp') def main(): From 3076781c8a0d9ad5efb2b497e5a1911bb8645c74 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 6 Aug 2013 17:25:07 -0400 Subject: [PATCH 0125/1195] Build using make on Linux --- brightray/script/build | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/brightray/script/build b/brightray/script/build index b308e183787..8e155d37fa6 100755 --- a/brightray/script/build +++ b/brightray/script/build @@ -13,22 +13,22 @@ GYP = { def main(): os.chdir(SOURCE_ROOT) - run_gyp() - build() + return (run_gyp() or build()) def run_gyp(): - subprocess.check_call([GYP, '--depth', '.', 'brightray.gyp']) + return subprocess.call([GYP, '--depth', '.', 'brightray.gyp']) def build(): if sys.platform == 'darwin': - subprocess.check_call(['xcodebuild']) - return + return subprocess.call(['xcodebuild']) + if sys.platform == 'linux2': + return subprocess.call(['make']) assert sys.platform == 'win32', sys.platform msbuild = os.path.join(os.environ['windir'], 'Microsoft.NET', 'Framework', 'v4.0.30319', 'MSBuild.exe') - subprocess.check_call([msbuild, 'brightray.sln']) + return subprocess.call([msbuild, 'brightray.sln']) if __name__ == '__main__': From d27a984378d5242d50f8501e55d027061b9d1055 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 6 Aug 2013 17:29:08 -0400 Subject: [PATCH 0126/1195] Define USE_X11 on Linux --- brightray/brightray.gypi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 7d4b1f42073..a8cb1ea556d 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -73,6 +73,13 @@ ], }, }, + 'conditions': [ + ['OS not in ["mac", "win"]', { + 'defines': [ + 'USE_X11', + ], + }], + ], }, 'Debug': { 'inherit_from': [ From 7f3afbaf3d41efecf063fdb0477bd90645aba43f Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 14 Aug 2013 07:14:25 -0400 Subject: [PATCH 0127/1195] Force building with Clang on Linux to get C++11 support --- brightray/brightray.gypi | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index a8cb1ea556d..0fe893d80ee 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -177,6 +177,16 @@ ], }, 'conditions': [ + ['OS=="linux"', { + 'make_global_settings': [ + ['CC', '/usr/bin/clang'], + ['CXX', '/usr/bin/clang++'], + ['LINK', '$(CXX)'], + ['CC.host', '$(CC)'], + ['CXX.host', '$(CXX)'], + ['LINK.host', '$(LINK)'], + ], + }], ['OS=="win"', { 'target_defaults': { 'include_dirs': [ From 22ea2073df6dd3434c90de126cadd159e6638bec Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 14 Aug 2013 07:58:36 -0400 Subject: [PATCH 0128/1195] Compile as C++11 on Linux --- brightray/brightray.gypi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 0fe893d80ee..ad18976fd3f 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -174,6 +174,11 @@ ['exclude', '_win\.(cc|h)$'], ], }], + ['OS=="linux"', { + 'cflags_cc': [ + '-std=gnu++11', + ], + }], ], }, 'conditions': [ From 9638e3956f7e48596f5e9acdd15189e3647aa11c Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 14 Aug 2013 08:08:59 -0400 Subject: [PATCH 0129/1195] Don't use base::DIR_APP_DATA on Linux It doesn't exist. Instead, match content_shell by putting application-specific data in $XDG_CONFIG_HOME or ~/.config. --- brightray/browser/browser_context.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 494f08f6403..31c00b8d6aa 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -9,6 +9,7 @@ #include "browser/network_delegate.h" #include "common/application_info.h" +#include "base/environment.h" #include "base/files/file_path.h" #include "base/path_service.h" #include "base/prefs/json_pref_store.h" @@ -20,6 +21,10 @@ #include "content/public/browser/storage_partition.h" #include "url_request_context_getter.h" +#if defined(OS_LINUX) +#include "base/nix/xdg_util.h" +#endif + namespace brightray { class BrowserContext::ResourceContext : public content::ResourceContext { @@ -83,7 +88,15 @@ base::FilePath BrowserContext::GetPath() { return path_; base::FilePath path; +#if defined(OS_LINUX) + scoped_ptr env(base::Environment::Create()); + path = base::nix::GetXDGDirectory(env.get(), + base::nix::kXdgConfigHomeEnvVar, + base::nix::kDotConfigDir); +#else CHECK(PathService::Get(base::DIR_APP_DATA, &path)); +#endif + path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); return path_; } From 1161da6527481477df3be38344f0ac42da30d9ab Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 14 Aug 2013 08:17:52 -0400 Subject: [PATCH 0130/1195] Mention that Clang 3.0 is needed on Linux --- brightray/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/README.md b/brightray/README.md index ad939344c4d..8882bae914b 100644 --- a/brightray/README.md +++ b/brightray/README.md @@ -15,6 +15,8 @@ sample application written using Brightray. * Python 2.7 * gyp +* Linux: + * Clang 3.0 * Mac: * Xcode * Windows: From 710d0fc6c5d97557bfbb7734126a9a2bf485db22 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 15 Aug 2013 16:07:14 -0400 Subject: [PATCH 0131/1195] Make overriding BrowserContext::RegisterPrefs actually work We were calling it before derived classes' vtables were set up. Now we wait to call it until the BrowserContext is fully constructed. --- brightray/browser/browser_context.cc | 3 +++ brightray/browser/browser_context.h | 2 ++ brightray/browser/browser_main_parts.cc | 1 + 3 files changed, 6 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 31c00b8d6aa..3ade3b1c51a 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -48,6 +48,9 @@ private: }; BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { +} + +void BrowserContext::Initialize() { auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); PrefServiceBuilder builder; builder.WithUserFilePrefs(prefs_path, diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 85f00148c9c..ec3f1f6e5a2 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -22,6 +22,8 @@ public: BrowserContext(); ~BrowserContext(); + void Initialize(); + net::URLRequestContextGetter* CreateRequestContext(content::ProtocolHandlerMap*); PrefService* prefs() { return prefs_.get(); } diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 04e67f24fb1..bb435057c05 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -22,6 +22,7 @@ BrowserMainParts::~BrowserMainParts() { void BrowserMainParts::PreMainMessageLoopRun() { browser_context_.reset(CreateBrowserContext()); + browser_context_->Initialize(); // These two objects are owned by devtools_http_handler_. auto delegate = new DevToolsDelegate; From f17f9d932c85c44e3349d58bc28f623ee8771dd8 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 Aug 2013 07:48:37 -0400 Subject: [PATCH 0132/1195] Include gyp as a submodule This makes it so you don't have to install gyp on your system before you can build. --- brightray/.gitmodules | 3 +++ brightray/README.md | 1 - brightray/script/build | 6 ++---- brightray/vendor/gyp | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) create mode 160000 brightray/vendor/gyp diff --git a/brightray/.gitmodules b/brightray/.gitmodules index b5a3d92f902..1e27bc6b5a2 100644 --- a/brightray/.gitmodules +++ b/brightray/.gitmodules @@ -1,3 +1,6 @@ [submodule "vendor/libchromiumcontent"] path = vendor/libchromiumcontent url = https://github.com/brightray/libchromiumcontent +[submodule "vendor/gyp"] + path = vendor/gyp + url = https://github.com/svn2github/gyp diff --git a/brightray/README.md b/brightray/README.md index 8882bae914b..deac3f13e71 100644 --- a/brightray/README.md +++ b/brightray/README.md @@ -14,7 +14,6 @@ sample application written using Brightray. ### Prerequisites * Python 2.7 -* gyp * Linux: * Clang 3.0 * Mac: diff --git a/brightray/script/build b/brightray/script/build index 8e155d37fa6..b13f892b64f 100755 --- a/brightray/script/build +++ b/brightray/script/build @@ -6,9 +6,7 @@ import sys SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) -GYP = { - 'win32': 'gyp.bat', -}.get(sys.platform, 'gyp') +GYP = os.path.join(SOURCE_ROOT, 'vendor', 'gyp', 'gyp_main.py') def main(): @@ -17,7 +15,7 @@ def main(): def run_gyp(): - return subprocess.call([GYP, '--depth', '.', 'brightray.gyp']) + return subprocess.call([sys.executable, GYP, '--depth', '.', 'brightray.gyp']) def build(): diff --git a/brightray/vendor/gyp b/brightray/vendor/gyp new file mode 160000 index 00000000000..6633baab29b --- /dev/null +++ b/brightray/vendor/gyp @@ -0,0 +1 @@ +Subproject commit 6633baab29b60f27e3dca607ffbef689ccdd82b8 From 7dd1b8195f04dac3104401308692774fe8285a33 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 Aug 2013 16:56:05 -0400 Subject: [PATCH 0133/1195] Update libchromiumcontent to Chrome 29 * vendor/libchromiumcontent 5ffcb39...ccec3a4 (2): > Merge pull request #25 from brightray/29.0.1547.57 > Switch back to using s3put on Linux --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 5ffcb396d64..ccec3a4031f 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 5ffcb396d64df97a2d0220101e1e52598a661fc8 +Subproject commit ccec3a4031fa79d61f4199d99e477813d2d72a5a From 4946ec9081ca81ab7febb070a131d0eb0059ee57 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 Aug 2013 16:56:30 -0400 Subject: [PATCH 0134/1195] Update for utf_string_conversions.h move in Chrome 29 --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 7f694ad54ff..840712c86a2 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -13,7 +13,7 @@ #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/stringprintf.h" -#include "base/utf_string_conversions.h" +#include "base/strings/utf_string_conversions.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_http_handler.h" From 7d3f371b517232b06dbdd1283358884c8512ec1a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 Aug 2013 16:56:41 -0400 Subject: [PATCH 0135/1195] Update for move of MessageLoop into base namespace --- brightray/browser/url_request_context_getter.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index e6d73a608f3..47eb355aec7 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -30,8 +30,8 @@ namespace brightray { URLRequestContextGetter::URLRequestContextGetter( const base::FilePath& base_path, - MessageLoop* io_loop, - MessageLoop* file_loop, + base::MessageLoop* io_loop, + base::MessageLoop* file_loop, scoped_ptr network_delegate, content::ProtocolHandlerMap* protocol_handlers) : base_path_(base_path), From 2c030a419d511c1003776e3a4d2870eddf869b86 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 Aug 2013 16:56:53 -0400 Subject: [PATCH 0136/1195] Update for webkit header moves --- brightray/common/content_client.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index 87cc07abfee..fc294f45ec5 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -9,7 +9,7 @@ #include "base/stringprintf.h" #include "base/string_util.h" #include "ui/base/resource/resource_bundle.h" -#include "webkit/user_agent/user_agent_util.h" +#include "webkit/common/user_agent/user_agent_util.h" namespace brightray { From b24d7d7c76373e02e787608bb8805c34e62b6cf4 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 Aug 2013 17:01:18 -0400 Subject: [PATCH 0137/1195] Update utf_string_conversions.h path in another place --- brightray/common/application_info_win.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/common/application_info_win.cc b/brightray/common/application_info_win.cc index 8363970ebd8..49c53796358 100644 --- a/brightray/common/application_info_win.cc +++ b/brightray/common/application_info_win.cc @@ -2,7 +2,7 @@ #include "base/file_version_info.h" #include "base/memory/scoped_ptr.h" -#include "base/utf_string_conversions.h" +#include "base/strings/utf_string_conversions.h" namespace brightray { From 8c7de2259bd10586b071895087a7beb1795390c8 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 23 Aug 2013 17:30:53 -0400 Subject: [PATCH 0138/1195] Update to latest libchromiumcontent * vendor/libchromiumcontent ccec3a4...a56056d (1): > Stop exporting GURL symbols from test_support_chromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index ccec3a4031f..a56056d8f6a 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit ccec3a4031fa79d61f4199d99e477813d2d72a5a +Subproject commit a56056d8f6af9d66ffdd998d136323ef659c10c6 From 0575987343fb94258865900b4ce9bffac137e81e Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 12:40:09 -0400 Subject: [PATCH 0139/1195] Update to Chrome 30 * vendor/libchromiumcontent a56056d...bfb2d7b (1): > Merge pull request #27 from brightray/chrome-30 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index a56056d8f6a..bfb2d7bd95b 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit a56056d8f6af9d66ffdd998d136323ef659c10c6 +Subproject commit bfb2d7bd95b41f328989622f7ac416c9544a9478 From 1e99ec9aedc1ee1f0d7cec0cc37da80072ecdae6 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 15:16:49 -0400 Subject: [PATCH 0140/1195] Update #includes for moves of string-related headers See http://src.chromium.org/viewvc/chrome?view=revision&revision=205050. --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- brightray/browser/notification_presenter_mac.mm | 2 +- brightray/browser/url_request_context_getter.cc | 2 +- brightray/common/content_client.cc | 4 ++-- brightray/common/main_delegate_mac.mm | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 840712c86a2..b92136321ac 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -12,7 +12,7 @@ #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" -#include "base/stringprintf.h" +#include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_client_host.h" diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 02ca2927fe3..416e455503a 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -5,7 +5,7 @@ #import "browser/notification_presenter_mac.h" -#import "base/stringprintf.h" +#import "base/strings/stringprintf.h" #import "base/strings/sys_string_conversions.h" #import "content/public/browser/render_view_host.h" #import "content/public/common/show_desktop_notification_params.h" diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 47eb355aec7..4595cf8c713 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -5,7 +5,7 @@ #include "browser/url_request_context_getter.h" #include "network_delegate.h" -#include "base/string_util.h" +#include "base/strings/string_util.h" #include "base/threading/worker_pool.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/cookie_store_factory.h" diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index fc294f45ec5..a518cc026ca 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -6,8 +6,8 @@ #include "common/application_info.h" -#include "base/stringprintf.h" -#include "base/string_util.h" +#include "base/strings/stringprintf.h" +#include "base/strings/string_util.h" #include "ui/base/resource/resource_bundle.h" #include "webkit/common/user_agent/user_agent_util.h" diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index c9aaecbede3..7c5aaf68da7 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -13,7 +13,7 @@ #include "base/mac/bundle_locations.h" #include "base/mac/mac_util.h" #include "base/path_service.h" -#include "base/stringprintf.h" +#include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" #include "content/public/common/content_paths.h" #include "content/public/common/content_switches.h" From 64a5ce6e15b17d130d2cdf5740df3a6ebe761ac6 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 15:17:39 -0400 Subject: [PATCH 0141/1195] Update for move of scoped_nsobject header and namespace See http://src.chromium.org/viewvc/chrome?view=revision&revision=207616. --- brightray/browser/inspectable_web_contents_view_mac.h | 4 ++-- brightray/browser/notification_presenter_mac.h | 6 +++--- brightray/browser/notification_presenter_mac.mm | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index a03ccaf6361..1b5a6e43322 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -3,7 +3,7 @@ #import "browser/inspectable_web_contents_view.h" -#import "base/memory/scoped_nsobject.h" +#import "base/mac/scoped_nsobject.h" @class BRYInspectableWebContentsView; @@ -26,7 +26,7 @@ private: // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; - scoped_nsobject view_; + base::scoped_nsobject view_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewMac); }; diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index 5cd2c87e40a..b3757bf56ea 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -8,7 +8,7 @@ #import "browser/notification_presenter.h" -#import "base/memory/scoped_nsobject.h" +#import "base/mac/scoped_nsobject.h" #import @class BRYUserNotificationCenterDelegate; @@ -30,8 +30,8 @@ class NotificationPresenterMac : public NotificationPresenter { int notification_id) OVERRIDE; private: - std::map> notification_map_; - scoped_nsobject delegate_; + std::map> notification_map_; + base::scoped_nsobject delegate_; }; } diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 416e455503a..dc2ad9231fb 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -56,7 +56,7 @@ struct NotificationID { int notification_id; }; -scoped_nsobject CreateUserNotification( +base::scoped_nsobject CreateUserNotification( const content::ShowDesktopNotificationHostMsgParams& params, int render_process_id, int render_view_id) { @@ -65,7 +65,7 @@ scoped_nsobject CreateUserNotification( notification.informativeText = base::SysUTF16ToNSString(params.body); notification.userInfo = NotificationID(render_process_id, render_view_id, params.notification_id).GetUserInfo(); - return scoped_nsobject(notification); + return base::scoped_nsobject(notification); } } From eb446fc7072ce9b74017f8a1a63245842da048b6 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 15:21:43 -0400 Subject: [PATCH 0142/1195] content::BrowserContext::GetPath is a const member function in Chrome 30 See http://src.chromium.org/viewvc/chrome?view=revision&revision=211931. --- brightray/browser/browser_context.cc | 28 +++++++++++++--------------- brightray/browser/browser_context.h | 2 +- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 3ade3b1c51a..38aecce7b77 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -51,6 +51,18 @@ BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { } void BrowserContext::Initialize() { + base::FilePath path; +#if defined(OS_LINUX) + scoped_ptr env(base::Environment::Create()); + path = base::nix::GetXDGDirectory(env.get(), + base::nix::kXdgConfigHomeEnvVar, + base::nix::kDotConfigDir); +#else + CHECK(PathService::Get(base::DIR_APP_DATA, &path)); +#endif + + path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); + auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); PrefServiceBuilder builder; builder.WithUserFilePrefs(prefs_path, @@ -86,21 +98,7 @@ scoped_ptr BrowserContext::CreateNetworkDelegate() { return make_scoped_ptr(new NetworkDelegate).Pass(); } -base::FilePath BrowserContext::GetPath() { - if (!path_.empty()) - return path_; - - base::FilePath path; -#if defined(OS_LINUX) - scoped_ptr env(base::Environment::Create()); - path = base::nix::GetXDGDirectory(env.get(), - base::nix::kXdgConfigHomeEnvVar, - base::nix::kDotConfigDir); -#else - CHECK(PathService::Get(base::DIR_APP_DATA, &path)); -#endif - - path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); +base::FilePath BrowserContext::GetPath() const { return path_; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index ec3f1f6e5a2..7067aab5313 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -35,7 +35,7 @@ protected: // Subclasses should override this to provide a custom NetworkDelegate implementation. virtual scoped_ptr CreateNetworkDelegate(); - virtual base::FilePath GetPath() OVERRIDE; + virtual base::FilePath GetPath() const OVERRIDE; private: class ResourceContext; From c1c4344879e87a842ccd070400957599f7a6f580 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 15:23:55 -0400 Subject: [PATCH 0143/1195] BrowserContext::GetSpeechRecognitionPreferences is gone in Chrome 30 See http://src.chromium.org/viewvc/chrome?view=revision&revision=210616. --- brightray/browser/browser_context.cc | 4 ---- brightray/browser/browser_context.h | 1 - 2 files changed, 5 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 38aecce7b77..660aa69fc0b 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -140,10 +140,6 @@ content::GeolocationPermissionContext* BrowserContext::GetGeolocationPermissionC return nullptr; } -content::SpeechRecognitionPreferences* BrowserContext::GetSpeechRecognitionPreferences() { - return nullptr; -} - quota::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() { return nullptr; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 7067aab5313..04a4c7eba69 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -51,7 +51,6 @@ private: virtual content::ResourceContext* GetResourceContext() OVERRIDE; virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; virtual content::GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; - virtual content::SpeechRecognitionPreferences* GetSpeechRecognitionPreferences() OVERRIDE; virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; base::FilePath path_; From 4d59060657a49e67230ff7be59aa3db739acb842 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 15:26:11 -0400 Subject: [PATCH 0144/1195] BrowserContext::RequestMIDISysExPermission was added in Chrome 30 See http://src.chromium.org/viewvc/chrome?view=revision&revision=211437. --- brightray/browser/browser_context.cc | 4 ++++ brightray/browser/browser_context.h | 1 + 2 files changed, 5 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 660aa69fc0b..26b62f4d316 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -126,6 +126,10 @@ net::URLRequestContextGetter* BrowserContext::GetMediaRequestContextForStoragePa return GetRequestContext(); } +void BrowserContext::RequestMIDISysExPermission(int render_process_id, int render_view_id, const GURL& requesting_frame, const MIDISysExPermissionCallback& callback) { + callback.Run(false); +} + content::ResourceContext* BrowserContext::GetResourceContext() { return resource_context_.get(); } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 04a4c7eba69..f18cfdadced 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -48,6 +48,7 @@ private: virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE; virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(int renderer_child_id) OVERRIDE; virtual net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition(const base::FilePath& partition_path, bool in_memory); + virtual void RequestMIDISysExPermission(int render_process_id, int render_view_id, const GURL& requesting_frame, const MIDISysExPermissionCallback&) OVERRIDE; virtual content::ResourceContext* GetResourceContext() OVERRIDE; virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; virtual content::GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; From aa4f991659a8d9188f8e7b26092ceeb58ebd6a78 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 15:29:17 -0400 Subject: [PATCH 0145/1195] Add DevToolsFrontendHostDelegate indexing methods from Chrome 30 See http://src.chromium.org/viewvc/chrome?view=revision&revision=215622. --- brightray/browser/inspectable_web_contents_impl.cc | 9 +++++++++ brightray/browser/inspectable_web_contents_impl.h | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index b92136321ac..341521cf9ba 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -123,6 +123,15 @@ void InspectableWebContentsImpl::AddFileSystem() { void InspectableWebContentsImpl::RemoveFileSystem(const std::string& file_system_path) { } +void InspectableWebContentsImpl::IndexPath(int request_id, const std::string& file_system_path) { +} + +void InspectableWebContentsImpl::StopIndexing(int request_id) { +} + +void InspectableWebContentsImpl::SearchInPath(int request_id, const std::string& file_system_path, const std::string& query) { +} + void InspectableWebContentsImpl::InspectedContentsClosing() { } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 95293e062bd..b2a77204720 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -60,6 +60,11 @@ private: virtual void RequestFileSystems() OVERRIDE; virtual void AddFileSystem() OVERRIDE; virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; + virtual void IndexPath(int request_id, const std::string& file_system_path) OVERRIDE; + virtual void StopIndexing(int request_id) OVERRIDE; + virtual void SearchInPath(int request_id, + const std::string& file_system_path, + const std::string& query) OVERRIDE; virtual void InspectedContentsClosing() OVERRIDE; // content::WebContentsObserver From d1623535e84cf5a48c771bc16cee148b470e0578 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 16:13:01 -0400 Subject: [PATCH 0146/1195] Update browser/media/* for Chrome 30 I took the latest versions of these files from chrome/browser/media, then pared them down to remove all Chrome-isms and uses of UI to prompt the user about allowing access to devices. --- .../media/media_capture_devices_dispatcher.cc | 123 +++++++++++------- .../media/media_capture_devices_dispatcher.h | 56 +++++--- .../media/media_stream_devices_controller.cc | 116 ++++++++++++++--- .../media/media_stream_devices_controller.h | 12 +- 4 files changed, 211 insertions(+), 96 deletions(-) diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index 3c15841c164..1c3f9430050 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -4,9 +4,10 @@ #include "browser/media/media_capture_devices_dispatcher.h" -#include "base/prefs/pref_service.h" +#include "base/logging.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/media_devices_monitor.h" +#include "content/public/common/desktop_media_id.h" #include "content/public/common/media_stream_request.h" namespace brightray { @@ -16,41 +17,40 @@ using content::MediaStreamDevices; namespace { -const content::MediaStreamDevice* FindDefaultDeviceWithId( +// Finds a device in |devices| that has |device_id|, or NULL if not found. +const content::MediaStreamDevice* FindDeviceWithId( const content::MediaStreamDevices& devices, const std::string& device_id) { - if (devices.empty()) - return NULL; - content::MediaStreamDevices::const_iterator iter = devices.begin(); for (; iter != devices.end(); ++iter) { if (iter->id == device_id) { return &(*iter); } } - - return &(*devices.begin()); + return NULL; }; } // namespace - MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { return Singleton::get(); } MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() - : devices_enumerated_(false) {} + : devices_enumerated_(false), + is_device_enumeration_disabled_(false) { + // MediaCaptureDevicesDispatcher is a singleton. It should be created on + // UI thread. + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); +} MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {} const MediaStreamDevices& MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!devices_enumerated_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&content::EnsureMonitorCaptureDevices)); + if (!is_device_enumeration_disabled_ && !devices_enumerated_) { + content::EnsureMonitorCaptureDevices(); devices_enumerated_ = true; } return audio_devices_; @@ -59,17 +59,14 @@ MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() { const MediaStreamDevices& MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!devices_enumerated_) { - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind(&content::EnsureMonitorCaptureDevices)); + if (!is_device_enumeration_disabled_ && !devices_enumerated_) { + content::EnsureMonitorCaptureDevices(); devices_enumerated_ = true; } return video_devices_; } -void MediaCaptureDevicesDispatcher::GetRequestedDevice( - const std::string& requested_device_id, +void MediaCaptureDevicesDispatcher::GetDefaultDevices( bool audio, bool video, content::MediaStreamDevices* devices) { @@ -77,32 +74,58 @@ void MediaCaptureDevicesDispatcher::GetRequestedDevice( DCHECK(audio || video); if (audio) { - const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices(); - const content::MediaStreamDevice* const device = - FindDefaultDeviceWithId(audio_devices, requested_device_id); + const content::MediaStreamDevice* device = GetFirstAvailableAudioDevice(); if (device) devices->push_back(*device); } + if (video) { - const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices(); - const content::MediaStreamDevice* const device = - FindDefaultDeviceWithId(video_devices, requested_device_id); + const content::MediaStreamDevice* device = GetFirstAvailableVideoDevice(); if (device) devices->push_back(*device); } } -void MediaCaptureDevicesDispatcher::GetDefaultDevices( - bool audio, - bool video, - content::MediaStreamDevices* devices) { - if (audio) { - GetRequestedDevice(std::string(), true, false, devices); - } +const content::MediaStreamDevice* +MediaCaptureDevicesDispatcher::GetRequestedAudioDevice( + const std::string& requested_audio_device_id) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices(); + const content::MediaStreamDevice* const device = + FindDeviceWithId(audio_devices, requested_audio_device_id); + return device; +} - if (video) { - GetRequestedDevice(std::string(), false, true, devices); - } +const content::MediaStreamDevice* +MediaCaptureDevicesDispatcher::GetFirstAvailableAudioDevice() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + const content::MediaStreamDevices& audio_devices = GetAudioCaptureDevices(); + if (audio_devices.empty()) + return NULL; + return &(*audio_devices.begin()); +} + +const content::MediaStreamDevice* +MediaCaptureDevicesDispatcher::GetRequestedVideoDevice( + const std::string& requested_video_device_id) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices(); + const content::MediaStreamDevice* const device = + FindDeviceWithId(video_devices, requested_video_device_id); + return device; +} + +const content::MediaStreamDevice* +MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + const content::MediaStreamDevices& video_devices = GetVideoCaptureDevices(); + if (video_devices.empty()) + return NULL; + return &(*video_devices.begin()); +} + +void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() { + is_device_enumeration_disabled_ = true; } void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged( @@ -126,15 +149,22 @@ void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged( void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( int render_process_id, int render_view_id, + int page_request_id, const content::MediaStreamDevice& device, content::MediaRequestState state) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind( - &MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread, - base::Unretained(this), render_process_id, render_view_id, device, - state)); + +} + +void MediaCaptureDevicesDispatcher::OnAudioStreamPlayingChanged( + int render_process_id, int render_view_id, int stream_id, + bool is_playing, float power_dbfs, bool clipped) { +} + +void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( + int render_process_id, + int render_view_id) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); } void MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread( @@ -145,17 +175,10 @@ void MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread( } void MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread( - const content::MediaStreamDevices& devices) { + const content::MediaStreamDevices& devices){ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); devices_enumerated_ = true; video_devices_ = devices; } -void MediaCaptureDevicesDispatcher::UpdateMediaRequestStateOnUIThread( - int render_process_id, - int render_view_id, - const content::MediaStreamDevice& device, - content::MediaRequestState state) { -} - -} +} // namespace brightray diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index 6edb12b5cf0..680455e2321 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -8,8 +8,8 @@ #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" -#include "base/observer_list.h" #include "content/public/browser/media_observer.h" +#include "content/public/browser/web_contents_delegate.h" #include "content/public/common/media_stream_request.h" namespace brightray { @@ -20,20 +20,35 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { public: static MediaCaptureDevicesDispatcher* GetInstance(); - // Helper for picking the device that was requested for an OpenDevice request. - // If the device requested is not available it will revert to using the first - // available one instead or will return an empty list if no devices of the - // requested kind are present. - void GetRequestedDevice(const std::string& requested_device_id, - bool audio, - bool video, - content::MediaStreamDevices* devices); + // Methods for observers. Called on UI thread. + const content::MediaStreamDevices& GetAudioCaptureDevices(); + const content::MediaStreamDevices& GetVideoCaptureDevices(); + + // Helper to get the default devices which can be used by the media request. + // Uses the first available devices if the default devices are not available. + // If the return list is empty, it means there is no available device on the + // OS. + // Called on the UI thread. void GetDefaultDevices(bool audio, bool video, content::MediaStreamDevices* devices); - const content::MediaStreamDevices& GetAudioCaptureDevices(); - const content::MediaStreamDevices& GetVideoCaptureDevices(); + // Helpers for picking particular requested devices, identified by raw id. + // If the device requested is not available it will return NULL. + const content::MediaStreamDevice* + GetRequestedAudioDevice(const std::string& requested_audio_device_id); + const content::MediaStreamDevice* + GetRequestedVideoDevice(const std::string& requested_video_device_id); + + // Returns the first available audio or video device, or NULL if no devices + // are available. + const content::MediaStreamDevice* GetFirstAvailableAudioDevice(); + const content::MediaStreamDevice* GetFirstAvailableVideoDevice(); + + // Unittests that do not require actual device enumeration should call this + // API on the singleton. It is safe to call this multiple times on the + // signleton. + void DisableDeviceEnumerationForTesting(); // Overridden from content::MediaObserver: virtual void OnAudioCaptureDevicesChanged( @@ -43,13 +58,18 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { virtual void OnMediaRequestStateChanged( int render_process_id, int render_view_id, + int page_request_id, const content::MediaStreamDevice& device, content::MediaRequestState state) OVERRIDE; virtual void OnAudioStreamPlayingChanged( int render_process_id, int render_view_id, int stream_id, - bool playing) OVERRIDE {} + bool is_playing, + float power_dBFS, + bool clipped) OVERRIDE; + virtual void OnCreatingAudioStream(int render_process_id, + int render_view_id) OVERRIDE; private: friend struct DefaultSingletonTraits; @@ -60,11 +80,6 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { // Called by the MediaObserver() functions, executed on UI thread. void UpdateAudioDevicesOnUIThread(const content::MediaStreamDevices& devices); void UpdateVideoDevicesOnUIThread(const content::MediaStreamDevices& devices); - void UpdateMediaRequestStateOnUIThread( - int render_process_id, - int render_view_id, - const content::MediaStreamDevice& device, - content::MediaRequestState state); // A list of cached audio capture devices. content::MediaStreamDevices audio_devices_; @@ -75,8 +90,13 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { // Flag to indicate if device enumeration has been done/doing. // Only accessed on UI thread. bool devices_enumerated_; + + // Flag used by unittests to disable device enumeration. + bool is_device_enumeration_disabled_; + + DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher); }; -} +} // namespace brightray #endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index ea53c20fd29..e6f0af89b73 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -4,9 +4,8 @@ #include "browser/media/media_stream_devices_controller.h" -#include "base/values.h" #include "browser/media/media_capture_devices_dispatcher.h" -#include "content/public/browser/browser_thread.h" + #include "content/public/common/media_stream_request.h" namespace brightray { @@ -20,7 +19,7 @@ bool HasAnyAvailableDevice() { MediaCaptureDevicesDispatcher::GetInstance()->GetVideoCaptureDevices(); return !audio_devices.empty() || !video_devices.empty(); -}; +} } // namespace @@ -29,15 +28,39 @@ MediaStreamDevicesController::MediaStreamDevicesController( const content::MediaResponseCallback& callback) : request_(request), callback_(callback), + // For MEDIA_OPEN_DEVICE requests (Pepper) we always request both webcam + // and microphone to avoid popping two infobars. microphone_requested_( - request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE), + request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || + request.request_type == content::MEDIA_OPEN_DEVICE), 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) { } -MediaStreamDevicesController::~MediaStreamDevicesController() {} +MediaStreamDevicesController::~MediaStreamDevicesController() { + if (!callback_.is_null()) { + callback_.Run(content::MediaStreamDevices(), + scoped_ptr()); + } +} bool MediaStreamDevicesController::TakeAction() { + // Tab capture is allowed for extensions only and infobar is not shown for + // extensions. + if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || + request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { + Deny(); + return true; + } + + // Deny the request if the security origin is empty, this happens with + // file access without |--allow-file-access-from-files| flag. + if (request_.security_origin.is_empty()) { + Deny(); + return true; + } + // Deny the request if there is no device attached to the OS. if (!HasAnyAvailableDevice()) { Deny(); @@ -53,34 +76,87 @@ void MediaStreamDevicesController::Accept() { content::MediaStreamDevices devices; if (microphone_requested_ || webcam_requested_) { switch (request_.request_type) { - case content::MEDIA_OPEN_DEVICE: + case content::MEDIA_OPEN_DEVICE: { + const content::MediaStreamDevice* device = NULL; // For open device request pick the desired device or fall back to the // first available of the given type. - MediaCaptureDevicesDispatcher::GetInstance()->GetRequestedDevice( - request_.requested_device_id, - microphone_requested_, - webcam_requested_, - &devices); + if (request_.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) { + device = MediaCaptureDevicesDispatcher::GetInstance()-> + GetRequestedAudioDevice(request_.requested_audio_device_id); + // TODO(wjia): Confirm this is the intended behavior. + if (!device) { + device = MediaCaptureDevicesDispatcher::GetInstance()-> + GetFirstAvailableAudioDevice(); + } + } else if (request_.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) { + // Pepper API opens only one device at a time. + device = MediaCaptureDevicesDispatcher::GetInstance()-> + GetRequestedVideoDevice(request_.requested_video_device_id); + // TODO(wjia): Confirm this is the intended behavior. + if (!device) { + device = MediaCaptureDevicesDispatcher::GetInstance()-> + GetFirstAvailableVideoDevice(); + } + } + if (device) + devices.push_back(*device); break; - case content::MEDIA_DEVICE_ACCESS: - case content::MEDIA_GENERATE_STREAM: - case content::MEDIA_ENUMERATE_DEVICES: + } case content::MEDIA_GENERATE_STREAM: { + bool needs_audio_device = microphone_requested_; + bool needs_video_device = webcam_requested_; + + // Get the exact audio or video device if an id is specified. + if (!request_.requested_audio_device_id.empty()) { + const content::MediaStreamDevice* audio_device = + MediaCaptureDevicesDispatcher::GetInstance()-> + GetRequestedAudioDevice(request_.requested_audio_device_id); + if (audio_device) { + devices.push_back(*audio_device); + needs_audio_device = false; + } + } + if (!request_.requested_video_device_id.empty()) { + const content::MediaStreamDevice* video_device = + MediaCaptureDevicesDispatcher::GetInstance()-> + GetRequestedVideoDevice(request_.requested_video_device_id); + if (video_device) { + devices.push_back(*video_device); + needs_video_device = false; + } + } + + // If either or both audio and video devices were requested but not + // specified by id, get the default devices. + if (needs_audio_device || needs_video_device) { + MediaCaptureDevicesDispatcher::GetInstance()-> + GetDefaultDevices(needs_audio_device, + needs_video_device, + &devices); + } + break; + } case content::MEDIA_DEVICE_ACCESS: // Get the default devices for the request. MediaCaptureDevicesDispatcher::GetInstance()-> GetDefaultDevices(microphone_requested_, webcam_requested_, &devices); break; + case content::MEDIA_ENUMERATE_DEVICES: + // Do nothing. + NOTREACHED(); + break; } } - LOG(ERROR) << "Accept"; - callback_.Run(devices, scoped_ptr()); + content::MediaResponseCallback cb = callback_; + callback_.Reset(); + cb.Run(devices, scoped_ptr()); } void MediaStreamDevicesController::Deny() { - callback_.Run(content::MediaStreamDevices(), - scoped_ptr()); + content::MediaResponseCallback cb = callback_; + callback_.Reset(); + cb.Run(content::MediaStreamDevices(), scoped_ptr()); } -} // namespace brightray +} // namespace brightray diff --git a/brightray/browser/media/media_stream_devices_controller.h b/brightray/browser/media/media_stream_devices_controller.h index bcf4a0f0049..8a029a38a08 100644 --- a/brightray/browser/media/media_stream_devices_controller.h +++ b/brightray/browser/media/media_stream_devices_controller.h @@ -5,6 +5,8 @@ #ifndef BRIGHTRAY_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ #define BRIGHTRAY_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ +#include + #include "content/public/browser/web_contents_delegate.h" namespace brightray { @@ -16,18 +18,12 @@ class MediaStreamDevicesController { virtual ~MediaStreamDevicesController(); - // Public method to be called before creating the MediaStreamInfoBarDelegate. - // This function will check the content settings exceptions and take the - // corresponding action on exception which matches the request. bool TakeAction(); - // Public methods to be called by MediaStreamInfoBarDelegate; - bool has_audio() const { return microphone_requested_; } - bool has_video() const { return webcam_requested_; } + private: void Accept(); void Deny(); - private: // The original request for access to devices. const content::MediaStreamRequest request_; @@ -41,6 +37,6 @@ class MediaStreamDevicesController { DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); }; -} // namespace brightray +} // namespace brightray #endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ From 4d6ee2c4167548943095646e2b2ab1f6949baff7 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 16:21:01 -0400 Subject: [PATCH 0147/1195] URLRequestContextStorage::set_http_server_properties takes a scoped_ptr in Chrome 30 See http://src.chromium.org/viewvc/chrome?view=revision&revision=212466. --- brightray/browser/url_request_context_getter.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 4595cf8c713..4fe6d3f1b94 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -87,7 +87,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); storage_->set_http_auth_handler_factory( net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); - storage_->set_http_server_properties(new net::HttpServerPropertiesImpl); + scoped_ptr server_properties(new net::HttpServerPropertiesImpl); + storage_->set_http_server_properties(server_properties.Pass()); base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); net::HttpCache::DefaultBackend* main_backend = From 91654243483e8986964813762d2b0305b54b0796 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 16:25:17 -0400 Subject: [PATCH 0148/1195] Update ResourceContext for Chrome 30 See http://src.chromium.org/viewvc/chrome?view=revision&revision=215991. --- brightray/browser/browser_context.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 26b62f4d316..e43607a196c 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -44,6 +44,16 @@ private: return getter_->GetURLRequestContext(); } + // FIXME: We should probably allow clients to override this to implement more restrictive policies. + virtual bool AllowMicAccess(const GURL& origin) OVERRIDE { + return true; + } + + // FIXME: We should probably allow clients to override this to implement more restrictive policies. + virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE { + return true; + } + URLRequestContextGetter* getter_; }; From b3b4ab2c70f4e0cfb4fb985bd4980ef771cf9587 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 17:02:35 -0400 Subject: [PATCH 0149/1195] Update ICU header include path I should have done this as part of #30. --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b576b273ec7..e7e6fcd6605 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -21,7 +21,7 @@ '<(libchromiumcontent_include_dir)/third_party/skia/include/config', # For SkMatrix.h. '<(libchromiumcontent_include_dir)/third_party/skia/include/core', - '<(libchromiumcontent_include_dir)/third_party/icu/public/common', + '<(libchromiumcontent_include_dir)/third_party/icu/source/common', ], }, 'sources': [ From 1f1f93465bdfba49c383f7fdf91943be22c36057 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Oct 2013 17:04:22 -0400 Subject: [PATCH 0150/1195] Make MediaStreamDevicesController::Accept/Deny public again Clients rely on this. --- brightray/browser/media/media_stream_devices_controller.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/browser/media/media_stream_devices_controller.h b/brightray/browser/media/media_stream_devices_controller.h index 8a029a38a08..820c8721365 100644 --- a/brightray/browser/media/media_stream_devices_controller.h +++ b/brightray/browser/media/media_stream_devices_controller.h @@ -18,12 +18,14 @@ class MediaStreamDevicesController { virtual ~MediaStreamDevicesController(); + // Accept or deny the request based on the default policy. bool TakeAction(); - private: + // Explicitly accept or deny the request. void Accept(); void Deny(); + private: // The original request for access to devices. const content::MediaStreamRequest request_; From d06ac209473294f9c6056902b0bc951940acca25 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 8 Oct 2013 13:20:43 -0400 Subject: [PATCH 0151/1195] Update to latest libchromiumcontent * vendor/libchromiumcontent bfb2d7b...759a8d0 (1): > Remove googleurl/ from the distribution --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index bfb2d7bd95b..759a8d09471 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit bfb2d7bd95b41f328989622f7ac416c9544a9478 +Subproject commit 759a8d09471fef04acf32d5fc8c48676090b357d From c0e744db789008f764e0a07b46aab1c9391da0c0 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 9 Oct 2013 12:58:36 -0400 Subject: [PATCH 0152/1195] Update libchromiumcontent to use Xcode's clang * vendor/libchromiumcontent 759a8d0...21d99bd (1): > Merge pull request #28 from brightray/xcode-clang --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 759a8d09471..21d99bd412d 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 759a8d09471fef04acf32d5fc8c48676090b357d +Subproject commit 21d99bd412dda76aca6bcc722134d24d8ea17746 From 8ae459e9fa34b8c3e8c485bfcdc00d4a787b68cd Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 10 Oct 2013 14:07:20 -0400 Subject: [PATCH 0153/1195] Work around http://crbug.com/279472 for devtools views --- brightray/browser/inspectable_web_contents_impl.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 341521cf9ba..935026df319 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -58,6 +58,12 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const { void InspectableWebContentsImpl::ShowDevTools() { if (!devtools_web_contents_) { devtools_web_contents_.reset(content::WebContents::Create(content::WebContents::CreateParams(web_contents_->GetBrowserContext()))); + +#if defined(OS_MACOSX) + // Work around http://crbug.com/279472. + devtools_web_contents_->GetView()->SetAllowOverlappingViews(true); +#endif + Observe(devtools_web_contents_.get()); devtools_web_contents_->SetDelegate(this); From 6b9e61c65da7c1d373c9c0c11fa1f61dd90857d3 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 10 Oct 2013 16:23:52 -0400 Subject: [PATCH 0154/1195] Fix flashing in WebContents we create If the embedding app creates them it's up to them to fix this. --- brightray/browser/inspectable_web_contents.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents.cc b/brightray/browser/inspectable_web_contents.cc index ca3bded4a48..5e3af6013de 100644 --- a/brightray/browser/inspectable_web_contents.cc +++ b/brightray/browser/inspectable_web_contents.cc @@ -2,10 +2,18 @@ #include "browser/inspectable_web_contents_impl.h" +#include "content/public/browser/web_contents_view.h" + namespace brightray { InspectableWebContents* InspectableWebContents::Create(const content::WebContents::CreateParams& create_params) { - return Create(content::WebContents::Create(create_params)); + auto contents = content::WebContents::Create(create_params); +#if defined(OS_MACOSX) + // Work around http://crbug.com/279472. + contents->GetView()->SetAllowOverlappingViews(true); +#endif + + return Create(contents); } InspectableWebContents* InspectableWebContents::Create(content::WebContents* web_contents) { From 9d29c8eb7c4343a54162ce4ff4bccb41343ad62b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 14 May 2013 14:45:34 +0800 Subject: [PATCH 0155/1195] Use the "chrome-devtools://" scheme to open devtools. --- brightray/brightray.gyp | 6 +- brightray/browser/browser_main_parts.cc | 12 +-- brightray/browser/browser_main_parts.h | 8 +- brightray/browser/devtools_delegate.cc | 49 --------- brightray/browser/devtools_delegate.h | 32 ------ brightray/browser/devtools_ui.cc | 102 ++++++++++++++++++ brightray/browser/devtools_ui.h | 28 +++++ .../browser/inspectable_web_contents_impl.cc | 9 +- .../browser/web_ui_controller_factory.cc | 59 ++++++++++ brightray/browser/web_ui_controller_factory.h | 42 ++++++++ 10 files changed, 246 insertions(+), 101 deletions(-) delete mode 100644 brightray/browser/devtools_delegate.cc delete mode 100644 brightray/browser/devtools_delegate.h create mode 100644 brightray/browser/devtools_ui.cc create mode 100644 brightray/browser/devtools_ui.h create mode 100644 brightray/browser/web_ui_controller_factory.cc create mode 100644 brightray/browser/web_ui_controller_factory.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index e7e6fcd6605..128d81ea77b 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -35,8 +35,8 @@ 'browser/default_web_contents_delegate.cc', 'browser/default_web_contents_delegate.h', 'browser/default_web_contents_delegate_mac.mm', - 'browser/devtools_delegate.cc', - 'browser/devtools_delegate.h', + 'browser/devtools_ui.cc', + 'browser/devtools_ui.h', 'browser/download_manager_delegate.cc', 'browser/download_manager_delegate.h', 'browser/inspectable_web_contents.cc', @@ -66,6 +66,8 @@ 'browser/win/devtools_window.h', 'browser/win/inspectable_web_contents_view_win.cc', 'browser/win/inspectable_web_contents_view_win.h', + 'browser/web_ui_controller_factory.cc', + 'browser/web_ui_controller_factory.h', 'common/application_info.h', 'common/application_info_mac.mm', 'common/application_info_win.cc', diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index bb435057c05..15a7192d009 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -5,9 +5,8 @@ #include "browser/browser_main_parts.h" #include "browser/browser_context.h" -#include "browser/devtools_delegate.h" +#include "browser/web_ui_controller_factory.h" -#include "content/public/browser/devtools_http_handler.h" #include "net/socket/tcp_listen_socket.h" namespace brightray { @@ -16,19 +15,14 @@ BrowserMainParts::BrowserMainParts() { } BrowserMainParts::~BrowserMainParts() { - devtools_http_handler_->Stop(); - devtools_http_handler_ = nullptr; } void BrowserMainParts::PreMainMessageLoopRun() { browser_context_.reset(CreateBrowserContext()); browser_context_->Initialize(); - // These two objects are owned by devtools_http_handler_. - auto delegate = new DevToolsDelegate; - auto factory = new net::TCPListenSocketFactory("127.0.0.1", 0); - - devtools_http_handler_ = content::DevToolsHttpHandler::Start(factory, std::string(), delegate); + web_ui_controller_factory_.reset(new WebUIControllerFactory(browser_context_.get())); + content::WebUIControllerFactory::RegisterFactory(web_ui_controller_factory_.get()); } BrowserContext* BrowserMainParts::CreateBrowserContext() { diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 7120c619b0b..ca80e557654 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -9,13 +9,10 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" -namespace content { -class DevToolsHttpHandler; -} - namespace brightray { class BrowserContext; +class WebUIControllerFactory; class BrowserMainParts : public content::BrowserMainParts { public: @@ -23,7 +20,6 @@ public: ~BrowserMainParts(); BrowserContext* browser_context() { return browser_context_.get(); } - content::DevToolsHttpHandler* devtools_http_handler() { return devtools_http_handler_; } protected: // Subclasses should override this to provide their own BrowserContxt implementation. The caller @@ -38,7 +34,7 @@ protected: private: scoped_ptr browser_context_; - content::DevToolsHttpHandler* devtools_http_handler_; + scoped_ptr web_ui_controller_factory_; DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); }; diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_delegate.cc deleted file mode 100644 index ccbcd362aa9..00000000000 --- a/brightray/browser/devtools_delegate.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE-CHROMIUM file. - -#include "devtools_delegate.h" - -namespace brightray { - -DevToolsDelegate::DevToolsDelegate() { -} - -DevToolsDelegate::~DevToolsDelegate() { -} - -std::string DevToolsDelegate::GetDiscoveryPageHTML() { - return std::string(); -} - -bool DevToolsDelegate::BundlesFrontendResources() { - return true; -} - -base::FilePath DevToolsDelegate::GetDebugFrontendDir() { - return base::FilePath(); -} - -std::string DevToolsDelegate::GetPageThumbnailData(const GURL&) { - return std::string(); -} - -content::RenderViewHost* DevToolsDelegate::CreateNewTarget() { - return nullptr; -} - -content::DevToolsHttpHandlerDelegate::TargetType DevToolsDelegate::GetTargetType(content::RenderViewHost*) { - return kTargetTypeTab; -} - -std::string DevToolsDelegate::GetViewDescription(content::RenderViewHost*) { - return std::string(); -} - -scoped_refptr DevToolsDelegate::CreateSocketForTethering( - net::StreamListenSocket::Delegate*, - std::string* name) { - return nullptr; -} - -} diff --git a/brightray/browser/devtools_delegate.h b/brightray/browser/devtools_delegate.h deleted file mode 100644 index 12dd2087ee7..00000000000 --- a/brightray/browser/devtools_delegate.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE-CHROMIUM file. - -#ifndef BRIGHTRAY_BROWSER_DEVTOOLS_DELEGATE_H_ -#define BRIGHTRAY_BROWSER_DEVTOOLS_DELEGATE_H_ - -#include "content/public/browser/devtools_http_handler_delegate.h" - -namespace brightray { - -class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { -public: - DevToolsDelegate(); - ~DevToolsDelegate(); - -private: - virtual std::string GetDiscoveryPageHTML() OVERRIDE; - virtual bool BundlesFrontendResources() OVERRIDE; - virtual base::FilePath GetDebugFrontendDir() OVERRIDE; - virtual std::string GetPageThumbnailData(const GURL&) OVERRIDE; - virtual content::RenderViewHost* CreateNewTarget() OVERRIDE; - virtual TargetType GetTargetType(content::RenderViewHost*) OVERRIDE; - virtual std::string GetViewDescription(content::RenderViewHost*) OVERRIDE; - virtual scoped_refptr CreateSocketForTethering( - net::StreamListenSocket::Delegate*, - std::string* name) OVERRIDE; -}; - -} - -#endif diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc new file mode 100644 index 00000000000..571dc8adb62 --- /dev/null +++ b/brightray/browser/devtools_ui.cc @@ -0,0 +1,102 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/devtools_ui.h" + +#include + +#include "browser/browser_context.h" + +#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/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; + +namespace brightray { + +namespace { + +const char kChromeUIDevToolsBundledHost[] = "devtools"; + +std::string PathWithoutParams(const std::string& path) { + return GURL(std::string("chrome-devtools://devtools/") + path) + .path().substr(1); +} + +std::string GetMimeTypeForPath(const std::string& path) { + std::string filename = PathWithoutParams(path); + if (EndsWith(filename, ".html", false)) { + return "text/html"; + } else if (EndsWith(filename, ".css", false)) { + return "text/css"; + } else if (EndsWith(filename, ".js", false)) { + return "application/javascript"; + } else if (EndsWith(filename, ".png", false)) { + return "image/png"; + } else if (EndsWith(filename, ".gif", false)) { + return "image/gif"; + } else if (EndsWith(filename, ".manifest", false)) { + return "text/cache-manifest"; + } + NOTREACHED(); + return "text/plain"; +} + +class BundledDataSource : public content::URLDataSource { + public: + explicit BundledDataSource() { + } + + // content::URLDataSource implementation. + virtual std::string GetSource() const OVERRIDE { + return kChromeUIDevToolsBundledHost; + } + + virtual void StartDataRequest(const std::string& path, + int render_process_id, + int render_view_id, + const GotDataCallback& callback) OVERRIDE { + std::string filename = PathWithoutParams(path); + + int resource_id = + content::DevToolsHttpHandler::GetFrontendResourceId(filename); + + DLOG_IF(WARNING, -1 == resource_id) << "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)); + callback.Run(bytes); + } + + virtual std::string GetMimeType(const std::string& path) const OVERRIDE { + return GetMimeTypeForPath(path); + } + + virtual bool ShouldAddContentSecurityPolicy() const OVERRIDE { + return false; + } + + private: + virtual ~BundledDataSource() {} + DISALLOW_COPY_AND_ASSIGN(BundledDataSource); +}; + +} + +DevToolsUI::DevToolsUI(BrowserContext* browser_context, content::WebUI* web_ui) + : WebUIController(web_ui), + browser_context_(browser_context) { + web_ui->SetBindings(0); + content::URLDataSource::Add(browser_context_, new BundledDataSource()); +} + +} diff --git a/brightray/browser/devtools_ui.h b/brightray/browser/devtools_ui.h new file mode 100644 index 00000000000..6ac205ab548 --- /dev/null +++ b/brightray/browser/devtools_ui.h @@ -0,0 +1,28 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_DEVTOOLS_UI_H_ +#define BRIGHTRAY_BROWSER_DEVTOOLS_UI_H_ + +#include "base/compiler_specific.h" +#include "content/public/browser/web_ui_controller.h" + +namespace brightray { + +class BrowserContext; + +class DevToolsUI : public content::WebUIController { + public: + explicit DevToolsUI(BrowserContext* browser_context, content::WebUI* web_ui); + + private: + // Weak reference to the browser context. + BrowserContext* browser_context_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsUI); +}; + +} + +#endif diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 935026df319..f143768ec34 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -25,8 +25,13 @@ namespace brightray { namespace { +const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html"; const char kDockSidePref[] = "brightray.devtools.dockside"; +GURL GetDevToolsURL() { + return GURL(kChromeUIDevToolsURL); +} + } // Implemented separately on each platform. @@ -70,9 +75,7 @@ void InspectableWebContentsImpl::ShowDevTools() { agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_->GetRenderViewHost()); frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(devtools_web_contents_.get(), this)); - auto handler = BrowserClient::Get()->browser_main_parts()->devtools_http_handler(); - auto url = handler->GetFrontendURL(nullptr); - devtools_web_contents_->GetController().LoadURL(url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); + devtools_web_contents_->GetController().LoadURL(GetDevToolsURL(), content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); } view_->SetDockSide(dock_side_); diff --git a/brightray/browser/web_ui_controller_factory.cc b/brightray/browser/web_ui_controller_factory.cc new file mode 100644 index 00000000000..61f6bf993c5 --- /dev/null +++ b/brightray/browser/web_ui_controller_factory.cc @@ -0,0 +1,59 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/web_ui_controller_factory.h" + +#include "browser/browser_context.h" +#include "browser/devtools_ui.h" + +#include "content/public/browser/web_contents.h" +#include "content/public/browser/web_ui.h" +#include "content/public/common/url_constants.h" + +namespace brightray { + +namespace { + +const char kChromeUIDevToolsBundledHost[] = "devtools"; + +} + +WebUIControllerFactory::WebUIControllerFactory(BrowserContext* browser_context) + : browser_context_(browser_context) { + DCHECK(browser_context_); +} + +WebUIControllerFactory::~WebUIControllerFactory() { +} + +content::WebUI::TypeID WebUIControllerFactory::GetWebUIType( + content::BrowserContext* browser_context, const GURL& url) const { + if (url.host() == kChromeUIDevToolsBundledHost) { + return const_cast(this); + } + + return content::WebUI::kNoWebUI; +} + +bool WebUIControllerFactory::UseWebUIForURL( + content::BrowserContext* browser_context, const GURL& url) const { + return GetWebUIType(browser_context, url) != content::WebUI::kNoWebUI; +} + +bool WebUIControllerFactory::UseWebUIBindingsForURL( + content::BrowserContext* browser_context, const GURL& url) const { + return UseWebUIForURL(browser_context, url); +} + +content::WebUIController* WebUIControllerFactory::CreateWebUIControllerForURL( + content::WebUI* web_ui, const GURL& url) const { + DCHECK(browser_context_); + + if (url.host() == kChromeUIDevToolsBundledHost) + return new DevToolsUI(browser_context_, web_ui); + + return NULL; +} + +} diff --git a/brightray/browser/web_ui_controller_factory.h b/brightray/browser/web_ui_controller_factory.h new file mode 100644 index 00000000000..1ee3f9b2dfd --- /dev/null +++ b/brightray/browser/web_ui_controller_factory.h @@ -0,0 +1,42 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_WEB_UI_CONTROLLER_FACTORY_H_ +#define BRIGHTRAY_BROWSER_WEB_UI_CONTROLLER_FACTORY_H_ + +#include "base/basictypes.h" +#include "content/public/browser/web_ui.h" +#include "content/public/browser/web_ui_controller_factory.h" + +namespace brightray { + +class BrowserContext; + +class WebUIControllerFactory : public content::WebUIControllerFactory { + public: + WebUIControllerFactory(BrowserContext* browser_context); + virtual ~WebUIControllerFactory(); + + virtual content::WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context, + const GURL& url) const OVERRIDE; + virtual bool UseWebUIForURL(content::BrowserContext* browser_context, + const GURL& url) const OVERRIDE; + virtual bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, + const GURL& url) const OVERRIDE; + virtual content::WebUIController* CreateWebUIControllerForURL( + content::WebUI* web_ui, + const GURL& url) const OVERRIDE; + + static WebUIControllerFactory* GetInstance(); + + private: + // Weak reference to the browser context. + BrowserContext* browser_context_; + + DISALLOW_COPY_AND_ASSIGN(WebUIControllerFactory); +}; + +} + +#endif From 2cd6dd791eca7bcecfddfdbce3f8aa2829c4d426 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 14 May 2013 15:17:17 +0800 Subject: [PATCH 0156/1195] Setup devtools in the correct phase. * RegisterDevToolsClientHostFor should be called right after the agent_host and the frontend host are created. * SetupDevToolsFrontendClient should be called before the devtools window is going to start navigation. --- brightray/browser/inspectable_web_contents_impl.cc | 5 ++++- brightray/browser/inspectable_web_contents_impl.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index f143768ec34..48da9f1fb00 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -74,6 +74,7 @@ void InspectableWebContentsImpl::ShowDevTools() { agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_->GetRenderViewHost()); frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(devtools_web_contents_.get(), this)); + content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get()); devtools_web_contents_->GetController().LoadURL(GetDevToolsURL(), content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); } @@ -145,8 +146,10 @@ void InspectableWebContentsImpl::InspectedContentsClosing() { } void InspectableWebContentsImpl::RenderViewCreated(content::RenderViewHost* render_view_host) { +} + +void InspectableWebContentsImpl::AboutToNavigateRenderView(content::RenderViewHost* render_view_host) { content::DevToolsClientHost::SetupDevToolsFrontendClient(web_contents()->GetRenderViewHost()); - content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get()); } void InspectableWebContentsImpl::DidFinishLoad(int64, const GURL&, bool is_main_frame, content::RenderViewHost*) { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index b2a77204720..c47eb871cd6 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -70,6 +70,7 @@ private: // content::WebContentsObserver virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE; + virtual void AboutToNavigateRenderView(content::RenderViewHost* render_view_host) OVERRIDE; virtual void DidFinishLoad(int64 frame_id, const GURL& validated_url, bool is_main_frame, From f623ddf7fc7ed00ac1ab16c6f72a4c4c73999bfd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 14 May 2013 15:36:40 +0800 Subject: [PATCH 0157/1195] Cleanup unused headers, data members and functions. --- brightray/browser/browser_main_parts.cc | 2 -- brightray/browser/devtools_ui.cc | 5 ++--- brightray/browser/devtools_ui.h | 3 --- brightray/browser/inspectable_web_contents_impl.cc | 10 ++-------- brightray/browser/inspectable_web_contents_impl.h | 1 - 5 files changed, 4 insertions(+), 17 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 15a7192d009..8bcaf3621b1 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -7,8 +7,6 @@ #include "browser/browser_context.h" #include "browser/web_ui_controller_factory.h" -#include "net/socket/tcp_listen_socket.h" - namespace brightray { BrowserMainParts::BrowserMainParts() { diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 571dc8adb62..94e581728ab 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -93,10 +93,9 @@ class BundledDataSource : public content::URLDataSource { } DevToolsUI::DevToolsUI(BrowserContext* browser_context, content::WebUI* web_ui) - : WebUIController(web_ui), - browser_context_(browser_context) { + : WebUIController(web_ui) { web_ui->SetBindings(0); - content::URLDataSource::Add(browser_context_, new BundledDataSource()); + content::URLDataSource::Add(browser_context, new BundledDataSource()); } } diff --git a/brightray/browser/devtools_ui.h b/brightray/browser/devtools_ui.h index 6ac205ab548..70ab0f2686d 100644 --- a/brightray/browser/devtools_ui.h +++ b/brightray/browser/devtools_ui.h @@ -17,9 +17,6 @@ class DevToolsUI : public content::WebUIController { explicit DevToolsUI(BrowserContext* browser_context, content::WebUI* web_ui); private: - // Weak reference to the browser context. - BrowserContext* browser_context_; - DISALLOW_COPY_AND_ASSIGN(DevToolsUI); }; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 48da9f1fb00..08d820d4631 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -28,10 +28,6 @@ namespace { const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html"; const char kDockSidePref[] = "brightray.devtools.dockside"; -GURL GetDevToolsURL() { - return GURL(kChromeUIDevToolsURL); -} - } // Implemented separately on each platform. @@ -76,7 +72,8 @@ void InspectableWebContentsImpl::ShowDevTools() { frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(devtools_web_contents_.get(), this)); content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get()); - devtools_web_contents_->GetController().LoadURL(GetDevToolsURL(), content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); + GURL devtools_url(kChromeUIDevToolsURL); + devtools_web_contents_->GetController().LoadURL(devtools_url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); } view_->SetDockSide(dock_side_); @@ -145,9 +142,6 @@ void InspectableWebContentsImpl::SearchInPath(int request_id, const std::string& void InspectableWebContentsImpl::InspectedContentsClosing() { } -void InspectableWebContentsImpl::RenderViewCreated(content::RenderViewHost* render_view_host) { -} - void InspectableWebContentsImpl::AboutToNavigateRenderView(content::RenderViewHost* render_view_host) { content::DevToolsClientHost::SetupDevToolsFrontendClient(web_contents()->GetRenderViewHost()); } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index c47eb871cd6..f81ccc0185a 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -69,7 +69,6 @@ private: // content::WebContentsObserver - virtual void RenderViewCreated(content::RenderViewHost*) OVERRIDE; virtual void AboutToNavigateRenderView(content::RenderViewHost* render_view_host) OVERRIDE; virtual void DidFinishLoad(int64 frame_id, const GURL& validated_url, From ae1e26bdddfb8a249d78f2fd0f0f469c96165a88 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Wed, 23 Oct 2013 12:13:24 -0400 Subject: [PATCH 0158/1195] Fix a hang on quit when application cache is used If you navigated to a page that used the HTML Application Cache, you'd see a hang on quit with a backtrace like so: + 2825 content::ContentMain(int, char const**, content::ContentMainDelegate*) (in libchromiumcontent.dylib) + 64 [0xb33190] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x96b261 [0xb34261] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x96a409 [0xb33409] + 2825 content::BrowserMain(content::MainFunctionParams const&) (in libchromiumcontent.dylib) + 200 [0x14290b8] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x1265426 [0x142e426] + 2825 content::BrowserMainLoop::~BrowserMainLoop() (in libchromiumcontent.dylib) + 17 [0x14294a1] + 2825 content::BrowserMainLoop::~BrowserMainLoop() (in libchromiumcontent.dylib) + 357 [0x1429625] + 2825 brightray::BrowserMainParts::~BrowserMainParts() (in ) + 70 [0x68df6] + 2825 scoped_ptr >::~scoped_ptr() (in ) + 23 [0x68ff7] + 2825 scoped_ptr >::~scoped_ptr() (in ) + 23 [0x69297] + 2825 base::internal::scoped_ptr_impl >::~scoped_ptr_impl() (in ) + 23 [0x692b7] + 2825 base::internal::scoped_ptr_impl >::~scoped_ptr_impl() (in ) + 50 [0x692f2] + 2825 base::DefaultDeleter::operator()(brightray::BrowserContext*) const (in ) + 46 [0x6916e] + 2825 brightray::BrowserContext::~BrowserContext() (in ) + 127 [0x672bf] + 2825 base::SupportsUserData::~SupportsUserData() (in libchromiumcontent.dylib) + 57 [0xccc019] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0xb03230 [0xccc230] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0xb0324e [0xccc24e] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x14c4239 [0x168d239] + 2825 content::StoragePartitionImpl::~StoragePartitionImpl() (in libchromiumcontent.dylib) + 17 [0x16899a1] + 2825 content::StoragePartitionImpl::~StoragePartitionImpl() (in libchromiumcontent.dylib) + 491 [0x1689bab] + 2825 content::ChromeAppCacheService::DeleteOnCorrectThread() const (in libchromiumcontent.dylib) + 66 [0x1424f32] + 2825 content::ChromeAppCacheService::~ChromeAppCacheService() (in libchromiumcontent.dylib) + 50 [0x1424e32] + 2825 appcache::AppCacheService::~AppCacheService() (in libchromiumcontent.dylib) + 301 [0x2b8ad2d] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x29c9b81 [0x2b92b81] + 2825 ??? (in libchromiumcontent.dylib) load address 0x1c9000 + 0x29c9da4 [0x2b92da4] + 2825 appcache::AppCacheDiskCache::~AppCacheDiskCache() (in libchromiumcontent.dylib) + 17 [0x2b78c71] + 2825 appcache::AppCacheDiskCache::~AppCacheDiskCache() (in libchromiumcontent.dylib) + 135 [0x2b78d17] + 2825 disk_cache::BackendImpl::~BackendImpl() (in libchromiumcontent.dylib) + 17 [0x25979a1] + 2825 disk_cache::BackendImpl::~BackendImpl() (in libchromiumcontent.dylib) + 305 [0x2597af1] + 2825 base::WaitableEvent::Wait() (in libchromiumcontent.dylib) + 50 [0xccd942] + 2825 base::WaitableEvent::TimedWait(base::TimeDelta const&) (in libchromiumcontent.dylib) + 347 [0xccdb3b] + 2825 base::ConditionVariable::Wait() (in libchromiumcontent.dylib) + 35 [0xcccbb3] + 2825 pthread_cond_wait$UNIX2003 (in libsystem_c.dylib) + 71 [0x964d3089] + 2825 _pthread_cond_wait (in libsystem_c.dylib) + 833 [0x9644d280] + 2825 __psynch_cvwait (in libsystem_kernel.dylib) + 10 [0x94b8e8e2] BackendImpl was waiting on BrowserThread::CACHE, but that thread had already been stopped. The solution is to destroy the BrowserContext before threads have been stopped. We now do this in BrowserMainParts::PostMainMessageLoopRun, which matches content_shell. --- brightray/browser/browser_main_parts.cc | 4 ++++ brightray/browser/browser_main_parts.h | 1 + 2 files changed, 5 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 8bcaf3621b1..c41a6a3a6f3 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -23,6 +23,10 @@ void BrowserMainParts::PreMainMessageLoopRun() { content::WebUIControllerFactory::RegisterFactory(web_ui_controller_factory_.get()); } +void BrowserMainParts::PostMainMessageLoopRun() { + browser_context_.reset(); +} + BrowserContext* BrowserMainParts::CreateBrowserContext() { return new BrowserContext; } diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index ca80e557654..210ff7e31ba 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -31,6 +31,7 @@ protected: #endif virtual void PreMainMessageLoopRun() OVERRIDE; + virtual void PostMainMessageLoopRun() OVERRIDE; private: scoped_ptr browser_context_; From 04b9bd21f888d9976d10f8c1613e72d26e4cc4ab Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Thu, 7 Nov 2013 14:02:35 -0600 Subject: [PATCH 0159/1195] WIP: builds (but displys nothing) on Linux --- brightray/.gitignore | 6 +++ brightray/brightray.gyp | 12 +++++ .../inspectable_web_contents_view_linux.cc | 47 +++++++++++++++++++ .../inspectable_web_contents_view_linux.h | 33 +++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 brightray/browser/linux/inspectable_web_contents_view_linux.cc create mode 100644 brightray/browser/linux/inspectable_web_contents_view_linux.h diff --git a/brightray/.gitignore b/brightray/.gitignore index 4ee8ba8eacf..3f04a5e2f1b 100644 --- a/brightray/.gitignore +++ b/brightray/.gitignore @@ -7,3 +7,9 @@ # Vim *.swp + +# Linux +Makefile +*.Makefile +*.mk +out/ diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b576b273ec7..7b5f88a3e98 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -46,6 +46,8 @@ 'browser/inspectable_web_contents_view.h', 'browser/inspectable_web_contents_view_mac.h', 'browser/inspectable_web_contents_view_mac.mm', + 'browser/linux/inspectable_web_contents_view_linux.h', + 'browser/linux/inspectable_web_contents_view_linux.cc', 'browser/mac/bry_application.h', 'browser/mac/bry_application.mm', 'browser/mac/bry_inspectable_web_contents_view.h', @@ -79,6 +81,16 @@ 'common/main_delegate_mac.mm', ], 'conditions': [ + ['OS=="linux"', { + 'cflags': [ + '-fno-rtti', + ], + 'link_settings': { + 'libraries': [ + '<(brightray_source_root)/<(libchromiumcontent_library_dir)/libchromiumcontent.so', + ], + }, + }], ['OS=="mac"', { 'link_settings': { 'libraries': [ diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc new file mode 100644 index 00000000000..2eda56fa33c --- /dev/null +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -0,0 +1,47 @@ +#include "inspectable_web_contents_view_linux.h" + +#include "browser/browser_client.h" +#include "browser/inspectable_web_contents_impl.h" + +#include "content/public/browser/web_contents_view.h" + +namespace brightray { + +InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { + return new InspectableWebContentsViewLinux(inspectable_web_contents); +} + +InspectableWebContentsViewLinux::InspectableWebContentsViewLinux(InspectableWebContentsImpl* inspectable_web_contents) + : inspectable_web_contents_(inspectable_web_contents) { + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::InspectableWebContentsViewLinux\n"); +} + +InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() { + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux\n"); +} + +gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const { + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::~GetNativeView\n"); + return NULL; +} + +void InspectableWebContentsViewLinux::ShowDevTools() { + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::ShowDevTools\n"); +} + +void InspectableWebContentsViewLinux::CloseDevTools() { + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::CloseDevTools\n"); +} + +bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::SetDockSide\n"); + return false; +} + +} diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/linux/inspectable_web_contents_view_linux.h new file mode 100644 index 00000000000..832481a0572 --- /dev/null +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.h @@ -0,0 +1,33 @@ +#ifndef BRIGHTRAY_BROWSER_LINUX_INSPECTABLE_WEB_CONTENTS_VIEW_LINUX_H_ +#define BRIGHTRAY_BROWSER_LINUX_INSPECTABLE_WEB_CONTENTS_VIEW_LINUX_H_ + +#include "browser/inspectable_web_contents_view.h" + +#include "base/compiler_specific.h" + +namespace brightray { + +class InspectableWebContentsImpl; + +class InspectableWebContentsViewLinux : public InspectableWebContentsView { +public: + InspectableWebContentsViewLinux(InspectableWebContentsImpl*); + ~InspectableWebContentsViewLinux(); + + virtual gfx::NativeView GetNativeView() const OVERRIDE; + virtual void ShowDevTools() OVERRIDE; + virtual void CloseDevTools() OVERRIDE; + virtual bool SetDockSide(const std::string& side) OVERRIDE; + + InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; } + +private: + // Owns us. + InspectableWebContentsImpl* inspectable_web_contents_; + + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewLinux); +}; + +} + +#endif From 90e619a6d9eaa40d73a8f08ffc5ffc24701e88e0 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Thu, 7 Nov 2013 17:25:51 -0600 Subject: [PATCH 0160/1195] fix typo --- brightray/browser/linux/inspectable_web_contents_view_linux.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index 2eda56fa33c..f4c3331016c 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -24,7 +24,7 @@ InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() { gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const { // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::~GetNativeView\n"); + fprintf(stderr, "InspectableWebContentsViewLinux::GetNativeView\n"); return NULL; } From c6ce51863a51ff71e09fd0a1cab13292c2458435 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Thu, 7 Nov 2013 23:42:15 -0600 Subject: [PATCH 0161/1195] implement GetNativeView --- .../inspectable_web_contents_view_linux.cc | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index f4c3331016c..2ef27e4fb09 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -13,34 +13,32 @@ InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContents InspectableWebContentsViewLinux::InspectableWebContentsViewLinux(InspectableWebContentsImpl* inspectable_web_contents) : inspectable_web_contents_(inspectable_web_contents) { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::InspectableWebContentsViewLinux\n"); + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::InspectableWebContentsViewLinux\n"); } InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux\n"); + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux\n"); } gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::GetNativeView\n"); - return NULL; + return inspectable_web_contents_->GetWebContents()->GetView()->GetNativeView(); } void InspectableWebContentsViewLinux::ShowDevTools() { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::ShowDevTools\n"); + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::ShowDevTools\n"); } void InspectableWebContentsViewLinux::CloseDevTools() { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::CloseDevTools\n"); + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::CloseDevTools\n"); } bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::SetDockSide\n"); + // TODO + fprintf(stderr, "InspectableWebContentsViewLinux::SetDockSide\n"); return false; } From 90db457258b2fc9adffc5b27a256849db7dbc731 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Sat, 9 Nov 2013 01:03:46 -0600 Subject: [PATCH 0162/1195] move -fno-rtti into brightray.gypi target_defaults --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index ad18976fd3f..ad824d6d749 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -177,6 +177,7 @@ ['OS=="linux"', { 'cflags_cc': [ '-std=gnu++11', + '-fno-rtti', ], }], ], From 7ebb19b9b115501e780dbab09a8fdf53d811675f Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Mon, 11 Nov 2013 16:34:27 -0600 Subject: [PATCH 0163/1195] use linux branch of libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 21d99bd412d..87c197cfd79 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 21d99bd412dda76aca6bcc722134d24d8ea17746 +Subproject commit 87c197cfd79e34baf8b666d552add2bedd01d43c From 72b41ed31b0f8057dd5dd81cadd31555634707bd Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Mon, 11 Nov 2013 18:15:22 -0600 Subject: [PATCH 0164/1195] pick up chrome_sandbox changes --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 87c197cfd79..58d63bfde11 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 87c197cfd79e34baf8b666d552add2bedd01d43c +Subproject commit 58d63bfde11b47a83fe014f9589865c1f6352566 From f6784a18016543163d46c72a6036b261166b8f1e Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Tue, 12 Nov 2013 10:19:42 -0600 Subject: [PATCH 0165/1195] move gtk dependency to brightray --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index ad824d6d749..911bdc30904 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -178,6 +178,7 @@ 'cflags_cc': [ '-std=gnu++11', '-fno-rtti', + ' Date: Tue, 12 Nov 2013 11:43:29 -0600 Subject: [PATCH 0166/1195] use merged master of libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 58d63bfde11..430d2991ce0 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 58d63bfde11b47a83fe014f9589865c1f6352566 +Subproject commit 430d2991ce0371f60eaea220c0272bacc8a58860 From 5e7359bc5aaf69d6970f90d60e0b5819d272d659 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Tue, 12 Nov 2013 11:51:25 -0600 Subject: [PATCH 0167/1195] don't build Linux sources on other platforms --- brightray/brightray.gypi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 911bdc30904..5587c5dd724 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -180,6 +180,11 @@ '-fno-rtti', ' Date: Wed, 13 Nov 2013 00:42:14 -0600 Subject: [PATCH 0168/1195] link libencryptor --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b40bcd8006b..a4ba5f7861c 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -90,6 +90,7 @@ 'link_settings': { 'libraries': [ '<(brightray_source_root)/<(libchromiumcontent_library_dir)/libchromiumcontent.so', + '<(brightray_source_root)/<(libchromiumcontent_library_dir)/libencryptor.a', ], }, }], From 236e993ac5dabbd56beec184dd45bb205a9afb7e Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Wed, 13 Nov 2013 01:45:08 -0600 Subject: [PATCH 0169/1195] use linux branch of libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 430d2991ce0..0799fdd0347 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 430d2991ce0371f60eaea220c0272bacc8a58860 +Subproject commit 0799fdd034742d6d746c64940d52c599986f7179 From 616cb8212d075a243a7961386a4b2a590685f49e Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Wed, 13 Nov 2013 15:34:07 -0600 Subject: [PATCH 0170/1195] current libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 0799fdd0347..593a0574a00 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 0799fdd034742d6d746c64940d52c599986f7179 +Subproject commit 593a0574a00c962ca8d2484e2f44fab1405c5a2a From cbb00f77c2897a3879c10635b9ee29fe821103ff Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Wed, 13 Nov 2013 23:22:50 -0600 Subject: [PATCH 0171/1195] current libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 593a0574a00..804a3fb837e 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 593a0574a00c962ca8d2484e2f44fab1405c5a2a +Subproject commit 804a3fb837e22060067e01f46f0d92708d8c3cbc From 3b3d6b2938f512c76e344bb5a2bdf9ae34aa57ff Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Wed, 13 Nov 2013 23:48:06 -0600 Subject: [PATCH 0172/1195] current libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 804a3fb837e..593a0574a00 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 804a3fb837e22060067e01f46f0d92708d8c3cbc +Subproject commit 593a0574a00c962ca8d2484e2f44fab1405c5a2a From 85a86a96213951dd615ba2962cc0bcef381c35a1 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Wed, 13 Nov 2013 23:50:23 -0600 Subject: [PATCH 0173/1195] current libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 593a0574a00..804a3fb837e 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 593a0574a00c962ca8d2484e2f44fab1405c5a2a +Subproject commit 804a3fb837e22060067e01f46f0d92708d8c3cbc From 282639a79aba67c3b51aa14041776b1cffce7186 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Fri, 15 Nov 2013 14:23:52 -0600 Subject: [PATCH 0174/1195] implement dev tools --- .../inspectable_web_contents_view_linux.cc | 216 +++++++++++++++++- .../inspectable_web_contents_view_linux.h | 21 ++ 2 files changed, 225 insertions(+), 12 deletions(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index 2ef27e4fb09..3a8428217c4 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -1,5 +1,8 @@ #include "inspectable_web_contents_view_linux.h" +#include +#include +#include "base/strings/stringprintf.h" #include "browser/browser_client.h" #include "browser/inspectable_web_contents_impl.h" @@ -12,34 +15,223 @@ InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContents } InspectableWebContentsViewLinux::InspectableWebContentsViewLinux(InspectableWebContentsImpl* inspectable_web_contents) - : inspectable_web_contents_(inspectable_web_contents) { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::InspectableWebContentsViewLinux\n"); + : inspectable_web_contents_(inspectable_web_contents), devtools_window(NULL) { } InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux\n"); + if (devtools_window) gtk_widget_destroy(devtools_window); } +#if 0 // some utility functions to debug GTK window hierarchies +static void dump_one(GtkWidget *wat, int indent) { + GtkAllocation alloc; + gtk_widget_get_allocation(wat, &alloc); + fprintf(stderr, "%*s[%p] %s @%d,%d %dx%d", + indent, "", wat, + g_type_name_from_instance((GTypeInstance*)wat), + alloc.x, alloc.y, alloc.width, alloc.height); + if (GTK_IS_WINDOW(wat)) fprintf(stderr, " - \"%s\"", gtk_window_get_title(GTK_WINDOW(wat))); + fputc('\n', stderr); +} + +static void dump_the_whole_tree(GtkWidget *wat, int indent) { + if (!wat) { + fprintf(stderr, "(nil)\n"); + return; + } + dump_one(wat, indent); + GList *kids = gtk_container_get_children(GTK_CONTAINER(wat)); + for (GList *p=kids; p; p=p->next) { + dump_the_whole_tree(GTK_WIDGET(p->data), indent+2); + } +} + +static void dump_parents(GtkWidget *wat) { + fprintf(stderr, "Parents:\n"); + for (GtkWidget *p=gtk_widget_get_parent(wat); p; p=gtk_widget_get_parent(p)) { + dump_one(p, 2); + } +} +#endif + gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const { return inspectable_web_contents_->GetWebContents()->GetView()->GetNativeView(); } + +/* This code is a little bit hairy. + The dev tools can be in any one of five places: + 1. Unassigned and invisible. This is the default state until someone asks + to 'inspect element' for the first time. In this case, devtools->parent is + NULL. + 2. In an onscreen window, visible. + 3. In the bottom half of a GtkVPaned. + 4. In the right half of a GtkHPaned. + 5. In an offscreen window, invisible. This is where they go once they have + been displayed and the user asks to "close" them. They can't be put back + into the unassigned state. + ShowDevTools() and is responsible for transitioning from any one of these + states to the three visible states, 2-4, as indicated by the contents of the + 'dockside' variable. The helper functions ShowDevToolsInWindow and + ShowDevToolsInPane focus on transitioning to states 2 and 3+4, respectively. + These helper functions are responsible for the entire transition, including + cleaning up any extraneous containers from the old state. + + Hiding the dev tools is taken care of by CloseDevTools (from paned states + 3+4 to invisible state 5) or by the "delete-event" signal on the + devtools_window (from window state 2 to 5). + + Remember that GTK does reference counting, so a view with no refs and no + parent will be freed. Views that have a ref but no parents will lose their + dimensions. So it's best to move the devtools view from place to place with + gtk_widget_reparent whenever possible. Unfortunately, one cannot reparent + things into a GtkPaned, so fairly brittle use of g_object_[un]ref and + gtk_container_remove happens. +*/ + void InspectableWebContentsViewLinux::ShowDevTools() { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::ShowDevTools\n"); + GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); + GtkWidget *parent = gtk_widget_get_parent(devtools); + + DLOG(INFO) << base::StringPrintf("InspectableWebContentsViewLinux::ShowDevTools - parent=%s@%p window=%p dockside=\"%s\"", + g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window, dockside.c_str()); + + if (!parent || GTK_IS_PANED(parent)) { + if (dockside == "undocked") ShowDevToolsInWindow(); + else if (dockside == "bottom") ShowDevToolsInPane(true); + else if (dockside == "right") ShowDevToolsInPane(false); + } + else { + DCHECK(parent == devtools_window); + if (dockside == "undocked") gtk_widget_show_all(parent); + else if (dockside == "bottom") ShowDevToolsInPane(true); + else if (dockside == "right") ShowDevToolsInPane(false); + } } void InspectableWebContentsViewLinux::CloseDevTools() { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::CloseDevTools\n"); + GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); + GtkWidget *parent = gtk_widget_get_parent(devtools); + + DLOG(INFO) << base::StringPrintf("InspectableWebContentsViewLinux::CloseDevTools - parent=%s@%p window=%p dockside=\"%s\"", + g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window, dockside.c_str()); + + if (!parent) { + return; // Not visible -> nothing to do + } + else if (GTK_IS_PANED(parent)) { + GtkWidget *browser = GetBrowserWindow(); + GtkWidget *view = GetNativeView(); + + if (!devtools_window) MakeDevToolsWindow(); + gtk_widget_reparent(devtools, devtools_window); + g_object_ref(parent); + gtk_container_remove(GTK_CONTAINER(browser), parent); + gtk_widget_reparent(view, browser); + g_object_unref(parent); + } + else { + DCHECK(parent == devtools_window); + gtk_widget_hide(parent); + } } bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { - // TODO - fprintf(stderr, "InspectableWebContentsViewLinux::SetDockSide\n"); - return false; + DLOG(INFO) << "InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\""; + if (side != "undocked" && side != "bottom" && side != "right") return false; // unsupported display location + if (dockside == side) return true; // no change from current location + + dockside = side; + + // If devtools already has a parent, then we're being asked to move it. + GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); + if (gtk_widget_get_parent(devtools)) { + ShowDevTools(); + } + + return true; +} + +void InspectableWebContentsViewLinux::ShowDevToolsInWindow() { + GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); + GtkWidget *parent = gtk_widget_get_parent(devtools); + + if (!devtools_window) MakeDevToolsWindow(); + if (!parent) { + gtk_container_add(GTK_CONTAINER(devtools_window), devtools); + } + else if (parent != devtools_window) { + DCHECK(GTK_IS_PANED(parent)); + gtk_widget_reparent(devtools, devtools_window); + + // Remove the pane. + GtkWidget *view = GetNativeView(); + GtkWidget *browser = GetBrowserWindow(); + g_object_ref(view); + gtk_container_remove(GTK_CONTAINER(parent), view); + gtk_container_remove(GTK_CONTAINER(browser), parent); + gtk_container_add(GTK_CONTAINER(browser), view); + g_object_unref(view); + } + gtk_widget_show_all(devtools_window); +} + +void InspectableWebContentsViewLinux::MakeDevToolsWindow() { + DCHECK(!devtools_window); + devtools_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(devtools_window), "Developer Tools"); + gtk_window_set_default_size(GTK_WINDOW(devtools_window), 800, 600); + g_signal_connect(GTK_OBJECT(devtools_window), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), this); +} + +void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) { + GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); + GtkWidget *parent = gtk_widget_get_parent(devtools); + GtkWidget *pane = on_bottom ? gtk_vpaned_new() : gtk_hpaned_new(); + GtkWidget *view = GetNativeView(); + GtkWidget *browser = GetBrowserWindow(); + + GtkAllocation alloc; + gtk_widget_get_allocation(browser, &alloc); + gtk_paned_set_position(GTK_PANED(pane), on_bottom ? alloc.height*2/3 : alloc.width/2); + if (!parent) { + g_object_ref(view); + gtk_container_remove(GTK_CONTAINER(browser), view); + gtk_paned_add1(GTK_PANED(pane), view); + gtk_paned_add2(GTK_PANED(pane), devtools); + g_object_unref(view); + } + else if (GTK_IS_PANED(parent)) { + g_object_ref(view); + g_object_ref(devtools); + gtk_container_remove(GTK_CONTAINER(parent), view); + gtk_container_remove(GTK_CONTAINER(parent), devtools); + gtk_paned_add1(GTK_PANED(pane), view); + gtk_paned_add2(GTK_PANED(pane), devtools); + g_object_unref(view); + g_object_unref(devtools); + gtk_container_remove(GTK_CONTAINER(browser), parent); + } + else { + DCHECK(parent == devtools_window); + g_object_ref(view); + gtk_container_remove(GTK_CONTAINER(devtools_window), devtools); + gtk_container_remove(GTK_CONTAINER(browser), view); + gtk_paned_add1(GTK_PANED(pane), view); + gtk_paned_add2(GTK_PANED(pane), devtools); + g_object_unref(view); + gtk_widget_hide(devtools_window); + } + gtk_container_add(GTK_CONTAINER(browser), pane); + gtk_widget_show_all(pane); +} + +GtkWidget *InspectableWebContentsViewLinux::GetBrowserWindow() { + GtkWidget *view = GetNativeView(); + GtkWidget *parent = gtk_widget_get_parent(view); + GtkWidget *browser = GTK_IS_PANED(parent) ? gtk_widget_get_parent(parent) : parent; + DCHECK(GTK_IS_WINDOW(browser)); + return browser; } } diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/linux/inspectable_web_contents_view_linux.h index 832481a0572..f0b89929804 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.h +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.h @@ -25,6 +25,27 @@ private: // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; + std::string dockside; + GtkWidget *devtools_window; + + // Show the dev tools in their own window. If they're already shown + // somewhere else, remove them cleanly and take any GtkPaned out of the + // window. + void ShowDevToolsInWindow(); + + // Show the dev tools in a vpaned (on the bottom) or hpaned (on the + // right). If they're already shown in a pane, move them and remove the + // old pane. If they're already shown in a window, hide (don't delete) + // that window. + void ShowDevToolsInPane(bool on_bottom); + + // Create a new window for dev tools. This function doesn't actually + // put the dev tools in the window or show the window. + void MakeDevToolsWindow(); + + // Get the GtkWindow* that contains this object. + GtkWidget *GetBrowserWindow(); + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewLinux); }; From 7e1a4003df70b5eb044bb4cad0166ac4ec60233d Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Fri, 15 Nov 2013 22:18:59 -0600 Subject: [PATCH 0175/1195] don't force all applications to link libencryptor.a --- brightray/brightray.gyp | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index a4ba5f7861c..b40bcd8006b 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -90,7 +90,6 @@ 'link_settings': { 'libraries': [ '<(brightray_source_root)/<(libchromiumcontent_library_dir)/libchromiumcontent.so', - '<(brightray_source_root)/<(libchromiumcontent_library_dir)/libencryptor.a', ], }, }], From a18842de1a913f2f40daa14ef9c9ea5f7b98fc65 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Fri, 15 Nov 2013 22:22:25 -0600 Subject: [PATCH 0176/1195] give member variables trailing _ - also, reorder member variables to come after methods --- .../inspectable_web_contents_view_linux.cc | 62 +++++++++---------- .../inspectable_web_contents_view_linux.h | 40 ++++++------ 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index 3a8428217c4..eb792aa69d8 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -15,11 +15,11 @@ InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContents } InspectableWebContentsViewLinux::InspectableWebContentsViewLinux(InspectableWebContentsImpl* inspectable_web_contents) - : inspectable_web_contents_(inspectable_web_contents), devtools_window(NULL) { + : inspectable_web_contents_(inspectable_web_contents), devtools_window_(NULL) { } InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() { - if (devtools_window) gtk_widget_destroy(devtools_window); + if (devtools_window_) gtk_widget_destroy(devtools_window_); } #if 0 // some utility functions to debug GTK window hierarchies @@ -72,14 +72,14 @@ gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const { into the unassigned state. ShowDevTools() and is responsible for transitioning from any one of these states to the three visible states, 2-4, as indicated by the contents of the - 'dockside' variable. The helper functions ShowDevToolsInWindow and + 'dockside_' variable. The helper functions ShowDevToolsInWindow and ShowDevToolsInPane focus on transitioning to states 2 and 3+4, respectively. These helper functions are responsible for the entire transition, including cleaning up any extraneous containers from the old state. Hiding the dev tools is taken care of by CloseDevTools (from paned states 3+4 to invisible state 5) or by the "delete-event" signal on the - devtools_window (from window state 2 to 5). + devtools_window_ (from window state 2 to 5). Remember that GTK does reference counting, so a view with no refs and no parent will be freed. Views that have a ref but no parents will lose their @@ -94,18 +94,18 @@ void InspectableWebContentsViewLinux::ShowDevTools() { GtkWidget *parent = gtk_widget_get_parent(devtools); DLOG(INFO) << base::StringPrintf("InspectableWebContentsViewLinux::ShowDevTools - parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window, dockside.c_str()); + g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window_, dockside_.c_str()); if (!parent || GTK_IS_PANED(parent)) { - if (dockside == "undocked") ShowDevToolsInWindow(); - else if (dockside == "bottom") ShowDevToolsInPane(true); - else if (dockside == "right") ShowDevToolsInPane(false); + if (dockside_ == "undocked") ShowDevToolsInWindow(); + else if (dockside_ == "bottom") ShowDevToolsInPane(true); + else if (dockside_ == "right") ShowDevToolsInPane(false); } else { - DCHECK(parent == devtools_window); - if (dockside == "undocked") gtk_widget_show_all(parent); - else if (dockside == "bottom") ShowDevToolsInPane(true); - else if (dockside == "right") ShowDevToolsInPane(false); + DCHECK(parent == devtools_window_); + if (dockside_ == "undocked") gtk_widget_show_all(parent); + else if (dockside_ == "bottom") ShowDevToolsInPane(true); + else if (dockside_ == "right") ShowDevToolsInPane(false); } } @@ -114,7 +114,7 @@ void InspectableWebContentsViewLinux::CloseDevTools() { GtkWidget *parent = gtk_widget_get_parent(devtools); DLOG(INFO) << base::StringPrintf("InspectableWebContentsViewLinux::CloseDevTools - parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window, dockside.c_str()); + g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window_, dockside_.c_str()); if (!parent) { return; // Not visible -> nothing to do @@ -123,15 +123,15 @@ void InspectableWebContentsViewLinux::CloseDevTools() { GtkWidget *browser = GetBrowserWindow(); GtkWidget *view = GetNativeView(); - if (!devtools_window) MakeDevToolsWindow(); - gtk_widget_reparent(devtools, devtools_window); + if (!devtools_window_) MakeDevToolsWindow(); + gtk_widget_reparent(devtools, devtools_window_); g_object_ref(parent); gtk_container_remove(GTK_CONTAINER(browser), parent); gtk_widget_reparent(view, browser); g_object_unref(parent); } else { - DCHECK(parent == devtools_window); + DCHECK(parent == devtools_window_); gtk_widget_hide(parent); } } @@ -139,9 +139,9 @@ void InspectableWebContentsViewLinux::CloseDevTools() { bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { DLOG(INFO) << "InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\""; if (side != "undocked" && side != "bottom" && side != "right") return false; // unsupported display location - if (dockside == side) return true; // no change from current location + if (dockside_ == side) return true; // no change from current location - dockside = side; + dockside_ = side; // If devtools already has a parent, then we're being asked to move it. GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); @@ -156,13 +156,13 @@ void InspectableWebContentsViewLinux::ShowDevToolsInWindow() { GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); GtkWidget *parent = gtk_widget_get_parent(devtools); - if (!devtools_window) MakeDevToolsWindow(); + if (!devtools_window_) MakeDevToolsWindow(); if (!parent) { - gtk_container_add(GTK_CONTAINER(devtools_window), devtools); + gtk_container_add(GTK_CONTAINER(devtools_window_), devtools); } - else if (parent != devtools_window) { + else if (parent != devtools_window_) { DCHECK(GTK_IS_PANED(parent)); - gtk_widget_reparent(devtools, devtools_window); + gtk_widget_reparent(devtools, devtools_window_); // Remove the pane. GtkWidget *view = GetNativeView(); @@ -173,15 +173,15 @@ void InspectableWebContentsViewLinux::ShowDevToolsInWindow() { gtk_container_add(GTK_CONTAINER(browser), view); g_object_unref(view); } - gtk_widget_show_all(devtools_window); + gtk_widget_show_all(devtools_window_); } void InspectableWebContentsViewLinux::MakeDevToolsWindow() { - DCHECK(!devtools_window); - devtools_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(devtools_window), "Developer Tools"); - gtk_window_set_default_size(GTK_WINDOW(devtools_window), 800, 600); - g_signal_connect(GTK_OBJECT(devtools_window), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), this); + DCHECK(!devtools_window_); + devtools_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(devtools_window_), "Developer Tools"); + gtk_window_set_default_size(GTK_WINDOW(devtools_window_), 800, 600); + g_signal_connect(GTK_OBJECT(devtools_window_), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), this); } void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) { @@ -213,14 +213,14 @@ void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) { gtk_container_remove(GTK_CONTAINER(browser), parent); } else { - DCHECK(parent == devtools_window); + DCHECK(parent == devtools_window_); g_object_ref(view); - gtk_container_remove(GTK_CONTAINER(devtools_window), devtools); + gtk_container_remove(GTK_CONTAINER(devtools_window_), devtools); gtk_container_remove(GTK_CONTAINER(browser), view); gtk_paned_add1(GTK_PANED(pane), view); gtk_paned_add2(GTK_PANED(pane), devtools); g_object_unref(view); - gtk_widget_hide(devtools_window); + gtk_widget_hide(devtools_window_); } gtk_container_add(GTK_CONTAINER(browser), pane); gtk_widget_show_all(pane); diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/linux/inspectable_web_contents_view_linux.h index f0b89929804..f82de0a54cd 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.h +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.h @@ -22,29 +22,29 @@ public: InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; } private: + // Show the dev tools in their own window. If they're already shown + // somewhere else, remove them cleanly and take any GtkPaned out of the + // window. + void ShowDevToolsInWindow(); + + // Show the dev tools in a vpaned (on the bottom) or hpaned (on the + // right). If they're already shown in a pane, move them and remove the + // old pane. If they're already shown in a window, hide (don't delete) + // that window. + void ShowDevToolsInPane(bool on_bottom); + + // Create a new window for dev tools. This function doesn't actually + // put the dev tools in the window or show the window. + void MakeDevToolsWindow(); + + // Get the GtkWindow* that contains this object. + GtkWidget *GetBrowserWindow(); + // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; - std::string dockside; - GtkWidget *devtools_window; - - // Show the dev tools in their own window. If they're already shown - // somewhere else, remove them cleanly and take any GtkPaned out of the - // window. - void ShowDevToolsInWindow(); - - // Show the dev tools in a vpaned (on the bottom) or hpaned (on the - // right). If they're already shown in a pane, move them and remove the - // old pane. If they're already shown in a window, hide (don't delete) - // that window. - void ShowDevToolsInPane(bool on_bottom); - - // Create a new window for dev tools. This function doesn't actually - // put the dev tools in the window or show the window. - void MakeDevToolsWindow(); - - // Get the GtkWindow* that contains this object. - GtkWidget *GetBrowserWindow(); + std::string dockside_; + GtkWidget *devtools_window_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewLinux); }; From c0543d9b465c8c900d8a096a7e43ea5ce5157c96 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Fri, 15 Nov 2013 23:04:02 -0600 Subject: [PATCH 0177/1195] current libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 804a3fb837e..f8c75f2bc74 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 804a3fb837e22060067e01f46f0d92708d8c3cbc +Subproject commit f8c75f2bc74500e5f24574e22e289b329b5a9a5e From 5ae0b3094c160d81b12e719ccfaa383b3d9bfa03 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Sat, 16 Nov 2013 00:49:53 -0600 Subject: [PATCH 0178/1195] current libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index f8c75f2bc74..8fe70e336bc 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit f8c75f2bc74500e5f24574e22e289b329b5a9a5e +Subproject commit 8fe70e336bc8ebde82225d692ef254999defe243 From ceb8113ca68603fa0c02cd52f14f710f06741580 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Sat, 16 Nov 2013 01:14:51 -0600 Subject: [PATCH 0179/1195] current libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 8fe70e336bc..7ddba388364 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 8fe70e336bc8ebde82225d692ef254999defe243 +Subproject commit 7ddba388364ee0b429a2b72555daa55e3270876f From 43f3d0acdc0713de93766608a92b1fd80ed39e21 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 17:36:57 -0500 Subject: [PATCH 0180/1195] Run cpplint as part of our CI build This will help ensure a consistent C++ coding style. --- brightray/.gitmodules | 3 +++ brightray/script/cibuild | 1 + brightray/script/cpplint | 36 ++++++++++++++++++++++++++++++ brightray/vendor/google-styleguide | 1 + 4 files changed, 41 insertions(+) create mode 100755 brightray/script/cpplint create mode 160000 brightray/vendor/google-styleguide diff --git a/brightray/.gitmodules b/brightray/.gitmodules index 1e27bc6b5a2..17120b4cdf6 100644 --- a/brightray/.gitmodules +++ b/brightray/.gitmodules @@ -4,3 +4,6 @@ [submodule "vendor/gyp"] path = vendor/gyp url = https://github.com/svn2github/gyp +[submodule "vendor/google-styleguide"] + path = vendor/google-styleguide + url = https://github.com/svn2github/sgss-mirror-google-styleguide diff --git a/brightray/script/cibuild b/brightray/script/cibuild index 318331ffb3b..ab6b8eaeadf 100755 --- a/brightray/script/cibuild +++ b/brightray/script/cibuild @@ -18,6 +18,7 @@ def main(): url = 'https://{0}.s3.amazonaws.com/libchromiumcontent'.format(os.environ['JANKY_ARTIFACTS_S3_BUCKET']) return (run_script('bootstrap', url) or + run_script('cpplint') or run_script('build')) diff --git a/brightray/script/cpplint b/brightray/script/cpplint new file mode 100755 index 00000000000..2b2851f2774 --- /dev/null +++ b/brightray/script/cpplint @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import fnmatch +import os +import subprocess +import sys + + +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'google-styleguide', 'trunk', 'cpplint', 'cpplint.py') + + +def main(): + os.chdir(SOURCE_ROOT) + files = list_files(['browser', 'common'], + ['*.cc', '*.mm', '*.h']) + return cpplint(files) + + +def list_files(directories, filters): + matches = [] + for directory in directories: + for root, _, filenames, in os.walk(directory): + for f in filters: + for filename in fnmatch.filter(filenames, f): + matches.append(os.path.join(root, filename)) + return matches + + +def cpplint(files): + rules = '--filter=-build/header_guard' + return subprocess.call([sys.executable, CPPLINT, rules] + files) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/brightray/vendor/google-styleguide b/brightray/vendor/google-styleguide new file mode 160000 index 00000000000..8025f5495c0 --- /dev/null +++ b/brightray/vendor/google-styleguide @@ -0,0 +1 @@ +Subproject commit 8025f5495c04f1cf9e0d65a0aaa97b58c304faf7 From 101a7bfa21a65bb6c39522bc739cca26fd7a85f8 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 17:39:01 -0500 Subject: [PATCH 0181/1195] Fix cpplint errors in browser_client.cc --- brightray/browser/browser_client.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 1c19f622ef0..c407989af49 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -42,18 +42,23 @@ NotificationPresenter* BrowserClient::notification_presenter() { return notification_presenter_.get(); } -BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts(const content::MainFunctionParams&) { +BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts( + const content::MainFunctionParams&) { return new BrowserMainParts; } -content::BrowserMainParts* BrowserClient::CreateBrowserMainParts(const content::MainFunctionParams& parameters) { +content::BrowserMainParts* BrowserClient::CreateBrowserMainParts( + const content::MainFunctionParams& parameters) { DCHECK(!browser_main_parts_); browser_main_parts_ = OverrideCreateBrowserMainParts(parameters); return browser_main_parts_; } -net::URLRequestContextGetter* BrowserClient::CreateRequestContext(content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers) { - return static_cast(browser_context)->CreateRequestContext(protocol_handlers); +net::URLRequestContextGetter* BrowserClient::CreateRequestContext( + content::BrowserContext* browser_context, + content::ProtocolHandlerMap* protocol_handlers) { + auto context = static_cast(browser_context); + return context->CreateRequestContext(protocol_handlers); } void BrowserClient::ShowDesktopNotification( @@ -74,11 +79,12 @@ void BrowserClient::CancelDesktopNotification( auto presenter = notification_presenter(); if (!presenter) return; - presenter->CancelNotification(render_process_id, render_view_id, notification_id); + presenter->CancelNotification( + render_process_id, render_view_id, notification_id); } content::MediaObserver* BrowserClient::GetMediaObserver() { return MediaCaptureDevicesDispatcher::GetInstance(); } -} +} // namespace brightray From cc4aeb995bd2f5477367e4cddeee2dfc71af5637 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 17:42:56 -0500 Subject: [PATCH 0182/1195] Fix cpplint errors in browser_context.cc --- brightray/browser/browser_context.cc | 55 +++++++++++++++++++--------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index e43607a196c..060ba3b427d 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include "browser_context.h" +#include "browser/browser_context.h" #include "browser/download_manager_delegate.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/network_delegate.h" +#include "browser/url_request_context_getter.h" #include "common/application_info.h" #include "base/environment.h" @@ -19,7 +20,6 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" -#include "url_request_context_getter.h" #if defined(OS_LINUX) #include "base/nix/xdg_util.h" @@ -28,28 +28,30 @@ namespace brightray { class BrowserContext::ResourceContext : public content::ResourceContext { -public: + public: ResourceContext() : getter_(nullptr) {} void set_url_request_context_getter(URLRequestContextGetter* getter) { getter_ = getter; } -private: + private: virtual net::HostResolver* GetHostResolver() OVERRIDE { return getter_->host_resolver(); } - + virtual net::URLRequestContext* GetRequestContext() OVERRIDE { return getter_->GetURLRequestContext(); } - // FIXME: We should probably allow clients to override this to implement more restrictive policies. + // FIXME: We should probably allow clients to override this to implement more + // restrictive policies. virtual bool AllowMicAccess(const GURL& origin) OVERRIDE { return true; } - - // FIXME: We should probably allow clients to override this to implement more restrictive policies. + + // FIXME: We should probably allow clients to override this to implement more + // restrictive policies. virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE { return true; } @@ -76,7 +78,8 @@ void BrowserContext::Initialize() { auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); PrefServiceBuilder builder; builder.WithUserFilePrefs(prefs_path, - JsonPrefStore::GetTaskRunnerForFile(prefs_path, content::BrowserThread::GetBlockingPool())); + JsonPrefStore::GetTaskRunnerForFile( + prefs_path, content::BrowserThread::GetBlockingPool())); auto registry = make_scoped_refptr(new PrefRegistrySimple); RegisterInternalPrefs(registry); @@ -92,12 +95,17 @@ void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { InspectableWebContentsImpl::RegisterPrefs(registry); } -net::URLRequestContextGetter* BrowserContext::CreateRequestContext(content::ProtocolHandlerMap* protocol_handlers) { +net::URLRequestContextGetter* BrowserContext::CreateRequestContext( + content::ProtocolHandlerMap* protocol_handlers) { DCHECK(!url_request_getter_); + auto io_loop = content::BrowserThread::UnsafeGetMessageLoopForThread( + content::BrowserThread::IO), + auto file_loop = content::BrowserThread::UnsafeGetMessageLoopForThread( + content::BrowserThread::FILE), url_request_getter_ = new URLRequestContextGetter( GetPath(), - content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::IO), - content::BrowserThread::UnsafeGetMessageLoopForThread(content::BrowserThread::FILE), + io_loop, + file_loop, CreateNetworkDelegate().Pass(), protocol_handlers); resource_context_->set_url_request_context_getter(url_request_getter_.get()); @@ -120,7 +128,8 @@ net::URLRequestContextGetter* BrowserContext::GetRequestContext() { return GetDefaultStoragePartition(this)->GetURLRequestContext(); } -net::URLRequestContextGetter* BrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) { +net::URLRequestContextGetter* BrowserContext::GetRequestContextForRenderProcess( + int renderer_child_id) { return GetRequestContext(); } @@ -128,15 +137,24 @@ net::URLRequestContextGetter* BrowserContext::GetMediaRequestContext() { return GetRequestContext(); } -net::URLRequestContextGetter* BrowserContext::GetMediaRequestContextForRenderProcess(int renderer_child_id) { +net::URLRequestContextGetter* + BrowserContext::GetMediaRequestContextForRenderProcess( + int renderer_child_id) { return GetRequestContext(); } -net::URLRequestContextGetter* BrowserContext::GetMediaRequestContextForStoragePartition(const base::FilePath& partition_path, bool in_memory) { +net::URLRequestContextGetter* + BrowserContext::GetMediaRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory) { return GetRequestContext(); } -void BrowserContext::RequestMIDISysExPermission(int render_process_id, int render_view_id, const GURL& requesting_frame, const MIDISysExPermissionCallback& callback) { +void BrowserContext::RequestMIDISysExPermission( + int render_process_id, + int render_view_id, + const GURL& requesting_frame, + const MIDISysExPermissionCallback& callback) { callback.Run(false); } @@ -150,7 +168,8 @@ content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() { return download_manager_delegate_.get(); } -content::GeolocationPermissionContext* BrowserContext::GetGeolocationPermissionContext() { +content::GeolocationPermissionContext* + BrowserContext::GetGeolocationPermissionContext() { return nullptr; } @@ -158,4 +177,4 @@ quota::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() { return nullptr; } -} +} // namespace brightray From a35a57c3c4079289b6b749001863b852c90d9d0f Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 17:51:19 -0500 Subject: [PATCH 0183/1195] Fix cpplint errors in browser_main_parts.cc --- brightray/browser/browser_main_parts.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index c41a6a3a6f3..60057034f6e 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -19,8 +19,10 @@ void BrowserMainParts::PreMainMessageLoopRun() { browser_context_.reset(CreateBrowserContext()); browser_context_->Initialize(); - web_ui_controller_factory_.reset(new WebUIControllerFactory(browser_context_.get())); - content::WebUIControllerFactory::RegisterFactory(web_ui_controller_factory_.get()); + web_ui_controller_factory_.reset( + new WebUIControllerFactory(browser_context_.get())); + content::WebUIControllerFactory::RegisterFactory( + web_ui_controller_factory_.get()); } void BrowserMainParts::PostMainMessageLoopRun() { @@ -31,4 +33,4 @@ BrowserContext* BrowserMainParts::CreateBrowserContext() { return new BrowserContext; } -} +} // namespace brightray From 0c13adb134ffcbed1709ba385a50e5532d77e01b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 17:51:49 -0500 Subject: [PATCH 0184/1195] Don't require all files to have a copyright/license header The LICENSE file at the root of the repository is enough. --- brightray/script/cpplint | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/script/cpplint b/brightray/script/cpplint index 2b2851f2774..f5911be304b 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -28,7 +28,7 @@ def list_files(directories, filters): def cpplint(files): - rules = '--filter=-build/header_guard' + rules = '--filter=-build/header_guard,-legal/copyright' return subprocess.call([sys.executable, CPPLINT, rules] + files) From dfb8a809ee44916509ff65fc9dcf6f9bd5681c72 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 17:52:24 -0500 Subject: [PATCH 0185/1195] Fix cpplint errors in default_web_contents_delegate.cc --- brightray/browser/default_web_contents_delegate.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/default_web_contents_delegate.cc b/brightray/browser/default_web_contents_delegate.cc index f4e08b84098..05bdac399ad 100644 --- a/brightray/browser/default_web_contents_delegate.cc +++ b/brightray/browser/default_web_contents_delegate.cc @@ -18,4 +18,4 @@ void DefaultWebContentsDelegate::RequestMediaAccessPermission( controller.TakeAction(); } -} +} // namespace brightray From ef5992b0eb4b2ee04a72d79280cba68ba34f2bfa Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 17:53:38 -0500 Subject: [PATCH 0186/1195] Fix cpplint errors in devtools_ui.cc --- brightray/browser/devtools_ui.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 94e581728ab..def3ecb4694 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -90,12 +90,12 @@ class BundledDataSource : public content::URLDataSource { DISALLOW_COPY_AND_ASSIGN(BundledDataSource); }; -} +} // namespace DevToolsUI::DevToolsUI(BrowserContext* browser_context, content::WebUI* web_ui) - : WebUIController(web_ui) { + : WebUIController(web_ui) { web_ui->SetBindings(0); content::URLDataSource::Add(browser_context, new BundledDataSource()); } -} +} // namespace brightray From c97a22ef8d93442ad15708e7b9b90a2900bbf342 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 17:54:14 -0500 Subject: [PATCH 0187/1195] Fix cpplint errors in inspectable_web_contents.cc --- brightray/browser/inspectable_web_contents.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.cc b/brightray/browser/inspectable_web_contents.cc index 5e3af6013de..5090011a203 100644 --- a/brightray/browser/inspectable_web_contents.cc +++ b/brightray/browser/inspectable_web_contents.cc @@ -6,7 +6,8 @@ namespace brightray { -InspectableWebContents* InspectableWebContents::Create(const content::WebContents::CreateParams& create_params) { +InspectableWebContents* InspectableWebContents::Create( + const content::WebContents::CreateParams& create_params) { auto contents = content::WebContents::Create(create_params); #if defined(OS_MACOSX) // Work around http://crbug.com/279472. @@ -16,8 +17,9 @@ InspectableWebContents* InspectableWebContents::Create(const content::WebContent return Create(contents); } -InspectableWebContents* InspectableWebContents::Create(content::WebContents* web_contents) { +InspectableWebContents* InspectableWebContents::Create( + content::WebContents* web_contents) { return new InspectableWebContentsImpl(web_contents); } -} +} // namespace brightray From 784e270a4f58d27033965034dac973cfde424b06 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:08:34 -0500 Subject: [PATCH 0188/1195] Fix cpplint errors in inspectable_web_contents_impl.cc --- .../browser/inspectable_web_contents_impl.cc | 77 +++++++++++++------ 1 file changed, 55 insertions(+), 22 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 08d820d4631..b7ac0e74cd3 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -5,6 +5,8 @@ #include "browser/inspectable_web_contents_impl.h" +#include + #include "browser/browser_client.h" #include "browser/browser_context.h" #include "browser/browser_main_parts.h" @@ -31,15 +33,18 @@ const char kDockSidePref[] = "brightray.devtools.dockside"; } // Implemented separately on each platform. -InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl*); +InspectableWebContentsView* CreateInspectableContentsView( + InspectableWebContentsImpl* inspectable_web_contents_impl); void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { registry->RegisterStringPref(kDockSidePref, "bottom"); } -InspectableWebContentsImpl::InspectableWebContentsImpl(content::WebContents* web_contents) +InspectableWebContentsImpl::InspectableWebContentsImpl( + content::WebContents* web_contents) : web_contents_(web_contents) { - auto context = static_cast(web_contents_->GetBrowserContext()); + auto context = static_cast( + web_contents_->GetBrowserContext()); dock_side_ = context->prefs()->GetString(kDockSidePref); view_.reset(CreateInspectableContentsView(this)); @@ -58,7 +63,9 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const { void InspectableWebContentsImpl::ShowDevTools() { if (!devtools_web_contents_) { - devtools_web_contents_.reset(content::WebContents::Create(content::WebContents::CreateParams(web_contents_->GetBrowserContext()))); + auto create_params = content::WebContents::CreateParams( + web_contents_->GetBrowserContext()); + devtools_web_contents_.reset(content::WebContents::Create(create_params)); #if defined(OS_MACOSX) // Work around http://crbug.com/279472. @@ -68,12 +75,20 @@ void InspectableWebContentsImpl::ShowDevTools() { Observe(devtools_web_contents_.get()); devtools_web_contents_->SetDelegate(this); - agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_->GetRenderViewHost()); - frontend_host_.reset(content::DevToolsClientHost::CreateDevToolsFrontendHost(devtools_web_contents_.get(), this)); - content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, frontend_host_.get()); + agent_host_ = content::DevToolsAgentHost::GetOrCreateFor( + web_contents_->GetRenderViewHost()); + frontend_host_.reset( + content::DevToolsClientHost::CreateDevToolsFrontendHost( + devtools_web_contents_.get(), this)); + content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( + agent_host_, frontend_host_.get()); GURL devtools_url(kChromeUIDevToolsURL); - devtools_web_contents_->GetController().LoadURL(devtools_url, content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); + devtools_web_contents_->GetController().LoadURL( + devtools_url, + content::Referrer(), + content::PAGE_TRANSITION_AUTO_TOPLEVEL, + std::string()); } view_->SetDockSide(dock_side_); @@ -81,8 +96,10 @@ void InspectableWebContentsImpl::ShowDevTools() { } void InspectableWebContentsImpl::UpdateFrontendDockSide() { - auto javascript = base::StringPrintf("InspectorFrontendAPI.setDockSide(\"%s\")", dock_side_.c_str()); - devtools_web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame(string16(), ASCIIToUTF16(javascript)); + auto javascript = base::StringPrintf( + "InspectorFrontendAPI.setDockSide(\"%s\")", dock_side_.c_str()); + devtools_web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( + string16(), ASCIIToUTF16(javascript)); } void InspectableWebContentsImpl::ActivateWindow() { @@ -106,7 +123,8 @@ void InspectableWebContentsImpl::SetDockSide(const std::string& side) { dock_side_ = side; - auto context = static_cast(web_contents_->GetBrowserContext()); + auto context = static_cast( + web_contents_->GetBrowserContext()); context->prefs()->SetString(kDockSidePref, side); UpdateFrontendDockSide(); @@ -115,10 +133,12 @@ void InspectableWebContentsImpl::SetDockSide(const std::string& side) { void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) { } -void InspectableWebContentsImpl::SaveToFile(const std::string& url, const std::string& content, bool save_as) { +void InspectableWebContentsImpl::SaveToFile( + const std::string& url, const std::string& content, bool save_as) { } -void InspectableWebContentsImpl::AppendToFile(const std::string& url, const std::string& content) { +void InspectableWebContentsImpl::AppendToFile( + const std::string& url, const std::string& content) { } void InspectableWebContentsImpl::RequestFileSystems() { @@ -127,26 +147,36 @@ void InspectableWebContentsImpl::RequestFileSystems() { void InspectableWebContentsImpl::AddFileSystem() { } -void InspectableWebContentsImpl::RemoveFileSystem(const std::string& file_system_path) { +void InspectableWebContentsImpl::RemoveFileSystem( + const std::string& file_system_path) { } -void InspectableWebContentsImpl::IndexPath(int request_id, const std::string& file_system_path) { +void InspectableWebContentsImpl::IndexPath( + int request_id, const std::string& file_system_path) { } void InspectableWebContentsImpl::StopIndexing(int request_id) { } -void InspectableWebContentsImpl::SearchInPath(int request_id, const std::string& file_system_path, const std::string& query) { +void InspectableWebContentsImpl::SearchInPath( + int request_id, + const std::string& file_system_path, + const std::string& query) { } void InspectableWebContentsImpl::InspectedContentsClosing() { } -void InspectableWebContentsImpl::AboutToNavigateRenderView(content::RenderViewHost* render_view_host) { - content::DevToolsClientHost::SetupDevToolsFrontendClient(web_contents()->GetRenderViewHost()); +void InspectableWebContentsImpl::AboutToNavigateRenderView( + content::RenderViewHost* render_view_host) { + content::DevToolsClientHost::SetupDevToolsFrontendClient( + web_contents()->GetRenderViewHost()); } -void InspectableWebContentsImpl::DidFinishLoad(int64, const GURL&, bool is_main_frame, content::RenderViewHost*) { +void InspectableWebContentsImpl::DidFinishLoad(int64 frame_id, + const GURL& validated_url, + bool is_main_frame, + content::RenderViewHost*) { if (!is_main_frame) return; @@ -154,16 +184,19 @@ void InspectableWebContentsImpl::DidFinishLoad(int64, const GURL&, bool is_main_ } void InspectableWebContentsImpl::WebContentsDestroyed(content::WebContents*) { - content::DevToolsManager::GetInstance()->ClientHostClosing(frontend_host_.get()); + content::DevToolsManager::GetInstance()->ClientHostClosing( + frontend_host_.get()); Observe(nullptr); agent_host_ = nullptr; frontend_host_.reset(); } -void InspectableWebContentsImpl::HandleKeyboardEvent(content::WebContents* source, const content::NativeWebKeyboardEvent& event) { +void InspectableWebContentsImpl::HandleKeyboardEvent( + content::WebContents* source, + const content::NativeWebKeyboardEvent& event) { auto delegate = web_contents_->GetDelegate(); if (delegate) delegate->HandleKeyboardEvent(source, event); } -} +} // namespace brightray From 843b21a3e81dc1822e6b5c20707d89ac4112c6f0 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:09:21 -0500 Subject: [PATCH 0189/1195] Fix cpplint errors in network_delegate.cc --- brightray/browser/network_delegate.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index 8213a744edb..57dd6565397 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -2,7 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include "network_delegate.h" +#include "browser/network_delegate.h" + +#include #include "net/base/net_errors.h" @@ -102,4 +104,4 @@ void NetworkDelegate::OnRequestWaitStateChange( RequestWaitState waiting) { } -} +} // namespace brightray From 57ae05b6360d78df69c1569933c0136d9913d80a Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:11:47 -0500 Subject: [PATCH 0190/1195] Fix cpplint errors in url_request_context_getter.cc --- .../browser/url_request_context_getter.cc | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 4fe6d3f1b94..ecba106e96b 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -4,7 +4,10 @@ #include "browser/url_request_context_getter.h" -#include "network_delegate.h" +#include + +#include "browser/network_delegate.h" + #include "base/strings/string_util.h" #include "base/threading/worker_pool.h" #include "content/public/browser/browser_thread.h" @@ -43,7 +46,8 @@ URLRequestContextGetter::URLRequestContextGetter( std::swap(protocol_handlers_, *protocol_handlers); - proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService(io_loop_->message_loop_proxy(), file_loop_)); + proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( + io_loop_->message_loop_proxy(), file_loop_)); } URLRequestContextGetter::~URLRequestContextGetter() { @@ -53,8 +57,7 @@ net::HostResolver* URLRequestContextGetter::host_resolver() { return url_request_context_->host_resolver(); } -net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() -{ +net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); if (!url_request_context_.get()) { @@ -87,7 +90,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); storage_->set_http_auth_handler_factory( net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); - scoped_ptr server_properties(new net::HttpServerPropertiesImpl); + scoped_ptr server_properties( + new net::HttpServerPropertiesImpl); storage_->set_http_server_properties(server_properties.Pass()); base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); @@ -130,21 +134,25 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() new net::URLRequestJobFactoryImpl()); for (auto it = protocol_handlers_.begin(), end = protocol_handlers_.end(); it != end; ++it) { - bool set_protocol = job_factory->SetProtocolHandler(it->first, it->second.release()); + bool set_protocol = job_factory->SetProtocolHandler( + it->first, it->second.release()); DCHECK(set_protocol); } protocol_handlers_.clear(); - job_factory->SetProtocolHandler(chrome::kDataScheme, new net::DataProtocolHandler); - job_factory->SetProtocolHandler(chrome::kFileScheme, new net::FileProtocolHandler); + job_factory->SetProtocolHandler( + chrome::kDataScheme, new net::DataProtocolHandler); + job_factory->SetProtocolHandler( + chrome::kFileScheme, new net::FileProtocolHandler); storage_->set_job_factory(job_factory.release()); } return url_request_context_.get(); } -scoped_refptr URLRequestContextGetter::GetNetworkTaskRunner() const -{ - return content::BrowserThread::GetMessageLoopProxyForThread(content::BrowserThread::IO); +scoped_refptr + URLRequestContextGetter::GetNetworkTaskRunner() const { + return content::BrowserThread::GetMessageLoopProxyForThread( + content::BrowserThread::IO); } -} +} // namespace brightray From 80dab9d862eb5d493cfb97629c6e4f9554523318 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:12:05 -0500 Subject: [PATCH 0191/1195] Fix cpplint errors in web_ui_controller_factory.cc --- brightray/browser/web_ui_controller_factory.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/web_ui_controller_factory.cc b/brightray/browser/web_ui_controller_factory.cc index 61f6bf993c5..9a9694de083 100644 --- a/brightray/browser/web_ui_controller_factory.cc +++ b/brightray/browser/web_ui_controller_factory.cc @@ -56,4 +56,4 @@ content::WebUIController* WebUIControllerFactory::CreateWebUIControllerForURL( return NULL; } -} +} // namespace brightray From 74661c342ffc857e5c91ce7ed4fe1e432e15f245 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:13:10 -0500 Subject: [PATCH 0192/1195] Fix cpplint errors in browser_client.h --- brightray/browser/browser_client.h | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index f5bc9d618fe..41a3861f61f 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -14,7 +14,7 @@ class BrowserMainParts; class NotificationPresenter; class BrowserClient : public content::ContentBrowserClient { -public: + public: static BrowserClient* Get(); BrowserClient(); @@ -24,17 +24,21 @@ public: BrowserMainParts* browser_main_parts() { return browser_main_parts_; } NotificationPresenter* notification_presenter(); -protected: - // Subclasses should override this to provide their own BrowserMainParts implementation. The - // lifetime of the returned instance is managed by the caller. - virtual BrowserMainParts* OverrideCreateBrowserMainParts(const content::MainFunctionParams&); + protected: + // Subclasses should override this to provide their own BrowserMainParts + // implementation. The lifetime of the returned instance is managed by the + // caller. + virtual BrowserMainParts* OverrideCreateBrowserMainParts( + const content::MainFunctionParams&); - // Subclasses that override this (e.g., to provide their own protocol handlers) should call this - // implementation after doing their own work. - virtual net::URLRequestContextGetter* CreateRequestContext(content::BrowserContext*, content::ProtocolHandlerMap*) OVERRIDE; + // Subclasses that override this (e.g., to provide their own protocol + // handlers) should call this implementation after doing their own work. + virtual net::URLRequestContextGetter* CreateRequestContext( + content::BrowserContext*, content::ProtocolHandlerMap*) OVERRIDE; -private: - virtual content::BrowserMainParts* CreateBrowserMainParts(const content::MainFunctionParams&) OVERRIDE; + private: + virtual content::BrowserMainParts* CreateBrowserMainParts( + const content::MainFunctionParams&) OVERRIDE; virtual void ShowDesktopNotification( const content::ShowDesktopNotificationHostMsgParams&, int render_process_id, @@ -52,6 +56,6 @@ private: DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; -} +} // namespace brightray #endif From 991133b8e9985d83cab389044af472cea71587bf Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:15:10 -0500 Subject: [PATCH 0193/1195] Fix cpplint errors in browser_context.h --- brightray/browser/browser_context.h | 43 +++++++++++++++++++---------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index f18cfdadced..6356277942e 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -18,41 +18,54 @@ class NetworkDelegate; class URLRequestContextGetter; class BrowserContext : public content::BrowserContext { -public: + public: BrowserContext(); ~BrowserContext(); void Initialize(); - net::URLRequestContextGetter* CreateRequestContext(content::ProtocolHandlerMap*); + net::URLRequestContextGetter* CreateRequestContext( + content::ProtocolHandlerMap*); PrefService* prefs() { return prefs_.get(); } -protected: + protected: // Subclasses should override this to register custom preferences. - virtual void RegisterPrefs(PrefRegistrySimple*) {} + virtual void RegisterPrefs(PrefRegistrySimple* pref_registry) {} - // Subclasses should override this to provide a custom NetworkDelegate implementation. + // Subclasses should override this to provide a custom NetworkDelegate + // implementation. virtual scoped_ptr CreateNetworkDelegate(); virtual base::FilePath GetPath() const OVERRIDE; -private: + private: class ResourceContext; - void RegisterInternalPrefs(PrefRegistrySimple*); + void RegisterInternalPrefs(PrefRegistrySimple* pref_registry); virtual bool IsOffTheRecord() const OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; - virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess(int renderer_child_id); + virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( + int renderer_child_id); virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE; - virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess(int renderer_child_id) OVERRIDE; - virtual net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition(const base::FilePath& partition_path, bool in_memory); - virtual void RequestMIDISysExPermission(int render_process_id, int render_view_id, const GURL& requesting_frame, const MIDISysExPermissionCallback&) OVERRIDE; + virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( + int renderer_child_id) OVERRIDE; + virtual net::URLRequestContextGetter* + GetMediaRequestContextForStoragePartition( + const base::FilePath& partition_path, bool in_memory); + virtual void RequestMIDISysExPermission( + int render_process_id, + int render_view_id, + const GURL& requesting_frame, + const MIDISysExPermissionCallback&) OVERRIDE; virtual content::ResourceContext* GetResourceContext() OVERRIDE; - virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; - virtual content::GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; - virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; + virtual content::DownloadManagerDelegate* + GetDownloadManagerDelegate() OVERRIDE; + virtual content::GeolocationPermissionContext* + GetGeolocationPermissionContext() OVERRIDE; + virtual quota::SpecialStoragePolicy* + GetSpecialStoragePolicy() OVERRIDE; base::FilePath path_; scoped_ptr resource_context_; @@ -63,6 +76,6 @@ private: DISALLOW_COPY_AND_ASSIGN(BrowserContext); }; -} +} // namespace brightray #endif From 24fbf6e2ef71e1596eff66be41a8f8960b5dee5f Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:15:45 -0500 Subject: [PATCH 0194/1195] Build before running cpplint Let's make sure things build before we check coding style. If it doesn't even build, who cares about the style? --- brightray/script/cibuild | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/script/cibuild b/brightray/script/cibuild index ab6b8eaeadf..bfe1ec92b80 100755 --- a/brightray/script/cibuild +++ b/brightray/script/cibuild @@ -18,8 +18,8 @@ def main(): url = 'https://{0}.s3.amazonaws.com/libchromiumcontent'.format(os.environ['JANKY_ARTIFACTS_S3_BUCKET']) return (run_script('bootstrap', url) or - run_script('cpplint') or - run_script('build')) + run_script('build') or + run_script('cpplint')) def copy_to_environment(credentials_file): From a6ecd039e25f9d0b2b8bc49fb4d882ac67c4bec9 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:16:41 -0500 Subject: [PATCH 0195/1195] Fix typos --- brightray/browser/browser_context.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 060ba3b427d..20b70470552 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -99,9 +99,9 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers) { DCHECK(!url_request_getter_); auto io_loop = content::BrowserThread::UnsafeGetMessageLoopForThread( - content::BrowserThread::IO), + content::BrowserThread::IO); auto file_loop = content::BrowserThread::UnsafeGetMessageLoopForThread( - content::BrowserThread::FILE), + content::BrowserThread::FILE); url_request_getter_ = new URLRequestContextGetter( GetPath(), io_loop, From 7bada7851945cf82776d022b4d75463318208046 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:17:23 -0500 Subject: [PATCH 0196/1195] Fix cpplint errors in browser_main_parts.h --- brightray/browser/browser_main_parts.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 210ff7e31ba..f0aeb427796 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -15,15 +15,15 @@ class BrowserContext; class WebUIControllerFactory; class BrowserMainParts : public content::BrowserMainParts { -public: + public: BrowserMainParts(); ~BrowserMainParts(); BrowserContext* browser_context() { return browser_context_.get(); } -protected: - // Subclasses should override this to provide their own BrowserContxt implementation. The caller - // takes ownership of the returned object. + protected: + // Subclasses should override this to provide their own BrowserContxt + // implementation. The caller takes ownership of the returned object. virtual BrowserContext* CreateBrowserContext(); #if defined(OS_MACOSX) @@ -33,13 +33,13 @@ protected: virtual void PreMainMessageLoopRun() OVERRIDE; virtual void PostMainMessageLoopRun() OVERRIDE; -private: + private: scoped_ptr browser_context_; scoped_ptr web_ui_controller_factory_; DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); }; -} +} // namespace brightray #endif From fd54c435a9d52d7c1280a0dcef78497e14f86cf2 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:18:22 -0500 Subject: [PATCH 0197/1195] Fix cpplint errors in default_web_contents_delegate.h --- .../browser/default_web_contents_delegate.h | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/brightray/browser/default_web_contents_delegate.h b/brightray/browser/default_web_contents_delegate.h index b4dabdd03b8..5b16b10f653 100644 --- a/brightray/browser/default_web_contents_delegate.h +++ b/brightray/browser/default_web_contents_delegate.h @@ -5,22 +5,24 @@ namespace brightray { -// This class provides some sane default behaviors to any content::WebContents instance (e.g., -// keyboard shortcut handling on Mac). +// This class provides some sane default behaviors to any content::WebContents +// instance (e.g., keyboard shortcut handling on Mac). class DefaultWebContentsDelegate : public content::WebContentsDelegate { -public: + public: DefaultWebContentsDelegate(); ~DefaultWebContentsDelegate(); -protected: - virtual void RequestMediaAccessPermission(content::WebContents*, - const content::MediaStreamRequest&, - const content::MediaResponseCallback&) OVERRIDE; + protected: + virtual void RequestMediaAccessPermission( + content::WebContents*, + const content::MediaStreamRequest&, + const content::MediaResponseCallback&) OVERRIDE; #if defined(OS_MACOSX) - virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; + virtual void HandleKeyboardEvent( + content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; #endif }; -} +} // namespace brightray #endif From 9ac1a539ee78e7ad6ef49cc9cb086d564af59043 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:20:17 -0500 Subject: [PATCH 0198/1195] Fix all remaining readability/namespace errors --- brightray/browser/devtools_ui.h | 2 +- brightray/browser/download_manager_delegate.h | 2 +- brightray/browser/inspectable_web_contents.h | 2 +- brightray/browser/inspectable_web_contents_impl.h | 2 +- brightray/browser/inspectable_web_contents_view.h | 2 +- brightray/browser/inspectable_web_contents_view_mac.h | 2 +- brightray/browser/linux/inspectable_web_contents_view_linux.cc | 2 +- brightray/browser/linux/inspectable_web_contents_view_linux.h | 2 +- brightray/browser/network_delegate.h | 2 +- brightray/browser/notification_presenter.h | 2 +- brightray/browser/notification_presenter_mac.h | 2 +- brightray/browser/url_request_context_getter.h | 2 +- brightray/browser/web_ui_controller_factory.h | 2 +- brightray/browser/win/devtools_window.cc | 2 +- brightray/browser/win/devtools_window.h | 2 +- brightray/browser/win/inspectable_web_contents_view_win.cc | 2 +- brightray/browser/win/inspectable_web_contents_view_win.h | 2 +- brightray/common/application_info_win.cc | 2 +- brightray/common/content_client.cc | 2 +- brightray/common/content_client.h | 2 +- brightray/common/main_delegate.cc | 2 +- brightray/common/main_delegate.h | 2 +- 22 files changed, 22 insertions(+), 22 deletions(-) diff --git a/brightray/browser/devtools_ui.h b/brightray/browser/devtools_ui.h index 70ab0f2686d..1f5ff4f7217 100644 --- a/brightray/browser/devtools_ui.h +++ b/brightray/browser/devtools_ui.h @@ -20,6 +20,6 @@ class DevToolsUI : public content::WebUIController { DISALLOW_COPY_AND_ASSIGN(DevToolsUI); }; -} +} // namespace brightray #endif diff --git a/brightray/browser/download_manager_delegate.h b/brightray/browser/download_manager_delegate.h index c25d2e7a16a..95ac7d5a817 100644 --- a/brightray/browser/download_manager_delegate.h +++ b/brightray/browser/download_manager_delegate.h @@ -14,6 +14,6 @@ class DownloadManagerDelegate : public content::DownloadManagerDelegate { DISALLOW_COPY_AND_ASSIGN(DownloadManagerDelegate); }; -} +} // namespace brightray #endif diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 0a585146866..d539a53b9a0 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -22,6 +22,6 @@ public: virtual void ShowDevTools() = 0; }; -} +} // namespace brightray #endif diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index f81ccc0185a..3fd83d1651f 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -90,6 +90,6 @@ private: DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); }; -} +} // namespace brightray #endif diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 3964cc682c0..ac731ac9b0d 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -16,6 +16,6 @@ public: virtual bool SetDockSide(const std::string& side) = 0; }; -} +} // namespace brightray #endif diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 1b5a6e43322..3ac76b3bee2 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -31,6 +31,6 @@ private: DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewMac); }; -} +} // namespace brightray #endif diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index eb792aa69d8..f48c77bba7e 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -234,4 +234,4 @@ GtkWidget *InspectableWebContentsViewLinux::GetBrowserWindow() { return browser; } -} +} // namespace brightray diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/linux/inspectable_web_contents_view_linux.h index f82de0a54cd..94dfa97a1ad 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.h +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.h @@ -49,6 +49,6 @@ private: DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewLinux); }; -} +} // namespace brightray #endif diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index aff8e228856..91c2379dad5 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -37,6 +37,6 @@ class NetworkDelegate : public net::NetworkDelegate { DISALLOW_COPY_AND_ASSIGN(NetworkDelegate); }; -} +} // namespace brightray #endif diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index a106edab208..3f238b2b867 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -23,6 +23,6 @@ class NotificationPresenter { int notification_id) = 0; }; -} +} // namespace brightray #endif diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index b3757bf56ea..b2a9e59fca4 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -34,6 +34,6 @@ class NotificationPresenterMac : public NotificationPresenter { base::scoped_nsobject delegate_; }; -} +} // namespace brightray #endif diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 7d4efb6c00d..fa7f0952cdb 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -53,6 +53,6 @@ private: DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter); }; -} +} // namespace brightray #endif diff --git a/brightray/browser/web_ui_controller_factory.h b/brightray/browser/web_ui_controller_factory.h index 1ee3f9b2dfd..4a451389538 100644 --- a/brightray/browser/web_ui_controller_factory.h +++ b/brightray/browser/web_ui_controller_factory.h @@ -37,6 +37,6 @@ class WebUIControllerFactory : public content::WebUIControllerFactory { DISALLOW_COPY_AND_ASSIGN(WebUIControllerFactory); }; -} +} // namespace brightray #endif diff --git a/brightray/browser/win/devtools_window.cc b/brightray/browser/win/devtools_window.cc index 8bed3e89f7d..442bffa13cc 100644 --- a/brightray/browser/win/devtools_window.cc +++ b/brightray/browser/win/devtools_window.cc @@ -44,4 +44,4 @@ LRESULT DevToolsWindow::OnSize(UINT, WPARAM, LPARAM, BOOL&) { return 0; } -} +} // namespace brightray diff --git a/brightray/browser/win/devtools_window.h b/brightray/browser/win/devtools_window.h index 7181ab8e4d3..40f2d5afdb2 100644 --- a/brightray/browser/win/devtools_window.h +++ b/brightray/browser/win/devtools_window.h @@ -31,6 +31,6 @@ class DevToolsWindow : public ui::WindowImpl, public base::SupportsWeakPtrproduct_version()); } -} +} // namespace brightray diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index a518cc026ca..4f45ba7cd4b 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -37,4 +37,4 @@ gfx::Image& ContentClient::GetNativeImageNamed(int resource_id) const { return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); } -} +} // namespace brightray diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index 8a93771018e..e8bc579d7b4 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -24,6 +24,6 @@ private: DISALLOW_COPY_AND_ASSIGN(ContentClient); }; -} +} // namespace brightray #endif diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index b58b2e9d72f..cfa4cd67599 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -57,4 +57,4 @@ void MainDelegate::InitializeResourceBundle() { ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(*it, ui::SCALE_FACTOR_NONE); } -} +} // namespace brightray diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index ba99f5155f0..d9e9e17c2e4 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -47,5 +47,5 @@ private: DISALLOW_COPY_AND_ASSIGN(MainDelegate); }; -} +} // namespace brightray #endif From 0805b414e99ac134e1d50b792868b05ce22c601e Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:20:54 -0500 Subject: [PATCH 0199/1195] Fix cpplint errors in inspectable_web_contents.h --- brightray/browser/inspectable_web_contents.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index d539a53b9a0..9c381ae7403 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -8,10 +8,12 @@ namespace brightray { class InspectableWebContentsView; class InspectableWebContents { -public: - static InspectableWebContents* Create(const content::WebContents::CreateParams&); + public: + static InspectableWebContents* Create( + const content::WebContents::CreateParams&); - // The returned InspectableWebContents takes ownership of the passed-in WebContents. + // The returned InspectableWebContents takes ownership of the passed-in + // WebContents. static InspectableWebContents* Create(content::WebContents*); virtual ~InspectableWebContents() {} From 877a1f03712efc4de4933aeec66bbb70a7414b15 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:22:48 -0500 Subject: [PATCH 0200/1195] Fix cpplint errors in inspectable_web_contents_impl.h --- .../browser/inspectable_web_contents_impl.h | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 3fd83d1651f..6aab5bab3ea 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -8,6 +8,8 @@ #include "browser/inspectable_web_contents.h" +#include + #include "content/public/browser/devtools_frontend_host_delegate.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" @@ -28,10 +30,10 @@ class InspectableWebContentsImpl : content::DevToolsFrontendHostDelegate, content::WebContentsObserver, content::WebContentsDelegate { -public: - static void RegisterPrefs(PrefRegistrySimple*); + public: + static void RegisterPrefs(PrefRegistrySimple* pref_registry); - InspectableWebContentsImpl(content::WebContents*); + explicit InspectableWebContentsImpl(content::WebContents*); virtual ~InspectableWebContentsImpl(); virtual InspectableWebContentsView* GetView() const OVERRIDE; @@ -39,13 +41,15 @@ public: virtual void ShowDevTools() OVERRIDE; - content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); } + content::WebContents* devtools_web_contents() { + return devtools_web_contents_.get(); + } -private: + private: void UpdateFrontendDockSide(); // content::DevToolsFrontendHostDelegate - + virtual void ActivateWindow() OVERRIDE; virtual void ChangeAttachedWindowHeight(unsigned height) OVERRIDE; virtual void CloseWindow() OVERRIDE; @@ -60,16 +64,18 @@ private: virtual void RequestFileSystems() OVERRIDE; virtual void AddFileSystem() OVERRIDE; virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; - virtual void IndexPath(int request_id, const std::string& file_system_path) OVERRIDE; + virtual void IndexPath(int request_id, + const std::string& file_system_path) OVERRIDE; virtual void StopIndexing(int request_id) OVERRIDE; virtual void SearchInPath(int request_id, const std::string& file_system_path, const std::string& query) OVERRIDE; virtual void InspectedContentsClosing() OVERRIDE; - + // content::WebContentsObserver - - virtual void AboutToNavigateRenderView(content::RenderViewHost* render_view_host) OVERRIDE; + + virtual void AboutToNavigateRenderView( + content::RenderViewHost* render_view_host) OVERRIDE; virtual void DidFinishLoad(int64 frame_id, const GURL& validated_url, bool is_main_frame, @@ -77,9 +83,10 @@ private: virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE; // content::WebContentsDelegate - - virtual void HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; - + + virtual void HandleKeyboardEvent( + content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; + scoped_ptr web_contents_; scoped_ptr frontend_host_; scoped_ptr devtools_web_contents_; From ea689b31a4c558736d8a44ab2b6b380d660041dd Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:23:13 -0500 Subject: [PATCH 0201/1195] Fix cpplint errors in inspectable_web_contents_view.h --- brightray/browser/inspectable_web_contents_view.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index ac731ac9b0d..daa332d1c5e 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -1,12 +1,14 @@ #ifndef BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_H_ #define BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_H_ +#include + #include "ui/gfx/native_widget_types.h" namespace brightray { class InspectableWebContentsView { -public: + public: virtual ~InspectableWebContentsView() {} virtual gfx::NativeView GetNativeView() const = 0; From cb684c5c6eaf1c9ab2bfd4ada0859f1cc1f01ffa Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:24:36 -0500 Subject: [PATCH 0202/1195] Fix cpplint errors in inspectable_web_contents_view_mac.h --- .../inspectable_web_contents_view_mac.h | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 3ac76b3bee2..839b56a744f 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -1,9 +1,11 @@ #ifndef BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_MAC_H_ #define BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_MAC_H_ -#import "browser/inspectable_web_contents_view.h" +#include "browser/inspectable_web_contents_view.h" -#import "base/mac/scoped_nsobject.h" +#include + +#include "base/mac/scoped_nsobject.h" @class BRYInspectableWebContentsView; @@ -12,20 +14,23 @@ namespace brightray { class InspectableWebContentsImpl; class InspectableWebContentsViewMac : public InspectableWebContentsView { -public: - InspectableWebContentsViewMac(InspectableWebContentsImpl*); - + public: + explicit InspectableWebContentsViewMac( + InspectableWebContentsImpl* inspectable_web_contents_impl); + virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; - InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; } + InspectableWebContentsImpl* inspectable_web_contents() { + return inspectable_web_contents_; + } -private: + private: // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; - + base::scoped_nsobject view_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewMac); From ec59df1a516d58f4b59686c7eb049364e9aff014 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:36:34 -0500 Subject: [PATCH 0203/1195] Fix cpplint errors in network_delegate.h --- brightray/browser/network_delegate.h | 55 +++++++++++++++++++++------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 91c2379dad5..d257fdbf4c9 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -7,6 +7,8 @@ #include "net/base/network_delegate.h" +#include + namespace brightray { class NetworkDelegate : public net::NetworkDelegate { @@ -15,23 +17,48 @@ class NetworkDelegate : public net::NetworkDelegate { virtual ~NetworkDelegate(); protected: - virtual int OnBeforeURLRequest(net::URLRequest* request, const net::CompletionCallback& callback, GURL* new_url) OVERRIDE; - virtual int OnBeforeSendHeaders(net::URLRequest* request, const net::CompletionCallback& callback, net::HttpRequestHeaders* headers) OVERRIDE; - virtual void OnSendHeaders(net::URLRequest* request, const net::HttpRequestHeaders& headers) OVERRIDE; - virtual int OnHeadersReceived(net::URLRequest* request, const net::CompletionCallback& callback, const net::HttpResponseHeaders* original_response_headers, scoped_refptr* override_response_headers) OVERRIDE; - virtual void OnBeforeRedirect(net::URLRequest* request, const GURL& new_location) OVERRIDE; + virtual int OnBeforeURLRequest(net::URLRequest* request, + const net::CompletionCallback& callback, + GURL* new_url) OVERRIDE; + virtual int OnBeforeSendHeaders(net::URLRequest* request, + const net::CompletionCallback& callback, + net::HttpRequestHeaders* headers) OVERRIDE; + virtual void OnSendHeaders(net::URLRequest* request, + const net::HttpRequestHeaders& headers) OVERRIDE; + virtual int OnHeadersReceived( + net::URLRequest* request, + const net::CompletionCallback& callback, + const net::HttpResponseHeaders* original_response_headers, + scoped_refptr* + override_response_headers) OVERRIDE; + virtual void OnBeforeRedirect(net::URLRequest* request, + const GURL& new_location) OVERRIDE; virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; - virtual void OnRawBytesRead(const net::URLRequest& request, int bytes_read) OVERRIDE; + virtual void OnRawBytesRead(const net::URLRequest& request, + int bytes_read) OVERRIDE; virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE; virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE; - virtual void OnPACScriptError(int line_number, const string16& error) OVERRIDE; - virtual AuthRequiredResponse OnAuthRequired(net::URLRequest* request, const net::AuthChallengeInfo& auth_info, const AuthCallback& callback, net::AuthCredentials* credentials) OVERRIDE; - virtual bool OnCanGetCookies(const net::URLRequest& request, const net::CookieList& cookie_list) OVERRIDE; - virtual bool OnCanSetCookie(const net::URLRequest& request, const std::string& cookie_line, net::CookieOptions* options) OVERRIDE; - virtual bool OnCanAccessFile(const net::URLRequest& request, const base::FilePath& path) const OVERRIDE; - virtual bool OnCanThrottleRequest(const net::URLRequest& request) const OVERRIDE; - virtual int OnBeforeSocketStreamConnect(net::SocketStream* stream, const net::CompletionCallback& callback) OVERRIDE; - virtual void OnRequestWaitStateChange(const net::URLRequest& request, RequestWaitState state) OVERRIDE; + virtual void OnPACScriptError(int line_number, + const string16& error) OVERRIDE; + virtual AuthRequiredResponse OnAuthRequired( + net::URLRequest* request, + const net::AuthChallengeInfo& auth_info, + const AuthCallback& callback, + net::AuthCredentials* credentials) OVERRIDE; + virtual bool OnCanGetCookies(const net::URLRequest& request, + const net::CookieList& cookie_list) OVERRIDE; + virtual bool OnCanSetCookie(const net::URLRequest& request, + const std::string& cookie_line, + net::CookieOptions* options) OVERRIDE; + virtual bool OnCanAccessFile(const net::URLRequest& request, + const base::FilePath& path) const OVERRIDE; + virtual bool OnCanThrottleRequest( + const net::URLRequest& request) const OVERRIDE; + virtual int OnBeforeSocketStreamConnect( + net::SocketStream* stream, + const net::CompletionCallback& callback) OVERRIDE; + virtual void OnRequestWaitStateChange(const net::URLRequest& request, + RequestWaitState state) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(NetworkDelegate); From d4ad45334fbbc1db8bd1780848c2176fa928d30d Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:42:15 -0500 Subject: [PATCH 0204/1195] Turn off build/include_what_you_use Chromium doesn't seem to use this rule. --- brightray/browser/inspectable_web_contents_impl.cc | 2 -- brightray/browser/inspectable_web_contents_impl.h | 2 -- brightray/browser/inspectable_web_contents_view.h | 2 -- brightray/browser/inspectable_web_contents_view_mac.h | 2 -- brightray/browser/network_delegate.cc | 2 -- brightray/browser/network_delegate.h | 2 -- brightray/browser/notification_presenter.h | 2 +- brightray/script/cpplint | 2 +- 8 files changed, 2 insertions(+), 14 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index b7ac0e74cd3..5f561953218 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -5,8 +5,6 @@ #include "browser/inspectable_web_contents_impl.h" -#include - #include "browser/browser_client.h" #include "browser/browser_context.h" #include "browser/browser_main_parts.h" diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 6aab5bab3ea..50592fd3fc5 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -8,8 +8,6 @@ #include "browser/inspectable_web_contents.h" -#include - #include "content/public/browser/devtools_frontend_host_delegate.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index daa332d1c5e..eed32f34919 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -1,8 +1,6 @@ #ifndef BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_H_ #define BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_H_ -#include - #include "ui/gfx/native_widget_types.h" namespace brightray { diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 839b56a744f..f31149f570b 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -3,8 +3,6 @@ #include "browser/inspectable_web_contents_view.h" -#include - #include "base/mac/scoped_nsobject.h" @class BRYInspectableWebContentsView; diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index 57dd6565397..6467dc3e3d6 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -4,8 +4,6 @@ #include "browser/network_delegate.h" -#include - #include "net/base/net_errors.h" namespace brightray { diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index d257fdbf4c9..0d4f2d3600c 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -7,8 +7,6 @@ #include "net/base/network_delegate.h" -#include - namespace brightray { class NetworkDelegate : public net::NetworkDelegate { diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index 3f238b2b867..db925f5e927 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -9,7 +9,7 @@ namespace brightray { class NotificationPresenter { public: - virtual ~NotificationPresenter() {}; + virtual ~NotificationPresenter() {} static NotificationPresenter* Create(); diff --git a/brightray/script/cpplint b/brightray/script/cpplint index f5911be304b..051370dac17 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -28,7 +28,7 @@ def list_files(directories, filters): def cpplint(files): - rules = '--filter=-build/header_guard,-legal/copyright' + rules = '--filter=-build/header_guard,-build/include_what_you_use,-legal/copyright' return subprocess.call([sys.executable, CPPLINT, rules] + files) From cf4d966958d8154f2da3d53792ce5c27cf9d40dc Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:43:20 -0500 Subject: [PATCH 0205/1195] Fix cpplint errors in notification_presenter_mac.h --- brightray/browser/notification_presenter_mac.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index b2a9e59fca4..fef6bde3f27 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -30,7 +30,9 @@ class NotificationPresenterMac : public NotificationPresenter { int notification_id) OVERRIDE; private: - std::map> notification_map_; + typedef NotificationMap std::map>; + NotificationMap notification_map_; base::scoped_nsobject delegate_; }; From 7a362b741308b39ce7c7a424e891389538e4b937 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:43:46 -0500 Subject: [PATCH 0206/1195] Fix cpplint errors in url_request_context_getter.h --- brightray/browser/url_request_context_getter.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index fa7f0952cdb..c9700250aad 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -25,7 +25,7 @@ namespace brightray { class NetworkDelegate; class URLRequestContextGetter : public net::URLRequestContextGetter { -public: + public: URLRequestContextGetter( const base::FilePath& base_path, base::MessageLoop* io_loop, @@ -37,8 +37,9 @@ public: net::HostResolver* host_resolver(); virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; -private: - virtual scoped_refptr GetNetworkTaskRunner() const OVERRIDE; + private: + virtual scoped_refptr + GetNetworkTaskRunner() const OVERRIDE; base::FilePath base_path_; base::MessageLoop* io_loop_; From 9f82d5876167410b200b18f1a6a3e225f6273792 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:46:23 -0500 Subject: [PATCH 0207/1195] Fix cpplint errors in web_ui_controller_factory.h --- brightray/browser/web_ui_controller_factory.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/web_ui_controller_factory.h b/brightray/browser/web_ui_controller_factory.h index 4a451389538..74db390746d 100644 --- a/brightray/browser/web_ui_controller_factory.h +++ b/brightray/browser/web_ui_controller_factory.h @@ -15,11 +15,11 @@ class BrowserContext; class WebUIControllerFactory : public content::WebUIControllerFactory { public: - WebUIControllerFactory(BrowserContext* browser_context); + explicit WebUIControllerFactory(BrowserContext* browser_context); virtual ~WebUIControllerFactory(); - virtual content::WebUI::TypeID GetWebUIType(content::BrowserContext* browser_context, - const GURL& url) const OVERRIDE; + virtual content::WebUI::TypeID GetWebUIType( + content::BrowserContext* browser_context, const GURL& url) const OVERRIDE; virtual bool UseWebUIForURL(content::BrowserContext* browser_context, const GURL& url) const OVERRIDE; virtual bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, From 23bcf4099f2c7de64b35e182a09934402e6e559d Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:52:02 -0500 Subject: [PATCH 0208/1195] Fix cpplint errors in inspectable_web_contents_view_linux.h --- .../linux/inspectable_web_contents_view_linux.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/linux/inspectable_web_contents_view_linux.h index 94dfa97a1ad..c6605b3939f 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.h +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.h @@ -10,8 +10,9 @@ namespace brightray { class InspectableWebContentsImpl; class InspectableWebContentsViewLinux : public InspectableWebContentsView { -public: - InspectableWebContentsViewLinux(InspectableWebContentsImpl*); + public: + explicit InspectableWebContentsViewLinux( + InspectableWebContentsImpl* inspectable_web_contents_impl); ~InspectableWebContentsViewLinux(); virtual gfx::NativeView GetNativeView() const OVERRIDE; @@ -19,9 +20,11 @@ public: virtual void CloseDevTools() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; - InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; } + InspectableWebContentsImpl* inspectable_web_contents() { + return inspectable_web_contents_; + } -private: + private: // Show the dev tools in their own window. If they're already shown // somewhere else, remove them cleanly and take any GtkPaned out of the // window. From e5e3dc6a786314c4e292dccb482e4d520f25d08d Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:53:16 -0500 Subject: [PATCH 0209/1195] Ignore .mm files for cpplint It doesn't process them anyway. --- brightray/script/cpplint | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/script/cpplint b/brightray/script/cpplint index 051370dac17..d6e5ebcf9f2 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -13,7 +13,7 @@ CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'google-styleguide', 'trunk', 'cpp def main(): os.chdir(SOURCE_ROOT) files = list_files(['browser', 'common'], - ['*.cc', '*.mm', '*.h']) + ['*.cc', '*.h']) return cpplint(files) From 236efa8be563aaaa53e99d990acc9a8e66541851 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:53:34 -0500 Subject: [PATCH 0210/1195] Fix cpplint errors in bry_application.h --- brightray/browser/mac/bry_application.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/mac/bry_application.h b/brightray/browser/mac/bry_application.h index f64d5db4e36..98594861496 100644 --- a/brightray/browser/mac/bry_application.h +++ b/brightray/browser/mac/bry_application.h @@ -1,6 +1,6 @@ #import "base/mac/scoped_sending_event.h" -@interface BRYApplication : NSApplication { +@interface BRYApplication : NSApplication { BOOL _handlingSendEvent; } From 84ae61744d05840e147931697e05bbe8fd276b97 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:55:06 -0500 Subject: [PATCH 0211/1195] Ignore cpplint errors in bry_inspectable_web_contents_view_private.h It's not a C++ header. --- brightray/script/cpplint | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/brightray/script/cpplint b/brightray/script/cpplint index d6e5ebcf9f2..089b210c2fe 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -9,12 +9,16 @@ import sys SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'google-styleguide', 'trunk', 'cpplint', 'cpplint.py') +IGNORED_FILES = [ + 'browser/mac/bry_inspectable_web_contents_view_private.h', +] + def main(): os.chdir(SOURCE_ROOT) files = list_files(['browser', 'common'], ['*.cc', '*.h']) - return cpplint(files) + return cpplint(set(files) - set(IGNORED_FILES)) def list_files(directories, filters): @@ -29,7 +33,7 @@ def list_files(directories, filters): def cpplint(files): rules = '--filter=-build/header_guard,-build/include_what_you_use,-legal/copyright' - return subprocess.call([sys.executable, CPPLINT, rules] + files) + return subprocess.call([sys.executable, CPPLINT, rules] + list(files)) if __name__ == '__main__': From 6aec3006e6652b1a975f000b4311a0cb505a5fdb Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:56:07 -0500 Subject: [PATCH 0212/1195] Fix whitespace/comment errors --- brightray/browser/media/media_capture_devices_dispatcher.cc | 2 +- brightray/browser/media/media_capture_devices_dispatcher.h | 2 +- brightray/browser/media/media_stream_devices_controller.cc | 2 +- brightray/browser/media/media_stream_devices_controller.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index 1c3f9430050..a6b584e9c58 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -181,4 +181,4 @@ void MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread( video_devices_ = devices; } -} // namespace brightray +} // namespace brightray diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index 680455e2321..d10c27df1bc 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -97,6 +97,6 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { DISALLOW_COPY_AND_ASSIGN(MediaCaptureDevicesDispatcher); }; -} // namespace brightray +} // namespace brightray #endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index e6f0af89b73..a85c1c928d4 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -159,4 +159,4 @@ void MediaStreamDevicesController::Deny() { cb.Run(content::MediaStreamDevices(), scoped_ptr()); } -} // namespace brightray +} // namespace brightray diff --git a/brightray/browser/media/media_stream_devices_controller.h b/brightray/browser/media/media_stream_devices_controller.h index 820c8721365..9100fa4e27e 100644 --- a/brightray/browser/media/media_stream_devices_controller.h +++ b/brightray/browser/media/media_stream_devices_controller.h @@ -39,6 +39,6 @@ class MediaStreamDevicesController { DISALLOW_COPY_AND_ASSIGN(MediaStreamDevicesController); }; -} // namespace brightray +} // namespace brightray #endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_STREAM_DEVICES_CONTROLLER_H_ From 9306fecea869fb3a7027bfe4b20f45e6048eeed9 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:56:44 -0500 Subject: [PATCH 0213/1195] Fix cpplint errors in content_client.cc --- brightray/common/content_client.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index 4f45ba7cd4b..dd6ce530690 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -22,19 +22,23 @@ ContentClient::~ContentClient() { std::string ContentClient::GetProduct() const { auto name = GetApplicationName(); RemoveChars(name, kWhitespaceASCII, &name); - return base::StringPrintf("%s/%s", name.c_str(), GetApplicationVersion().c_str()); + return base::StringPrintf("%s/%s", + name.c_str(), GetApplicationVersion().c_str()); } std::string ContentClient::GetUserAgent() const { return webkit_glue::BuildUserAgentFromProduct(GetProduct()); } -base::StringPiece ContentClient::GetDataResource(int resource_id, ui::ScaleFactor scale_factor) const { - return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(resource_id, scale_factor); +base::StringPiece ContentClient::GetDataResource( + int resource_id, ui::ScaleFactor scale_factor) const { + return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( + resource_id, scale_factor); } gfx::Image& ContentClient::GetNativeImageNamed(int resource_id) const { - return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); + return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( + resource_id); } } // namespace brightray From 2c1e1b039dc0b311dbdfb0365b5126aae11e23d0 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:57:25 -0500 Subject: [PATCH 0214/1195] Fix cpplint errors in main_application_bundle.h --- brightray/common/mac/main_application_bundle.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/brightray/common/mac/main_application_bundle.h b/brightray/common/mac/main_application_bundle.h index 61f19adadd7..78e6bc200b4 100644 --- a/brightray/common/mac/main_application_bundle.h +++ b/brightray/common/mac/main_application_bundle.h @@ -9,12 +9,13 @@ class FilePath; namespace brightray { -// The "main" application bundle is the outermost bundle for this logical application. E.g., if you -// have MyApp.app and MyApp.app/Contents/Frameworks/MyApp Helper.app, the main application bundle is -// MyApp.app, no matter which executable is currently running. +// The "main" application bundle is the outermost bundle for this logical +// application. E.g., if you have MyApp.app and +// MyApp.app/Contents/Frameworks/MyApp Helper.app, the main application bundle +// is MyApp.app, no matter which executable is currently running. NSBundle* MainApplicationBundle(); base::FilePath MainApplicationBundlePath(); -} +} // namespace brightray #endif From 32f4862e56e911dd6be9d4cae1ac2de1c6b87755 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:57:54 -0500 Subject: [PATCH 0215/1195] Fix cpplint errors in main_delegate.h --- brightray/common/main_delegate.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index d9e9e17c2e4..e1d033312c9 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -5,10 +5,11 @@ #ifndef BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ #define BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ +#include + #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "content/public/app/content_main_delegate.h" -#include namespace base { class FilePath; @@ -19,21 +20,23 @@ namespace brightray { class ContentClient; class MainDelegate : public content::ContentMainDelegate { -public: + public: MainDelegate(); ~MainDelegate(); -protected: - // Subclasses can override this to provide their own ContentClient implementation. + protected: + // Subclasses can override this to provide their own ContentClient + // implementation. virtual scoped_ptr CreateContentClient(); - // Subclasses can override this to provide additional .pak files to be included in the ui::ResourceBundle. + // Subclasses can override this to provide additional .pak files to be + // included in the ui::ResourceBundle. virtual void AddPakPaths(std::vector* pak_paths) {} virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; virtual void PreSandboxStartup() OVERRIDE; -private: + private: void InitializeResourceBundle(); #if defined(OS_MACOSX) static base::FilePath GetResourcesPakFilePath(); From 51a2779fdbc4f9d94286302670bb116a1962d980 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 18:58:25 -0500 Subject: [PATCH 0216/1195] Fix cpplint errors in main_delegate.cc --- brightray/common/main_delegate.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index cfa4cd67599..4c903149d09 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -53,8 +53,10 @@ void MainDelegate::InitializeResourceBundle() { std::vector pak_paths; AddPakPaths(&pak_paths); - for (auto it = pak_paths.begin(), end = pak_paths.end(); it != end; ++it) - ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(*it, ui::SCALE_FACTOR_NONE); + for (auto it = pak_paths.begin(), end = pak_paths.end(); it != end; ++it) { + ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( + *it, ui::SCALE_FACTOR_NONE); + } } } // namespace brightray From 779dfd2bafafee0a1b2d815f0f4d929c39345af2 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:01:36 -0500 Subject: [PATCH 0217/1195] Fix most cpplint errors in devtools_window.h It's still complaining about the non-const reference in BOOL&. --- brightray/browser/win/devtools_window.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/brightray/browser/win/devtools_window.h b/brightray/browser/win/devtools_window.h index 40f2d5afdb2..738af0a427c 100644 --- a/brightray/browser/win/devtools_window.h +++ b/brightray/browser/win/devtools_window.h @@ -8,9 +8,11 @@ namespace brightray { class InspectableWebContentsViewWin; -class DevToolsWindow : public ui::WindowImpl, public base::SupportsWeakPtr { +class DevToolsWindow : public ui::WindowImpl, + public base::SupportsWeakPtr { public: - static DevToolsWindow* Create(InspectableWebContentsViewWin*); + static DevToolsWindow* Create( + InspectableWebContentsViewWin* inspectable_web_contents_view_win); BEGIN_MSG_MAP_EX(DevToolsWindow) MESSAGE_HANDLER(WM_CREATE, OnCreate) @@ -19,7 +21,8 @@ class DevToolsWindow : public ui::WindowImpl, public base::SupportsWeakPtr Date: Sun, 17 Nov 2013 19:02:49 -0500 Subject: [PATCH 0218/1195] Fix cpplint errors in inspectable_web_contents_view_win.cc --- .../win/inspectable_web_contents_view_win.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index 508d4c0bc93..a25cdc8919f 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -15,11 +15,13 @@ const int kWindowInset = 100; } -InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { +InspectableWebContentsView* CreateInspectableContentsView( + InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewWin(inspectable_web_contents); } -InspectableWebContentsViewWin::InspectableWebContentsViewWin(InspectableWebContentsImpl* inspectable_web_contents) +InspectableWebContentsViewWin::InspectableWebContentsViewWin( + InspectableWebContentsImpl* inspectable_web_contents) : inspectable_web_contents_(inspectable_web_contents) { } @@ -29,7 +31,8 @@ InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { } gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { - return inspectable_web_contents_->GetWebContents()->GetView()->GetNativeView(); + auto web_contents = inspectable_web_contents_->GetWebContents(); + return web_contents->GetView()->GetNativeView(); } void InspectableWebContentsViewWin::ShowDevTools() { @@ -41,7 +44,9 @@ void InspectableWebContentsViewWin::ShowDevTools() { auto contents_view = inspectable_web_contents_->GetWebContents()->GetView(); auto size = contents_view->GetContainerSize(); size.Enlarge(-kWindowInset, -kWindowInset); - ui::CenterAndSizeWindow(contents_view->GetNativeView(), devtools_window_->hwnd(), size); + ui::CenterAndSizeWindow(contents_view->GetNativeView(), + devtools_window_->hwnd(), + size); ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL); } From ae504c319eed27b1605f9d9c03c0283d24d66e72 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:03:09 -0500 Subject: [PATCH 0219/1195] Fix cpplint errors in content_client.h --- brightray/common/content_client.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index e8bc579d7b4..11ad7e0aea2 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -11,14 +11,15 @@ namespace brightray { class ContentClient : public content::ContentClient { -public: + public: ContentClient(); ~ContentClient(); -private: + private: virtual std::string GetProduct() const OVERRIDE; virtual std::string GetUserAgent() const OVERRIDE; - virtual base::StringPiece GetDataResource(int resource_id, ui::ScaleFactor) const OVERRIDE; + virtual base::StringPiece GetDataResource(int resource_id, + ui::ScaleFactor) const OVERRIDE; virtual gfx::Image& GetNativeImageNamed(int resource_id) const OVERRIDE; DISALLOW_COPY_AND_ASSIGN(ContentClient); From 0271ff1964186d3341880a0d23e6712e04a4b2d1 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:03:41 -0500 Subject: [PATCH 0220/1195] Fix cpplint errors in inspectable_web_contents_view_win.h --- .../browser/win/inspectable_web_contents_view_win.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index c24594d09ca..534f4997284 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -12,8 +12,9 @@ class DevToolsWindow; class InspectableWebContentsImpl; class InspectableWebContentsViewWin : public InspectableWebContentsView { -public: - InspectableWebContentsViewWin(InspectableWebContentsImpl*); + public: + explicit InspectableWebContentsViewWin( + InspectableWebContentsImpl* inspectable_web_contents_impl); ~InspectableWebContentsViewWin(); virtual gfx::NativeView GetNativeView() const OVERRIDE; @@ -21,9 +22,11 @@ public: virtual void CloseDevTools() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; - InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; } + InspectableWebContentsImpl* inspectable_web_contents() { + return inspectable_web_contents_; + } -private: + private: // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; From 1595940723e9378aa0ced3bdfe6e2e23979d5361 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:05:21 -0500 Subject: [PATCH 0221/1195] Fix cpplint errors in devtools_window.cc --- brightray/browser/win/devtools_window.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/brightray/browser/win/devtools_window.cc b/brightray/browser/win/devtools_window.cc index 442bffa13cc..9fc4b5dba88 100644 --- a/brightray/browser/win/devtools_window.cc +++ b/brightray/browser/win/devtools_window.cc @@ -8,7 +8,8 @@ namespace brightray { -DevToolsWindow* DevToolsWindow::Create(InspectableWebContentsViewWin* controller) { +DevToolsWindow* DevToolsWindow::Create( + InspectableWebContentsViewWin* controller) { return new DevToolsWindow(controller); } @@ -20,13 +21,18 @@ DevToolsWindow::~DevToolsWindow() { } LRESULT DevToolsWindow::OnCreate(UINT, WPARAM, LPARAM, BOOL&) { - SetParent(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), hwnd()); + auto devtools_web_contents = + controller_->inspectable_web_contents()->devtools_web_contents(); + SetParent(devtools_web_contents->GetView()->GetNativeView(), hwnd()); SetWindowText(hwnd(), L"Developer Tools"); return 0; } LRESULT DevToolsWindow::OnDestroy(UINT, WPARAM, LPARAM, BOOL&) { - SetParent(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), ui::GetHiddenWindow()); + auto devtools_web_contents = + controller_->inspectable_web_contents()->devtools_web_contents(); + SetParent( + devtools_web_contents->GetView()->GetNativeView(), ui::GetHiddenWindow()); delete this; return 0; } @@ -35,7 +41,9 @@ LRESULT DevToolsWindow::OnSize(UINT, WPARAM, LPARAM, BOOL&) { RECT rect; GetClientRect(hwnd(), &rect); - SetWindowPos(controller_->inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(), + auto devtools_web_contents = + controller_->inspectable_web_contents()->devtools_web_contents(); + SetWindowPos(devtools_web_contents->GetView()->GetNativeView(), nullptr, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, From 4938fc62ad8d351f9ed25caa6c5706e9dfd7c517 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:12:50 -0500 Subject: [PATCH 0222/1195] Fix most cpplint errors in inspectable_web_contents_view_linux.cc --- .../inspectable_web_contents_view_linux.cc | 104 +++++++++++------- 1 file changed, 66 insertions(+), 38 deletions(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index f48c77bba7e..c08aa65d5b3 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -1,4 +1,4 @@ -#include "inspectable_web_contents_view_linux.h" +#include "browser/linux/inspectable_web_contents_view_linux.h" #include #include @@ -10,12 +10,15 @@ namespace brightray { -InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { +InspectableWebContentsView* CreateInspectableContentsView( + InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewLinux(inspectable_web_contents); } -InspectableWebContentsViewLinux::InspectableWebContentsViewLinux(InspectableWebContentsImpl* inspectable_web_contents) - : inspectable_web_contents_(inspectable_web_contents), devtools_window_(NULL) { +InspectableWebContentsViewLinux::InspectableWebContentsViewLinux( + InspectableWebContentsImpl* inspectable_web_contents) + : inspectable_web_contents_(inspectable_web_contents), + devtools_window_(NULL) { } InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() { @@ -26,11 +29,13 @@ InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() { static void dump_one(GtkWidget *wat, int indent) { GtkAllocation alloc; gtk_widget_get_allocation(wat, &alloc); - fprintf(stderr, "%*s[%p] %s @%d,%d %dx%d", + fprintf(stderr, "%*s[%p] %s @%d,%d %dx%d", indent, "", wat, g_type_name_from_instance((GTypeInstance*)wat), alloc.x, alloc.y, alloc.width, alloc.height); - if (GTK_IS_WINDOW(wat)) fprintf(stderr, " - \"%s\"", gtk_window_get_title(GTK_WINDOW(wat))); + if (GTK_IS_WINDOW(wat)) { + fprintf(stderr, " - \"%s\"", gtk_window_get_title(GTK_WINDOW(wat))); + } fputc('\n', stderr); } @@ -41,21 +46,22 @@ static void dump_the_whole_tree(GtkWidget *wat, int indent) { } dump_one(wat, indent); GList *kids = gtk_container_get_children(GTK_CONTAINER(wat)); - for (GList *p=kids; p; p=p->next) { + for (GList *p = kids; p; p = p->next) { dump_the_whole_tree(GTK_WIDGET(p->data), indent+2); } } static void dump_parents(GtkWidget *wat) { fprintf(stderr, "Parents:\n"); - for (GtkWidget *p=gtk_widget_get_parent(wat); p; p=gtk_widget_get_parent(p)) { + for (GtkWidget *p = gtk_widget_get_parent(wat); p; p = gtk_widget_get_parent(p)) { dump_one(p, 2); } } #endif gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const { - return inspectable_web_contents_->GetWebContents()->GetView()->GetNativeView(); + auto web_contents = inspectable_web_contents_->GetWebContents(); + return web_contents->GetView()->GetNativeView(); } @@ -90,18 +96,23 @@ gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const { */ void InspectableWebContentsViewLinux::ShowDevTools() { - GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); + auto devtools_web_contents = + inspectable_web_contents()->devtools_web_contents(); + GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView(); GtkWidget *parent = gtk_widget_get_parent(devtools); - DLOG(INFO) << base::StringPrintf("InspectableWebContentsViewLinux::ShowDevTools - parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window_, dockside_.c_str()); + DLOG(INFO) << base::StringPrintf( + "InspectableWebContentsViewLinux::ShowDevTools - parent=%s@%p window=%p dockside=\"%s\"", + g_type_name_from_instance((GTypeInstance*)parent), + parent, + devtools_window_, + dockside_.c_str()); if (!parent || GTK_IS_PANED(parent)) { if (dockside_ == "undocked") ShowDevToolsInWindow(); else if (dockside_ == "bottom") ShowDevToolsInPane(true); else if (dockside_ == "right") ShowDevToolsInPane(false); - } - else { + } else { DCHECK(parent == devtools_window_); if (dockside_ == "undocked") gtk_widget_show_all(parent); else if (dockside_ == "bottom") ShowDevToolsInPane(true); @@ -110,16 +121,22 @@ void InspectableWebContentsViewLinux::ShowDevTools() { } void InspectableWebContentsViewLinux::CloseDevTools() { - GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); + auto devtools_web_contents = + inspectable_web_contents()->devtools_web_contents(); + GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView(); GtkWidget *parent = gtk_widget_get_parent(devtools); - DLOG(INFO) << base::StringPrintf("InspectableWebContentsViewLinux::CloseDevTools - parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance((GTypeInstance*)parent), parent, devtools_window_, dockside_.c_str()); + DLOG(INFO) << base::StringPrintf( + "InspectableWebContentsViewLinux::CloseDevTools - parent=%s@%p window=%p dockside=\"%s\"", + g_type_name_from_instance((GTypeInstance*)parent), + parent, + devtools_window_, + dockside_.c_str()); - if (!parent) { + if (!parent) return; // Not visible -> nothing to do - } - else if (GTK_IS_PANED(parent)) { + + if (GTK_IS_PANED(parent)) { GtkWidget *browser = GetBrowserWindow(); GtkWidget *view = GetNativeView(); @@ -129,22 +146,26 @@ void InspectableWebContentsViewLinux::CloseDevTools() { gtk_container_remove(GTK_CONTAINER(browser), parent); gtk_widget_reparent(view, browser); g_object_unref(parent); - } - else { + } else { DCHECK(parent == devtools_window_); gtk_widget_hide(parent); } } bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { - DLOG(INFO) << "InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\""; - if (side != "undocked" && side != "bottom" && side != "right") return false; // unsupported display location - if (dockside_ == side) return true; // no change from current location + DLOG(INFO) << + "InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\""; + if (side != "undocked" && side != "bottom" && side != "right") + return false; // unsupported display location + if (dockside_ == side) + return true; // no change from current location dockside_ = side; // If devtools already has a parent, then we're being asked to move it. - GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); + auto devtools_web_contents = + inspectable_web_contents()->devtools_web_contents(); + GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView(); if (gtk_widget_get_parent(devtools)) { ShowDevTools(); } @@ -153,14 +174,16 @@ bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { } void InspectableWebContentsViewLinux::ShowDevToolsInWindow() { - GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); + auto devtools_web_contents = + inspectable_web_contents()->devtools_web_contents(); + GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView(); GtkWidget *parent = gtk_widget_get_parent(devtools); - if (!devtools_window_) MakeDevToolsWindow(); + if (!devtools_window_) + MakeDevToolsWindow(); if (!parent) { gtk_container_add(GTK_CONTAINER(devtools_window_), devtools); - } - else if (parent != devtools_window_) { + } else if (parent != devtools_window_) { DCHECK(GTK_IS_PANED(parent)); gtk_widget_reparent(devtools, devtools_window_); @@ -181,11 +204,16 @@ void InspectableWebContentsViewLinux::MakeDevToolsWindow() { devtools_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(devtools_window_), "Developer Tools"); gtk_window_set_default_size(GTK_WINDOW(devtools_window_), 800, 600); - g_signal_connect(GTK_OBJECT(devtools_window_), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), this); + g_signal_connect(GTK_OBJECT(devtools_window_), + "delete-event", + G_CALLBACK(gtk_widget_hide_on_delete), + this); } void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) { - GtkWidget *devtools = inspectable_web_contents()->devtools_web_contents()->GetView()->GetNativeView(); + auto devtools_web_contents = + inspectable_web_contents()->devtools_web_contents(); + GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView(); GtkWidget *parent = gtk_widget_get_parent(devtools); GtkWidget *pane = on_bottom ? gtk_vpaned_new() : gtk_hpaned_new(); GtkWidget *view = GetNativeView(); @@ -193,15 +221,15 @@ void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) { GtkAllocation alloc; gtk_widget_get_allocation(browser, &alloc); - gtk_paned_set_position(GTK_PANED(pane), on_bottom ? alloc.height*2/3 : alloc.width/2); + gtk_paned_set_position(GTK_PANED(pane), + on_bottom ? alloc.height * 2 / 3 : alloc.width / 2); if (!parent) { g_object_ref(view); gtk_container_remove(GTK_CONTAINER(browser), view); gtk_paned_add1(GTK_PANED(pane), view); gtk_paned_add2(GTK_PANED(pane), devtools); g_object_unref(view); - } - else if (GTK_IS_PANED(parent)) { + } else if (GTK_IS_PANED(parent)) { g_object_ref(view); g_object_ref(devtools); gtk_container_remove(GTK_CONTAINER(parent), view); @@ -211,8 +239,7 @@ void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) { g_object_unref(view); g_object_unref(devtools); gtk_container_remove(GTK_CONTAINER(browser), parent); - } - else { + } else { DCHECK(parent == devtools_window_); g_object_ref(view); gtk_container_remove(GTK_CONTAINER(devtools_window_), devtools); @@ -229,7 +256,8 @@ void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) { GtkWidget *InspectableWebContentsViewLinux::GetBrowserWindow() { GtkWidget *view = GetNativeView(); GtkWidget *parent = gtk_widget_get_parent(view); - GtkWidget *browser = GTK_IS_PANED(parent) ? gtk_widget_get_parent(parent) : parent; + GtkWidget *browser = + GTK_IS_PANED(parent) ? gtk_widget_get_parent(parent) : parent; DCHECK(GTK_IS_WINDOW(browser)); return browser; } From d0566e6e053bb485133ba2e9c556b482ee802243 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:13:44 -0500 Subject: [PATCH 0223/1195] Fix cpplint errors in application_info_win.cc --- brightray/common/application_info_win.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/brightray/common/application_info_win.cc b/brightray/common/application_info_win.cc index 6bb5dd96d28..696d8b36b5e 100644 --- a/brightray/common/application_info_win.cc +++ b/brightray/common/application_info_win.cc @@ -7,12 +7,16 @@ namespace brightray { std::string GetApplicationName() { - auto info = make_scoped_ptr(FileVersionInfo::CreateFileVersionInfoForModule(GetModuleHandle(nullptr))); + auto module = GetModuleHandle(nullptr); + auto info = make_scoped_ptr( + FileVersionInfo::CreateFileVersionInfoForModule(module)); return UTF16ToUTF8(info->product_name()); } std::string GetApplicationVersion() { - auto info = make_scoped_ptr(FileVersionInfo::CreateFileVersionInfoForModule(GetModuleHandle(nullptr))); + auto module = GetModuleHandle(nullptr); + auto info = make_scoped_ptr( + FileVersionInfo::CreateFileVersionInfoForModule(module)); return UTF16ToUTF8(info->product_version()); } From 7b47a6152de7bac94f137f655077fabe2f044a25 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:14:08 -0500 Subject: [PATCH 0224/1195] Fix cpplint errors in media_capture_devices_dispatcher.cc --- brightray/browser/media/media_capture_devices_dispatcher.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index a6b584e9c58..eb3e6731a27 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -28,7 +28,7 @@ const content::MediaStreamDevice* FindDeviceWithId( } } return NULL; -}; +} } // namespace @@ -153,7 +153,6 @@ void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( const content::MediaStreamDevice& device, content::MediaRequestState state) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - } void MediaCaptureDevicesDispatcher::OnAudioStreamPlayingChanged( @@ -175,7 +174,7 @@ void MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread( } void MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread( - const content::MediaStreamDevices& devices){ + const content::MediaStreamDevices& devices) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); devices_enumerated_ = true; video_devices_ = devices; From 654f415a49e39ca6833cb21a1328edc4140be2d4 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:14:24 -0500 Subject: [PATCH 0225/1195] Fix cpplint errors in common/mac/foundation_util.h --- brightray/common/mac/foundation_util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/common/mac/foundation_util.h b/brightray/common/mac/foundation_util.h index 509c635b04f..3b7e6a66a95 100644 --- a/brightray/common/mac/foundation_util.h +++ b/brightray/common/mac/foundation_util.h @@ -6,8 +6,8 @@ #import -// base/mac/foundation_util.h contains an incompatible declaration of NSSearchPathDirectory, -// so here we #define it to be something else. +// base/mac/foundation_util.h contains an incompatible declaration of +// NSSearchPathDirectory, so here we #define it to be something else. #define NSSearchPathDirectory NSSearchPathDirectory___PRE_10_8 #import "base/mac/foundation_util.h" #undef NSSearchPathDirectory From cdbfff2fcf0f89cc9ccd27db50f1ed30c63eb053 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:15:26 -0500 Subject: [PATCH 0226/1195] Fix backwards typedef --- brightray/browser/notification_presenter_mac.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index fef6bde3f27..e4656b98f02 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -30,8 +30,8 @@ class NotificationPresenterMac : public NotificationPresenter { int notification_id) OVERRIDE; private: - typedef NotificationMap std::map>; + typedef std::map> + NotificationMap; NotificationMap notification_map_; base::scoped_nsobject delegate_; }; From 07de5ef46251f478a67017b9e6fe274c3afd07e7 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:19:58 -0500 Subject: [PATCH 0227/1195] Silence warnings about ui::WindowImpl's BOOL& parameters --- brightray/script/cpplint | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/brightray/script/cpplint b/brightray/script/cpplint index 089b210c2fe..18e7ef7b3f1 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -13,6 +13,14 @@ IGNORED_FILES = [ 'browser/mac/bry_inspectable_web_contents_view_private.h', ] +FILTERS = [ + '-build/header_guard', + '-build/include_what_you_use', + '-legal/copyright', + # cpplint doesn't like the BOOL& parameters that ui::WindowImpl uses. + '-runtime/references', +] + def main(): os.chdir(SOURCE_ROOT) @@ -32,8 +40,7 @@ def list_files(directories, filters): def cpplint(files): - rules = '--filter=-build/header_guard,-build/include_what_you_use,-legal/copyright' - return subprocess.call([sys.executable, CPPLINT, rules] + list(files)) + return subprocess.call([sys.executable, CPPLINT, '--filter=' + ','.join(FILTERS)] + list(files)) if __name__ == '__main__': From 3d8b636f9e506261c3993a8d716a68fbe5c1d095 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:21:50 -0500 Subject: [PATCH 0228/1195] Fix remaining cpplint errors in inspectable_web_contents_view_linux.cc --- .../linux/inspectable_web_contents_view_linux.cc | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index c08aa65d5b3..dc58b38dfff 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -31,7 +31,7 @@ static void dump_one(GtkWidget *wat, int indent) { gtk_widget_get_allocation(wat, &alloc); fprintf(stderr, "%*s[%p] %s @%d,%d %dx%d", indent, "", wat, - g_type_name_from_instance((GTypeInstance*)wat), + g_type_name_from_instance(reinterpret_cast(wat)), alloc.x, alloc.y, alloc.width, alloc.height); if (GTK_IS_WINDOW(wat)) { fprintf(stderr, " - \"%s\"", gtk_window_get_title(GTK_WINDOW(wat))); @@ -53,7 +53,9 @@ static void dump_the_whole_tree(GtkWidget *wat, int indent) { static void dump_parents(GtkWidget *wat) { fprintf(stderr, "Parents:\n"); - for (GtkWidget *p = gtk_widget_get_parent(wat); p; p = gtk_widget_get_parent(p)) { + for (GtkWidget *p = gtk_widget_get_parent(wat); + p; + p = gtk_widget_get_parent(p)) { dump_one(p, 2); } } @@ -102,8 +104,9 @@ void InspectableWebContentsViewLinux::ShowDevTools() { GtkWidget *parent = gtk_widget_get_parent(devtools); DLOG(INFO) << base::StringPrintf( - "InspectableWebContentsViewLinux::ShowDevTools - parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance((GTypeInstance*)parent), + "InspectableWebContentsViewLinux::ShowDevTools - " \ + "parent=%s@%p window=%p dockside=\"%s\"", + g_type_name_from_instance(reinterpret_cast(parent)), parent, devtools_window_, dockside_.c_str()); @@ -127,8 +130,9 @@ void InspectableWebContentsViewLinux::CloseDevTools() { GtkWidget *parent = gtk_widget_get_parent(devtools); DLOG(INFO) << base::StringPrintf( - "InspectableWebContentsViewLinux::CloseDevTools - parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance((GTypeInstance*)parent), + "InspectableWebContentsViewLinux::CloseDevTools - " \ + "parent=%s@%p window=%p dockside=\"%s\"", + g_type_name_from_instance(reinterpret_cast(parent)), parent, devtools_window_, dockside_.c_str()); From c9e948dc58023e460cfabea591879258716f2467 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Sun, 17 Nov 2013 19:22:53 -0500 Subject: [PATCH 0229/1195] Make ignoring files work on Windows --- brightray/script/cpplint | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/script/cpplint b/brightray/script/cpplint index 18e7ef7b3f1..69b7aaff9a0 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -10,7 +10,7 @@ SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'google-styleguide', 'trunk', 'cpplint', 'cpplint.py') IGNORED_FILES = [ - 'browser/mac/bry_inspectable_web_contents_view_private.h', + os.path.join('browser', 'mac', 'bry_inspectable_web_contents_view_private.h'), ] FILTERS = [ From 9f9aeac59f5adbb5f070db26d85188af3bb05637 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Sun, 17 Nov 2013 22:25:24 -0600 Subject: [PATCH 0230/1195] safer casts, clearer if-else chain --- .../linux/inspectable_web_contents_view_linux.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index dc58b38dfff..2546bccc823 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -31,7 +31,7 @@ static void dump_one(GtkWidget *wat, int indent) { gtk_widget_get_allocation(wat, &alloc); fprintf(stderr, "%*s[%p] %s @%d,%d %dx%d", indent, "", wat, - g_type_name_from_instance(reinterpret_cast(wat)), + g_type_name_from_instance(static_cast(wat)), alloc.x, alloc.y, alloc.width, alloc.height); if (GTK_IS_WINDOW(wat)) { fprintf(stderr, " - \"%s\"", gtk_window_get_title(GTK_WINDOW(wat))); @@ -106,7 +106,7 @@ void InspectableWebContentsViewLinux::ShowDevTools() { DLOG(INFO) << base::StringPrintf( "InspectableWebContentsViewLinux::ShowDevTools - " \ "parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance(reinterpret_cast(parent)), + g_type_name_from_instance(static_cast(parent)), parent, devtools_window_, dockside_.c_str()); @@ -132,15 +132,14 @@ void InspectableWebContentsViewLinux::CloseDevTools() { DLOG(INFO) << base::StringPrintf( "InspectableWebContentsViewLinux::CloseDevTools - " \ "parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance(reinterpret_cast(parent)), + g_type_name_from_instance(static_cast(parent)), parent, devtools_window_, dockside_.c_str()); - if (!parent) + if (!parent) { return; // Not visible -> nothing to do - - if (GTK_IS_PANED(parent)) { + } else if (GTK_IS_PANED(parent)) { GtkWidget *browser = GetBrowserWindow(); GtkWidget *view = GetNativeView(); From 470daa571c9c99e396b955645ff9203e491f0f8c Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Sun, 17 Nov 2013 22:27:23 -0600 Subject: [PATCH 0231/1195] back to reinterpret_cast --- .../browser/linux/inspectable_web_contents_view_linux.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index 2546bccc823..cbe8e4e9c34 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -31,7 +31,7 @@ static void dump_one(GtkWidget *wat, int indent) { gtk_widget_get_allocation(wat, &alloc); fprintf(stderr, "%*s[%p] %s @%d,%d %dx%d", indent, "", wat, - g_type_name_from_instance(static_cast(wat)), + g_type_name_from_instance(reinterpret_cast(wat)), alloc.x, alloc.y, alloc.width, alloc.height); if (GTK_IS_WINDOW(wat)) { fprintf(stderr, " - \"%s\"", gtk_window_get_title(GTK_WINDOW(wat))); @@ -106,7 +106,7 @@ void InspectableWebContentsViewLinux::ShowDevTools() { DLOG(INFO) << base::StringPrintf( "InspectableWebContentsViewLinux::ShowDevTools - " \ "parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance(static_cast(parent)), + g_type_name_from_instance(reinterpret_cast(parent)), parent, devtools_window_, dockside_.c_str()); @@ -132,7 +132,7 @@ void InspectableWebContentsViewLinux::CloseDevTools() { DLOG(INFO) << base::StringPrintf( "InspectableWebContentsViewLinux::CloseDevTools - " \ "parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance(static_cast(parent)), + g_type_name_from_instance(reinterpret_cast(parent)), parent, devtools_window_, dockside_.c_str()); From 89795c9b1493c8efdcb3968162c0a0467763ecc6 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 25 Nov 2013 16:28:57 -0500 Subject: [PATCH 0232/1195] Stop the devtools from turning black when the window gets big enough We need to use UnderlayOpenGLHostingWindow to show the devtools to ensure they remain visible even when they get large. --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 09b5c863b02..24987e5c1c5 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -6,6 +6,7 @@ #import "content/public/browser/render_widget_host_view.h" #import "content/public/browser/web_contents_view.h" +#import "ui/base/cocoa/underlay_opengl_hosting_window.h" using namespace brightray; @@ -130,8 +131,8 @@ void SetActive(content::WebContents* web_contents, bool active) { - (void)moveToWindow { if (!_private->window) { auto styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask | NSTexturedBackgroundWindowMask | NSUnifiedTitleAndToolbarWindowMask; - auto contentRect = [NSWindow contentRectForFrameRect:devtoolsWindowFrame(_private->splitView) styleMask:styleMask]; - _private->window = [[NSWindow alloc] initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:YES]; + auto contentRect = [UnderlayOpenGLHostingWindow contentRectForFrameRect:devtoolsWindowFrame(_private->splitView) styleMask:styleMask]; + _private->window = [[UnderlayOpenGLHostingWindow alloc] initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:YES]; _private->window.delegate = self; _private->window.releasedWhenClosed = NO; _private->window.title = @"Developer Tools"; From e1b6718c390fe2314ffef01e62a2c8693eabb966 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Tue, 26 Nov 2013 10:51:27 -0600 Subject: [PATCH 0233/1195] include library dependencies explicitly This is necessary for more recent versions of Clang, e.g., on Debian unstable. --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b40bcd8006b..0a41a149048 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -90,6 +90,8 @@ 'link_settings': { 'libraries': [ '<(brightray_source_root)/<(libchromiumcontent_library_dir)/libchromiumcontent.so', + '-lpthread', + ' Date: Wed, 27 Nov 2013 15:55:06 -0600 Subject: [PATCH 0234/1195] make BrowserContext::Initialize virtual --- brightray/browser/browser_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 6356277942e..b92deb75c57 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -22,7 +22,7 @@ class BrowserContext : public content::BrowserContext { BrowserContext(); ~BrowserContext(); - void Initialize(); + virtual void Initialize(); net::URLRequestContextGetter* CreateRequestContext( content::ProtocolHandlerMap*); From 1da8c37098c56619c5509f550882209e1ecbf09e Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 2 Dec 2013 11:17:25 -0500 Subject: [PATCH 0235/1195] Update libchromiumcontent to Chrome 31 * vendor/libchromiumcontent f484ce1...4252769 (1): > Merge pull request #32 from brightray/chrome-31 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 7ddba388364..42527696408 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 7ddba388364ee0b429a2b72555daa55e3270876f +Subproject commit 4252769640884c1964cb936c91521e1a1fb50500 From 265076f19ad78b09764e94727c61a75ed9dc4500 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 2 Dec 2013 12:38:24 -0500 Subject: [PATCH 0236/1195] Update for changes to devtools in Chrome 31 browser/devtools_embedder_message_dispatcher.* came from chrome/browser/devtools, and were modified just enough to compile within brightray. --- brightray/brightray.gyp | 2 + .../devtools_embedder_message_dispatcher.cc | 208 ++++++++++++++++++ .../devtools_embedder_message_dispatcher.h | 68 ++++++ .../browser/inspectable_web_contents_impl.cc | 11 +- .../browser/inspectable_web_contents_impl.h | 14 +- 5 files changed, 297 insertions(+), 6 deletions(-) create mode 100644 brightray/browser/devtools_embedder_message_dispatcher.cc create mode 100644 brightray/browser/devtools_embedder_message_dispatcher.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 0a41a149048..1781172b970 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -35,6 +35,8 @@ 'browser/default_web_contents_delegate.cc', 'browser/default_web_contents_delegate.h', 'browser/default_web_contents_delegate_mac.mm', + 'browser/devtools_embedder_message_dispatcher.cc', + 'browser/devtools_embedder_message_dispatcher.h', 'browser/devtools_ui.cc', 'browser/devtools_ui.h', 'browser/download_manager_delegate.cc', diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc new file mode 100644 index 00000000000..2d6c61ec1c8 --- /dev/null +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -0,0 +1,208 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/devtools_embedder_message_dispatcher.h" + +#include "base/bind.h" +#include "base/json/json_reader.h" +#include "base/values.h" + +namespace brightray { + +namespace { + +static const char kFrontendHostMethod[] = "method"; +static const char kFrontendHostParams[] = "params"; + +bool GetValue(const base::ListValue& list, int pos, std::string& value) { + return list.GetString(pos, &value); +} + +bool GetValue(const base::ListValue& list, int pos, int& value) { + return list.GetInteger(pos, &value); +} + +bool GetValue(const base::ListValue& list, int pos, bool& value) { + return list.GetBoolean(pos, &value); +} + +template +struct StorageTraits { + typedef T StorageType; +}; + +template +struct StorageTraits { + typedef T StorageType; +}; + +template +class Argument { + public: + typedef typename StorageTraits::StorageType ValueType; + + Argument(const base::ListValue& list, int pos) { + valid_ = GetValue(list, pos, value_); + } + + ValueType value() const { return value_; } + bool valid() const { return valid_; } + + private: + ValueType value_; + bool valid_; +}; + +bool ParseAndHandle0(const base::Callback& handler, + const base::ListValue& list) { + handler.Run(); + return true; +} + +template +bool ParseAndHandle1(const base::Callback& handler, + const base::ListValue& list) { + if (list.GetSize() != 1) + return false; + Argument arg1(list, 0); + if (!arg1.valid()) + return false; + handler.Run(arg1.value()); + return true; +} + +template +bool ParseAndHandle2(const base::Callback& handler, + const base::ListValue& list) { + if (list.GetSize() != 2) + return false; + Argument arg1(list, 0); + if (!arg1.valid()) + return false; + Argument arg2(list, 1); + if (!arg2.valid()) + return false; + handler.Run(arg1.value(), arg2.value()); + return true; +} + +template +bool ParseAndHandle3(const base::Callback& handler, + const base::ListValue& list) { + if (list.GetSize() != 3) + return false; + Argument arg1(list, 0); + if (!arg1.valid()) + return false; + Argument arg2(list, 1); + if (!arg2.valid()) + return false; + Argument arg3(list, 2); + if (!arg3.valid()) + return false; + handler.Run(arg1.value(), arg2.value(), arg3.value()); + return true; +} + +typedef base::Callback ListValueParser; + +ListValueParser BindToListParser(const base::Callback& handler) { + return base::Bind(&ParseAndHandle0, handler); +} + +template +ListValueParser BindToListParser(const base::Callback& handler) { + return base::Bind(&ParseAndHandle1, handler); +} + +template +ListValueParser BindToListParser(const base::Callback& handler) { + return base::Bind(&ParseAndHandle2, handler); +} + +template +ListValueParser BindToListParser( + const base::Callback& handler) { + return base::Bind(&ParseAndHandle3, handler); +} + +} // namespace + +DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher( + Delegate* delegate) { + RegisterHandler("bringToFront", + BindToListParser(base::Bind(&Delegate::ActivateWindow, + base::Unretained(delegate)))); + RegisterHandler("closeWindow", + BindToListParser(base::Bind(&Delegate::CloseWindow, + base::Unretained(delegate)))); + RegisterHandler("moveWindowBy", + BindToListParser(base::Bind(&Delegate::MoveWindow, + base::Unretained(delegate)))); + RegisterHandler("requestSetDockSide", + BindToListParser(base::Bind(&Delegate::SetDockSide, + base::Unretained(delegate)))); + RegisterHandler("openInNewTab", + BindToListParser(base::Bind(&Delegate::OpenInNewTab, + base::Unretained(delegate)))); + RegisterHandler("save", + BindToListParser(base::Bind(&Delegate::SaveToFile, + base::Unretained(delegate)))); + RegisterHandler("append", + BindToListParser(base::Bind(&Delegate::AppendToFile, + base::Unretained(delegate)))); + RegisterHandler("requestFileSystems", + BindToListParser(base::Bind(&Delegate::RequestFileSystems, + base::Unretained(delegate)))); + RegisterHandler("addFileSystem", + BindToListParser(base::Bind(&Delegate::AddFileSystem, + base::Unretained(delegate)))); + RegisterHandler("removeFileSystem", + BindToListParser(base::Bind(&Delegate::RemoveFileSystem, + base::Unretained(delegate)))); + RegisterHandler("indexPath", + BindToListParser(base::Bind(&Delegate::IndexPath, + base::Unretained(delegate)))); + RegisterHandler("stopIndexing", + BindToListParser(base::Bind(&Delegate::StopIndexing, + base::Unretained(delegate)))); + RegisterHandler("searchInPath", + BindToListParser(base::Bind(&Delegate::SearchInPath, + base::Unretained(delegate)))); +} + +DevToolsEmbedderMessageDispatcher::~DevToolsEmbedderMessageDispatcher() {} + +void DevToolsEmbedderMessageDispatcher::Dispatch(const std::string& message) { + std::string method; + base::ListValue empty_params; + base::ListValue* params = &empty_params; + + base::DictionaryValue* dict; + scoped_ptr parsed_message(base::JSONReader::Read(message)); + if (!parsed_message || + !parsed_message->GetAsDictionary(&dict) || + !dict->GetString(kFrontendHostMethod, &method) || + (dict->HasKey(kFrontendHostParams) && + !dict->GetList(kFrontendHostParams, ¶ms))) { + LOG(ERROR) << "Cannot parse frontend host message: " << message; + return; + } + + HandlerMap::iterator it = handlers_.find(method); + if (it == handlers_.end()) { + LOG(ERROR) << "Unsupported frontend host method: " << message; + return; + } + + if (!it->second.Run(*params)) + LOG(ERROR) << "Invalid frontend host message parameters: " << message; +} + +void DevToolsEmbedderMessageDispatcher::RegisterHandler( + const std::string& method, const Handler& handler) { + handlers_[method] = handler; +} + +} // namespace brightray diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h new file mode 100644 index 00000000000..df21050320e --- /dev/null +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -0,0 +1,68 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_ +#define BRIGHTRAY_BROWSER_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_ + +#include +#include + +#include "base/callback.h" + +namespace base { +class ListValue; +} + +namespace brightray { + +/** + * Dispatcher for messages sent from the DevTools frontend running in an + * isolated renderer (on chrome-devtools://) to the embedder in the browser. + * + * The messages are sent via InspectorFrontendHost.sendMessageToEmbedder method. + */ +class DevToolsEmbedderMessageDispatcher { + public: + class Delegate { + public: + virtual ~Delegate() {} + + virtual void ActivateWindow() = 0; + virtual void CloseWindow() = 0; + virtual void MoveWindow(int x, int y) = 0; + virtual void SetDockSide(const std::string& side) = 0; + virtual void OpenInNewTab(const std::string& url) = 0; + virtual void SaveToFile(const std::string& url, + const std::string& content, + bool save_as) = 0; + virtual void AppendToFile(const std::string& url, + const std::string& content) = 0; + virtual void RequestFileSystems() = 0; + virtual void AddFileSystem() = 0; + virtual void RemoveFileSystem(const std::string& file_system_path) = 0; + virtual void IndexPath(int request_id, + const std::string& file_system_path) = 0; + virtual void StopIndexing(int request_id) = 0; + virtual void SearchInPath(int request_id, + const std::string& file_system_path, + const std::string& query) = 0; + }; + + explicit DevToolsEmbedderMessageDispatcher(Delegate* delegate); + + ~DevToolsEmbedderMessageDispatcher(); + + void Dispatch(const std::string& message); + + private: + typedef base::Callback Handler; + void RegisterHandler(const std::string& method, const Handler& handler); + + typedef std::map HandlerMap; + HandlerMap handlers_; +}; + +} // namespace brightray + +#endif // BRIGHTRAY_BROWSER_DEVTOOLS_EMBEDDER_MESSAGE_DISPATCHER_H_ diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 5f561953218..e3cefbe180c 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -61,6 +61,9 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const { void InspectableWebContentsImpl::ShowDevTools() { if (!devtools_web_contents_) { + embedder_message_dispatcher_.reset( + new DevToolsEmbedderMessageDispatcher(this)); + auto create_params = content::WebContents::CreateParams( web_contents_->GetBrowserContext()); devtools_web_contents_.reset(content::WebContents::Create(create_params)); @@ -103,9 +106,6 @@ void InspectableWebContentsImpl::UpdateFrontendDockSide() { void InspectableWebContentsImpl::ActivateWindow() { } -void InspectableWebContentsImpl::ChangeAttachedWindowHeight(unsigned height) { -} - void InspectableWebContentsImpl::CloseWindow() { view_->CloseDevTools(); devtools_web_contents_.reset(); @@ -162,6 +162,11 @@ void InspectableWebContentsImpl::SearchInPath( const std::string& query) { } +void InspectableWebContentsImpl::DispatchOnEmbedder( + const std::string& message) { + embedder_message_dispatcher_->Dispatch(message); +} + void InspectableWebContentsImpl::InspectedContentsClosing() { } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 50592fd3fc5..804d8dccfe2 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -8,6 +8,8 @@ #include "browser/inspectable_web_contents.h" +#include "browser/devtools_embedder_message_dispatcher.h" + #include "content/public/browser/devtools_frontend_host_delegate.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" @@ -27,7 +29,8 @@ class InspectableWebContentsImpl : public InspectableWebContents, content::DevToolsFrontendHostDelegate, content::WebContentsObserver, - content::WebContentsDelegate { + content::WebContentsDelegate, + DevToolsEmbedderMessageDispatcher::Delegate { public: static void RegisterPrefs(PrefRegistrySimple* pref_registry); @@ -46,10 +49,9 @@ class InspectableWebContentsImpl : private: void UpdateFrontendDockSide(); - // content::DevToolsFrontendHostDelegate + // DevToolsEmbedderMessageDispacher::Delegate virtual void ActivateWindow() OVERRIDE; - virtual void ChangeAttachedWindowHeight(unsigned height) OVERRIDE; virtual void CloseWindow() OVERRIDE; virtual void MoveWindow(int x, int y) OVERRIDE; virtual void SetDockSide(const std::string& side) OVERRIDE; @@ -68,6 +70,10 @@ class InspectableWebContentsImpl : virtual void SearchInPath(int request_id, const std::string& file_system_path, const std::string& query) OVERRIDE; + + // content::DevToolsFrontendHostDelegate + + virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; virtual void InspectedContentsClosing() OVERRIDE; // content::WebContentsObserver @@ -92,6 +98,8 @@ class InspectableWebContentsImpl : scoped_refptr agent_host_; std::string dock_side_; + scoped_ptr embedder_message_dispatcher_; + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); }; From cfeddb5bcbbeaf3d9593e394255066465d49836c Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 2 Dec 2013 11:39:26 -0500 Subject: [PATCH 0237/1195] Update for changes to net::FileProtocolHandler in Chrome 31 I just copied the way that Chrome initializes this object. --- brightray/browser/url_request_context_getter.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index ecba106e96b..8d2abf5a32c 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -9,6 +9,7 @@ #include "browser/network_delegate.h" #include "base/strings/string_util.h" +#include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/cookie_store_factory.h" @@ -142,7 +143,11 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { job_factory->SetProtocolHandler( chrome::kDataScheme, new net::DataProtocolHandler); job_factory->SetProtocolHandler( - chrome::kFileScheme, new net::FileProtocolHandler); + chrome::kFileScheme, + new net::FileProtocolHandler( + content::BrowserThread::GetBlockingPool()-> + GetTaskRunnerWithShutdownBehavior( + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); storage_->set_job_factory(job_factory.release()); } From ab8cb1e3a5feaca6b298f6ffbe1b85129645940d Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 2 Dec 2013 11:39:51 -0500 Subject: [PATCH 0238/1195] Update for changes to content::CreatePersistentCookieStore in Chrome 31 I just copied how Chrome initializes this object. --- brightray/browser/url_request_context_getter.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 8d2abf5a32c..6b71e20f55e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -70,6 +70,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { base_path_.Append(FILE_PATH_LITERAL("Cookies")), false, nullptr, + nullptr, nullptr)); storage_->set_server_bound_cert_service(new net::ServerBoundCertService( new net::DefaultServerBoundCertStore(NULL), From 9c5b81bf7ae749bb7f2e243ad6912f93daf3b8e6 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 2 Dec 2013 11:40:43 -0500 Subject: [PATCH 0239/1195] Stop setting helper process names on OS X See https://codereview.chromium.org/45253002. --- brightray/common/main_delegate.cc | 1 - brightray/common/main_delegate.h | 1 - brightray/common/main_delegate_mac.mm | 18 ------------------ 3 files changed, 20 deletions(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 4c903149d09..a5ecc5f4598 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -34,7 +34,6 @@ void MainDelegate::PreSandboxStartup() { #if defined(OS_MACOSX) OverrideChildProcessPath(); OverrideFrameworkBundlePath(); - SetProcessName(); #endif InitializeResourceBundle(); } diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index e1d033312c9..5850f9593b2 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -42,7 +42,6 @@ class MainDelegate : public content::ContentMainDelegate { static base::FilePath GetResourcesPakFilePath(); static void OverrideChildProcessPath(); static void OverrideFrameworkBundlePath(); - static void SetProcessName(); #endif scoped_ptr content_client_; diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index 7c5aaf68da7..c710fa1da21 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -11,7 +11,6 @@ #include "base/command_line.h" #include "base/mac/bundle_locations.h" -#include "base/mac/mac_util.h" #include "base/path_service.h" #include "base/strings/stringprintf.h" #include "base/strings/sys_string_conversions.h" @@ -48,21 +47,4 @@ void MainDelegate::OverrideChildProcessPath() { PathService::Override(content::CHILD_PROCESS_EXE, helper_path); } -void MainDelegate::SetProcessName() { - const auto& command_line = *CommandLine::ForCurrentProcess(); - auto process_type = command_line.GetSwitchValueASCII(switches::kProcessType); - std::string suffix; - if (process_type == switches::kRendererProcess) - suffix = "Renderer"; - else if (process_type == switches::kPluginProcess || process_type == switches::kPpapiPluginProcess) - suffix = "Plug-In Host"; - else if (process_type == switches::kUtilityProcess) - suffix = "Utility"; - else - return; - - auto name = base::SysUTF8ToNSString(base::StringPrintf("%s %s", GetApplicationName().c_str(), suffix.c_str())); - base::mac::SetProcessName(base::mac::NSToCFCast(name)); -} - } From 7e6f5aa734e5b489bea9f39afb620319afd90696 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 2 Dec 2013 11:47:58 -0500 Subject: [PATCH 0240/1195] Update for ui -> gfx moves in Chrome 31 See https://codereview.chromium.org/23769011. --- brightray/browser/win/devtools_window.h | 4 ++-- .../browser/win/inspectable_web_contents_view_win.cc | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/brightray/browser/win/devtools_window.h b/brightray/browser/win/devtools_window.h index 738af0a427c..a6b11bb11e0 100644 --- a/brightray/browser/win/devtools_window.h +++ b/brightray/browser/win/devtools_window.h @@ -2,13 +2,13 @@ #define BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ #include "base/memory/weak_ptr.h" -#include "ui/base/win/window_impl.h" +#include "ui/gfx/win/window_impl.h" namespace brightray { class InspectableWebContentsViewWin; -class DevToolsWindow : public ui::WindowImpl, +class DevToolsWindow : public gfx::WindowImpl, public base::SupportsWeakPtr { public: static DevToolsWindow* Create( diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index a25cdc8919f..49135713194 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -5,7 +5,7 @@ #include "browser/win/devtools_window.h" #include "content/public/browser/web_contents_view.h" -#include "ui/base/win/hwnd_util.h" +#include "ui/gfx/win/hwnd_util.h" namespace brightray { @@ -44,9 +44,9 @@ void InspectableWebContentsViewWin::ShowDevTools() { auto contents_view = inspectable_web_contents_->GetWebContents()->GetView(); auto size = contents_view->GetContainerSize(); size.Enlarge(-kWindowInset, -kWindowInset); - ui::CenterAndSizeWindow(contents_view->GetNativeView(), - devtools_window_->hwnd(), - size); + gfx::CenterAndSizeWindow(contents_view->GetNativeView(), + devtools_window_->hwnd(), + size); ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL); } From c9c218edc64fc8be3084309449d05adf95bdc3fe Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 2 Dec 2013 15:10:16 -0500 Subject: [PATCH 0241/1195] Update to 64-bit libchromiumcontent * vendor/libchromiumcontent 4252769...5cce386 (1): > Merge pull request #31 from brightray/mac-x64 --- brightray/brightray.gypi | 2 +- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 5587c5dd724..226524620ad 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -31,7 +31,7 @@ 'target_defaults': { 'xcode_settings': { 'ALWAYS_SEARCH_USER_PATHS': 'NO', - 'ARCHS': '$(ARCHS_STANDARD_32_BIT)', + 'ARCHS': '$(ARCHS_STANDARD_64_BIT)', 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11', 'CLANG_CXX_LIBRARY': 'libstdc++', 'COMBINE_HIDPI_IMAGES': 'YES', diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 42527696408..5cce3860fee 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 4252769640884c1964cb936c91521e1a1fb50500 +Subproject commit 5cce3860fee8a3a981d74d9f616029b807c0738f From 1c56afe9d8bb5d5d9c64b0a0bd900d99870a4177 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 3 Dec 2013 17:12:21 -0500 Subject: [PATCH 0242/1195] Create a BrowserClient by default This way applications that don't need to customize the BrowserClient get one for free. --- brightray/common/main_delegate.cc | 9 +++++++++ brightray/common/main_delegate.h | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index a5ecc5f4598..f85c769bafc 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -58,4 +58,13 @@ void MainDelegate::InitializeResourceBundle() { } } +content::ContentBrowserClient* MainDelegate::CreateContentBrowserClient() { + browser_client_ = CreateBrowserClient().Pass(); + return browser_client_.get(); +} + +scoped_ptr MainDelegate::CreateBrowserClient() { + return make_scoped_ptr(new BrowserClient).Pass(); +} + } // namespace brightray diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 5850f9593b2..0c5107327f7 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -17,6 +17,7 @@ class FilePath; namespace brightray { +class BrowserClient; class ContentClient; class MainDelegate : public content::ContentMainDelegate { @@ -29,6 +30,10 @@ class MainDelegate : public content::ContentMainDelegate { // implementation. virtual scoped_ptr CreateContentClient(); + // Subclasses can override this to provide their own BrowserClient + // implementation. + virtual scoped_ptr CreateBrowserClient(); + // Subclasses can override this to provide additional .pak files to be // included in the ui::ResourceBundle. virtual void AddPakPaths(std::vector* pak_paths) {} @@ -37,6 +42,8 @@ class MainDelegate : public content::ContentMainDelegate { virtual void PreSandboxStartup() OVERRIDE; private: + virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE; + void InitializeResourceBundle(); #if defined(OS_MACOSX) static base::FilePath GetResourcesPakFilePath(); @@ -45,6 +52,7 @@ class MainDelegate : public content::ContentMainDelegate { #endif scoped_ptr content_client_; + scoped_ptr browser_client_; DISALLOW_COPY_AND_ASSIGN(MainDelegate); }; From cf08bb098fda0af379f2d16464f4450ba02b2945 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 5 Dec 2013 02:50:17 -0800 Subject: [PATCH 0243/1195] Update libchromiumcontent for net_with_v8. --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 5cce3860fee..ee2e80aa49f 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 5cce3860fee8a3a981d74d9f616029b807c0738f +Subproject commit ee2e80aa49f917edfb7a72ace71d513af4731b62 From 0a1f756ca65c63071b1860cbe377b08b2ff1e6d8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 5 Dec 2013 02:56:28 -0800 Subject: [PATCH 0244/1195] Use "ProxyResolverV8" instead of "SystemProxyResolver" as proxy service. SystemProxyResolver is untested and could cause random crashes. --- brightray/browser/browser_main_parts.cc | 10 ++++++++++ brightray/browser/browser_main_parts.h | 1 + .../browser/url_request_context_getter.cc | 20 +++++++++++++------ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 60057034f6e..8601b0426cd 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -6,6 +6,7 @@ #include "browser/browser_context.h" #include "browser/web_ui_controller_factory.h" +#include "net/proxy/proxy_resolver_v8.h" namespace brightray { @@ -29,6 +30,15 @@ void BrowserMainParts::PostMainMessageLoopRun() { browser_context_.reset(); } +int BrowserMainParts::PreCreateThreads() { +#if defined(OS_WIN) + net::ProxyResolverV8::CreateIsolate(); +#else + net::ProxyResolverV8::RememberDefaultIsolate(); +#endif + return 0; +} + BrowserContext* BrowserMainParts::CreateBrowserContext() { return new BrowserContext; } diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index f0aeb427796..6e2f3531f67 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -32,6 +32,7 @@ class BrowserMainParts : public content::BrowserMainParts { virtual void PreMainMessageLoopRun() OVERRIDE; virtual void PostMainMessageLoopRun() OVERRIDE; + virtual int PreCreateThreads() OVERRIDE; private: scoped_ptr browser_context_; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 6b71e20f55e..e1df64c23fe 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -19,7 +19,11 @@ #include "net/http/http_auth_handler_factory.h" #include "net/http/http_cache.h" #include "net/http/http_server_properties_impl.h" +#include "net/proxy/dhcp_proxy_script_fetcher_factory.h" +#include "net/proxy/proxy_config_service.h" +#include "net/proxy/proxy_script_fetcher_impl.h" #include "net/proxy/proxy_service.h" +#include "net/proxy/proxy_service_v8.h" #include "net/ssl/default_server_bound_cert_store.h" #include "net/ssl/server_bound_cert_service.h" #include "net/ssl/ssl_config_service_defaults.h" @@ -83,12 +87,6 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { net::HostResolver::CreateDefaultResolver(NULL)); storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); - // TODO(jam): use v8 if possible, look at chrome code. - storage_->set_proxy_service( - net::ProxyService::CreateUsingSystemProxyResolver( - proxy_config_service_.release(), - 0, - NULL)); storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); storage_->set_http_auth_handler_factory( net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); @@ -128,6 +126,16 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.host_resolver = url_request_context_->host_resolver(); + net::DhcpProxyScriptFetcherFactory dhcp_factory; + storage_->set_proxy_service( + net::CreateProxyServiceUsingV8ProxyResolver( + proxy_config_service_.release(), + new net::ProxyScriptFetcherImpl(url_request_context_.get()), + dhcp_factory.Create(url_request_context_.get()), + url_request_context_->host_resolver(), + NULL, + url_request_context_->network_delegate())); + net::HttpCache* main_cache = new net::HttpCache( network_session_params, main_backend); storage_->set_http_transaction_factory(main_cache); From de7892cd6e66fcb39e41ea8ae32d9546c21cf47c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 5 Nov 2013 10:29:53 +0800 Subject: [PATCH 0245/1195] Add API to get whether the devtools is opened. --- brightray/browser/inspectable_web_contents.h | 1 + brightray/browser/inspectable_web_contents_impl.cc | 4 ++++ brightray/browser/inspectable_web_contents_impl.h | 1 + brightray/browser/inspectable_web_contents_view.h | 1 + brightray/browser/inspectable_web_contents_view_mac.h | 1 + brightray/browser/inspectable_web_contents_view_mac.mm | 4 ++++ brightray/browser/mac/bry_inspectable_web_contents_view.mm | 6 +++++- .../browser/mac/bry_inspectable_web_contents_view_private.h | 3 ++- brightray/browser/win/inspectable_web_contents_view_win.cc | 4 ++++ brightray/browser/win/inspectable_web_contents_view_win.h | 1 + 10 files changed, 24 insertions(+), 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 9c381ae7403..04ba87bf0df 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -22,6 +22,7 @@ class InspectableWebContents { virtual content::WebContents* GetWebContents() const = 0; virtual void ShowDevTools() = 0; + virtual bool IsDevToolsOpened() = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index e3cefbe180c..0b194e70e61 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -96,6 +96,10 @@ void InspectableWebContentsImpl::ShowDevTools() { view_->ShowDevTools(); } +bool InspectableWebContentsImpl::IsDevToolsOpened() { + return devtools_web_contents_ && view_->IsDevToolsOpened(); +} + void InspectableWebContentsImpl::UpdateFrontendDockSide() { auto javascript = base::StringPrintf( "InspectorFrontendAPI.setDockSide(\"%s\")", dock_side_.c_str()); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 804d8dccfe2..f0a55f5dac5 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -41,6 +41,7 @@ class InspectableWebContentsImpl : virtual content::WebContents* GetWebContents() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; + virtual bool IsDevToolsOpened() OVERRIDE; content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index eed32f34919..ff71bac783b 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -13,6 +13,7 @@ class InspectableWebContentsView { virtual void ShowDevTools() = 0; virtual void CloseDevTools() = 0; + virtual bool IsDevToolsOpened() = 0; virtual bool SetDockSide(const std::string& side) = 0; }; diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index f31149f570b..4390db290f8 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -19,6 +19,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; + virtual bool IsDevToolsOpened() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index c9cc215591c..adde9b05033 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -29,6 +29,10 @@ void InspectableWebContentsViewMac::CloseDevTools() { [view_ setDevToolsVisible:NO]; } +bool InspectableWebContentsViewMac::IsDevToolsOpened() { + return [view_ isDevToolsVisible]; +} + bool InspectableWebContentsViewMac::SetDockSide(const std::string& side) { return [view_ setDockSide:side]; } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 24987e5c1c5..813d4fb6732 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -112,6 +112,10 @@ void SetActive(content::WebContents* web_contents, bool active) { [_private->splitView adjustSubviews]; } +- (BOOL)isDevToolsVisible { + return _private->visible; +} + - (BOOL)setDockSide:(const std::string&)side { if (side == "right") { _private->splitView.vertical = YES; @@ -221,4 +225,4 @@ void SetActive(content::WebContents* web_contents, bool active) { @end @implementation BRYInspectableWebContentsViewPrivate -@end \ No newline at end of file +@end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view_private.h b/brightray/browser/mac/bry_inspectable_web_contents_view_private.h index ef8c50cc8b6..943ef93e312 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view_private.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view_private.h @@ -8,6 +8,7 @@ class InspectableWebContentsViewMac; - (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac *)inspectableWebContentsView; - (void)setDevToolsVisible:(BOOL)visible; +- (BOOL)isDevToolsVisible; - (BOOL)setDockSide:(const std::string&)side; -@end \ No newline at end of file +@end diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index 49135713194..d1530d1cee9 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -57,6 +57,10 @@ void InspectableWebContentsViewWin::CloseDevTools() { SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); } +bool InspectableWebContentsViewWin::IsDevToolsOpened() { + return devtools_window_; +} + bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { return false; } diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index 534f4997284..f79ce30bf3d 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -20,6 +20,7 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; + virtual bool IsDevToolsOpened() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { From a8c59110942c3d48c33a6f77e56380fc2146ca9a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Dec 2013 23:11:29 -0800 Subject: [PATCH 0246/1195] Implement IsDevToolsOpened for Linux. --- .../linux/inspectable_web_contents_view_linux.cc | 15 +++++++++++++++ .../linux/inspectable_web_contents_view_linux.h | 1 + 2 files changed, 16 insertions(+) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index cbe8e4e9c34..54f54cadabe 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -10,6 +10,17 @@ namespace brightray { +namespace { + +bool IsWidgetAncestryVisible(GtkWidget* widget) { + GtkWidget* parent = widget; + while (parent && gtk_widget_get_visible(parent)) + parent = gtk_widget_get_parent(parent); + return !parent; +} + +} + InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewLinux(inspectable_web_contents); @@ -155,6 +166,10 @@ void InspectableWebContentsViewLinux::CloseDevTools() { } } +bool InspectableWebContentsViewLinux::IsDevToolsOpened() { + return devtools_window_ && IsWidgetAncestryVisible(devtools_window_); +} + bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { DLOG(INFO) << "InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\""; diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/linux/inspectable_web_contents_view_linux.h index c6605b3939f..79ab6f731d5 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.h +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.h @@ -18,6 +18,7 @@ class InspectableWebContentsViewLinux : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; + virtual bool IsDevToolsOpened() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { From 7a5415a3b781ae1314c769b4040a7373012fb8dd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 9 Dec 2013 13:27:22 +0000 Subject: [PATCH 0247/1195] Fix IsDevToolsOpened when devtools is attched to pane on Linux. --- .../browser/linux/inspectable_web_contents_view_linux.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index 54f54cadabe..365a053e770 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -167,7 +167,10 @@ void InspectableWebContentsViewLinux::CloseDevTools() { } bool InspectableWebContentsViewLinux::IsDevToolsOpened() { - return devtools_window_ && IsWidgetAncestryVisible(devtools_window_); + auto devtools_web_contents = + inspectable_web_contents()->devtools_web_contents(); + GtkWidget* devtools = devtools_web_contents->GetView()->GetNativeView(); + return IsWidgetAncestryVisible(devtools); } bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { From b080e5c52d6c068d58315793794b9831b74e7c69 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 9 Dec 2013 04:34:44 -0800 Subject: [PATCH 0248/1195] Rename IsDevToolsOpened to IsDevToolsViewShowing. --- brightray/browser/inspectable_web_contents.h | 2 +- brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- brightray/browser/inspectable_web_contents_impl.h | 2 +- brightray/browser/inspectable_web_contents_view.h | 2 +- brightray/browser/inspectable_web_contents_view_mac.h | 2 +- brightray/browser/inspectable_web_contents_view_mac.mm | 2 +- .../browser/linux/inspectable_web_contents_view_linux.cc | 2 +- brightray/browser/linux/inspectable_web_contents_view_linux.h | 2 +- brightray/browser/win/inspectable_web_contents_view_win.cc | 2 +- brightray/browser/win/inspectable_web_contents_view_win.h | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 04ba87bf0df..49a50bc5079 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -22,7 +22,7 @@ class InspectableWebContents { virtual content::WebContents* GetWebContents() const = 0; virtual void ShowDevTools() = 0; - virtual bool IsDevToolsOpened() = 0; + virtual bool IsDevToolsViewShowing() = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 0b194e70e61..e972e568735 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -96,8 +96,8 @@ void InspectableWebContentsImpl::ShowDevTools() { view_->ShowDevTools(); } -bool InspectableWebContentsImpl::IsDevToolsOpened() { - return devtools_web_contents_ && view_->IsDevToolsOpened(); +bool InspectableWebContentsImpl::IsDevToolsViewShowing() { + return devtools_web_contents_ && view_->IsDevToolsViewShowing(); } void InspectableWebContentsImpl::UpdateFrontendDockSide() { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index f0a55f5dac5..53023204dd1 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -41,7 +41,7 @@ class InspectableWebContentsImpl : virtual content::WebContents* GetWebContents() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; - virtual bool IsDevToolsOpened() OVERRIDE; + virtual bool IsDevToolsViewShowing() OVERRIDE; content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index ff71bac783b..87274805f8e 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -13,7 +13,7 @@ class InspectableWebContentsView { virtual void ShowDevTools() = 0; virtual void CloseDevTools() = 0; - virtual bool IsDevToolsOpened() = 0; + virtual bool IsDevToolsViewShowing() = 0; virtual bool SetDockSide(const std::string& side) = 0; }; diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 4390db290f8..86cc7822178 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -19,7 +19,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; - virtual bool IsDevToolsOpened() OVERRIDE; + virtual bool IsDevToolsViewShowing() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index adde9b05033..95ed74f2dbd 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -29,7 +29,7 @@ void InspectableWebContentsViewMac::CloseDevTools() { [view_ setDevToolsVisible:NO]; } -bool InspectableWebContentsViewMac::IsDevToolsOpened() { +bool InspectableWebContentsViewMac::IsDevToolsViewShowing() { return [view_ isDevToolsVisible]; } diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index 365a053e770..58d7507fb43 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -166,7 +166,7 @@ void InspectableWebContentsViewLinux::CloseDevTools() { } } -bool InspectableWebContentsViewLinux::IsDevToolsOpened() { +bool InspectableWebContentsViewLinux::IsDevToolsViewShowing() { auto devtools_web_contents = inspectable_web_contents()->devtools_web_contents(); GtkWidget* devtools = devtools_web_contents->GetView()->GetNativeView(); diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/linux/inspectable_web_contents_view_linux.h index 79ab6f731d5..0a802239005 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.h +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.h @@ -18,7 +18,7 @@ class InspectableWebContentsViewLinux : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; - virtual bool IsDevToolsOpened() OVERRIDE; + virtual bool IsDevToolsViewShowing() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index d1530d1cee9..dca7ba4f3eb 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -57,7 +57,7 @@ void InspectableWebContentsViewWin::CloseDevTools() { SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); } -bool InspectableWebContentsViewWin::IsDevToolsOpened() { +bool InspectableWebContentsViewWin::IsDevToolsViewShowing() { return devtools_window_; } diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index f79ce30bf3d..55b09b2d3e4 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -20,7 +20,7 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; - virtual bool IsDevToolsOpened() OVERRIDE; + virtual bool IsDevToolsViewShowing() OVERRIDE; virtual bool SetDockSide(const std::string& side) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { From 1a09de095671257f7ee69e161452e525bea7ebd3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Dec 2013 23:54:46 -0800 Subject: [PATCH 0249/1195] The 'ARCHS' key should be an array. The ninja generator only supports setting the 'ARCHS' key as array, and ninja does not support '$(ARCHS_STANDARD_64_BIT)' too. The 'x86_64' is accepted by both ninja and xcodebuild, and is also used by node. --- brightray/brightray.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 226524620ad..e2deae347a8 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -31,7 +31,7 @@ 'target_defaults': { 'xcode_settings': { 'ALWAYS_SEARCH_USER_PATHS': 'NO', - 'ARCHS': '$(ARCHS_STANDARD_64_BIT)', + 'ARCHS': ['x86_64'], 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11', 'CLANG_CXX_LIBRARY': 'libstdc++', 'COMBINE_HIDPI_IMAGES': 'YES', From 39f5f52423bdac75eb0bdc609f49b8b4ede4132b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Dec 2013 17:26:04 +0800 Subject: [PATCH 0250/1195] Fix flash of page while resizing devtools NSSplitView divider. --- .../mac/bry_inspectable_web_contents_view.h | 3 +- .../mac/bry_inspectable_web_contents_view.mm | 37 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 87abc98c354..49eff626321 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -2,7 +2,8 @@ @class BRYInspectableWebContentsViewPrivate; -@interface BRYInspectableWebContentsView : NSView { +@interface BRYInspectableWebContentsView + : NSView { @private BRYInspectableWebContentsViewPrivate *_private; } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 24987e5c1c5..d4d8b374b06 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -10,10 +10,34 @@ using namespace brightray; +@interface GraySplitView : NSSplitView { + BOOL dividerHidden_; +} +@property(assign, nonatomic) BOOL dividerHidden; +- (NSColor*)dividerColor; +- (CGFloat)dividerThickness; +@end + + +@implementation GraySplitView + +@synthesize dividerHidden = dividerHidden_; + +- (NSColor*)dividerColor { + return [NSColor darkGrayColor]; +} + +- (CGFloat)dividerThickness { + return dividerHidden_ ? 0 : [super dividerThickness]; +} + +@end + + @interface BRYInspectableWebContentsViewPrivate : NSObject { @public InspectableWebContentsViewMac *inspectableWebContentsView; - NSSplitView *splitView; + GraySplitView *splitView; NSWindow *window; BOOL visible; } @@ -45,7 +69,8 @@ void SetActive(content::WebContents* web_contents, bool active) { _private = [[BRYInspectableWebContentsViewPrivate alloc] init]; _private->inspectableWebContentsView = inspectableWebContentsView; - _private->splitView = [[NSSplitView alloc] init]; + _private->splitView = [[GraySplitView alloc] init]; + _private->splitView.delegate = self; [self addSubview:_private->splitView]; _private->splitView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; @@ -203,6 +228,12 @@ void SetActive(content::WebContents* web_contents, bool active) { [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:newWindow]; } +#pragma mark - NSSplitViewDelegate + +-(void)splitViewWillResizeSubviews:(NSNotification *)notification { + [[_private->splitView window] disableScreenUpdatesUntilFlush]; +} + #pragma mark - NSWindowDelegate - (BOOL)windowShouldClose:(id)sender { @@ -221,4 +252,4 @@ void SetActive(content::WebContents* web_contents, bool active) { @end @implementation BRYInspectableWebContentsViewPrivate -@end \ No newline at end of file +@end From e0b8935fda87460a66fadd9deab218c3cbb3b62b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Dec 2013 23:33:50 +0800 Subject: [PATCH 0251/1195] Remove the unused dividerHidden property of GraySplitView. --- .../mac/bry_inspectable_web_contents_view.mm | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index d4d8b374b06..72e0a851c53 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -10,27 +10,14 @@ using namespace brightray; -@interface GraySplitView : NSSplitView { - BOOL dividerHidden_; -} -@property(assign, nonatomic) BOOL dividerHidden; +@interface GraySplitView : NSSplitView - (NSColor*)dividerColor; -- (CGFloat)dividerThickness; @end - @implementation GraySplitView - -@synthesize dividerHidden = dividerHidden_; - - (NSColor*)dividerColor { return [NSColor darkGrayColor]; } - -- (CGFloat)dividerThickness { - return dividerHidden_ ? 0 : [super dividerThickness]; -} - @end From b1dc139e4bcf912f1f448a42d2d5e3e42fc0fc1d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 15 Dec 2013 15:00:52 +0800 Subject: [PATCH 0252/1195] Set the proxy service a bit earlier to avoid crash. --- .../browser/url_request_context_getter.cc | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index e1df64c23fe..b5596b8e05a 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -86,6 +86,16 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { scoped_ptr host_resolver( net::HostResolver::CreateDefaultResolver(NULL)); + net::DhcpProxyScriptFetcherFactory dhcp_factory; + storage_->set_proxy_service( + net::CreateProxyServiceUsingV8ProxyResolver( + proxy_config_service_.release(), + new net::ProxyScriptFetcherImpl(url_request_context_.get()), + dhcp_factory.Create(url_request_context_.get()), + host_resolver.get(), + NULL, + url_request_context_->network_delegate())); + storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); storage_->set_http_auth_handler_factory( @@ -126,16 +136,6 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.host_resolver = url_request_context_->host_resolver(); - net::DhcpProxyScriptFetcherFactory dhcp_factory; - storage_->set_proxy_service( - net::CreateProxyServiceUsingV8ProxyResolver( - proxy_config_service_.release(), - new net::ProxyScriptFetcherImpl(url_request_context_.get()), - dhcp_factory.Create(url_request_context_.get()), - url_request_context_->host_resolver(), - NULL, - url_request_context_->network_delegate())); - net::HttpCache* main_cache = new net::HttpCache( network_session_params, main_backend); storage_->set_http_transaction_factory(main_cache); From a82e9f30ed9041d90eb4bf38cadebf6d0c48a652 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Wed, 18 Dec 2013 15:02:49 -0600 Subject: [PATCH 0253/1195] use libnotify to pop up notifications on Linux --- brightray/brightray.gyp | 4 +- brightray/browser/browser_client.cc | 2 +- .../linux/notification_presenter_linux.cc | 125 ++++++++++++++++++ .../linux/notification_presenter_linux.h | 36 +++++ 4 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 brightray/browser/linux/notification_presenter_linux.cc create mode 100644 brightray/browser/linux/notification_presenter_linux.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 1781172b970..a4baef81f6f 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -64,6 +64,8 @@ 'browser/notification_presenter.h', 'browser/notification_presenter_mac.h', 'browser/notification_presenter_mac.mm', + 'browser/linux/notification_presenter_linux.h', + 'browser/linux/notification_presenter_linux.cc', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', 'browser/win/devtools_window.cc', @@ -93,7 +95,7 @@ 'libraries': [ '<(brightray_source_root)/<(libchromiumcontent_library_dir)/libchromiumcontent.so', '-lpthread', - '. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/linux/notification_presenter_linux.h" + +#include "base/strings/stringprintf.h" +#include "base/strings/utf_string_conversions.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/common/show_desktop_notification_params.h" +#include "common/application_info.h" + +#include + +namespace brightray { + +namespace { + +struct NotificationID { + NotificationID( + int render_process_id, + int render_view_id, + int notification_id) + : render_process_id(render_process_id), + render_view_id(render_view_id), + notification_id(notification_id) { + } + + std::string GetID() { + return base::StringPrintf("%d:%d:%d", render_process_id, render_view_id, notification_id); + } + + int render_process_id; + int render_view_id; + int notification_id; +}; + +void log_and_clear_error(GError *error, const char *context) { + if (error) { + LOG(ERROR) << context << ": domain=" << error->domain << " code=" << error->code << " message=\"" << error->message << "\""; + g_error_free(error); + } +} + +void closed_cb(NotifyNotification *notification, NotificationID *ID) { + auto host = content::RenderViewHost::FromID(ID->render_process_id, ID->render_view_id); + if (host) host->DesktopNotificationPostClick(ID->notification_id); +} + +NotifyNotification *CreateUserNotification( + const content::ShowDesktopNotificationHostMsgParams& params, + int render_process_id, + int render_view_id) { + std::string title = base::UTF16ToUTF8(params.title); + std::string body = base::UTF16ToUTF8(params.body); + NotifyNotification *notification = notify_notification_new(title.c_str(), body.c_str(), NULL); + + return notification; +} + +} + +NotificationPresenter* NotificationPresenter::Create() { + if (!notify_is_initted()) { + notify_init(GetApplicationName().c_str()); + } + return new NotificationPresenterLinux; +} + +void NotificationPresenterLinux::ShowNotification( + const content::ShowDesktopNotificationHostMsgParams& params, + int render_process_id, + int render_view_id) { + DLOG(INFO) << "ShowNotification: process=" << render_process_id + << " view=" << render_view_id + << " notification=" << params.notification_id + << " title=\"" << params.title << '"' + << " body=\"" << params.body << '"'; + NotifyNotification *notification = CreateUserNotification(params, render_process_id, render_view_id); + NotificationID ID(render_process_id, render_view_id, params.notification_id); + std::pair p = notification_map_.insert(std::make_pair(ID.GetID(), notification)); + + g_signal_connect(notification, "closed", G_CALLBACK(closed_cb), new NotificationID(ID)); // FIXME: closure to free it + + GError *error = NULL; + notify_notification_show(notification, &error); + log_and_clear_error(error, "notify_notification_show"); + + auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id); + if (!host) + return; + + host->DesktopNotificationPostDisplay(ID.notification_id); +} + +void NotificationPresenterLinux::CancelNotification( + int render_process_id, + int render_view_id, + int notification_id) { + DLOG(INFO) << "CancelNotification: process=" << render_process_id + << " view=" << render_view_id + << " notification=" << notification_id; + + auto found = notification_map_.find(NotificationID(render_process_id, render_view_id, notification_id).GetID()); + if (found == notification_map_.end()) + return; + + auto notification = found->second; + + notification_map_.erase(found); + + GError *error = NULL; + notify_notification_close(notification, &error); + log_and_clear_error(error, "notify_notification_close"); + + NotificationID ID(render_process_id, render_view_id, notification_id); + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); + if (!host) + return; + + host->DesktopNotificationPostClose(ID.notification_id, false); +} + +} diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h new file mode 100644 index 00000000000..b3d77dc63e6 --- /dev/null +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -0,0 +1,36 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Patrick Reynolds . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_LINUX_H_ +#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_LINUX_H_ + +#include "base/compiler_specific.h" +#include "browser/notification_presenter.h" + +#include + +#include + +namespace brightray { + +class NotificationPresenterLinux : public NotificationPresenter { + public: + virtual void ShowNotification( + const content::ShowDesktopNotificationHostMsgParams&, + int render_process_id, + int render_view_id) OVERRIDE; + virtual void CancelNotification( + int render_process_id, + int render_view_id, + int notification_id) OVERRIDE; + + private: + typedef std::map NotificationMap; + NotificationMap notification_map_; +}; + +} // namespace brightray + +#endif From 272b3c30d3258db597eb66d262e18155b916df8f Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Wed, 18 Dec 2013 23:05:19 -0600 Subject: [PATCH 0254/1195] free notifications properly --- .../linux/notification_presenter_linux.cc | 124 ++++++++++-------- .../linux/notification_presenter_linux.h | 8 +- 2 files changed, 78 insertions(+), 54 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 56746bbf162..6848ce5111c 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -17,24 +17,9 @@ namespace brightray { namespace { -struct NotificationID { - NotificationID( - int render_process_id, - int render_view_id, - int notification_id) - : render_process_id(render_process_id), - render_view_id(render_view_id), - notification_id(notification_id) { - } - - std::string GetID() { - return base::StringPrintf("%d:%d:%d", render_process_id, render_view_id, notification_id); - } - - int render_process_id; - int render_view_id; - int notification_id; -}; +const char *kRenderProcessIDKey = "RenderProcessID"; +const char *kRenderViewIDKey = "RenderViewID"; +const char *kNotificationIDKey = "NotificationID"; void log_and_clear_error(GError *error, const char *context) { if (error) { @@ -43,20 +28,28 @@ void log_and_clear_error(GError *error, const char *context) { } } -void closed_cb(NotifyNotification *notification, NotificationID *ID) { - auto host = content::RenderViewHost::FromID(ID->render_process_id, ID->render_view_id); - if (host) host->DesktopNotificationPostClick(ID->notification_id); +void closed_cb(NotifyNotification *notification, NotificationPresenterLinux *obj) { + int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); + int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); + int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); + LOG(INFO) << "closed_cb: process=" << render_process_id + << " view=" << render_view_id + << " notification=" << notification_id + << " reason=" << notify_notification_get_closed_reason(notification); + obj->RemoveNotification(notification); } -NotifyNotification *CreateUserNotification( - const content::ShowDesktopNotificationHostMsgParams& params, - int render_process_id, - int render_view_id) { - std::string title = base::UTF16ToUTF8(params.title); - std::string body = base::UTF16ToUTF8(params.body); - NotifyNotification *notification = notify_notification_new(title.c_str(), body.c_str(), NULL); - - return notification; +void action_cb(NotifyNotification *notification, const char *action, NotificationPresenterLinux *obj) { + int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); + int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); + int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); + LOG(INFO) << "action_cb: process=" << render_process_id + << " view=" << render_view_id + << " notification=" << notification_id + << " action=\"" << action << '"'; + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); + if (host) host->DesktopNotificationPostClick(notification_id); + obj->RemoveNotification(notification); } } @@ -68,58 +61,85 @@ NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterLinux; } +NotificationPresenterLinux::NotificationPresenterLinux() : notifications_(NULL) { } + +NotificationPresenterLinux::~NotificationPresenterLinux() { + if (notifications_) { + for (GList *p = notifications_; p != NULL; p = p->next) { + g_object_unref(G_OBJECT(p->data)); + } + g_list_free(notifications_); + } +} + void NotificationPresenterLinux::ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, int render_process_id, int render_view_id) { - DLOG(INFO) << "ShowNotification: process=" << render_process_id - << " view=" << render_view_id - << " notification=" << params.notification_id - << " title=\"" << params.title << '"' - << " body=\"" << params.body << '"'; - NotifyNotification *notification = CreateUserNotification(params, render_process_id, render_view_id); - NotificationID ID(render_process_id, render_view_id, params.notification_id); - std::pair p = notification_map_.insert(std::make_pair(ID.GetID(), notification)); + LOG(INFO) << "ShowNotification: process=" << render_process_id + << " view=" << render_view_id + << " notification=" << params.notification_id + << " title=\"" << params.title << '"' + << " body=\"" << params.body << '"'; - g_signal_connect(notification, "closed", G_CALLBACK(closed_cb), new NotificationID(ID)); // FIXME: closure to free it + std::string title = base::UTF16ToUTF8(params.title); + std::string body = base::UTF16ToUTF8(params.body); + NotifyNotification *notification = notify_notification_new(title.c_str(), body.c_str(), NULL); + g_object_set_data(G_OBJECT(notification), kRenderProcessIDKey, GINT_TO_POINTER(render_process_id)); + g_object_set_data(G_OBJECT(notification), kRenderViewIDKey, GINT_TO_POINTER(render_view_id)); + g_object_set_data(G_OBJECT(notification), kNotificationIDKey, GINT_TO_POINTER(params.notification_id)); + g_signal_connect(notification, "closed", G_CALLBACK(closed_cb), this); + notify_notification_add_action(notification, "default", "View", (NotifyActionCallback)action_cb, this, NULL); + + notifications_ = g_list_append(notifications_, notification); GError *error = NULL; notify_notification_show(notification, &error); log_and_clear_error(error, "notify_notification_show"); - auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id); + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (!host) return; - host->DesktopNotificationPostDisplay(ID.notification_id); + host->DesktopNotificationPostDisplay(params.notification_id); } void NotificationPresenterLinux::CancelNotification( int render_process_id, int render_view_id, int notification_id) { - DLOG(INFO) << "CancelNotification: process=" << render_process_id - << " view=" << render_view_id - << " notification=" << notification_id; + LOG(INFO) << "CancelNotification: process=" << render_process_id + << " view=" << render_view_id + << " notification=" << notification_id; - auto found = notification_map_.find(NotificationID(render_process_id, render_view_id, notification_id).GetID()); - if (found == notification_map_.end()) + NotifyNotification *notification = NULL; + for (GList *p = notifications_; p != NULL; p = p->next) { + if (render_process_id == GPOINTER_TO_INT(g_object_get_data(G_OBJECT(p->data), kRenderProcessIDKey)) + && render_view_id == GPOINTER_TO_INT(g_object_get_data(G_OBJECT(p->data), kRenderViewIDKey)) + && notification_id == GPOINTER_TO_INT(g_object_get_data(G_OBJECT(p->data), kNotificationIDKey))) { + notification = (NotifyNotification*)p->data; + notifications_ = g_list_delete_link(notifications_, p); + break; + } + } + if (!notification) return; - auto notification = found->second; - - notification_map_.erase(found); - GError *error = NULL; notify_notification_close(notification, &error); log_and_clear_error(error, "notify_notification_close"); + g_object_unref(notification); - NotificationID ID(render_process_id, render_view_id, notification_id); auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (!host) return; - host->DesktopNotificationPostClose(ID.notification_id, false); + host->DesktopNotificationPostClose(notification_id, false); +} + +void NotificationPresenterLinux::RemoveNotification(NotifyNotification *former_notification) { + notifications_ = g_list_remove(notifications_, former_notification); + g_object_unref(former_notification); } } diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index b3d77dc63e6..4b6344cfbe7 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -17,6 +17,9 @@ namespace brightray { class NotificationPresenterLinux : public NotificationPresenter { public: + NotificationPresenterLinux(); + ~NotificationPresenterLinux(); + virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams&, int render_process_id, @@ -26,9 +29,10 @@ class NotificationPresenterLinux : public NotificationPresenter { int render_view_id, int notification_id) OVERRIDE; + void RemoveNotification(NotifyNotification *former_notification); + private: - typedef std::map NotificationMap; - NotificationMap notification_map_; + GList *notifications_; }; } // namespace brightray From 04d5ed25d82481a7d7a11092aeb289e68915644d Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Wed, 18 Dec 2013 23:13:33 -0600 Subject: [PATCH 0255/1195] call PostClose when notification closed by click --- brightray/browser/linux/notification_presenter_linux.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 6848ce5111c..f4be61af006 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -32,6 +32,8 @@ void closed_cb(NotifyNotification *notification, NotificationPresenterLinux *obj int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); + if (host) host->DesktopNotificationPostClose(notification_id, false); LOG(INFO) << "closed_cb: process=" << render_process_id << " view=" << render_view_id << " notification=" << notification_id From c6424672f572ff644082b08edf86f8d87503ec34 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Wed, 18 Dec 2013 23:14:08 -0600 Subject: [PATCH 0256/1195] comments and cleanup --- .../linux/notification_presenter_linux.cc | 37 ++++++------------- .../linux/notification_presenter_linux.h | 9 ++++- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index f4be61af006..4081b2bd54e 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -28,27 +28,21 @@ void log_and_clear_error(GError *error, const char *context) { } } -void closed_cb(NotifyNotification *notification, NotificationPresenterLinux *obj) { +void NotificationClosedCallback(NotifyNotification *notification, NotificationPresenterLinux *obj) { int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (host) host->DesktopNotificationPostClose(notification_id, false); - LOG(INFO) << "closed_cb: process=" << render_process_id - << " view=" << render_view_id - << " notification=" << notification_id - << " reason=" << notify_notification_get_closed_reason(notification); obj->RemoveNotification(notification); } -void action_cb(NotifyNotification *notification, const char *action, NotificationPresenterLinux *obj) { +void NotificationViewCallback(NotifyNotification *notification, const char *action, NotificationPresenterLinux *obj) { int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); - LOG(INFO) << "action_cb: process=" << render_process_id - << " view=" << render_view_id - << " notification=" << notification_id - << " action=\"" << action << '"'; + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (host) host->DesktopNotificationPostClick(notification_id); obj->RemoveNotification(notification); @@ -66,6 +60,7 @@ NotificationPresenter* NotificationPresenter::Create() { NotificationPresenterLinux::NotificationPresenterLinux() : notifications_(NULL) { } NotificationPresenterLinux::~NotificationPresenterLinux() { + // unref any outstanding notifications, and then free the list. if (notifications_) { for (GList *p = notifications_; p != NULL; p = p->next) { g_object_unref(G_OBJECT(p->data)); @@ -78,20 +73,16 @@ void NotificationPresenterLinux::ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, int render_process_id, int render_view_id) { - LOG(INFO) << "ShowNotification: process=" << render_process_id - << " view=" << render_view_id - << " notification=" << params.notification_id - << " title=\"" << params.title << '"' - << " body=\"" << params.body << '"'; - std::string title = base::UTF16ToUTF8(params.title); std::string body = base::UTF16ToUTF8(params.body); NotifyNotification *notification = notify_notification_new(title.c_str(), body.c_str(), NULL); g_object_set_data(G_OBJECT(notification), kRenderProcessIDKey, GINT_TO_POINTER(render_process_id)); g_object_set_data(G_OBJECT(notification), kRenderViewIDKey, GINT_TO_POINTER(render_view_id)); g_object_set_data(G_OBJECT(notification), kNotificationIDKey, GINT_TO_POINTER(params.notification_id)); - g_signal_connect(notification, "closed", G_CALLBACK(closed_cb), this); - notify_notification_add_action(notification, "default", "View", (NotifyActionCallback)action_cb, this, NULL); + g_signal_connect(notification, "closed", + G_CALLBACK(NotificationClosedCallback), this); + notify_notification_add_action(notification, "default", "View", + (NotifyActionCallback)NotificationViewCallback, this, NULL); notifications_ = g_list_append(notifications_, notification); @@ -110,10 +101,6 @@ void NotificationPresenterLinux::CancelNotification( int render_process_id, int render_view_id, int notification_id) { - LOG(INFO) << "CancelNotification: process=" << render_process_id - << " view=" << render_view_id - << " notification=" << notification_id; - NotifyNotification *notification = NULL; for (GList *p = notifications_; p != NULL; p = p->next) { if (render_process_id == GPOINTER_TO_INT(g_object_get_data(G_OBJECT(p->data), kRenderProcessIDKey)) @@ -139,9 +126,9 @@ void NotificationPresenterLinux::CancelNotification( host->DesktopNotificationPostClose(notification_id, false); } -void NotificationPresenterLinux::RemoveNotification(NotifyNotification *former_notification) { - notifications_ = g_list_remove(notifications_, former_notification); - g_object_unref(former_notification); +void NotificationPresenterLinux::RemoveNotification(NotifyNotification *notification) { + notifications_ = g_list_remove(notifications_, notification); + g_object_unref(notification); } } diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index 4b6344cfbe7..4433147c93a 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -29,9 +29,16 @@ class NotificationPresenterLinux : public NotificationPresenter { int render_view_id, int notification_id) OVERRIDE; - void RemoveNotification(NotifyNotification *former_notification); + void RemoveNotification(NotifyNotification *notification); private: + // A list of all open NotifyNotification objects. + // We do lookups here both by NotifyNotification object (when the user + // clicks a notification) and by the ID + // tuple (when the browser asks to dismiss a notification). So it's not + // a map. + // Entries in this list count as refs, so removal from this list should + // always go with g_object_unref(). GList *notifications_; }; From ef6d5dbf4e46debcc0b8ba088d25916e2e98a12f Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Wed, 18 Dec 2013 23:20:00 -0600 Subject: [PATCH 0257/1195] authorship --- brightray/browser/linux/notification_presenter_linux.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 4081b2bd54e..be1d2bc9eb4 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -1,5 +1,5 @@ // Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2013 Adam Roben . All rights reserved. +// Copyright (c) 2013 Patrick Reynolds . All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. From de07839bb6261c71b560d0a5ce1b6ba427c73675 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 19 Dec 2013 09:08:21 -0500 Subject: [PATCH 0258/1195] Update to latest libchromiumcontent * vendor/libchromiumcontent ee2e80a...2cd1a60 (1): > Merge pull request #35 from brightray/content-test-suite --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index ee2e80aa49f..2cd1a60b38b 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit ee2e80aa49f917edfb7a72ace71d513af4731b62 +Subproject commit 2cd1a60b38babd5ec13884905422778f390a9bc0 From 4e31c0011d150d186d5eafad56d267fd2a595535 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Thu, 19 Dec 2013 13:06:05 -0600 Subject: [PATCH 0259/1195] keep cpplint happy, mostly about line length --- .../linux/notification_presenter_linux.cc | 81 ++++++++++++------- .../linux/notification_presenter_linux.h | 7 +- 2 files changed, 57 insertions(+), 31 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index be1d2bc9eb4..3796ab8dd30 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -3,6 +3,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. +#include + #include "browser/linux/notification_presenter_linux.h" #include "base/strings/stringprintf.h" @@ -11,8 +13,6 @@ #include "content/public/common/show_desktop_notification_params.h" #include "common/application_info.h" -#include - namespace brightray { namespace { @@ -23,32 +23,45 @@ const char *kNotificationIDKey = "NotificationID"; void log_and_clear_error(GError *error, const char *context) { if (error) { - LOG(ERROR) << context << ": domain=" << error->domain << " code=" << error->code << " message=\"" << error->message << "\""; + LOG(ERROR) << context + << ": domain=" << error->domain + << " code=" << error->code + << " message=\"" << error->message << '"'; g_error_free(error); } } -void NotificationClosedCallback(NotifyNotification *notification, NotificationPresenterLinux *obj) { - int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); - int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); - int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); +void NotificationClosedCallback(NotifyNotification *notification, + NotificationPresenterLinux *obj) { + int render_process_id = GPOINTER_TO_INT( + g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); + int render_view_id = GPOINTER_TO_INT( + g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); + int notification_id = GPOINTER_TO_INT( + g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); - auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); + auto host = + content::RenderViewHost::FromID(render_process_id, render_view_id); if (host) host->DesktopNotificationPostClose(notification_id, false); obj->RemoveNotification(notification); } -void NotificationViewCallback(NotifyNotification *notification, const char *action, NotificationPresenterLinux *obj) { - int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); - int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); - int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); +void NotificationViewCallback(NotifyNotification *notification, + const char *action, NotificationPresenterLinux *obj) { + int render_process_id = GPOINTER_TO_INT( + g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); + int render_view_id = GPOINTER_TO_INT( + g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); + int notification_id = GPOINTER_TO_INT( + g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); - auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); + auto host = + content::RenderViewHost::FromID(render_process_id, render_view_id); if (host) host->DesktopNotificationPostClick(notification_id); obj->RemoveNotification(notification); } -} +} // namespace NotificationPresenter* NotificationPresenter::Create() { if (!notify_is_initted()) { @@ -57,7 +70,8 @@ NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterLinux; } -NotificationPresenterLinux::NotificationPresenterLinux() : notifications_(NULL) { } +NotificationPresenterLinux::NotificationPresenterLinux() + : notifications_(NULL) { } NotificationPresenterLinux::~NotificationPresenterLinux() { // unref any outstanding notifications, and then free the list. @@ -75,10 +89,14 @@ void NotificationPresenterLinux::ShowNotification( int render_view_id) { std::string title = base::UTF16ToUTF8(params.title); std::string body = base::UTF16ToUTF8(params.body); - NotifyNotification *notification = notify_notification_new(title.c_str(), body.c_str(), NULL); - g_object_set_data(G_OBJECT(notification), kRenderProcessIDKey, GINT_TO_POINTER(render_process_id)); - g_object_set_data(G_OBJECT(notification), kRenderViewIDKey, GINT_TO_POINTER(render_view_id)); - g_object_set_data(G_OBJECT(notification), kNotificationIDKey, GINT_TO_POINTER(params.notification_id)); + NotifyNotification *notification = + notify_notification_new(title.c_str(), body.c_str(), NULL); + g_object_set_data(G_OBJECT(notification), + kRenderProcessIDKey, GINT_TO_POINTER(render_process_id)); + g_object_set_data(G_OBJECT(notification), + kRenderViewIDKey, GINT_TO_POINTER(render_view_id)); + g_object_set_data(G_OBJECT(notification), + kNotificationIDKey, GINT_TO_POINTER(params.notification_id)); g_signal_connect(notification, "closed", G_CALLBACK(NotificationClosedCallback), this); notify_notification_add_action(notification, "default", "View", @@ -90,7 +108,8 @@ void NotificationPresenterLinux::ShowNotification( notify_notification_show(notification, &error); log_and_clear_error(error, "notify_notification_show"); - auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); + auto host = + content::RenderViewHost::FromID(render_process_id, render_view_id); if (!host) return; @@ -103,10 +122,16 @@ void NotificationPresenterLinux::CancelNotification( int notification_id) { NotifyNotification *notification = NULL; for (GList *p = notifications_; p != NULL; p = p->next) { - if (render_process_id == GPOINTER_TO_INT(g_object_get_data(G_OBJECT(p->data), kRenderProcessIDKey)) - && render_view_id == GPOINTER_TO_INT(g_object_get_data(G_OBJECT(p->data), kRenderViewIDKey)) - && notification_id == GPOINTER_TO_INT(g_object_get_data(G_OBJECT(p->data), kNotificationIDKey))) { - notification = (NotifyNotification*)p->data; + int obj_render_process_id = GPOINTER_TO_INT( + g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); + int obj_render_view_id = GPOINTER_TO_INT( + g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); + int obj_notification_id = GPOINTER_TO_INT( + g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); + if (render_process_id == obj_render_process_id + && render_view_id == obj_render_view_id + && notification_id == obj_notification_id) { + notification = reinterpret_cast(p->data); notifications_ = g_list_delete_link(notifications_, p); break; } @@ -119,16 +144,18 @@ void NotificationPresenterLinux::CancelNotification( log_and_clear_error(error, "notify_notification_close"); g_object_unref(notification); - auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); + auto host = + content::RenderViewHost::FromID(render_process_id, render_view_id); if (!host) return; host->DesktopNotificationPostClose(notification_id, false); } -void NotificationPresenterLinux::RemoveNotification(NotifyNotification *notification) { +void NotificationPresenterLinux::RemoveNotification( + NotifyNotification *notification) { notifications_ = g_list_remove(notifications_, notification); g_object_unref(notification); } -} +} // namespace brightray diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index 4433147c93a..0f52fd55fdd 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -6,13 +6,12 @@ #ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_LINUX_H_ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_LINUX_H_ +#include +#include + #include "base/compiler_specific.h" #include "browser/notification_presenter.h" -#include - -#include - namespace brightray { class NotificationPresenterLinux : public NotificationPresenter { From 46ec999b139f9d535fb20f7658cdff166506e754 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Thu, 19 Dec 2013 13:19:12 -0600 Subject: [PATCH 0260/1195] allow 100-character lines --- brightray/script/cpplint | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/script/cpplint b/brightray/script/cpplint index 69b7aaff9a0..58a6a5e0b5c 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -8,6 +8,7 @@ import sys SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'google-styleguide', 'trunk', 'cpplint', 'cpplint.py') +LINE_LENGTH = 100 IGNORED_FILES = [ os.path.join('browser', 'mac', 'bry_inspectable_web_contents_view_private.h'), @@ -40,7 +41,7 @@ def list_files(directories, filters): def cpplint(files): - return subprocess.call([sys.executable, CPPLINT, '--filter=' + ','.join(FILTERS)] + list(files)) + return subprocess.call([sys.executable, CPPLINT, '--linelength=%d' % LINE_LENGTH, '--filter=' + ','.join(FILTERS)] + list(files)) if __name__ == '__main__': From 8d2b392f07b1f467d0d9f3fee0fa6fc7685e6805 Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Thu, 19 Dec 2013 13:39:37 -0600 Subject: [PATCH 0261/1195] undo some ugly line wrapping --- .../linux/notification_presenter_linux.cc | 94 +++++++------------ 1 file changed, 36 insertions(+), 58 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 3796ab8dd30..3544dbc4bed 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -31,34 +31,25 @@ void log_and_clear_error(GError *error, const char *context) { } } -void NotificationClosedCallback(NotifyNotification *notification, - NotificationPresenterLinux *obj) { - int render_process_id = GPOINTER_TO_INT( - g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); - int render_view_id = GPOINTER_TO_INT( - g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); - int notification_id = GPOINTER_TO_INT( - g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); +void NotificationClosedCallback(NotifyNotification *noti, NotificationPresenterLinux *obj) { + int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderProcessIDKey)); + int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderViewIDKey)); + int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kNotificationIDKey)); - auto host = - content::RenderViewHost::FromID(render_process_id, render_view_id); + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (host) host->DesktopNotificationPostClose(notification_id, false); - obj->RemoveNotification(notification); + obj->RemoveNotification(noti); } -void NotificationViewCallback(NotifyNotification *notification, - const char *action, NotificationPresenterLinux *obj) { - int render_process_id = GPOINTER_TO_INT( - g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); - int render_view_id = GPOINTER_TO_INT( - g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); - int notification_id = GPOINTER_TO_INT( - g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); +void NotificationViewCallback(NotifyNotification *noti, const char *action, + NotificationPresenterLinux *obj) { + int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderProcessIDKey)); + int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderViewIDKey)); + int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kNotificationIDKey)); - auto host = - content::RenderViewHost::FromID(render_process_id, render_view_id); + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (host) host->DesktopNotificationPostClick(notification_id); - obj->RemoveNotification(notification); + obj->RemoveNotification(noti); } } // namespace @@ -70,8 +61,7 @@ NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterLinux; } -NotificationPresenterLinux::NotificationPresenterLinux() - : notifications_(NULL) { } +NotificationPresenterLinux::NotificationPresenterLinux() : notifications_(NULL) { } NotificationPresenterLinux::~NotificationPresenterLinux() { // unref any outstanding notifications, and then free the list. @@ -89,27 +79,22 @@ void NotificationPresenterLinux::ShowNotification( int render_view_id) { std::string title = base::UTF16ToUTF8(params.title); std::string body = base::UTF16ToUTF8(params.body); - NotifyNotification *notification = - notify_notification_new(title.c_str(), body.c_str(), NULL); - g_object_set_data(G_OBJECT(notification), - kRenderProcessIDKey, GINT_TO_POINTER(render_process_id)); - g_object_set_data(G_OBJECT(notification), - kRenderViewIDKey, GINT_TO_POINTER(render_view_id)); - g_object_set_data(G_OBJECT(notification), - kNotificationIDKey, GINT_TO_POINTER(params.notification_id)); - g_signal_connect(notification, "closed", + NotifyNotification *noti = notify_notification_new(title.c_str(), body.c_str(), NULL); + g_object_set_data(G_OBJECT(noti), kRenderProcessIDKey, GINT_TO_POINTER(render_process_id)); + g_object_set_data(G_OBJECT(noti), kRenderViewIDKey, GINT_TO_POINTER(render_view_id)); + g_object_set_data(G_OBJECT(noti), kNotificationIDKey, GINT_TO_POINTER(params.notification_id)); + g_signal_connect(noti, "closed", G_CALLBACK(NotificationClosedCallback), this); - notify_notification_add_action(notification, "default", "View", + notify_notification_add_action(noti, "default", "View", (NotifyActionCallback)NotificationViewCallback, this, NULL); - notifications_ = g_list_append(notifications_, notification); + notifications_ = g_list_append(notifications_, noti); GError *error = NULL; - notify_notification_show(notification, &error); + notify_notification_show(noti, &error); log_and_clear_error(error, "notify_notification_show"); - auto host = - content::RenderViewHost::FromID(render_process_id, render_view_id); + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (!host) return; @@ -120,42 +105,35 @@ void NotificationPresenterLinux::CancelNotification( int render_process_id, int render_view_id, int notification_id) { - NotifyNotification *notification = NULL; + NotifyNotification *noti = NULL; for (GList *p = notifications_; p != NULL; p = p->next) { - int obj_render_process_id = GPOINTER_TO_INT( - g_object_get_data(G_OBJECT(notification), kRenderProcessIDKey)); - int obj_render_view_id = GPOINTER_TO_INT( - g_object_get_data(G_OBJECT(notification), kRenderViewIDKey)); - int obj_notification_id = GPOINTER_TO_INT( - g_object_get_data(G_OBJECT(notification), kNotificationIDKey)); - if (render_process_id == obj_render_process_id - && render_view_id == obj_render_view_id - && notification_id == obj_notification_id) { - notification = reinterpret_cast(p->data); + int rpid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderProcessIDKey)); + int rvid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderViewIDKey)); + int nid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kNotificationIDKey)); + if (render_process_id == rpid && render_view_id == rvid && notification_id == nid) { + noti = reinterpret_cast(p->data); notifications_ = g_list_delete_link(notifications_, p); break; } } - if (!notification) + if (!noti) return; GError *error = NULL; - notify_notification_close(notification, &error); + notify_notification_close(noti, &error); log_and_clear_error(error, "notify_notification_close"); - g_object_unref(notification); + g_object_unref(noti); - auto host = - content::RenderViewHost::FromID(render_process_id, render_view_id); + auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (!host) return; host->DesktopNotificationPostClose(notification_id, false); } -void NotificationPresenterLinux::RemoveNotification( - NotifyNotification *notification) { - notifications_ = g_list_remove(notifications_, notification); - g_object_unref(notification); +void NotificationPresenterLinux::RemoveNotification(NotifyNotification *noti) { + notifications_ = g_list_remove(notifications_, noti); + g_object_unref(noti); } } // namespace brightray From 967e8170f505de84afdb1fcbc4d2722fa8534b0a Mon Sep 17 00:00:00 2001 From: Patrick Reynolds Date: Thu, 19 Dec 2013 16:01:01 -0600 Subject: [PATCH 0262/1195] brevity and style --- .../linux/notification_presenter_linux.cc | 71 +++++++++++-------- .../linux/notification_presenter_linux.h | 6 +- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 3544dbc4bed..06a9d0d42d0 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -22,19 +22,28 @@ const char *kRenderViewIDKey = "RenderViewID"; const char *kNotificationIDKey = "NotificationID"; void log_and_clear_error(GError *error, const char *context) { - if (error) { - LOG(ERROR) << context - << ": domain=" << error->domain - << " code=" << error->code - << " message=\"" << error->message << '"'; - g_error_free(error); - } + if (!error) return; + + LOG(ERROR) << context + << ": domain=" << error->domain + << " code=" << error->code + << " message=\"" << error->message << '"'; + g_error_free(error); } +int GetObjectInt(NotifyNotification *noti, const char *key) { + return GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), key)); +} + +void SetObjectInt(NotifyNotification *noti, const char *key, int value) { + g_object_set_data(G_OBJECT(noti), key, GINT_TO_POINTER(value)); +} + + void NotificationClosedCallback(NotifyNotification *noti, NotificationPresenterLinux *obj) { - int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderProcessIDKey)); - int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderViewIDKey)); - int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kNotificationIDKey)); + int render_process_id = GetObjectInt(noti, kRenderProcessIDKey); + int render_view_id = GetObjectInt(noti, kRenderViewIDKey); + int notification_id = GetObjectInt(noti, kNotificationIDKey); auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (host) host->DesktopNotificationPostClose(notification_id, false); @@ -43,9 +52,9 @@ void NotificationClosedCallback(NotifyNotification *noti, NotificationPresenterL void NotificationViewCallback(NotifyNotification *noti, const char *action, NotificationPresenterLinux *obj) { - int render_process_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderProcessIDKey)); - int render_view_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderViewIDKey)); - int notification_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kNotificationIDKey)); + int render_process_id = GetObjectInt(noti, kRenderProcessIDKey); + int render_view_id = GetObjectInt(noti, kRenderViewIDKey); + int notification_id = GetObjectInt(noti, kNotificationIDKey); auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); if (host) host->DesktopNotificationPostClick(notification_id); @@ -61,16 +70,16 @@ NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterLinux; } -NotificationPresenterLinux::NotificationPresenterLinux() : notifications_(NULL) { } +NotificationPresenterLinux::NotificationPresenterLinux() : notifications_(nullptr) { } NotificationPresenterLinux::~NotificationPresenterLinux() { // unref any outstanding notifications, and then free the list. - if (notifications_) { - for (GList *p = notifications_; p != NULL; p = p->next) { - g_object_unref(G_OBJECT(p->data)); - } - g_list_free(notifications_); + if (!notifications_) return; + + for (GList *p = notifications_; p != nullptr; p = p->next) { + g_object_unref(G_OBJECT(p->data)); } + g_list_free(notifications_); } void NotificationPresenterLinux::ShowNotification( @@ -79,18 +88,18 @@ void NotificationPresenterLinux::ShowNotification( int render_view_id) { std::string title = base::UTF16ToUTF8(params.title); std::string body = base::UTF16ToUTF8(params.body); - NotifyNotification *noti = notify_notification_new(title.c_str(), body.c_str(), NULL); - g_object_set_data(G_OBJECT(noti), kRenderProcessIDKey, GINT_TO_POINTER(render_process_id)); - g_object_set_data(G_OBJECT(noti), kRenderViewIDKey, GINT_TO_POINTER(render_view_id)); - g_object_set_data(G_OBJECT(noti), kNotificationIDKey, GINT_TO_POINTER(params.notification_id)); + NotifyNotification *noti = notify_notification_new(title.c_str(), body.c_str(), nullptr); + SetObjectInt(noti, kRenderProcessIDKey, render_process_id); + SetObjectInt(noti, kRenderViewIDKey, render_view_id); + SetObjectInt(noti, kNotificationIDKey, params.notification_id); g_signal_connect(noti, "closed", G_CALLBACK(NotificationClosedCallback), this); notify_notification_add_action(noti, "default", "View", - (NotifyActionCallback)NotificationViewCallback, this, NULL); + (NotifyActionCallback)NotificationViewCallback, this, nullptr); notifications_ = g_list_append(notifications_, noti); - GError *error = NULL; + GError *error = nullptr; notify_notification_show(noti, &error); log_and_clear_error(error, "notify_notification_show"); @@ -105,11 +114,11 @@ void NotificationPresenterLinux::CancelNotification( int render_process_id, int render_view_id, int notification_id) { - NotifyNotification *noti = NULL; - for (GList *p = notifications_; p != NULL; p = p->next) { - int rpid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderProcessIDKey)); - int rvid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kRenderViewIDKey)); - int nid = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), kNotificationIDKey)); + NotifyNotification *noti = nullptr; + for (GList *p = notifications_; p != nullptr; p = p->next) { + int rpid = GetObjectInt(noti, kRenderProcessIDKey); + int rvid = GetObjectInt(noti, kRenderViewIDKey); + int nid = GetObjectInt(noti, kNotificationIDKey); if (render_process_id == rpid && render_view_id == rvid && notification_id == nid) { noti = reinterpret_cast(p->data); notifications_ = g_list_delete_link(notifications_, p); @@ -119,7 +128,7 @@ void NotificationPresenterLinux::CancelNotification( if (!noti) return; - GError *error = NULL; + GError *error = nullptr; notify_notification_close(noti, &error); log_and_clear_error(error, "notify_notification_close"); g_object_unref(noti); diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index 0f52fd55fdd..dc868917e36 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -19,6 +19,9 @@ class NotificationPresenterLinux : public NotificationPresenter { NotificationPresenterLinux(); ~NotificationPresenterLinux(); + void RemoveNotification(NotifyNotification *notification); + + private: virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams&, int render_process_id, @@ -28,9 +31,6 @@ class NotificationPresenterLinux : public NotificationPresenter { int render_view_id, int notification_id) OVERRIDE; - void RemoveNotification(NotifyNotification *notification); - - private: // A list of all open NotifyNotification objects. // We do lookups here both by NotifyNotification object (when the user // clicks a notification) and by the ID From 13f816b4bb34344d262f72a3bb94b7ba1b7e5e96 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 31 Dec 2013 11:09:24 +0000 Subject: [PATCH 0263/1195] Add flag to disable clang under Linux. --- brightray/brightray.gyp | 2 +- brightray/brightray.gypi | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index a4baef81f6f..9504a57786f 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -88,7 +88,7 @@ ], 'conditions': [ ['OS=="linux"', { - 'cflags': [ + 'cflags_cc': [ '-fno-rtti', ], 'link_settings': { diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index e2deae347a8..27e13a6173e 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -8,6 +8,9 @@ 'mac_deployment_target%': '10.8', 'mac_sdkroot%': 'macosx', + # Build with clang under Linux. + 'linux_clang%': 1, + 'win_release_RuntimeLibrary%': '2', # /MD (nondebug DLL) 'win_debug_RuntimeLibrary%': '3', # /MTd (debug DLL) @@ -176,7 +179,6 @@ }], ['OS=="linux"', { 'cflags_cc': [ - '-std=gnu++11', '-fno-rtti', ' Date: Wed, 1 Jan 2014 02:29:27 +0000 Subject: [PATCH 0264/1195] '-std=gnu++11' is also needed by g++. --- brightray/brightray.gypi | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 27e13a6173e..daf5f2737cf 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -179,6 +179,7 @@ }], ['OS=="linux"', { 'cflags_cc': [ + '-std=gnu++11', '-fno-rtti', ' Date: Fri, 23 Aug 2013 08:19:37 -0400 Subject: [PATCH 0265/1195] Fix assertions in Debug builds about using NetworkDelegate on the wrong thread We have to create it on the IO thread. --- brightray/browser/browser_context.cc | 2 +- brightray/browser/url_request_context_getter.cc | 5 +++-- brightray/browser/url_request_context_getter.h | 5 ++++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 20b70470552..230a8243386 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -106,7 +106,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( GetPath(), io_loop, file_loop, - CreateNetworkDelegate().Pass(), + base::Bind(&BrowserContext::CreateNetworkDelegate, base::Unretained(this)), protocol_handlers); resource_context_->set_url_request_context_getter(url_request_getter_.get()); return url_request_getter_.get(); diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index b5596b8e05a..4324a931165 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -40,12 +40,12 @@ URLRequestContextGetter::URLRequestContextGetter( const base::FilePath& base_path, base::MessageLoop* io_loop, base::MessageLoop* file_loop, - scoped_ptr network_delegate, + base::Callback(void)> network_delegate_factory, content::ProtocolHandlerMap* protocol_handlers) : base_path_(base_path), io_loop_(io_loop), file_loop_(file_loop), - network_delegate_(network_delegate.Pass()) { + network_delegate_factory_(network_delegate_factory) { // Must first be created on the UI thread. DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); @@ -67,6 +67,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext()); + network_delegate_ = network_delegate_factory_.Run().Pass(); url_request_context_->set_network_delegate(network_delegate_.get()); storage_.reset( new net::URLRequestContextStorage(url_request_context_.get())); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index c9700250aad..7d3e174cd40 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -5,6 +5,7 @@ #ifndef BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_ #define BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_ +#include "base/callback.h" #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/content_browser_client.h" @@ -30,7 +31,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { const base::FilePath& base_path, base::MessageLoop* io_loop, base::MessageLoop* file_loop, - scoped_ptr, + base::Callback(void)>, content::ProtocolHandlerMap*); virtual ~URLRequestContextGetter(); @@ -45,6 +46,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { base::MessageLoop* io_loop_; base::MessageLoop* file_loop_; + base::Callback(void)> network_delegate_factory_; + scoped_ptr proxy_config_service_; scoped_ptr network_delegate_; scoped_ptr storage_; From 5cf32f1f9c830c83c14f3de5646d582f6f8a95df Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 30 Jan 2014 21:58:55 +0800 Subject: [PATCH 0266/1195] Update libchromiumcontent for --commit argument of download script. --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 2cd1a60b38b..0027a764ce5 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 2cd1a60b38babd5ec13884905422778f390a9bc0 +Subproject commit 0027a764ce54f20ddcabe6f946e8bd6c07325b0a From a8f34982a09370ee476b30f587501c8ccc91f069 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 30 Jan 2014 22:01:22 +0800 Subject: [PATCH 0267/1195] Enable passing --commit to download script. --- brightray/script/bootstrap | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index 0325f49b0c3..05011fce3cd 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -15,11 +15,13 @@ DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download') def main(): args = parse_args() return (update_submodules() or - download_libchromiumcontent(args.url)) + download_libchromiumcontent(args.commit, args.url)) def parse_args(): parser = argparse.ArgumentParser(description='Bootstrap this project') + parser.add_argument('-c', '--commit', nargs='?', default='HEAD', + help='The commit of libchromiumcontent to download.') parser.add_argument('url', help='The base URL from which to download ' 'libchromiumcontent (i.e., the URL you passed to ' 'libchromiumcontent\'s script/upload script') @@ -32,11 +34,11 @@ def update_submodules(): '--recursive'])) -def download_libchromiumcontent(url): +def download_libchromiumcontent(commit, url): mkdir_p(DOWNLOAD_DIR) download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', 'download') - return subprocess.call([sys.executable, download, '-f', url, + return subprocess.call([sys.executable, download, '-f', '-c', commit, url, os.path.join(DOWNLOAD_DIR, 'libchromiumcontent')]) From c4935acbb1d236066f17cfba867cdd49d8e3f202 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 30 Jan 2014 09:01:23 -0500 Subject: [PATCH 0268/1195] Fix debug assertions about transport_security_state This code was added to content_shell in https://chromiumcodereview.appspot.com/16501002 and we never picked it up. --- brightray/browser/url_request_context_getter.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 4324a931165..4b26d7a9364 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -98,6 +98,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { url_request_context_->network_delegate())); storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); + storage_->set_transport_security_state(new net::TransportSecurityState); storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); storage_->set_http_auth_handler_factory( net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); @@ -118,6 +119,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { net::HttpNetworkSession::Params network_session_params; network_session_params.cert_verifier = url_request_context_->cert_verifier(); + network_session_params.transport_security_state = + url_request_context_->transport_security_state(); network_session_params.server_bound_cert_service = url_request_context_->server_bound_cert_service(); network_session_params.proxy_service = From e8de51a8dd6e6c8f89dfba8c5f4f80fc63f3e5b2 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 30 Jan 2014 09:03:00 -0500 Subject: [PATCH 0269/1195] Destroy ResourceContext on the IO thread This matches content_shell and fixes a debug assertion (and maybe even a crash). --- brightray/browser/browser_context.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 230a8243386..4970530d7bf 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -89,6 +89,9 @@ void BrowserContext::Initialize() { } BrowserContext::~BrowserContext() { + content::BrowserThread::DeleteSoon(content::BrowserThread::IO, + FROM_HERE, + resource_context_.release()); } void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { From f7fb6371c225b30b27c94f72a8003aa786d29371 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 31 Jan 2014 10:38:12 -0500 Subject: [PATCH 0270/1195] Increase the open file limit on OS X to 1024 The default (256) is too low for pages that load a lot of resources all at once. See https://codereview.chromium.org/125151 and bugs like https://code.google.com/p/chromium/issues/detail?id=14137 and https://code.google.com/p/chromium/issues/detail?id=151039. The new limit matches what Chrome itself uses. --- brightray/browser/browser_main_parts.h | 1 + brightray/browser/browser_main_parts_mac.mm | 30 +++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 6e2f3531f67..79d343ac608 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -27,6 +27,7 @@ class BrowserMainParts : public content::BrowserMainParts { virtual BrowserContext* CreateBrowserContext(); #if defined(OS_MACOSX) + virtual void PreEarlyInitialization() OVERRIDE; virtual void PreMainMessageLoopStart() OVERRIDE; #endif diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm index 373280ca444..44b9494374a 100644 --- a/brightray/browser/browser_main_parts_mac.mm +++ b/brightray/browser/browser_main_parts_mac.mm @@ -1,10 +1,40 @@ #import "browser_main_parts.h" +#import "base/logging.h" #import "base/mac/bundle_locations.h" #import namespace brightray { +namespace { + +// Sets the file descriptor soft limit to |max_descriptors| or the OS hard limit, whichever is +// lower. +void SetFileDescriptorLimit(rlim_t max_descriptors) { + rlimit limits; + if (getrlimit(RLIMIT_NOFILE, &limits) != 0) { + PLOG(INFO) << "Failed to get file descriptor limit"; + return; + } + + auto new_limit = max_descriptors; + if (limits.rlim_max > 0) + new_limit = std::min(new_limit, limits.rlim_max); + limits.rlim_cur = new_limit; + if (setrlimit(RLIMIT_NOFILE, &limits) != 0) + PLOG(INFO) << "Failed to set file descriptor limit"; +} + +} // namespace + +void BrowserMainParts::PreEarlyInitialization() { + // We use quite a few file descriptors for our IPC, and the default limit on the Mac is low (256), + // so bump it up. + // See http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/chrome_browser_main_posix.cc?revision=244734#l295 + // and https://codereview.chromium.org/125151 + SetFileDescriptorLimit(1024); +} + // Replicates NSApplicationMain, but doesn't start a run loop. void BrowserMainParts::PreMainMessageLoopStart() { auto infoDictionary = base::mac::OuterBundle().infoDictionary; From e3aaaf2643869f3aac727d61849808f035c215a6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 16:12:02 +0800 Subject: [PATCH 0271/1195] Add InspectableWebContentsDelegate. --- brightray/brightray.gyp | 1 + brightray/browser/inspectable_web_contents.h | 4 +++ .../inspectable_web_contents_delegate.h | 26 +++++++++++++++++++ .../browser/inspectable_web_contents_impl.cc | 14 ++++++++-- .../browser/inspectable_web_contents_impl.h | 7 +++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 brightray/browser/inspectable_web_contents_delegate.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 9504a57786f..532011bc955 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -43,6 +43,7 @@ 'browser/download_manager_delegate.h', 'browser/inspectable_web_contents.cc', 'browser/inspectable_web_contents.h', + 'browser/inspectable_web_contents_delegate.h', 'browser/inspectable_web_contents_impl.cc', 'browser/inspectable_web_contents_impl.h', 'browser/inspectable_web_contents_view.h', diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 49a50bc5079..b436c391ce3 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -5,6 +5,7 @@ namespace brightray { +class InspectableWebContentsDelegate; class InspectableWebContentsView; class InspectableWebContents { @@ -23,6 +24,9 @@ class InspectableWebContents { virtual void ShowDevTools() = 0; virtual bool IsDevToolsViewShowing() = 0; + + // The delegate manages its own life. + virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h new file mode 100644 index 00000000000..7ef79f60e0e --- /dev/null +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -0,0 +1,26 @@ +#ifndef BRIGHTRAY_INSPECTABLE_WEB_CONTENTS_DELEGATE_H_ +#define BRIGHTRAY_INSPECTABLE_WEB_CONTENTS_DELEGATE_H_ + +#include + +namespace brightray { + +class InspectableWebContentsDelegate { + public: + virtual ~InspectableWebContentsDelegate() {} + + // Called when the devtools is going to change the dock side, returning true + // to override the default behavior. + // Receiver should set |succeed| to |false| if it failed to handle this. + virtual bool DevToolsSetDockSide(const std::string& side, bool* succeed) { + return false; + } + + // Called when the devtools is going to be showed, returning true to override + // the default behavior. + virtual bool DevToolsShow(const std::string& side) { return false; } +}; + +} // namespace brightray + +#endif // BRIGHTRAY_INSPECTABLE_WEB_CONTENTS_DELEGATE_H_ diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index e972e568735..cf73a26443d 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -8,6 +8,7 @@ #include "browser/browser_client.h" #include "browser/browser_context.h" #include "browser/browser_main_parts.h" +#include "browser/inspectable_web_contents_delegate.h" #include "browser/inspectable_web_contents_view.h" #include "base/prefs/pref_registry_simple.h" @@ -40,7 +41,8 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { InspectableWebContentsImpl::InspectableWebContentsImpl( content::WebContents* web_contents) - : web_contents_(web_contents) { + : web_contents_(web_contents), + delegate_(nullptr) { auto context = static_cast( web_contents_->GetBrowserContext()); dock_side_ = context->prefs()->GetString(kDockSidePref); @@ -92,6 +94,9 @@ void InspectableWebContentsImpl::ShowDevTools() { std::string()); } + if (delegate_ && delegate_->DevToolsShow(dock_side_)) + return; + view_->SetDockSide(dock_side_); view_->ShowDevTools(); } @@ -120,8 +125,13 @@ void InspectableWebContentsImpl::MoveWindow(int x, int y) { } void InspectableWebContentsImpl::SetDockSide(const std::string& side) { - if (!view_->SetDockSide(side)) + bool succeed = true; + if (delegate_ && delegate_->DevToolsSetDockSide(side, &succeed)) { + if (!succeed) // delegate failed to set dock side. + return; + } else if (!view_->SetDockSide(side)) { return; + } dock_side_ = side; diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 53023204dd1..f48f0a47bcb 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -23,6 +23,7 @@ class DevToolsClientHost; namespace brightray { +class InspectableWebContentsDelegate; class InspectableWebContentsView; class InspectableWebContentsImpl : @@ -43,6 +44,10 @@ class InspectableWebContentsImpl : virtual void ShowDevTools() OVERRIDE; virtual bool IsDevToolsViewShowing() OVERRIDE; + virtual void SetDelegate(InspectableWebContentsDelegate* delegate) { + delegate_ = delegate; + } + content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); } @@ -101,6 +106,8 @@ class InspectableWebContentsImpl : scoped_ptr embedder_message_dispatcher_; + InspectableWebContentsDelegate* delegate_; + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); }; From 5768ff698107b4a63fd275dcea19a5c0268c385a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Mar 2014 19:47:33 +0800 Subject: [PATCH 0272/1195] Enable delegate to change the dock side. --- brightray/browser/inspectable_web_contents_delegate.h | 3 ++- brightray/browser/inspectable_web_contents_impl.cc | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index 7ef79f60e0e..0b2f3f6a2b2 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -18,7 +18,8 @@ class InspectableWebContentsDelegate { // Called when the devtools is going to be showed, returning true to override // the default behavior. - virtual bool DevToolsShow(const std::string& side) { return false; } + // Receiver is given the chance to change the |dock_side|. + virtual bool DevToolsShow(std::string* dock_side) { return false; } }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index cf73a26443d..c4a8f75ef4b 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -94,7 +94,7 @@ void InspectableWebContentsImpl::ShowDevTools() { std::string()); } - if (delegate_ && delegate_->DevToolsShow(dock_side_)) + if (delegate_ && delegate_->DevToolsShow(&dock_side_)) return; view_->SetDockSide(dock_side_); From d2ff5ad798b75547aeaef0ce52463e97656192a0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 20 Mar 2014 09:26:21 +0800 Subject: [PATCH 0273/1195] Provide a way to close devtools completely. --- brightray/browser/inspectable_web_contents.h | 2 ++ brightray/browser/inspectable_web_contents_impl.cc | 12 +++++++++--- brightray/browser/inspectable_web_contents_impl.h | 1 + brightray/browser/inspectable_web_contents_view.h | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index b436c391ce3..313e4ebea2c 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -23,6 +23,8 @@ class InspectableWebContents { virtual content::WebContents* GetWebContents() const = 0; virtual void ShowDevTools() = 0; + // Close the DevTools completely instead of just hide it. + virtual void CloseDevTools() = 0; virtual bool IsDevToolsViewShowing() = 0; // The delegate manages its own life. diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c4a8f75ef4b..b22b4a287fb 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -101,6 +101,14 @@ void InspectableWebContentsImpl::ShowDevTools() { view_->ShowDevTools(); } +void InspectableWebContentsImpl::CloseDevTools() { + if (IsDevToolsViewShowing()) { + view_->CloseDevTools(); + devtools_web_contents_.reset(); + web_contents_->GetView()->Focus(); + } +} + bool InspectableWebContentsImpl::IsDevToolsViewShowing() { return devtools_web_contents_ && view_->IsDevToolsViewShowing(); } @@ -116,9 +124,7 @@ void InspectableWebContentsImpl::ActivateWindow() { } void InspectableWebContentsImpl::CloseWindow() { - view_->CloseDevTools(); - devtools_web_contents_.reset(); - web_contents_->GetView()->Focus(); + CloseDevTools(); } void InspectableWebContentsImpl::MoveWindow(int x, int y) { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index f48f0a47bcb..8581b24ec47 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -42,6 +42,7 @@ class InspectableWebContentsImpl : virtual content::WebContents* GetWebContents() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; + virtual void CloseDevTools() OVERRIDE; virtual bool IsDevToolsViewShowing() OVERRIDE; virtual void SetDelegate(InspectableWebContentsDelegate* delegate) { diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 87274805f8e..18fd192a67e 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -12,6 +12,7 @@ class InspectableWebContentsView { virtual gfx::NativeView GetNativeView() const = 0; virtual void ShowDevTools() = 0; + // Hide the DevTools view. virtual void CloseDevTools() = 0; virtual bool IsDevToolsViewShowing() = 0; virtual bool SetDockSide(const std::string& side) = 0; From 54060ed53d9bd664b0586e61609a25a467e4879a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 5 Apr 2014 00:10:09 +0800 Subject: [PATCH 0274/1195] Enable delegate to override SaveToFile and AppendToFile. --- brightray/browser/inspectable_web_contents_delegate.h | 6 ++++++ brightray/browser/inspectable_web_contents_impl.cc | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index 0b2f3f6a2b2..d86285789e3 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -20,6 +20,12 @@ class InspectableWebContentsDelegate { // the default behavior. // Receiver is given the chance to change the |dock_side|. virtual bool DevToolsShow(std::string* dock_side) { return false; } + + // Requested by WebContents of devtools. + virtual void DevToolsSaveToFile( + const std::string& url, const std::string& content, bool save_as) {} + virtual void DevToolsAppendToFile( + const std::string& url, const std::string& content) {} }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index b22b4a287fb..1ccb4e1054d 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -153,10 +153,14 @@ void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) { void InspectableWebContentsImpl::SaveToFile( const std::string& url, const std::string& content, bool save_as) { + if (delegate_) + delegate_->DevToolsSaveToFile(url, content, save_as); } void InspectableWebContentsImpl::AppendToFile( const std::string& url, const std::string& content) { + if (delegate_) + delegate_->DevToolsAppendToFile(url, content); } void InspectableWebContentsImpl::RequestFileSystems() { From 5e0dd5c687dabb135ede4fe1b1bd77c2121287bb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 23 Apr 2014 11:20:12 +0800 Subject: [PATCH 0275/1195] Remove from notification center when web contents is destroyed. --- brightray/browser/inspectable_web_contents_view_mac.h | 1 + brightray/browser/inspectable_web_contents_view_mac.mm | 4 ++++ brightray/browser/mac/bry_inspectable_web_contents_view.h | 1 + brightray/browser/mac/bry_inspectable_web_contents_view.mm | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 86cc7822178..927a91a362d 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -15,6 +15,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView { public: explicit InspectableWebContentsViewMac( InspectableWebContentsImpl* inspectable_web_contents_impl); + virtual ~InspectableWebContentsViewMac(); virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index 95ed74f2dbd..54ad9f19404 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -17,6 +17,10 @@ InspectableWebContentsViewMac::InspectableWebContentsViewMac(InspectableWebConte view_([[BRYInspectableWebContentsView alloc] initWithInspectableWebContentsViewMac:this]) { } +InspectableWebContentsViewMac::~InspectableWebContentsViewMac() { + [view_ removeFromNotificationCenter]; +} + gfx::NativeView InspectableWebContentsViewMac::GetNativeView() const { return view_.get(); } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 49eff626321..5c17e6c0165 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -8,6 +8,7 @@ BRYInspectableWebContentsViewPrivate *_private; } +- (void)removeFromNotificationCenter; - (IBAction)showDevTools:(id)sender; @end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index f193f7ef765..edc455c2fd7 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -76,6 +76,10 @@ void SetActive(content::WebContents* web_contents, bool active) { [super dealloc]; } +- (void)removeFromNotificationCenter { + [NSNotificationCenter.defaultCenter removeObserver:self]; +} + - (IBAction)showDevTools:(id)sender { _private->inspectableWebContentsView->inspectable_web_contents()->ShowDevTools(); } From e1988d3b8e9987000646d2cc3fa59ea6c8dd2012 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 18 May 2014 19:48:31 +0800 Subject: [PATCH 0276/1195] Update to latest gyp. This fixes warnings like 'xxx.o has no symbols'. --- brightray/vendor/gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/gyp b/brightray/vendor/gyp index 6633baab29b..81cdff9bb79 160000 --- a/brightray/vendor/gyp +++ b/brightray/vendor/gyp @@ -1 +1 @@ -Subproject commit 6633baab29b60f27e3dca607ffbef689ccdd82b8 +Subproject commit 81cdff9bb79bff2fcfe51ba4637fe8ebdd4ffb7f From d5d923439e96357910b9ea2720de21291108f60c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 4 Jun 2014 21:55:50 +0800 Subject: [PATCH 0277/1195] Update to latest libchromiumcontent. --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 0027a764ce5..656be940848 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 0027a764ce54f20ddcabe6f946e8bd6c07325b0a +Subproject commit 656be9408484de40ba4938ef47acdebeec8a1784 From 4e69bd17336aa50675dcfa26aae054daf8e9d2ea Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Jun 2014 09:10:26 +0800 Subject: [PATCH 0278/1195] Add 'third_party/skia/include/core' to include_dirs. --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 532011bc955..8dd2a64ce08 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -13,6 +13,7 @@ '.', '<(libchromiumcontent_include_dir)', '<(libchromiumcontent_include_dir)/third_party/skia/include/config', + '<(libchromiumcontent_include_dir)/third_party/skia/include/core', ], 'direct_dependent_settings': { 'include_dirs': [ From b0374b6a1d20ca6e902f4ab64af8806bf9b9a0ea Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Jun 2014 09:58:28 +0800 Subject: [PATCH 0279/1195] Use views::View to represent web view. --- .../win/inspectable_web_contents_view_win.cc | 44 ++++++++++++++++++- .../win/inspectable_web_contents_view_win.h | 9 ++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index dca7ba4f3eb..00c661c22b2 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -6,6 +6,8 @@ #include "content/public/browser/web_contents_view.h" #include "ui/gfx/win/hwnd_util.h" +#include "ui/views/controls/webview/webview.h" +#include "ui/views/view.h" namespace brightray { @@ -15,6 +17,41 @@ const int kWindowInset = 100; } +class ContainerView : public views::View { + public: + explicit ContainerView(InspectableWebContentsViewWin* web_contents_view) + : container_view_created_(false), + web_view_(new views::WebView(NULL)), + web_contents_view_(web_contents_view) { + web_view_->SetWebContents( + web_contents_view_->inspectable_web_contents()->GetWebContents()); + } + + private: + // views::View: + virtual void Layout() OVERRIDE { + web_view_->SetBounds(0, 0, width(), height()); + } + + virtual void ViewHierarchyChanged( + const ViewHierarchyChangedDetails& details) OVERRIDE { + View::ViewHierarchyChanged(details); + // We're not using child == this because a Widget may not be + // available when this is added to the hierarchy. + if (details.is_add && GetWidget() && !container_view_created_) { + container_view_created_ = true; + AddChildView(web_view_); + } + } + + // True if the container view has already been created, or false otherwise. + bool container_view_created_; + + views::WebView* web_view_; + + InspectableWebContentsViewWin* web_contents_view_; +}; + InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewWin(inspectable_web_contents); @@ -22,7 +59,8 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsViewWin::InspectableWebContentsViewWin( InspectableWebContentsImpl* inspectable_web_contents) - : inspectable_web_contents_(inspectable_web_contents) { + : inspectable_web_contents_(inspectable_web_contents), + container_(new ContainerView(this)) { } InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { @@ -30,6 +68,10 @@ InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { DestroyWindow(devtools_window_->hwnd()); } +views::View* InspectableWebContentsViewWin::GetView() const { + return container_; +} + gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { auto web_contents = inspectable_web_contents_->GetWebContents(); return web_contents->GetView()->GetNativeView(); diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index 55b09b2d3e4..382a0f46029 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -6,8 +6,13 @@ #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" +namespace views { +class View; +} + namespace brightray { +class ContainerView; class DevToolsWindow; class InspectableWebContentsImpl; @@ -17,6 +22,8 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { InspectableWebContentsImpl* inspectable_web_contents_impl); ~InspectableWebContentsViewWin(); + views::View* GetView() const; + virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; @@ -31,6 +38,8 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; + ContainerView* container_; + base::WeakPtr devtools_window_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewWin); From 566022cb6667d84e25194392bda2ad6fcd14f7bf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Jun 2014 10:03:35 +0800 Subject: [PATCH 0280/1195] ContainerView should manage itself. --- brightray/browser/win/inspectable_web_contents_view_win.cc | 3 ++- brightray/browser/win/inspectable_web_contents_view_win.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index 00c661c22b2..65b9ff17603 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -23,6 +23,7 @@ class ContainerView : public views::View { : container_view_created_(false), web_view_(new views::WebView(NULL)), web_contents_view_(web_contents_view) { + set_owned_by_client(); web_view_->SetWebContents( web_contents_view_->inspectable_web_contents()->GetWebContents()); } @@ -69,7 +70,7 @@ InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { } views::View* InspectableWebContentsViewWin::GetView() const { - return container_; + return container_.get(); } gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index 382a0f46029..5548f8ce75c 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -4,6 +4,7 @@ #include "browser/inspectable_web_contents_view.h" #include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" namespace views { @@ -38,7 +39,7 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; - ContainerView* container_; + scoped_ptr container_; base::WeakPtr devtools_window_; From bd0f9df96cb3d7f4fd9900614443bc1c5311820f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Jun 2014 10:29:39 +0800 Subject: [PATCH 0281/1195] Put devtools in split view. --- .../win/inspectable_web_contents_view_win.cc | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index 65b9ff17603..89d4ade98cb 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -6,6 +6,7 @@ #include "content/public/browser/web_contents_view.h" #include "ui/gfx/win/hwnd_util.h" +#include "ui/views/controls/single_split_view.h" #include "ui/views/controls/webview/webview.h" #include "ui/views/view.h" @@ -24,14 +25,49 @@ class ContainerView : public views::View { web_view_(new views::WebView(NULL)), web_contents_view_(web_contents_view) { set_owned_by_client(); + web_view_->set_owned_by_client(); web_view_->SetWebContents( web_contents_view_->inspectable_web_contents()->GetWebContents()); } + void ShowDevTools() { + if (IsDevToolsViewShowing()) + return; + + RemoveChildView(web_view_.get()); + devtools_view_ = new views::WebView(NULL); + devtools_view_->SetWebContents(web_contents_view_-> + inspectable_web_contents()->devtools_web_contents()); + split_view_.reset(new views::SingleSplitView( + web_view_.get(), + devtools_view_, + views::SingleSplitView::VERTICAL_SPLIT, + NULL)); + AddChildView(split_view_.get()); + Layout(); + } + + void CloseDevTools() { + if (!IsDevToolsViewShowing()) + return; + + RemoveChildView(split_view_.get()); + split_view_.reset(); + AddChildView(web_view_.get()); + Layout(); + } + + bool IsDevToolsViewShowing() { + return split_view_; + } + private: // views::View: virtual void Layout() OVERRIDE { - web_view_->SetBounds(0, 0, width(), height()); + if (split_view_) + split_view_->SetBounds(0, 0, width(), height()); + else + web_view_->SetBounds(0, 0, width(), height()); } virtual void ViewHierarchyChanged( @@ -41,14 +77,16 @@ class ContainerView : public views::View { // available when this is added to the hierarchy. if (details.is_add && GetWidget() && !container_view_created_) { container_view_created_ = true; - AddChildView(web_view_); + AddChildView(web_view_.get()); } } // True if the container view has already been created, or false otherwise. bool container_view_created_; - views::WebView* web_view_; + scoped_ptr web_view_; + scoped_ptr split_view_; + views::WebView* devtools_view_; // Owned by split_view_. InspectableWebContentsViewWin* web_contents_view_; }; @@ -79,6 +117,9 @@ gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { } void InspectableWebContentsViewWin::ShowDevTools() { + container_->ShowDevTools(); + return; + if (!devtools_window_) { devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr(); devtools_window_->Init(HWND_DESKTOP, gfx::Rect()); @@ -95,13 +136,16 @@ void InspectableWebContentsViewWin::ShowDevTools() { } void InspectableWebContentsViewWin::CloseDevTools() { + container_->CloseDevTools(); + return; + if (!devtools_window_) return; SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); } bool InspectableWebContentsViewWin::IsDevToolsViewShowing() { - return devtools_window_; + return container_->IsDevToolsViewShowing() || devtools_window_; } bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { From 1943d88bdce6d240e21e8797385291fd41309c6f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Jun 2014 11:37:07 +0800 Subject: [PATCH 0282/1195] Handle focus correctly. --- .../browser/win/inspectable_web_contents_view_win.cc | 9 +++++++++ .../browser/win/inspectable_web_contents_view_win.h | 1 + 2 files changed, 10 insertions(+) diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index 89d4ade98cb..88857e5e46a 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -30,6 +30,10 @@ class ContainerView : public views::View { web_contents_view_->inspectable_web_contents()->GetWebContents()); } + views::View* GetWebView() const { + return web_view_.get(); + } + void ShowDevTools() { if (IsDevToolsViewShowing()) return; @@ -45,6 +49,7 @@ class ContainerView : public views::View { NULL)); AddChildView(split_view_.get()); Layout(); + devtools_view_->RequestFocus(); } void CloseDevTools() { @@ -111,6 +116,10 @@ views::View* InspectableWebContentsViewWin::GetView() const { return container_.get(); } +views::View* InspectableWebContentsViewWin::GetWebView() const { + return container_->GetWebView(); +} + gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { auto web_contents = inspectable_web_contents_->GetWebContents(); return web_contents->GetView()->GetNativeView(); diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index 5548f8ce75c..e7d288affda 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -24,6 +24,7 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { ~InspectableWebContentsViewWin(); views::View* GetView() const; + views::View* GetWebView() const; virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; From d70d24c3608e00008d83e9b03dc720493beedbf5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Jun 2014 12:03:20 +0800 Subject: [PATCH 0283/1195] Implement setting dock side. --- .../win/inspectable_web_contents_view_win.cc | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index 88857e5e46a..02fe15c0f53 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -22,6 +22,7 @@ class ContainerView : public views::View { public: explicit ContainerView(InspectableWebContentsViewWin* web_contents_view) : container_view_created_(false), + dockside_("bottom"), web_view_(new views::WebView(NULL)), web_contents_view_(web_contents_view) { set_owned_by_client(); @@ -45,10 +46,12 @@ class ContainerView : public views::View { split_view_.reset(new views::SingleSplitView( web_view_.get(), devtools_view_, - views::SingleSplitView::VERTICAL_SPLIT, + GetSplitViewOrientation(), NULL)); + split_view_->set_divider_offset(GetSplitVievDividerOffset()); AddChildView(split_view_.get()); Layout(); + devtools_view_->RequestFocus(); } @@ -66,6 +69,22 @@ class ContainerView : public views::View { return split_view_; } + bool SetDockSide(const std::string& side) { + if (side != "bottom" && side != "right") + return false; // unsupported display location + if (dockside_ == side) + return true; // no change from current location + + dockside_ = side; + if (!IsDevToolsViewShowing()) + return true; + + split_view_->set_orientation(GetSplitViewOrientation()); + split_view_->set_divider_offset(GetSplitVievDividerOffset()); + split_view_->Layout(); + return true; + } + private: // views::View: virtual void Layout() OVERRIDE { @@ -86,9 +105,25 @@ class ContainerView : public views::View { } } + views::SingleSplitView::Orientation GetSplitViewOrientation() const { + if (dockside_ == "bottom") + return views::SingleSplitView::VERTICAL_SPLIT; + else + return views::SingleSplitView::HORIZONTAL_SPLIT; + } + + int GetSplitVievDividerOffset() const { + if (dockside_ == "bottom") + return height() * 2 / 3; + else + return width() * 2 / 3; + } + // True if the container view has already been created, or false otherwise. bool container_view_created_; + std::string dockside_; + scoped_ptr web_view_; scoped_ptr split_view_; views::WebView* devtools_view_; // Owned by split_view_. @@ -158,7 +193,7 @@ bool InspectableWebContentsViewWin::IsDevToolsViewShowing() { } bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { - return false; + return container_->SetDockSide(side); } } // namespace brightray From 9a70c9bb44be2d780047aa175240c208521e2372 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Jun 2014 12:35:23 +0800 Subject: [PATCH 0284/1195] Enable undocked devtools. --- .../win/inspectable_web_contents_view_win.cc | 79 +++++++++++-------- .../win/inspectable_web_contents_view_win.h | 2 +- 2 files changed, 46 insertions(+), 35 deletions(-) diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index 02fe15c0f53..24a52b658f7 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -22,7 +22,7 @@ class ContainerView : public views::View { public: explicit ContainerView(InspectableWebContentsViewWin* web_contents_view) : container_view_created_(false), - dockside_("bottom"), + dockside_("none"), // "none" is treated as "bottom". web_view_(new views::WebView(NULL)), web_contents_view_(web_contents_view) { set_owned_by_client(); @@ -69,20 +69,18 @@ class ContainerView : public views::View { return split_view_; } - bool SetDockSide(const std::string& side) { - if (side != "bottom" && side != "right") - return false; // unsupported display location + void SetDockSide(const std::string& side) { if (dockside_ == side) - return true; // no change from current location + return; // no change from current location dockside_ = side; if (!IsDevToolsViewShowing()) - return true; + return; split_view_->set_orientation(GetSplitViewOrientation()); split_view_->set_divider_offset(GetSplitVievDividerOffset()); split_view_->Layout(); - return true; + return; } private: @@ -106,17 +104,17 @@ class ContainerView : public views::View { } views::SingleSplitView::Orientation GetSplitViewOrientation() const { - if (dockside_ == "bottom") - return views::SingleSplitView::VERTICAL_SPLIT; - else + if (dockside_ == "right") return views::SingleSplitView::HORIZONTAL_SPLIT; + else + return views::SingleSplitView::VERTICAL_SPLIT; } int GetSplitVievDividerOffset() const { - if (dockside_ == "bottom") - return height() * 2 / 3; - else + if (dockside_ == "right") return width() * 2 / 3; + else + return height() * 2 / 3; } // True if the container view has already been created, or false otherwise. @@ -139,6 +137,7 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsViewWin::InspectableWebContentsViewWin( InspectableWebContentsImpl* inspectable_web_contents) : inspectable_web_contents_(inspectable_web_contents), + undocked_(false), container_(new ContainerView(this)) { } @@ -161,31 +160,30 @@ gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { } void InspectableWebContentsViewWin::ShowDevTools() { - container_->ShowDevTools(); - return; + if (undocked_) { + if (!devtools_window_) { + devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr(); + devtools_window_->Init(HWND_DESKTOP, gfx::Rect()); + } - if (!devtools_window_) { - devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr(); - devtools_window_->Init(HWND_DESKTOP, gfx::Rect()); + auto contents_view = inspectable_web_contents_->GetWebContents()->GetView(); + auto size = contents_view->GetContainerSize(); + size.Enlarge(-kWindowInset, -kWindowInset); + gfx::CenterAndSizeWindow(contents_view->GetNativeView(), + devtools_window_->hwnd(), + size); + + ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL); + } else { + container_->ShowDevTools(); } - - auto contents_view = inspectable_web_contents_->GetWebContents()->GetView(); - auto size = contents_view->GetContainerSize(); - size.Enlarge(-kWindowInset, -kWindowInset); - gfx::CenterAndSizeWindow(contents_view->GetNativeView(), - devtools_window_->hwnd(), - size); - - ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL); } void InspectableWebContentsViewWin::CloseDevTools() { - container_->CloseDevTools(); - return; - - if (!devtools_window_) - return; - SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); + if (undocked_) + SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); + else + container_->CloseDevTools(); } bool InspectableWebContentsViewWin::IsDevToolsViewShowing() { @@ -193,7 +191,20 @@ bool InspectableWebContentsViewWin::IsDevToolsViewShowing() { } bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { - return container_->SetDockSide(side); + if (side == "undocked") { + undocked_ = true; + container_->CloseDevTools(); + } else if (side == "right" || side == "bottom") { + undocked_ = false; + if (devtools_window_) + SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); + container_->SetDockSide(side); + } else { + return false; + } + + ShowDevTools(); + return true; } } // namespace brightray diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index e7d288affda..e55bbaac090 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -40,8 +40,8 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; + bool undocked_; scoped_ptr container_; - base::WeakPtr devtools_window_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewWin); From 1b274a1fd69d204bbfa63c8c3e4667a3b157bcde Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Jun 2014 12:44:30 +0800 Subject: [PATCH 0285/1195] Add comments on the usage of attached devtools. --- .../browser/win/inspectable_web_contents_view_win.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h index e55bbaac090..5f1321ae418 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ b/brightray/browser/win/inspectable_web_contents_view_win.h @@ -23,7 +23,16 @@ class InspectableWebContentsViewWin : public InspectableWebContentsView { InspectableWebContentsImpl* inspectable_web_contents_impl); ~InspectableWebContentsViewWin(); + // Returns the container control, which has devtools view attached. Unlike + // GetNativeView(), this returns a views::View instead of HWND, and can only + // be used by applications that use the views library, if you don't use the + // views library, you probably want to set dock side to "undocked" before + // showing the devtools, because devtools is showed attached by default and + // attached devtools is currently only supported when using views library. views::View* GetView() const; + + // Returns the web view control, which can be used by the + // GetInitiallyFocusedView() to set initial focus to web view. views::View* GetWebView() const; virtual gfx::NativeView GetNativeView() const OVERRIDE; From e71927c5da23fe3a6d1468234ff432e2d92e4256 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 17 Jun 2014 16:50:25 +0800 Subject: [PATCH 0286/1195] Closing devtools window means it is not visible. --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index edc455c2fd7..af78def9899 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -232,6 +232,7 @@ void SetActive(content::WebContents* web_contents, bool active) { #pragma mark - NSWindowDelegate - (BOOL)windowShouldClose:(id)sender { + _private->visible = NO; [_private->window orderOut:nil]; return NO; } From 92a4b25e472653b7f854c2fc18983d77fce37cef Mon Sep 17 00:00:00 2001 From: Rus Maxham Date: Mon, 23 Jun 2014 12:48:52 -0700 Subject: [PATCH 0287/1195] - remember position and size of developer tools window --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index af78def9899..da264327e6e 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -156,6 +156,7 @@ void SetActive(content::WebContents* web_contents, bool active) { _private->window.delegate = self; _private->window.releasedWhenClosed = NO; _private->window.title = @"Developer Tools"; + _private->window.frameAutosaveName = @"Developer Tools"; [_private->window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; [_private->window setContentBorderThickness:24 forEdge:NSMaxYEdge]; } From 3acba90225a42b8f1999fe9466c0b76133d1595b Mon Sep 17 00:00:00 2001 From: Rus Maxham Date: Mon, 23 Jun 2014 13:12:20 -0700 Subject: [PATCH 0288/1195] brightray namespaced frameAutosaveName --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index da264327e6e..84928d7990f 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -156,7 +156,7 @@ void SetActive(content::WebContents* web_contents, bool active) { _private->window.delegate = self; _private->window.releasedWhenClosed = NO; _private->window.title = @"Developer Tools"; - _private->window.frameAutosaveName = @"Developer Tools"; + _private->window.frameAutosaveName = @"brightray.developer.tools"; [_private->window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; [_private->window setContentBorderThickness:24 forEdge:NSMaxYEdge]; } @@ -188,7 +188,7 @@ void SetActive(content::WebContents* web_contents, bool active) { if (!devToolsWebContents) return NO; auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); - + return _private->window && devToolsView.window == _private->window; } @@ -200,7 +200,7 @@ void SetActive(content::WebContents* web_contents, bool active) { SetActive(inspectable_contents->devtools_web_contents(), active); return; } - + // Changes the window that hosts us always affect our main web contents. If the dev tools are also // hosted in this window, they are affected too. SetActive(inspectable_contents->GetWebContents(), active); From cca71fce9f180a478c19558b98e676ca24dbb644 Mon Sep 17 00:00:00 2001 From: Rus Maxham Date: Mon, 23 Jun 2014 13:16:01 -0700 Subject: [PATCH 0289/1195] less removal of whitespace --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 84928d7990f..4a8b9fd94c0 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -188,7 +188,7 @@ void SetActive(content::WebContents* web_contents, bool active) { if (!devToolsWebContents) return NO; auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); - + return _private->window && devToolsView.window == _private->window; } @@ -200,7 +200,7 @@ void SetActive(content::WebContents* web_contents, bool active) { SetActive(inspectable_contents->devtools_web_contents(), active); return; } - + // Changes the window that hosts us always affect our main web contents. If the dev tools are also // hosted in this window, they are affected too. SetActive(inspectable_contents->GetWebContents(), active); From 55cfef4432bef7ad14854afbf427caa715c19726 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 27 Jun 2014 11:54:15 -0400 Subject: [PATCH 0290/1195] Update libchromiumcontent to Chrome 35 * vendor/libchromiumcontent 656be94...ded3c0a (1): > Merge pull request #47 from brightray/chrome35 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 656be940848..ded3c0ad1d3 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 656be9408484de40ba4938ef47acdebeec8a1784 +Subproject commit ded3c0ad1d36cc900d94c7587a88d1b959ebc1c7 From ad0a5bdf80d74b74e2817c437ea9c1c2419e5944 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:10:35 -0400 Subject: [PATCH 0291/1195] Include Chrome's Skia config, not the default one This ensures we get Chrome's Skia settings. --- brightray/brightray.gyp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 8dd2a64ce08..3a5079c0573 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -12,15 +12,14 @@ 'include_dirs': [ '.', '<(libchromiumcontent_include_dir)', - '<(libchromiumcontent_include_dir)/third_party/skia/include/config', + '<(libchromiumcontent_include_dir)/skia/config', '<(libchromiumcontent_include_dir)/third_party/skia/include/core', ], 'direct_dependent_settings': { 'include_dirs': [ '..', '<(libchromiumcontent_include_dir)', - '<(libchromiumcontent_include_dir)/third_party/skia/include/config', - # For SkMatrix.h. + '<(libchromiumcontent_include_dir)/skia/config', '<(libchromiumcontent_include_dir)/third_party/skia/include/core', '<(libchromiumcontent_include_dir)/third_party/icu/source/common', ], From 202f7bcd4175339801d53cb19ff645d5dea31949 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:11:02 -0400 Subject: [PATCH 0292/1195] Fix include paths for WebIconURL.h It contains #include "public/platform/WebSize.h", so we have to set up the include path to make that work. --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 3a5079c0573..5925fc0f7c1 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -14,6 +14,7 @@ '<(libchromiumcontent_include_dir)', '<(libchromiumcontent_include_dir)/skia/config', '<(libchromiumcontent_include_dir)/third_party/skia/include/core', + '<(libchromiumcontent_include_dir)/third_party/WebKit', ], 'direct_dependent_settings': { 'include_dirs': [ @@ -22,6 +23,7 @@ '<(libchromiumcontent_include_dir)/skia/config', '<(libchromiumcontent_include_dir)/third_party/skia/include/core', '<(libchromiumcontent_include_dir)/third_party/icu/source/common', + '<(libchromiumcontent_include_dir)/third_party/WebKit', ], }, 'sources': [ From 500861d63d40323be0559a1d1aa8440f823d51ce Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:25:30 -0400 Subject: [PATCH 0293/1195] Update prefs code for Chrome 35 See https://codereview.chromium.org/64193003 --- brightray/browser/browser_context.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 4970530d7bf..cef50925de3 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -16,7 +16,7 @@ #include "base/prefs/json_pref_store.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" -#include "base/prefs/pref_service_builder.h" +#include "base/prefs/pref_service_factory.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" @@ -76,8 +76,8 @@ void BrowserContext::Initialize() { path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); - PrefServiceBuilder builder; - builder.WithUserFilePrefs(prefs_path, + base::PrefServiceFactory prefs_factory; + prefs_factory.SetUserPrefsFile(prefs_path, JsonPrefStore::GetTaskRunnerForFile( prefs_path, content::BrowserThread::GetBlockingPool())); @@ -85,7 +85,7 @@ void BrowserContext::Initialize() { RegisterInternalPrefs(registry); RegisterPrefs(registry); - prefs_.reset(builder.Create(registry)); + prefs_ = prefs_factory.Create(registry); } BrowserContext::~BrowserContext() { From 42b86242ea52cb42b2dc363bcb510a947d4918aa Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:27:22 -0400 Subject: [PATCH 0294/1195] Add support for Chrome 35's "protocol interceptors" See https://codereview.chromium.org/187223003 --- brightray/browser/browser_client.cc | 5 +++-- brightray/browser/browser_client.h | 4 +++- brightray/browser/browser_context.cc | 6 +++-- brightray/browser/browser_context.h | 3 ++- .../browser/url_request_context_getter.cc | 22 ++++++++++++++++--- .../browser/url_request_context_getter.h | 4 +++- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 82c0d7acb5f..fabd51cc74c 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -56,9 +56,10 @@ content::BrowserMainParts* BrowserClient::CreateBrowserMainParts( net::URLRequestContextGetter* BrowserClient::CreateRequestContext( content::BrowserContext* browser_context, - content::ProtocolHandlerMap* protocol_handlers) { + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector protocol_interceptors) { auto context = static_cast(browser_context); - return context->CreateRequestContext(protocol_handlers); + return context->CreateRequestContext(protocol_handlers, protocol_interceptors.Pass()); } void BrowserClient::ShowDesktopNotification( diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 41a3861f61f..42a7380a63c 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -34,7 +34,9 @@ class BrowserClient : public content::ContentBrowserClient { // Subclasses that override this (e.g., to provide their own protocol // handlers) should call this implementation after doing their own work. virtual net::URLRequestContextGetter* CreateRequestContext( - content::BrowserContext*, content::ProtocolHandlerMap*) OVERRIDE; + content::BrowserContext* browser_context, + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE; private: virtual content::BrowserMainParts* CreateBrowserMainParts( diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index cef50925de3..f2bd0e82923 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -99,7 +99,8 @@ void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { } net::URLRequestContextGetter* BrowserContext::CreateRequestContext( - content::ProtocolHandlerMap* protocol_handlers) { + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector protocol_interceptors) { DCHECK(!url_request_getter_); auto io_loop = content::BrowserThread::UnsafeGetMessageLoopForThread( content::BrowserThread::IO); @@ -110,7 +111,8 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( io_loop, file_loop, base::Bind(&BrowserContext::CreateNetworkDelegate, base::Unretained(this)), - protocol_handlers); + protocol_handlers, + protocol_interceptors.Pass()); resource_context_->set_url_request_context_getter(url_request_getter_.get()); return url_request_getter_.get(); } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index b92deb75c57..667d6a4802f 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -25,7 +25,8 @@ class BrowserContext : public content::BrowserContext { virtual void Initialize(); net::URLRequestContextGetter* CreateRequestContext( - content::ProtocolHandlerMap*); + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector protocol_interceptors); PrefService* prefs() { return prefs_.get(); } diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 4b26d7a9364..0e590aa5429 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -29,6 +29,7 @@ #include "net/ssl/ssl_config_service_defaults.h" #include "net/url_request/data_protocol_handler.h" #include "net/url_request/file_protocol_handler.h" +#include "net/url_request/protocol_intercept_job_factory.h" #include "net/url_request/static_http_user_agent_settings.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_storage.h" @@ -41,11 +42,13 @@ URLRequestContextGetter::URLRequestContextGetter( base::MessageLoop* io_loop, base::MessageLoop* file_loop, base::Callback(void)> network_delegate_factory, - content::ProtocolHandlerMap* protocol_handlers) + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector protocol_interceptors) : base_path_(base_path), io_loop_(io_loop), file_loop_(file_loop), - network_delegate_factory_(network_delegate_factory) { + network_delegate_factory_(network_delegate_factory), + protocol_interceptors_(protocol_interceptors.Pass()) { // Must first be created on the UI thread. DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); @@ -161,7 +164,20 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { content::BrowserThread::GetBlockingPool()-> GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); - storage_->set_job_factory(job_factory.release()); + + // Set up interceptors in the reverse order. + scoped_ptr top_job_factory = + job_factory.PassAs(); + for (content::ProtocolHandlerScopedVector::reverse_iterator i = + protocol_interceptors_.rbegin(); + i != protocol_interceptors_.rend(); + ++i) { + top_job_factory.reset(new net::ProtocolInterceptJobFactory( + top_job_factory.Pass(), make_scoped_ptr(*i))); + } + protocol_interceptors_.weak_clear(); + + storage_->set_job_factory(top_job_factory.release()); } return url_request_context_.get(); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 7d3e174cd40..ad09e2b409c 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -32,7 +32,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { base::MessageLoop* io_loop, base::MessageLoop* file_loop, base::Callback(void)>, - content::ProtocolHandlerMap*); + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector protocol_interceptors); virtual ~URLRequestContextGetter(); net::HostResolver* host_resolver(); @@ -53,6 +54,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr storage_; scoped_ptr url_request_context_; content::ProtocolHandlerMap protocol_handlers_; + content::ProtocolHandlerScopedVector protocol_interceptors_; DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter); }; From 5b93dc74e6ce01ff4a5a6ae2b7e022976cebceb5 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:27:58 -0400 Subject: [PATCH 0295/1195] Update BrowserContext for Chrome 35 --- brightray/browser/browser_context.cc | 26 ++++++++++++++++++++++++-- brightray/browser/browser_context.h | 19 +++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index f2bd0e82923..d82f4bc256e 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -155,14 +155,36 @@ net::URLRequestContextGetter* return GetRequestContext(); } -void BrowserContext::RequestMIDISysExPermission( +void BrowserContext::RequestMidiSysExPermission( int render_process_id, int render_view_id, + int bridge_id, const GURL& requesting_frame, - const MIDISysExPermissionCallback& callback) { + bool user_gesture, + const MidiSysExPermissionCallback& callback) { callback.Run(false); } +void BrowserContext::CancelMidiSysExPermissionRequest( + int render_process_id, + int render_view_id, + int bridge_id, + const GURL& requesting_frame) { +} + +void BrowserContext::RequestProtectedMediaIdentifierPermission( + int render_process_id, + int render_view_id, + int bridge_id, + int group_id, + const GURL& requesting_frame, + const ProtectedMediaIdentifierPermissionCallback& callback) { + callback.Run(false); +} + +void BrowserContext::CancelProtectedMediaIdentifierPermissionRequests(int group_id) { +} + content::ResourceContext* BrowserContext::GetResourceContext() { return resource_context_.get(); } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 667d6a4802f..a43d2380da1 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -55,11 +55,26 @@ class BrowserContext : public content::BrowserContext { virtual net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory); - virtual void RequestMIDISysExPermission( + virtual void RequestMidiSysExPermission( int render_process_id, int render_view_id, + int bridge_id, const GURL& requesting_frame, - const MIDISysExPermissionCallback&) OVERRIDE; + bool user_gesture, + const MidiSysExPermissionCallback& callback) OVERRIDE; + virtual void CancelMidiSysExPermissionRequest( + int render_process_id, + int render_view_id, + int bridge_id, + const GURL& requesting_frame) OVERRIDE; + virtual void RequestProtectedMediaIdentifierPermission( + int render_process_id, + int render_view_id, + int bridge_id, + int group_id, + const GURL& requesting_frame, + const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE; + virtual void CancelProtectedMediaIdentifierPermissionRequests(int group_id) OVERRIDE; virtual content::ResourceContext* GetResourceContext() OVERRIDE; virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; From 5b788476a569949348e07b82ad85fa7f7d033c8b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:29:38 -0400 Subject: [PATCH 0296/1195] Update for move of string symbols into base:: --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- brightray/browser/network_delegate.cc | 2 +- brightray/browser/network_delegate.h | 2 +- brightray/browser/url_request_context_getter.cc | 2 +- brightray/common/content_client.cc | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 1ccb4e1054d..739acf44ecb 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -117,7 +117,7 @@ void InspectableWebContentsImpl::UpdateFrontendDockSide() { auto javascript = base::StringPrintf( "InspectorFrontendAPI.setDockSide(\"%s\")", dock_side_.c_str()); devtools_web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( - string16(), ASCIIToUTF16(javascript)); + base::string16(), base::ASCIIToUTF16(javascript)); } void InspectableWebContentsImpl::ActivateWindow() { diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index 6467dc3e3d6..a915752b382 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -59,7 +59,7 @@ void NetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { } void NetworkDelegate::OnPACScriptError(int line_number, - const string16& error) { + const base::string16& error) { } NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired( diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 0d4f2d3600c..3e258ac14f1 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -37,7 +37,7 @@ class NetworkDelegate : public net::NetworkDelegate { virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE; virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE; virtual void OnPACScriptError(int line_number, - const string16& error) OVERRIDE; + const base::string16& error) OVERRIDE; virtual AuthRequiredResponse OnAuthRequired( net::URLRequest* request, const net::AuthChallengeInfo& auth_info, diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 0e590aa5429..47debda7ae9 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -85,7 +85,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { base::WorkerPool::GetTaskRunner(true))); storage_->set_http_user_agent_settings( new net::StaticHttpUserAgentSettings( - "en-us,en", EmptyString())); + "en-us,en", base::EmptyString())); scoped_ptr host_resolver( net::HostResolver::CreateDefaultResolver(NULL)); diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index dd6ce530690..3fd5f930183 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -21,7 +21,7 @@ ContentClient::~ContentClient() { std::string ContentClient::GetProduct() const { auto name = GetApplicationName(); - RemoveChars(name, kWhitespaceASCII, &name); + base::RemoveChars(name, base::kWhitespaceASCII, &name); return base::StringPrintf("%s/%s", name.c_str(), GetApplicationVersion().c_str()); } From e003cc9a0a20a17906cdae35fb9900ed0bab808d Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:31:32 -0400 Subject: [PATCH 0297/1195] Update MediaCaptureDevicesDispatcher for Chrome 35 See https://codereview.chromium.org/183743021 --- .../media/media_capture_devices_dispatcher.cc | 72 +++++++------------ .../media/media_capture_devices_dispatcher.h | 33 +++------ 2 files changed, 37 insertions(+), 68 deletions(-) diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index eb3e6731a27..65ea4b94be9 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -6,8 +6,7 @@ #include "base/logging.h" #include "content/public/browser/browser_thread.h" -#include "content/public/browser/media_devices_monitor.h" -#include "content/public/common/desktop_media_id.h" +#include "content/public/browser/media_capture_devices.h" #include "content/public/common/media_stream_request.h" namespace brightray { @@ -30,6 +29,11 @@ const content::MediaStreamDevice* FindDeviceWithId( return NULL; } +const MediaStreamDevices& EmptyDevices() { + static MediaStreamDevices* devices = new MediaStreamDevices; + return *devices; +} + } // namespace MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { @@ -37,8 +41,7 @@ MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { } MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() - : devices_enumerated_(false), - is_device_enumeration_disabled_(false) { + : is_device_enumeration_disabled_(false) { // MediaCaptureDevicesDispatcher is a singleton. It should be created on // UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -49,21 +52,17 @@ MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {} const MediaStreamDevices& MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!is_device_enumeration_disabled_ && !devices_enumerated_) { - content::EnsureMonitorCaptureDevices(); - devices_enumerated_ = true; - } - return audio_devices_; + if (is_device_enumeration_disabled_) + return EmptyDevices(); + return content::MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices(); } const MediaStreamDevices& MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - if (!is_device_enumeration_disabled_ && !devices_enumerated_) { - content::EnsureMonitorCaptureDevices(); - devices_enumerated_ = true; - } - return video_devices_; + if (is_device_enumeration_disabled_) + return EmptyDevices(); + return content::MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices(); } void MediaCaptureDevicesDispatcher::GetDefaultDevices( @@ -128,36 +127,33 @@ void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() { is_device_enumeration_disabled_ = true; } -void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged( - const content::MediaStreamDevices& devices) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread, - base::Unretained(this), devices)); +void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() { } -void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged( - const content::MediaStreamDevices& devices) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread, - base::Unretained(this), devices)); +void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() { } void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( int render_process_id, int render_view_id, int page_request_id, + const GURL& security_origin, const content::MediaStreamDevice& device, content::MediaRequestState state) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); } -void MediaCaptureDevicesDispatcher::OnAudioStreamPlayingChanged( - int render_process_id, int render_view_id, int stream_id, - bool is_playing, float power_dbfs, bool clipped) { +void MediaCaptureDevicesDispatcher::OnAudioStreamPlaying( + int render_process_id, + int render_frame_id, + int stream_id, + const ReadPowerAndClipCallback& power_read_callback) { +} + +void MediaCaptureDevicesDispatcher::OnAudioStreamStopped( + int render_process_id, + int render_frame_id, + int stream_id) { } void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( @@ -166,18 +162,4 @@ void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); } -void MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread( - const content::MediaStreamDevices& devices) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - devices_enumerated_ = true; - audio_devices_ = devices; -} - -void MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread( - const content::MediaStreamDevices& devices) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - devices_enumerated_ = true; - video_devices_ = devices; -} - } // namespace brightray diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index d10c27df1bc..3b29fae4701 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -51,23 +51,24 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { void DisableDeviceEnumerationForTesting(); // Overridden from content::MediaObserver: - virtual void OnAudioCaptureDevicesChanged( - const content::MediaStreamDevices& devices) OVERRIDE; - virtual void OnVideoCaptureDevicesChanged( - const content::MediaStreamDevices& devices) OVERRIDE; + virtual void OnAudioCaptureDevicesChanged() OVERRIDE; + virtual void OnVideoCaptureDevicesChanged() OVERRIDE; virtual void OnMediaRequestStateChanged( int render_process_id, int render_view_id, int page_request_id, + const GURL& security_origin, const content::MediaStreamDevice& device, content::MediaRequestState state) OVERRIDE; - virtual void OnAudioStreamPlayingChanged( + virtual void OnAudioStreamPlaying( int render_process_id, - int render_view_id, + int render_frame_id, int stream_id, - bool is_playing, - float power_dBFS, - bool clipped) OVERRIDE; + const ReadPowerAndClipCallback& power_read_callback) OVERRIDE; + virtual void OnAudioStreamStopped( + int render_process_id, + int render_frame_id, + int stream_id) OVERRIDE; virtual void OnCreatingAudioStream(int render_process_id, int render_view_id) OVERRIDE; @@ -77,20 +78,6 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { MediaCaptureDevicesDispatcher(); virtual ~MediaCaptureDevicesDispatcher(); - // Called by the MediaObserver() functions, executed on UI thread. - void UpdateAudioDevicesOnUIThread(const content::MediaStreamDevices& devices); - void UpdateVideoDevicesOnUIThread(const content::MediaStreamDevices& devices); - - // A list of cached audio capture devices. - content::MediaStreamDevices audio_devices_; - - // A list of cached video capture devices. - content::MediaStreamDevices video_devices_; - - // Flag to indicate if device enumeration has been done/doing. - // Only accessed on UI thread. - bool devices_enumerated_; - // Flag used by unittests to disable device enumeration. bool is_device_enumeration_disabled_; From 3a71958e16b16db9c648cea97f351be3aef0a96e Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:31:55 -0400 Subject: [PATCH 0298/1195] Update MediaStreamDevicesController for Chrome 35 See https://codereview.chromium.org/180633008 --- brightray/browser/media/media_stream_devices_controller.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index a85c1c928d4..4fd9894eca3 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -41,6 +41,7 @@ MediaStreamDevicesController::MediaStreamDevicesController( MediaStreamDevicesController::~MediaStreamDevicesController() { if (!callback_.is_null()) { callback_.Run(content::MediaStreamDevices(), + content::MEDIA_DEVICE_INVALID_STATE, scoped_ptr()); } } @@ -150,13 +151,13 @@ void MediaStreamDevicesController::Accept() { content::MediaResponseCallback cb = callback_; callback_.Reset(); - cb.Run(devices, scoped_ptr()); + cb.Run(devices, content::MEDIA_DEVICE_OK, scoped_ptr()); } void MediaStreamDevicesController::Deny() { content::MediaResponseCallback cb = callback_; callback_.Reset(); - cb.Run(content::MediaStreamDevices(), scoped_ptr()); + cb.Run(content::MediaStreamDevices(), content::MEDIA_DEVICE_PERMISSION_DENIED, scoped_ptr()); } } // namespace brightray From afc889b88369dceca0d50285ba48d87f23481391 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:33:11 -0400 Subject: [PATCH 0299/1195] Update NetworkDelegate for Chrome 35 --- brightray/browser/network_delegate.cc | 8 ++------ brightray/browser/network_delegate.h | 6 ++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index a915752b382..ec019a5f281 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -37,7 +37,8 @@ int NetworkDelegate::OnHeadersReceived( net::URLRequest* request, const net::CompletionCallback& callback, const net::HttpResponseHeaders* original_response_headers, - scoped_refptr* override_response_headers) { + scoped_refptr* override_response_headers, + GURL* allowed_unsafe_redirect_url) { return net::OK; } @@ -97,9 +98,4 @@ int NetworkDelegate::OnBeforeSocketStreamConnect( return net::OK; } -void NetworkDelegate::OnRequestWaitStateChange( - const net::URLRequest& request, - RequestWaitState waiting) { -} - } // namespace brightray diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 3e258ac14f1..94be71d9852 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -27,8 +27,8 @@ class NetworkDelegate : public net::NetworkDelegate { net::URLRequest* request, const net::CompletionCallback& callback, const net::HttpResponseHeaders* original_response_headers, - scoped_refptr* - override_response_headers) OVERRIDE; + scoped_refptr* override_response_headers, + GURL* allowed_unsafe_redirect_url) OVERRIDE; virtual void OnBeforeRedirect(net::URLRequest* request, const GURL& new_location) OVERRIDE; virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; @@ -55,8 +55,6 @@ class NetworkDelegate : public net::NetworkDelegate { virtual int OnBeforeSocketStreamConnect( net::SocketStream* stream, const net::CompletionCallback& callback) OVERRIDE; - virtual void OnRequestWaitStateChange(const net::URLRequest& request, - RequestWaitState state) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(NetworkDelegate); From 51ac56e4c4a938556733598b250dc4be00e1ac64 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:33:39 -0400 Subject: [PATCH 0300/1195] Update cookie store code for Chrome 35 See https://codereview.chromium.org/110883017 --- brightray/browser/url_request_context_getter.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 47debda7ae9..07bbe9f88bb 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -34,6 +34,7 @@ #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_storage.h" #include "net/url_request/url_request_job_factory_impl.h" +#include "webkit/browser/quota/special_storage_policy.h" namespace brightray { @@ -74,12 +75,12 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { url_request_context_->set_network_delegate(network_delegate_.get()); storage_.reset( new net::URLRequestContextStorage(url_request_context_.get())); - storage_->set_cookie_store(content::CreatePersistentCookieStore( + auto cookie_config = content::CookieStoreConfig( base_path_.Append(FILE_PATH_LITERAL("Cookies")), - false, + content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, nullptr, - nullptr, - nullptr)); + nullptr); + storage_->set_cookie_store(content::CreateCookieStore(cookie_config)); storage_->set_server_bound_cert_service(new net::ServerBoundCertService( new net::DefaultServerBoundCertStore(NULL), base::WorkerPool::GetTaskRunner(true))); @@ -157,9 +158,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } protocol_handlers_.clear(); job_factory->SetProtocolHandler( - chrome::kDataScheme, new net::DataProtocolHandler); + content::kDataScheme, new net::DataProtocolHandler); job_factory->SetProtocolHandler( - chrome::kFileScheme, + content::kFileScheme, new net::FileProtocolHandler( content::BrowserThread::GetBlockingPool()-> GetTaskRunnerWithShutdownBehavior( From 8e7fbd604cb6b7f097d89c0d22d8af3c317d5cd0 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:34:53 -0400 Subject: [PATCH 0301/1195] Update for move of BuildUserAgentFromProduct in Chrome 35 See https://codereview.chromium.org/186883002 --- brightray/common/content_client.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index 3fd5f930183..9d42e350191 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -8,8 +8,8 @@ #include "base/strings/stringprintf.h" #include "base/strings/string_util.h" +#include "content/public/common/user_agent.h" #include "ui/base/resource/resource_bundle.h" -#include "webkit/common/user_agent/user_agent_util.h" namespace brightray { @@ -27,7 +27,7 @@ std::string ContentClient::GetProduct() const { } std::string ContentClient::GetUserAgent() const { - return webkit_glue::BuildUserAgentFromProduct(GetProduct()); + return content::BuildUserAgentFromProduct(GetProduct()); } base::StringPiece ContentClient::GetDataResource( From 9602a9aed9f6c4c10aad8f6689387fa30d00f4f5 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 26 Jun 2014 16:35:27 -0400 Subject: [PATCH 0302/1195] Fix assertion in InitializeICU on launch We have to tell Chromium about our framework bundle earlier in the launch sequence so it can find icudtl.dat. See https://codereview.chromium.org/12470006 --- brightray/common/main_delegate.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index f85c769bafc..ea0cbdddb5a 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -27,14 +27,14 @@ scoped_ptr MainDelegate::CreateContentClient() { bool MainDelegate::BasicStartupComplete(int* exit_code) { content_client_ = CreateContentClient().Pass(); SetContentClient(content_client_.get()); - return false; -} - -void MainDelegate::PreSandboxStartup() { #if defined(OS_MACOSX) OverrideChildProcessPath(); OverrideFrameworkBundlePath(); #endif + return false; +} + +void MainDelegate::PreSandboxStartup() { InitializeResourceBundle(); } From 918f38e13fe6d2b6b21646acf2ab614b26e99270 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 27 Jun 2014 11:59:01 -0400 Subject: [PATCH 0303/1195] Fix long line --- brightray/browser/media/media_stream_devices_controller.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index 4fd9894eca3..22fb0d1310d 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -157,7 +157,9 @@ void MediaStreamDevicesController::Accept() { void MediaStreamDevicesController::Deny() { content::MediaResponseCallback cb = callback_; callback_.Reset(); - cb.Run(content::MediaStreamDevices(), content::MEDIA_DEVICE_PERMISSION_DENIED, scoped_ptr()); + cb.Run(content::MediaStreamDevices(), + content::MEDIA_DEVICE_PERMISSION_DENIED, + scoped_ptr()); } } // namespace brightray From f8b44a1785928d4691d44896d33706a940f9be15 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 27 Jun 2014 12:06:13 -0400 Subject: [PATCH 0304/1195] Use the MSBuild that comes with Visual Studio See http://msdn.microsoft.com/en-us/library/hh162058.aspx --- brightray/script/build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/script/build b/brightray/script/build index b13f892b64f..f337c37615b 100755 --- a/brightray/script/build +++ b/brightray/script/build @@ -25,7 +25,8 @@ def build(): return subprocess.call(['make']) assert sys.platform == 'win32', sys.platform - msbuild = os.path.join(os.environ['windir'], 'Microsoft.NET', 'Framework', 'v4.0.30319', 'MSBuild.exe') + program_files = os.environ.get('PROGRAMFILES(X86)', os.environ['PROGRAMFILES']) + msbuild = os.path.join(program_files, 'MSBuild', '12.0', 'Bin', 'MSBuild.exe') return subprocess.call([msbuild, 'brightray.sln']) From 78dd3390f5c548df20696ca059b1cb38078718e3 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 27 Jun 2014 13:40:06 -0400 Subject: [PATCH 0305/1195] Define USE_AURA for Windows This is true inside of libchromiumcontent, so we need to mirror that here. --- brightray/brightray.gypi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index daf5f2737cf..7edb5f9dbde 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -77,6 +77,11 @@ }, }, 'conditions': [ + ['OS=="win"', { + 'defines': [ + 'USE_AURA', + ], + }], ['OS not in ["mac", "win"]', { 'defines': [ 'USE_X11', From 307d936d759decce731427c2ad03b25c49fccf67 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 27 Jun 2014 13:40:33 -0400 Subject: [PATCH 0306/1195] Update to use CR_* Windows message macros See https://codereview.chromium.org/146833020. --- brightray/browser/win/devtools_window.cc | 6 +++--- brightray/browser/win/devtools_window.h | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/brightray/browser/win/devtools_window.cc b/brightray/browser/win/devtools_window.cc index 9fc4b5dba88..96d0a304847 100644 --- a/brightray/browser/win/devtools_window.cc +++ b/brightray/browser/win/devtools_window.cc @@ -20,7 +20,7 @@ DevToolsWindow::DevToolsWindow(InspectableWebContentsViewWin* controller) DevToolsWindow::~DevToolsWindow() { } -LRESULT DevToolsWindow::OnCreate(UINT, WPARAM, LPARAM, BOOL&) { +LRESULT DevToolsWindow::OnCreate(UINT, WPARAM, LPARAM) { auto devtools_web_contents = controller_->inspectable_web_contents()->devtools_web_contents(); SetParent(devtools_web_contents->GetView()->GetNativeView(), hwnd()); @@ -28,7 +28,7 @@ LRESULT DevToolsWindow::OnCreate(UINT, WPARAM, LPARAM, BOOL&) { return 0; } -LRESULT DevToolsWindow::OnDestroy(UINT, WPARAM, LPARAM, BOOL&) { +LRESULT DevToolsWindow::OnDestroy(UINT, WPARAM, LPARAM) { auto devtools_web_contents = controller_->inspectable_web_contents()->devtools_web_contents(); SetParent( @@ -37,7 +37,7 @@ LRESULT DevToolsWindow::OnDestroy(UINT, WPARAM, LPARAM, BOOL&) { return 0; } -LRESULT DevToolsWindow::OnSize(UINT, WPARAM, LPARAM, BOOL&) { +LRESULT DevToolsWindow::OnSize(UINT, WPARAM, LPARAM) { RECT rect; GetClientRect(hwnd(), &rect); diff --git a/brightray/browser/win/devtools_window.h b/brightray/browser/win/devtools_window.h index a6b11bb11e0..a7e34d2b738 100644 --- a/brightray/browser/win/devtools_window.h +++ b/brightray/browser/win/devtools_window.h @@ -14,20 +14,20 @@ class DevToolsWindow : public gfx::WindowImpl, static DevToolsWindow* Create( InspectableWebContentsViewWin* inspectable_web_contents_view_win); - BEGIN_MSG_MAP_EX(DevToolsWindow) - MESSAGE_HANDLER(WM_CREATE, OnCreate) - MESSAGE_HANDLER(WM_DESTROY, OnDestroy) - MESSAGE_HANDLER(WM_SIZE, OnSize) - END_MSG_MAP() + CR_BEGIN_MSG_MAP_EX(DevToolsWindow) + CR_MESSAGE_HANDLER_EX(WM_CREATE, OnCreate) + CR_MESSAGE_HANDLER_EX(WM_DESTROY, OnDestroy) + CR_MESSAGE_HANDLER_EX(WM_SIZE, OnSize) + CR_END_MSG_MAP() private: explicit DevToolsWindow( InspectableWebContentsViewWin* inspectable_web_contents_view_win); ~DevToolsWindow(); - LRESULT OnCreate(UINT message, WPARAM, LPARAM, BOOL& handled); - LRESULT OnDestroy(UINT message, WPARAM, LPARAM, BOOL& handled); - LRESULT OnSize(UINT message, WPARAM, LPARAM, BOOL& handled); + LRESULT OnCreate(UINT message, WPARAM, LPARAM); + LRESULT OnDestroy(UINT message, WPARAM, LPARAM); + LRESULT OnSize(UINT message, WPARAM, LPARAM); InspectableWebContentsViewWin* controller_; From 08c017bd7df962faa6599b63700859ff9a47a194 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 27 Jun 2014 13:45:04 -0400 Subject: [PATCH 0307/1195] Ignore a couple more files on Windows --- brightray/.gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/.gitignore b/brightray/.gitignore index 3f04a5e2f1b..859306a729e 100644 --- a/brightray/.gitignore +++ b/brightray/.gitignore @@ -2,6 +2,8 @@ /brightray.sdf /brightray.sln /brightray.vcxproj* +/brightray.suo +/brightray.v12.suo /brightray.xcodeproj/ /build/ From 1269e59a352ab94ef44591d52c40fea4970cbf83 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Fri, 27 Jun 2014 14:02:44 -0400 Subject: [PATCH 0308/1195] Update for move of string conversion functions into base:: --- brightray/common/application_info_win.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/common/application_info_win.cc b/brightray/common/application_info_win.cc index 696d8b36b5e..fd18d54b0ca 100644 --- a/brightray/common/application_info_win.cc +++ b/brightray/common/application_info_win.cc @@ -10,14 +10,14 @@ std::string GetApplicationName() { auto module = GetModuleHandle(nullptr); auto info = make_scoped_ptr( FileVersionInfo::CreateFileVersionInfoForModule(module)); - return UTF16ToUTF8(info->product_name()); + return base::UTF16ToUTF8(info->product_name()); } std::string GetApplicationVersion() { auto module = GetModuleHandle(nullptr); auto info = make_scoped_ptr( FileVersionInfo::CreateFileVersionInfoForModule(module)); - return UTF16ToUTF8(info->product_version()); + return base::UTF16ToUTF8(info->product_version()); } } // namespace brightray From ae1995f849aac92ec768361e73ad0ae56ee2bdbb Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Jul 2014 12:27:38 -0400 Subject: [PATCH 0309/1195] Update libchromiumcontent for better Chrome 35 support * vendor/libchromiumcontent ded3c0a...331dbed (2): > Merge pull request #48 from brightray/chrome35-brightray > Merge pull request #49 from brightray/linux-fix --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index ded3c0ad1d3..331dbed4467 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit ded3c0ad1d36cc900d94c7587a88d1b959ebc1c7 +Subproject commit 331dbed44676c534faf21f7db1985e796260649a From 8fd78b3593c9cb19d211bde76e248d9cf94fae39 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Jul 2014 12:28:10 -0400 Subject: [PATCH 0310/1195] Pull in generated headers from libchromiumcontent ui/views/view.h now includes ui/accessibility/ax_enums.h, which is a generated header. --- brightray/brightray.gyp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 5925fc0f7c1..3f52db663c9 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -15,15 +15,18 @@ '<(libchromiumcontent_include_dir)/skia/config', '<(libchromiumcontent_include_dir)/third_party/skia/include/core', '<(libchromiumcontent_include_dir)/third_party/WebKit', + '<(libchromiumcontent_library_dir)/gen', ], 'direct_dependent_settings': { 'include_dirs': [ + '.', '..', '<(libchromiumcontent_include_dir)', '<(libchromiumcontent_include_dir)/skia/config', '<(libchromiumcontent_include_dir)/third_party/skia/include/core', '<(libchromiumcontent_include_dir)/third_party/icu/source/common', '<(libchromiumcontent_include_dir)/third_party/WebKit', + '<(libchromiumcontent_library_dir)/gen', ], }, 'sources': [ From a1cf58f811a6068aebfa9e2df4b456f62514435b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Jul 2014 13:53:02 -0400 Subject: [PATCH 0311/1195] Link against chromiumviews This is needed for InspectableWebContentsViewWin. --- brightray/brightray.gyp | 1 + brightray/brightray.gypi | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 3f52db663c9..d7ae15b9ffc 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -117,6 +117,7 @@ 'link_settings': { 'libraries': [ '<(brightray_source_root)/<(libchromiumcontent_library_dir)/base_static.lib', + '<(brightray_source_root)/<(libchromiumcontent_library_dir)/chromiumviews.lib', '<(brightray_source_root)/<(libchromiumcontent_library_dir)/chromiumcontent.dll.lib', '<(brightray_source_root)/<(libchromiumcontent_library_dir)/sandbox_static.lib', ], diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 7edb5f9dbde..b73a7ea0765 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -72,6 +72,9 @@ 'VCLinkerTool': { 'AdditionalDependencies': [ 'advapi32.lib', + 'dwmapi.lib', + 'gdi32.lib', + 'oleacc.lib', 'user32.lib', ], }, @@ -80,6 +83,8 @@ ['OS=="win"', { 'defines': [ 'USE_AURA', + 'VIEWS_IMPLEMENTATION', + 'WEBVIEW_IMPLEMENTATION', ], }], ['OS not in ["mac", "win"]', { From 6bae1f4b44874299dd7a54abde25c5224479bb8b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Jul 2014 13:53:24 -0400 Subject: [PATCH 0312/1195] Set up a native screen on Windows This is needed to prevent a crash inside aura::WindowTreeHost::InitCompositor. --- brightray/browser/browser_main_parts.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 8601b0426cd..ceee0d51e6a 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -7,6 +7,8 @@ #include "browser/browser_context.h" #include "browser/web_ui_controller_factory.h" #include "net/proxy/proxy_resolver_v8.h" +#include "ui/gfx/screen.h" +#include "ui/views/widget/desktop_aura/desktop_screen.h" namespace brightray { @@ -24,6 +26,10 @@ void BrowserMainParts::PreMainMessageLoopRun() { new WebUIControllerFactory(browser_context_.get())); content::WebUIControllerFactory::RegisterFactory( web_ui_controller_factory_.get()); + +#if defined(OS_WIN) + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); +#endif } void BrowserMainParts::PostMainMessageLoopRun() { From 5b2a62627e3dbe041bd86983b9853a933f1f364c Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Jul 2014 13:55:10 -0400 Subject: [PATCH 0313/1195] Silence unused variable warning on Windows --- brightray/browser/url_request_context_getter.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 07bbe9f88bb..ceddfb14acf 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -154,6 +154,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { end = protocol_handlers_.end(); it != end; ++it) { bool set_protocol = job_factory->SetProtocolHandler( it->first, it->second.release()); + ALLOW_UNUSED(set_protocol); DCHECK(set_protocol); } protocol_handlers_.clear(); From 8f2a2e19b50aaf04a5a443e8815a1af8a2650ed4 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Jul 2014 14:21:40 -0400 Subject: [PATCH 0314/1195] Really fix unused-variable warnings I misunderstood how ALLOW_UNUSED is meant to be used. Using a macro like MSV_WARNING_SUPPRESS() would be nice, but for some reason it isn't working for me. So now we just manually reference the variable in the code. --- brightray/browser/url_request_context_getter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index ceddfb14acf..c5cb1061ca9 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -154,8 +154,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { end = protocol_handlers_.end(); it != end; ++it) { bool set_protocol = job_factory->SetProtocolHandler( it->first, it->second.release()); - ALLOW_UNUSED(set_protocol); DCHECK(set_protocol); + (void)set_protocol; // silence unused-variable warning in Release builds on Windows } protocol_handlers_.clear(); job_factory->SetProtocolHandler( From f65246b3cd8fa2e4601139e921855c935893a807 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Jul 2014 14:27:02 -0400 Subject: [PATCH 0315/1195] Fix coding style --- brightray/browser/url_request_context_getter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index c5cb1061ca9..578f5a3047a 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -155,7 +155,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { bool set_protocol = job_factory->SetProtocolHandler( it->first, it->second.release()); DCHECK(set_protocol); - (void)set_protocol; // silence unused-variable warning in Release builds on Windows + (void)set_protocol; // silence unused-variable warning in Release builds on Windows } protocol_handlers_.clear(); job_factory->SetProtocolHandler( From e86c409e6bca7ac32490999955a1df128b93e5cb Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Jul 2014 14:27:23 -0400 Subject: [PATCH 0316/1195] Update DevToolsWindow to use views and aura This is required to make it work in Chrome 35. --- brightray/browser/win/devtools_window.cc | 69 +++++++++++-------- brightray/browser/win/devtools_window.h | 22 +++--- .../win/inspectable_web_contents_view_win.cc | 19 ++--- 3 files changed, 55 insertions(+), 55 deletions(-) diff --git a/brightray/browser/win/devtools_window.cc b/brightray/browser/win/devtools_window.cc index 96d0a304847..bce83cc5fbd 100644 --- a/brightray/browser/win/devtools_window.cc +++ b/brightray/browser/win/devtools_window.cc @@ -4,52 +4,63 @@ #include "browser/win/inspectable_web_contents_view_win.h" #include "content/public/browser/web_contents_view.h" -#include "ui/base/win/hidden_window.h" +#include "ui/views/layout/fill_layout.h" +#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" +#include "ui/views/widget/widget_delegate.h" namespace brightray { +namespace { + +class WidgetDelegateView : public views::WidgetDelegateView { + public: + WidgetDelegateView() { + SetLayoutManager(new views::FillLayout); + } + + virtual void DeleteDelegate() OVERRIDE { delete this; } + virtual views::View* GetContentsView() OVERRIDE{ return this; } + virtual bool CanResize() const OVERRIDE { return true; } + virtual bool CanMaximize() const OVERRIDE { return true; } + virtual base::string16 GetWindowTitle() const OVERRIDE { return L"Developer Tools"; } + virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(800, 600); } + virtual gfx::Size GetMinimumSize() OVERRIDE { return gfx::Size(100, 100); } +}; + +} + DevToolsWindow* DevToolsWindow::Create( InspectableWebContentsViewWin* controller) { return new DevToolsWindow(controller); } DevToolsWindow::DevToolsWindow(InspectableWebContentsViewWin* controller) - : controller_(controller) { + : controller_(controller), + widget_(new views::Widget) { + auto delegate_view = new WidgetDelegateView; + views::Widget::InitParams params; + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + params.top_level = true; + params.native_widget = new views::DesktopNativeWidgetAura(widget_.get()); + params.delegate = delegate_view; + widget_->Init(params); + delegate_view->AddChildView(controller->GetView()); + delegate_view->Layout(); } DevToolsWindow::~DevToolsWindow() { } -LRESULT DevToolsWindow::OnCreate(UINT, WPARAM, LPARAM) { - auto devtools_web_contents = - controller_->inspectable_web_contents()->devtools_web_contents(); - SetParent(devtools_web_contents->GetView()->GetNativeView(), hwnd()); - SetWindowText(hwnd(), L"Developer Tools"); - return 0; +void DevToolsWindow::Show() { + widget_->Show(); } -LRESULT DevToolsWindow::OnDestroy(UINT, WPARAM, LPARAM) { - auto devtools_web_contents = - controller_->inspectable_web_contents()->devtools_web_contents(); - SetParent( - devtools_web_contents->GetView()->GetNativeView(), ui::GetHiddenWindow()); +void DevToolsWindow::Close() { + widget_->Hide(); +} + +void DevToolsWindow::Destroy() { delete this; - return 0; -} - -LRESULT DevToolsWindow::OnSize(UINT, WPARAM, LPARAM) { - RECT rect; - GetClientRect(hwnd(), &rect); - - auto devtools_web_contents = - controller_->inspectable_web_contents()->devtools_web_contents(); - SetWindowPos(devtools_web_contents->GetView()->GetNativeView(), - nullptr, - rect.left, rect.top, - rect.right - rect.left, rect.bottom - rect.top, - SWP_NOZORDER | SWP_SHOWWINDOW); - - return 0; } } // namespace brightray diff --git a/brightray/browser/win/devtools_window.h b/brightray/browser/win/devtools_window.h index a7e34d2b738..33c1a4120bc 100644 --- a/brightray/browser/win/devtools_window.h +++ b/brightray/browser/win/devtools_window.h @@ -1,35 +1,33 @@ #ifndef BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ #define BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ +#include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "ui/gfx/win/window_impl.h" + +namespace views { +class Widget; +} namespace brightray { class InspectableWebContentsViewWin; -class DevToolsWindow : public gfx::WindowImpl, - public base::SupportsWeakPtr { +class DevToolsWindow : public base::SupportsWeakPtr { public: static DevToolsWindow* Create( InspectableWebContentsViewWin* inspectable_web_contents_view_win); - CR_BEGIN_MSG_MAP_EX(DevToolsWindow) - CR_MESSAGE_HANDLER_EX(WM_CREATE, OnCreate) - CR_MESSAGE_HANDLER_EX(WM_DESTROY, OnDestroy) - CR_MESSAGE_HANDLER_EX(WM_SIZE, OnSize) - CR_END_MSG_MAP() + void Show(); + void Close(); + void Destroy(); private: explicit DevToolsWindow( InspectableWebContentsViewWin* inspectable_web_contents_view_win); ~DevToolsWindow(); - LRESULT OnCreate(UINT message, WPARAM, LPARAM); - LRESULT OnDestroy(UINT message, WPARAM, LPARAM); - LRESULT OnSize(UINT message, WPARAM, LPARAM); - InspectableWebContentsViewWin* controller_; + scoped_ptr widget_; DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); }; diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc index 24a52b658f7..641725889bf 100644 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ b/brightray/browser/win/inspectable_web_contents_view_win.cc @@ -143,7 +143,7 @@ InspectableWebContentsViewWin::InspectableWebContentsViewWin( InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { if (devtools_window_) - DestroyWindow(devtools_window_->hwnd()); + devtools_window_->Destroy(); } views::View* InspectableWebContentsViewWin::GetView() const { @@ -161,19 +161,10 @@ gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { void InspectableWebContentsViewWin::ShowDevTools() { if (undocked_) { - if (!devtools_window_) { + if (!devtools_window_) devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr(); - devtools_window_->Init(HWND_DESKTOP, gfx::Rect()); - } - auto contents_view = inspectable_web_contents_->GetWebContents()->GetView(); - auto size = contents_view->GetContainerSize(); - size.Enlarge(-kWindowInset, -kWindowInset); - gfx::CenterAndSizeWindow(contents_view->GetNativeView(), - devtools_window_->hwnd(), - size); - - ShowWindow(devtools_window_->hwnd(), SW_SHOWNORMAL); + devtools_window_->Show(); } else { container_->ShowDevTools(); } @@ -181,7 +172,7 @@ void InspectableWebContentsViewWin::ShowDevTools() { void InspectableWebContentsViewWin::CloseDevTools() { if (undocked_) - SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); + devtools_window_->Close(); else container_->CloseDevTools(); } @@ -197,7 +188,7 @@ bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { } else if (side == "right" || side == "bottom") { undocked_ = false; if (devtools_window_) - SendMessage(devtools_window_->hwnd(), WM_CLOSE, 0, 0); + devtools_window_->Close(); container_->SetDockSide(side); } else { return false; From 859051669b15384c4616067e180b1b106ffbf5c7 Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Jul 2014 14:40:22 -0400 Subject: [PATCH 0317/1195] Make sure our copy of gyp is used If gyp is installed on the system, gyp_main.py might find it instead of our own version. --- brightray/script/build | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/script/build b/brightray/script/build index f337c37615b..30ee528230a 100755 --- a/brightray/script/build +++ b/brightray/script/build @@ -15,7 +15,12 @@ def main(): def run_gyp(): - return subprocess.call([sys.executable, GYP, '--depth', '.', 'brightray.gyp']) + env = os.environ.copy() + gyp_pylib = os.path.join(os.path.dirname(GYP), 'pylib') + env['PYTHONPATH'] = os.path.pathsep.join([gyp_pylib, + env.get('PYTHONPATH', '')]) + return subprocess.call([sys.executable, GYP, '--depth', '.', + 'brightray.gyp'], env=env) def build(): From 8f367f6b35559109761316aa66988c04eeda98ce Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Mon, 7 Jul 2014 14:42:30 -0400 Subject: [PATCH 0318/1195] More coding style fixes --- brightray/browser/win/devtools_window.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/win/devtools_window.cc b/brightray/browser/win/devtools_window.cc index bce83cc5fbd..59857057d5a 100644 --- a/brightray/browser/win/devtools_window.cc +++ b/brightray/browser/win/devtools_window.cc @@ -19,7 +19,7 @@ class WidgetDelegateView : public views::WidgetDelegateView { } virtual void DeleteDelegate() OVERRIDE { delete this; } - virtual views::View* GetContentsView() OVERRIDE{ return this; } + virtual views::View* GetContentsView() OVERRIDE { return this; } virtual bool CanResize() const OVERRIDE { return true; } virtual bool CanMaximize() const OVERRIDE { return true; } virtual base::string16 GetWindowTitle() const OVERRIDE { return L"Developer Tools"; } @@ -27,7 +27,7 @@ class WidgetDelegateView : public views::WidgetDelegateView { virtual gfx::Size GetMinimumSize() OVERRIDE { return gfx::Size(100, 100); } }; -} +} // namespace DevToolsWindow* DevToolsWindow::Create( InspectableWebContentsViewWin* controller) { From 7d130c969788a7bf210ee321b3a84b44041889d0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 1 Jul 2014 20:57:49 +0800 Subject: [PATCH 0319/1195] mac: Revert to simplest undocked-only devtools. This makes porting Chrome's devtools easier. --- brightray/brightray.gyp | 1 - .../inspectable_web_contents_view_mac.mm | 5 +- .../mac/bry_inspectable_web_contents_view.h | 22 +- .../mac/bry_inspectable_web_contents_view.mm | 243 +++--------------- ...ry_inspectable_web_contents_view_private.h | 14 - 5 files changed, 59 insertions(+), 226 deletions(-) delete mode 100644 brightray/browser/mac/bry_inspectable_web_contents_view_private.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index d7ae15b9ffc..1c37fe83c25 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -60,7 +60,6 @@ 'browser/mac/bry_application.mm', 'browser/mac/bry_inspectable_web_contents_view.h', 'browser/mac/bry_inspectable_web_contents_view.mm', - 'browser/mac/bry_inspectable_web_contents_view_private.h', 'browser/media/media_capture_devices_dispatcher.cc', 'browser/media/media_capture_devices_dispatcher.h', 'browser/media/media_stream_devices_controller.cc', diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index 54ad9f19404..6ab97117270 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -1,13 +1,13 @@ #import "browser/inspectable_web_contents_view_mac.h" #import "browser/inspectable_web_contents.h" -#import "browser/mac/bry_inspectable_web_contents_view_private.h" +#import "browser/mac/bry_inspectable_web_contents_view.h" #import "content/public/browser/web_contents_view.h" #import namespace brightray { - + InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewMac(inspectable_web_contents); } @@ -18,7 +18,6 @@ InspectableWebContentsViewMac::InspectableWebContentsViewMac(InspectableWebConte } InspectableWebContentsViewMac::~InspectableWebContentsViewMac() { - [view_ removeFromNotificationCenter]; } gfx::NativeView InspectableWebContentsViewMac::GetNativeView() const { diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 5c17e6c0165..f689f1f38cc 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -1,14 +1,24 @@ #import -@class BRYInspectableWebContentsViewPrivate; +#include -@interface BRYInspectableWebContentsView - : NSView { -@private - BRYInspectableWebContentsViewPrivate *_private; +#include "base/mac/scoped_nsobject.h" + +namespace brightray { +class InspectableWebContentsViewMac; } -- (void)removeFromNotificationCenter; +@interface BRYInspectableWebContentsView : NSView { +@private + brightray::InspectableWebContentsViewMac* inspectableWebContentsView_; + base::scoped_nsobject devtools_window_; + BOOL devtools_visible_; +} + +- (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac*)inspectableWebContentsView; - (IBAction)showDevTools:(id)sender; +- (void)setDevToolsVisible:(BOOL)visible; +- (BOOL)isDevToolsVisible; +- (BOOL)setDockSide:(const std::string&)side ; @end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 4a8b9fd94c0..8c463dd325f 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -2,7 +2,6 @@ #import "browser/inspectable_web_contents_impl.h" #import "browser/inspectable_web_contents_view_mac.h" -#import "browser/mac/bry_inspectable_web_contents_view_private.h" #import "content/public/browser/render_widget_host_view.h" #import "content/public/browser/web_contents_view.h" @@ -10,243 +9,83 @@ using namespace brightray; -@interface GraySplitView : NSSplitView -- (NSColor*)dividerColor; -@end - -@implementation GraySplitView -- (NSColor*)dividerColor { - return [NSColor darkGrayColor]; -} -@end - - -@interface BRYInspectableWebContentsViewPrivate : NSObject { -@public - InspectableWebContentsViewMac *inspectableWebContentsView; - GraySplitView *splitView; - NSWindow *window; - BOOL visible; -} -@end - -namespace { - -NSRect devtoolsWindowFrame(NSView *referenceView) { - auto screenFrame = [referenceView.window convertRectToScreen:[referenceView convertRect:referenceView.bounds toView:nil]]; - return NSInsetRect(screenFrame, NSWidth(screenFrame) / 6, NSHeight(screenFrame) / 6); -} - -void SetActive(content::WebContents* web_contents, bool active) { - auto render_widget_host_view = web_contents->GetRenderWidgetHostView(); - if (!render_widget_host_view) - return; - - render_widget_host_view->SetActive(active); -} - -} - @implementation BRYInspectableWebContentsView -- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac *)inspectableWebContentsView { +- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)inspectableWebContentsView { self = [super init]; if (!self) return nil; - _private = [[BRYInspectableWebContentsViewPrivate alloc] init]; - _private->inspectableWebContentsView = inspectableWebContentsView; - _private->splitView = [[GraySplitView alloc] init]; - _private->splitView.delegate = self; + inspectableWebContentsView_ = inspectableWebContentsView; + devtools_visible_ = NO; - [self addSubview:_private->splitView]; - _private->splitView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; - _private->splitView.dividerStyle = NSSplitViewDividerStyleThin; - [_private->splitView addSubview:inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView()]; + auto webView = inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView(); + webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; + [self addSubview:webView]; return self; } - (void)dealloc { - [_private->window release]; - [_private->splitView release]; - [_private release]; - _private = nil; - [super dealloc]; } -- (void)removeFromNotificationCenter { - [NSNotificationCenter.defaultCenter removeObserver:self]; -} - - (IBAction)showDevTools:(id)sender { - _private->inspectableWebContentsView->inspectable_web_contents()->ShowDevTools(); + inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools(); } - (void)setDevToolsVisible:(BOOL)visible { - if (_private->visible == visible) + if (devtools_visible_ == visible) return; - _private->visible = visible; + devtools_visible_ = visible; - if ([self isDocked]) { - if (visible) { - [_private->window makeKeyAndOrderFront:nil]; - } else { - [_private->window orderOut:nil]; - } - return; + if (!devtools_window_) { + auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); + + auto styleMask = NSTitledWindowMask | NSClosableWindowMask | + NSMiniaturizableWindowMask | NSResizableWindowMask | + NSTexturedBackgroundWindowMask | + NSUnifiedTitleAndToolbarWindowMask; + devtools_window_.reset([[UnderlayOpenGLHostingWindow alloc] + initWithContentRect:NSMakeRect(0, 0, 800, 600) + styleMask:styleMask + backing:NSBackingStoreBuffered + defer:YES]); + [devtools_window_ setDelegate:self]; + [devtools_window_ setFrameAutosaveName:@"brightray.developer.tools"]; + [devtools_window_ setTitle:@"Developer Tools"]; + [devtools_window_ setReleasedWhenClosed:NO]; + [devtools_window_ setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; + [devtools_window_ setContentBorderThickness:24 forEdge:NSMaxYEdge]; + + NSView* contentView = [devtools_window_ contentView]; + devToolsView.frame = contentView.bounds; + devToolsView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; + + [contentView addSubview:devToolsView]; } - auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); - auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); - if (visible) { - auto inspectedView = _private->inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView(); - CGRect frame = NSRectToCGRect(inspectedView.frame); - CGRect inspectedViewFrame; - CGRect devToolsFrame; - CGFloat amount; - CGRectEdge edge; - if ([_private->splitView isVertical]) { - amount = CGRectGetWidth(frame) * 2 / 3; - edge = CGRectMaxXEdge; - } else { - amount = CGRectGetHeight(frame) * 2 / 3; - edge = CGRectMaxYEdge; - } - CGRectDivide(frame, &inspectedViewFrame, &devToolsFrame, amount, edge); - - inspectedView.frame = NSRectFromCGRect(inspectedViewFrame); - devToolsView.frame = NSRectFromCGRect(devToolsFrame); - - [_private->splitView addSubview:devToolsView]; + [devtools_window_ makeKeyAndOrderFront:nil]; } else { - [devToolsView removeFromSuperview]; + [devtools_window_ performClose:nil]; } - - [_private->splitView adjustSubviews]; } - (BOOL)isDevToolsVisible { - return _private->visible; + return devtools_visible_; } - (BOOL)setDockSide:(const std::string&)side { - if (side == "right") { - _private->splitView.vertical = YES; - [self moveToSplitView]; - } else if (side == "bottom") { - _private->splitView.vertical = NO; - [self moveToSplitView]; - } else if (side == "undocked") { - [self moveToWindow]; - } else { - return NO; - } - - return YES; -} - -- (void)moveToWindow { - if (!_private->window) { - auto styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask | NSTexturedBackgroundWindowMask | NSUnifiedTitleAndToolbarWindowMask; - auto contentRect = [UnderlayOpenGLHostingWindow contentRectForFrameRect:devtoolsWindowFrame(_private->splitView) styleMask:styleMask]; - _private->window = [[UnderlayOpenGLHostingWindow alloc] initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:YES]; - _private->window.delegate = self; - _private->window.releasedWhenClosed = NO; - _private->window.title = @"Developer Tools"; - _private->window.frameAutosaveName = @"brightray.developer.tools"; - [_private->window setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; - [_private->window setContentBorderThickness:24 forEdge:NSMaxYEdge]; - } - - auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); - auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); - - NSView *contentView = _private->window.contentView; - devToolsView.frame = contentView.bounds; - devToolsView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; - - [contentView addSubview:devToolsView]; - [_private->window makeKeyAndOrderFront:nil]; - [_private->splitView adjustSubviews]; -} - -- (void)moveToSplitView { - [_private->window orderOut:nil]; - - auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); - auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); - - [_private->splitView addSubview:devToolsView]; - [_private->splitView adjustSubviews]; -} - -- (BOOL)isDocked { - auto devToolsWebContents = _private->inspectableWebContentsView->inspectable_web_contents()->devtools_web_contents(); - if (!devToolsWebContents) - return NO; - auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); - - return _private->window && devToolsView.window == _private->window; -} - -- (void)window:(NSWindow *)window didBecomeActive:(BOOL)active { - auto inspectable_contents = _private->inspectableWebContentsView->inspectable_web_contents(); - - // Changes to the active state of the window we create only affects the dev tools contents. - if (window == _private->window) { - SetActive(inspectable_contents->devtools_web_contents(), active); - return; - } - - // Changes the window that hosts us always affect our main web contents. If the dev tools are also - // hosted in this window, they are affected too. - SetActive(inspectable_contents->GetWebContents(), active); - if (![self isDocked]) - return; - SetActive(inspectable_contents->devtools_web_contents(), active); -} - -#pragma mark - NSView - -- (void)viewWillMoveToWindow:(NSWindow *)newWindow { - if (self.window) { - [NSNotificationCenter.defaultCenter removeObserver:self name:NSWindowDidBecomeKeyNotification object:self.window]; - [NSNotificationCenter.defaultCenter removeObserver:self name:NSWindowDidResignKeyNotification object:self.window]; - } - - if (!newWindow) - return; - - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:newWindow]; - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(windowDidResignKey:) name:NSWindowDidResignKeyNotification object:newWindow]; -} - -#pragma mark - NSSplitViewDelegate - --(void)splitViewWillResizeSubviews:(NSNotification *)notification { - [[_private->splitView window] disableScreenUpdatesUntilFlush]; + return NO; } #pragma mark - NSWindowDelegate -- (BOOL)windowShouldClose:(id)sender { - _private->visible = NO; - [_private->window orderOut:nil]; - return NO; -} - -- (void)windowDidBecomeKey:(NSNotification *)notification { - [self window:notification.object didBecomeActive:YES]; -} - -- (void)windowDidResignKey:(NSNotification *)notification { - [self window:notification.object didBecomeActive:NO]; +- (void)windowWillClose:(NSNotification*)notification { + devtools_visible_ = NO; + devtools_window_.reset(); } @end - -@implementation BRYInspectableWebContentsViewPrivate -@end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view_private.h b/brightray/browser/mac/bry_inspectable_web_contents_view_private.h deleted file mode 100644 index 943ef93e312..00000000000 --- a/brightray/browser/mac/bry_inspectable_web_contents_view_private.h +++ /dev/null @@ -1,14 +0,0 @@ -#import "browser/mac/bry_inspectable_web_contents_view.h" - -namespace brightray { -class InspectableWebContentsViewMac; -} - -@interface BRYInspectableWebContentsView (Private) - -- (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac *)inspectableWebContentsView; -- (void)setDevToolsVisible:(BOOL)visible; -- (BOOL)isDevToolsVisible; -- (BOOL)setDockSide:(const std::string&)side; - -@end From 2efeaa268fd2f0fe8a0bd36ccf78bba52860f019 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Jul 2014 16:21:47 +0800 Subject: [PATCH 0320/1195] Place DevTools WebContents underneath inspected WebContents. This commit has this strategy implemented on Mac. See https://code.google.com/p/chromium/issues/detail?id=318751. --- brightray/brightray.gyp | 2 + .../devtools_contents_resizing_strategy.cc | 85 +++++++++++++ .../devtools_contents_resizing_strategy.h | 56 +++++++++ .../devtools_embedder_message_dispatcher.cc | 65 +++++++++- .../devtools_embedder_message_dispatcher.h | 6 +- .../inspectable_web_contents_delegate.h | 12 -- .../browser/inspectable_web_contents_impl.cc | 61 ++++----- .../browser/inspectable_web_contents_impl.h | 11 +- .../browser/inspectable_web_contents_view.h | 6 +- .../inspectable_web_contents_view_mac.h | 4 +- .../inspectable_web_contents_view_mac.mm | 18 ++- .../mac/bry_inspectable_web_contents_view.h | 17 ++- .../mac/bry_inspectable_web_contents_view.mm | 118 ++++++++++++++---- 13 files changed, 370 insertions(+), 91 deletions(-) create mode 100644 brightray/browser/devtools_contents_resizing_strategy.cc create mode 100644 brightray/browser/devtools_contents_resizing_strategy.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 1c37fe83c25..aae368994d3 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -40,6 +40,8 @@ 'browser/default_web_contents_delegate.cc', 'browser/default_web_contents_delegate.h', 'browser/default_web_contents_delegate_mac.mm', + 'browser/devtools_contents_resizing_strategy.cc', + 'browser/devtools_contents_resizing_strategy.h', 'browser/devtools_embedder_message_dispatcher.cc', 'browser/devtools_embedder_message_dispatcher.h', 'browser/devtools_ui.cc', diff --git a/brightray/browser/devtools_contents_resizing_strategy.cc b/brightray/browser/devtools_contents_resizing_strategy.cc new file mode 100644 index 00000000000..15d7a5253f1 --- /dev/null +++ b/brightray/browser/devtools_contents_resizing_strategy.cc @@ -0,0 +1,85 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "browser/devtools_contents_resizing_strategy.h" + +#include + +DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() { +} + +DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( + const gfx::Insets& insets, const gfx::Size& min_size) + : insets_(insets), + min_size_(min_size) { +} + +DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( + const gfx::Rect& bounds) + : bounds_(bounds) { +} + + +void DevToolsContentsResizingStrategy::CopyFrom( + const DevToolsContentsResizingStrategy& strategy) { + insets_ = strategy.insets(); + min_size_ = strategy.min_size(); + bounds_ = strategy.bounds(); +} + +bool DevToolsContentsResizingStrategy::Equals( + const DevToolsContentsResizingStrategy& strategy) { + return insets_ == strategy.insets() && min_size_ == strategy.min_size() && + bounds_ == strategy.bounds(); +} + +void ApplyDevToolsContentsResizingStrategy( + const DevToolsContentsResizingStrategy& strategy, + const gfx::Size& container_size, + const gfx::Rect& old_devtools_bounds, + const gfx::Rect& old_contents_bounds, + gfx::Rect* new_devtools_bounds, + gfx::Rect* new_contents_bounds) { + new_devtools_bounds->SetRect( + 0, 0, container_size.width(), container_size.height()); + + const gfx::Insets& insets = strategy.insets(); + const gfx::Size& min_size = strategy.min_size(); + const gfx::Rect& bounds = strategy.bounds(); + + if (!bounds.size().IsEmpty()) { + int left = std::min(bounds.x(), container_size.width()); + int top = std::min(bounds.y(), container_size.height()); + int width = std::min(bounds.width(), container_size.width() - left); + int height = std::min(bounds.height(), container_size.height() - top); + new_contents_bounds->SetRect(left, top, width, height); + return; + } + + int width = std::max(0, container_size.width() - insets.width()); + int left = insets.left(); + if (width < min_size.width() && insets.width() > 0) { + int min_width = std::min(min_size.width(), container_size.width()); + int insets_width = container_size.width() - min_width; + int insets_decrease = insets.width() - insets_width; + // Decrease both left and right insets proportionally. + left -= insets_decrease * insets.left() / insets.width(); + width = min_width; + } + left = std::max(0, std::min(container_size.width(), left)); + + int height = std::max(0, container_size.height() - insets.height()); + int top = insets.top(); + if (height < min_size.height() && insets.height() > 0) { + int min_height = std::min(min_size.height(), container_size.height()); + int insets_height = container_size.height() - min_height; + int insets_decrease = insets.height() - insets_height; + // Decrease both top and bottom insets proportionally. + top -= insets_decrease * insets.top() / insets.height(); + height = min_height; + } + top = std::max(0, std::min(container_size.height(), top)); + + new_contents_bounds->SetRect(left, top, width, height); +} diff --git a/brightray/browser/devtools_contents_resizing_strategy.h b/brightray/browser/devtools_contents_resizing_strategy.h new file mode 100644 index 00000000000..86ea260c71a --- /dev/null +++ b/brightray/browser/devtools_contents_resizing_strategy.h @@ -0,0 +1,56 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BRIGHTRAY_BROWSER_DEVTOOLS_CONTENTS_RESIZING_STRATEGY_H_ +#define BRIGHTRAY_BROWSER_DEVTOOLS_CONTENTS_RESIZING_STRATEGY_H_ + +#include "base/basictypes.h" +#include "ui/gfx/insets.h" +#include "ui/gfx/rect.h" +#include "ui/gfx/size.h" + +// This class knows how to resize both DevTools and inspected WebContents +// inside a browser window hierarchy. +class DevToolsContentsResizingStrategy { + public: + DevToolsContentsResizingStrategy(); + DevToolsContentsResizingStrategy( + const gfx::Insets& insets, + const gfx::Size& min_size); + explicit DevToolsContentsResizingStrategy(const gfx::Rect& bounds); + + void CopyFrom(const DevToolsContentsResizingStrategy& strategy); + bool Equals(const DevToolsContentsResizingStrategy& strategy); + + const gfx::Insets& insets() const { return insets_; } + const gfx::Size& min_size() const { return min_size_; } + const gfx::Rect& bounds() const { return bounds_; } + + private: + // Insets of contents inside DevTools. + gfx::Insets insets_; + + // Minimum size of contents. + gfx::Size min_size_; + + // Contents bounds. When non-empty, used instead of insets. + gfx::Rect bounds_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsContentsResizingStrategy); +}; + +// Applies contents resizing strategy, producing bounds for devtools and +// page contents views. Generally, page contents view is placed atop of devtools +// inside a common parent view, which size should be passed in |container_size|. +// When unknown, providing empty rect as previous devtools and contents bounds +// is allowed. +void ApplyDevToolsContentsResizingStrategy( + const DevToolsContentsResizingStrategy& strategy, + const gfx::Size& container_size, + const gfx::Rect& old_devtools_bounds, + const gfx::Rect& old_contents_bounds, + gfx::Rect* new_devtools_bounds, + gfx::Rect* new_contents_bounds); + +#endif // BRIGHTRAY_BROWSER_DEVTOOLS_CONTENTS_RESIZING_STRATEGY_H_ diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index 2d6c61ec1c8..98e4732208b 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -27,6 +27,36 @@ bool GetValue(const base::ListValue& list, int pos, bool& value) { return list.GetBoolean(pos, &value); } +bool GetValue(const base::ListValue& list, int pos, gfx::Insets& insets) { + const base::DictionaryValue* dict; + if (!list.GetDictionary(pos, &dict)) + return false; + int top = 0; + int left = 0; + int bottom = 0; + int right = 0; + if (!dict->GetInteger("top", &top) || + !dict->GetInteger("left", &left) || + !dict->GetInteger("bottom", &bottom) || + !dict->GetInteger("right", &right)) + return false; + insets.Set(top, left, bottom, right); + return true; +} + +bool GetValue(const base::ListValue& list, int pos, gfx::Size& size) { + const base::DictionaryValue* dict; + if (!list.GetDictionary(pos, &dict)) + return false; + int width = 0; + int height = 0; + if (!dict->GetInteger("width", &width) || + !dict->GetInteger("height", &height)) + return false; + size.SetSize(width, height); + return true; +} + template struct StorageTraits { typedef T StorageType; @@ -105,6 +135,28 @@ bool ParseAndHandle3(const base::Callback& handler, return true; } +template +bool ParseAndHandle3(const base::Callback& handler, + const base::ListValue& list) { + if (list.GetSize() != 3) + return false; + Argument arg1(list, 0); + if (!arg1.valid()) + return false; + Argument arg2(list, 1); + if (!arg2.valid()) + return false; + Argument arg3(list, 2); + if (!arg3.valid()) + return false; + Argument arg4(list, 3); + if (!arg4.valid()) + return false; + handler.Run(arg1.value(), arg2.value(), arg3.value(), arg4.value()); + return true; +} + + typedef base::Callback ListValueParser; ListValueParser BindToListParser(const base::Callback& handler) { @@ -127,6 +179,12 @@ ListValueParser BindToListParser( return base::Bind(&ParseAndHandle3, handler); } +template +ListValueParser BindToListParser( + const base::Callback& handler) { + return base::Bind(&ParseAndHandle3, handler); +} + } // namespace DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher( @@ -137,11 +195,14 @@ DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher( RegisterHandler("closeWindow", BindToListParser(base::Bind(&Delegate::CloseWindow, base::Unretained(delegate)))); + RegisterHandler("setContentsResizingStrategy", + BindToListParser(base::Bind(&Delegate::SetContentsResizingStrategy, + base::Unretained(delegate)))); RegisterHandler("moveWindowBy", BindToListParser(base::Bind(&Delegate::MoveWindow, base::Unretained(delegate)))); - RegisterHandler("requestSetDockSide", - BindToListParser(base::Bind(&Delegate::SetDockSide, + RegisterHandler("setIsDocked", + BindToListParser(base::Bind(&Delegate::SetIsDocked, base::Unretained(delegate)))); RegisterHandler("openInNewTab", BindToListParser(base::Bind(&Delegate::OpenInNewTab, diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index df21050320e..1f4a6e5d00c 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -9,6 +9,8 @@ #include #include "base/callback.h" +#include "ui/gfx/insets.h" +#include "ui/gfx/size.h" namespace base { class ListValue; @@ -30,8 +32,10 @@ class DevToolsEmbedderMessageDispatcher { virtual void ActivateWindow() = 0; virtual void CloseWindow() = 0; + virtual void SetContentsResizingStrategy( + const gfx::Insets& insets, const gfx::Size& min_size) = 0; virtual void MoveWindow(int x, int y) = 0; - virtual void SetDockSide(const std::string& side) = 0; + virtual void SetIsDocked(bool docked) = 0; virtual void OpenInNewTab(const std::string& url) = 0; virtual void SaveToFile(const std::string& url, const std::string& content, diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index d86285789e3..a6dc5e1c78f 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -9,18 +9,6 @@ class InspectableWebContentsDelegate { public: virtual ~InspectableWebContentsDelegate() {} - // Called when the devtools is going to change the dock side, returning true - // to override the default behavior. - // Receiver should set |succeed| to |false| if it failed to handle this. - virtual bool DevToolsSetDockSide(const std::string& side, bool* succeed) { - return false; - } - - // Called when the devtools is going to be showed, returning true to override - // the default behavior. - // Receiver is given the chance to change the |dock_side|. - virtual bool DevToolsShow(std::string* dock_side) { return false; } - // Requested by WebContents of devtools. virtual void DevToolsSaveToFile( const std::string& url, const std::string& content, bool save_as) {} diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 739acf44ecb..fa9b792976c 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -26,8 +26,8 @@ namespace brightray { namespace { -const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html"; -const char kDockSidePref[] = "brightray.devtools.dockside"; +const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?can_dock=true"; +const char kIsDockedPref[] = "brightray.devtools.isDocked"; } @@ -36,7 +36,7 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents_impl); void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { - registry->RegisterStringPref(kDockSidePref, "bottom"); + registry->RegisterBooleanPref(kIsDockedPref, true); } InspectableWebContentsImpl::InspectableWebContentsImpl( @@ -45,7 +45,7 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( delegate_(nullptr) { auto context = static_cast( web_contents_->GetBrowserContext()); - dock_side_ = context->prefs()->GetString(kDockSidePref); + is_docked_ = context->prefs()->GetBoolean(kIsDockedPref); view_.reset(CreateInspectableContentsView(this)); } @@ -62,6 +62,8 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const { } void InspectableWebContentsImpl::ShowDevTools() { + // Show devtools only after it has done loading, this is to make sure the + // SetIsDocked is called *BEFORE* ShowDevTools. if (!devtools_web_contents_) { embedder_message_dispatcher_.reset( new DevToolsEmbedderMessageDispatcher(this)); @@ -70,11 +72,6 @@ void InspectableWebContentsImpl::ShowDevTools() { web_contents_->GetBrowserContext()); devtools_web_contents_.reset(content::WebContents::Create(create_params)); -#if defined(OS_MACOSX) - // Work around http://crbug.com/279472. - devtools_web_contents_->GetView()->SetAllowOverlappingViews(true); -#endif - Observe(devtools_web_contents_.get()); devtools_web_contents_->SetDelegate(this); @@ -92,17 +89,13 @@ void InspectableWebContentsImpl::ShowDevTools() { content::Referrer(), content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); + } else { + view_->ShowDevTools(); } - - if (delegate_ && delegate_->DevToolsShow(&dock_side_)) - return; - - view_->SetDockSide(dock_side_); - view_->ShowDevTools(); } void InspectableWebContentsImpl::CloseDevTools() { - if (IsDevToolsViewShowing()) { + if (devtools_web_contents_) { view_->CloseDevTools(); devtools_web_contents_.reset(); web_contents_->GetView()->Focus(); @@ -113,13 +106,6 @@ bool InspectableWebContentsImpl::IsDevToolsViewShowing() { return devtools_web_contents_ && view_->IsDevToolsViewShowing(); } -void InspectableWebContentsImpl::UpdateFrontendDockSide() { - auto javascript = base::StringPrintf( - "InspectorFrontendAPI.setDockSide(\"%s\")", dock_side_.c_str()); - devtools_web_contents_->GetRenderViewHost()->ExecuteJavascriptInWebFrame( - base::string16(), base::ASCIIToUTF16(javascript)); -} - void InspectableWebContentsImpl::ActivateWindow() { } @@ -127,25 +113,26 @@ void InspectableWebContentsImpl::CloseWindow() { CloseDevTools(); } +void InspectableWebContentsImpl::SetContentsResizingStrategy( + const gfx::Insets& insets, const gfx::Size& min_size) { + DevToolsContentsResizingStrategy strategy(insets, min_size); + if (contents_resizing_strategy_.Equals(strategy)) + return; + + contents_resizing_strategy_.CopyFrom(strategy); + view_->SetContentsResizingStrategy(contents_resizing_strategy_); +} + void InspectableWebContentsImpl::MoveWindow(int x, int y) { } -void InspectableWebContentsImpl::SetDockSide(const std::string& side) { - bool succeed = true; - if (delegate_ && delegate_->DevToolsSetDockSide(side, &succeed)) { - if (!succeed) // delegate failed to set dock side. - return; - } else if (!view_->SetDockSide(side)) { - return; - } - - dock_side_ = side; +void InspectableWebContentsImpl::SetIsDocked(bool docked) { + view_->SetIsDocked(docked); + is_docked_ = docked; auto context = static_cast( web_contents_->GetBrowserContext()); - context->prefs()->SetString(kDockSidePref, side); - - UpdateFrontendDockSide(); + context->prefs()->SetBoolean(kIsDockedPref, docked); } void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) { @@ -207,7 +194,7 @@ void InspectableWebContentsImpl::DidFinishLoad(int64 frame_id, if (!is_main_frame) return; - UpdateFrontendDockSide(); + view_->ShowDevTools(); } void InspectableWebContentsImpl::WebContentsDestroyed(content::WebContents*) { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 8581b24ec47..913c59323c7 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -8,6 +8,7 @@ #include "browser/inspectable_web_contents.h" +#include "browser/devtools_contents_resizing_strategy.h" #include "browser/devtools_embedder_message_dispatcher.h" #include "content/public/browser/devtools_frontend_host_delegate.h" @@ -54,14 +55,14 @@ class InspectableWebContentsImpl : } private: - void UpdateFrontendDockSide(); - // DevToolsEmbedderMessageDispacher::Delegate virtual void ActivateWindow() OVERRIDE; virtual void CloseWindow() OVERRIDE; + virtual void SetContentsResizingStrategy( + const gfx::Insets& insets, const gfx::Size& min_size) OVERRIDE; virtual void MoveWindow(int x, int y) OVERRIDE; - virtual void SetDockSide(const std::string& side) OVERRIDE; + virtual void SetIsDocked(bool docked) OVERRIDE; virtual void OpenInNewTab(const std::string& url) OVERRIDE; virtual void SaveToFile(const std::string& url, const std::string& content, @@ -103,7 +104,9 @@ class InspectableWebContentsImpl : scoped_ptr devtools_web_contents_; scoped_ptr view_; scoped_refptr agent_host_; - std::string dock_side_; + + bool is_docked_; + DevToolsContentsResizingStrategy contents_resizing_strategy_; scoped_ptr embedder_message_dispatcher_; diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 18fd192a67e..251d4337a43 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -3,6 +3,8 @@ #include "ui/gfx/native_widget_types.h" +class DevToolsContentsResizingStrategy; + namespace brightray { class InspectableWebContentsView { @@ -15,7 +17,9 @@ class InspectableWebContentsView { // Hide the DevTools view. virtual void CloseDevTools() = 0; virtual bool IsDevToolsViewShowing() = 0; - virtual bool SetDockSide(const std::string& side) = 0; + virtual void SetIsDocked(bool docked) = 0; + virtual void SetContentsResizingStrategy( + const DevToolsContentsResizingStrategy& strategy) = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 927a91a362d..29a55bdd088 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -21,7 +21,9 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView { virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; virtual bool IsDevToolsViewShowing() OVERRIDE; - virtual bool SetDockSide(const std::string& side) OVERRIDE; + virtual void SetIsDocked(bool docked) OVERRIDE; + virtual void SetContentsResizingStrategy( + const DevToolsContentsResizingStrategy& strategy) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index 6ab97117270..89eb8ec0746 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -1,10 +1,11 @@ -#import "browser/inspectable_web_contents_view_mac.h" +#include "browser/inspectable_web_contents_view_mac.h" -#import "browser/inspectable_web_contents.h" +#import + +#include "browser/inspectable_web_contents.h" #import "browser/mac/bry_inspectable_web_contents_view.h" -#import "content/public/browser/web_contents_view.h" -#import +#include "content/public/browser/web_contents_view.h" namespace brightray { @@ -36,8 +37,13 @@ bool InspectableWebContentsViewMac::IsDevToolsViewShowing() { return [view_ isDevToolsVisible]; } -bool InspectableWebContentsViewMac::SetDockSide(const std::string& side) { - return [view_ setDockSide:side]; +void InspectableWebContentsViewMac::SetIsDocked(bool docked) { + [view_ setIsDocked:docked]; +} + +void InspectableWebContentsViewMac::SetContentsResizingStrategy( + const DevToolsContentsResizingStrategy& strategy) { + [view_ setContentsResizingStrategy:strategy]; } } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index f689f1f38cc..d5761bb5eec 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -1,24 +1,33 @@ #import -#include +#include "browser/devtools_contents_resizing_strategy.h" #include "base/mac/scoped_nsobject.h" +#include "ui/base/cocoa/base_view.h" +#include "ui/gfx/insets.h" namespace brightray { class InspectableWebContentsViewMac; } -@interface BRYInspectableWebContentsView : NSView { +@interface BRYInspectableWebContentsView : BaseView { @private brightray::InspectableWebContentsViewMac* inspectableWebContentsView_; + base::scoped_nsobject devtools_window_; BOOL devtools_visible_; + BOOL devtools_docked_; + + DevToolsContentsResizingStrategy strategy_; } - (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac*)inspectableWebContentsView; -- (IBAction)showDevTools:(id)sender; - (void)setDevToolsVisible:(BOOL)visible; - (BOOL)isDevToolsVisible; -- (BOOL)setDockSide:(const std::string&)side ; +- (void)setIsDocked:(BOOL)docked; +- (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy; + +// Adjust docked devtools to the contents resizing strategy. +- (void)update; @end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 8c463dd325f..22a0d02d405 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -1,11 +1,12 @@ -#import "browser/mac/bry_inspectable_web_contents_view.h" +#include "browser/mac/bry_inspectable_web_contents_view.h" -#import "browser/inspectable_web_contents_impl.h" -#import "browser/inspectable_web_contents_view_mac.h" +#include "browser/inspectable_web_contents_impl.h" +#include "browser/inspectable_web_contents_view_mac.h" -#import "content/public/browser/render_widget_host_view.h" -#import "content/public/browser/web_contents_view.h" +#include "content/public/browser/render_widget_host_view.h" +#include "content/public/browser/web_contents_view.h" #import "ui/base/cocoa/underlay_opengl_hosting_window.h" +#include "ui/gfx/mac/scoped_ns_disable_screen_updates.h" using namespace brightray; @@ -18,10 +19,12 @@ using namespace brightray; inspectableWebContentsView_ = inspectableWebContentsView; devtools_visible_ = NO; + devtools_docked_ = NO; - auto webView = inspectableWebContentsView->inspectable_web_contents()->GetWebContents()->GetView()->GetNativeView(); - webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; - [self addSubview:webView]; + auto contents = inspectableWebContentsView->inspectable_web_contents()->GetWebContents(); + auto contentsView = contents->GetView()->GetNativeView(); + [contentsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; + [self addSubview:contentsView]; return self; } @@ -30,16 +33,53 @@ using namespace brightray; [super dealloc]; } +- (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { + [self adjustSubviews]; +} + - (IBAction)showDevTools:(id)sender { inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools(); } - (void)setDevToolsVisible:(BOOL)visible { - if (devtools_visible_ == visible) + if (visible == devtools_visible_) return; - devtools_visible_ = visible; - if (!devtools_window_) { + auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); + + devtools_visible_ = visible; + if (devtools_docked_) { + if (visible) { + // Place the devToolsView under contentsView, notice that we didn't set + // sizes for them until the setContentsResizingStrategy message. + [self addSubview:devToolsView positioned:NSWindowBelow relativeTo:nil]; + [self update]; + } else { + gfx::ScopedNSDisableScreenUpdates disabler; + devToolsWebContents->GetView()->RemoveOverlayView(); + [devToolsView removeFromSuperview]; + [self adjustSubviews]; + } + } else { + if (visible) + [devtools_window_ makeKeyAndOrderFront:nil]; + else + devtools_window_.reset(); + } +} + +- (BOOL)isDevToolsVisible { + return devtools_visible_; +} + +- (void)setIsDocked:(BOOL)docked { + // Revert to no-devtools state. + [self setDevToolsVisible:NO]; + + // Switch to new state. + devtools_docked_ = docked; + if (!docked) { auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); @@ -65,27 +105,59 @@ using namespace brightray; [contentView addSubview:devToolsView]; } + [self setDevToolsVisible:YES]; +} - if (visible) { - [devtools_window_ makeKeyAndOrderFront:nil]; - } else { - [devtools_window_ performClose:nil]; +- (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy { + strategy_.CopyFrom(strategy); + [self update]; +} + +- (void)update { + if (!devtools_docked_) + return; + + auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); + auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + + gfx::ScopedNSDisableScreenUpdates disabler; + devToolsWebContents->GetView()->SetOverlayView( + contents->GetView(), + gfx::Point(strategy_.insets().left(), strategy_.insets().top())); + [self adjustSubviews]; +} + +- (void)adjustSubviews { + if (![[self subviews] count]) + return; + + if (![self isDevToolsVisible] || devtools_window_) { + DCHECK_EQ(1u, [[self subviews] count]); + NSView* contents = [[self subviews] objectAtIndex:0]; + [contents setFrame:[self bounds]]; + return; } -} -- (BOOL)isDevToolsVisible { - return devtools_visible_; -} + NSView* devToolsView = [[self subviews] objectAtIndex:0]; + NSView* contentsView = [[self subviews] objectAtIndex:1]; -- (BOOL)setDockSide:(const std::string&)side { - return NO; + DCHECK_EQ(2u, [[self subviews] count]); + + gfx::Rect new_devtools_bounds; + gfx::Rect new_contents_bounds; + ApplyDevToolsContentsResizingStrategy( + strategy_, gfx::Size(NSSizeToCGSize([self bounds].size)), + [self flipNSRectToRect:[devToolsView bounds]], + [self flipNSRectToRect:[contentsView bounds]], + &new_devtools_bounds, &new_contents_bounds); + [devToolsView setFrame:[self flipRectToNSRect:new_devtools_bounds]]; + [contentsView setFrame:[self flipRectToNSRect:new_contents_bounds]]; } #pragma mark - NSWindowDelegate - (void)windowWillClose:(NSNotification*)notification { - devtools_visible_ = NO; - devtools_window_.reset(); + inspectableWebContentsView_->inspectable_web_contents()->CloseDevTools(); } @end From 7a2dc3fc4f971fc3dda6f56e132d85db7c49abfb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Jul 2014 16:37:05 +0800 Subject: [PATCH 0321/1195] mac: Make focus back to browser window when devtools is closed. --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 22a0d02d405..64d94ef105b 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -62,10 +62,12 @@ using namespace brightray; [self adjustSubviews]; } } else { - if (visible) + if (visible) { [devtools_window_ makeKeyAndOrderFront:nil]; - else + } else { + [[self window] makeKeyAndOrderFront:nil]; devtools_window_.reset(); + } } } From 1722532e6d5eda81fe3af06985291cb3ced2adad Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Jul 2014 16:48:54 +0800 Subject: [PATCH 0322/1195] No need to remember dock state. All devtools states are remembered by devtools itself now. --- brightray/browser/inspectable_web_contents_impl.cc | 9 --------- brightray/browser/inspectable_web_contents_impl.h | 1 - 2 files changed, 10 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index fa9b792976c..26fcc2b0f0f 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -43,10 +43,6 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( content::WebContents* web_contents) : web_contents_(web_contents), delegate_(nullptr) { - auto context = static_cast( - web_contents_->GetBrowserContext()); - is_docked_ = context->prefs()->GetBoolean(kIsDockedPref); - view_.reset(CreateInspectableContentsView(this)); } @@ -128,11 +124,6 @@ void InspectableWebContentsImpl::MoveWindow(int x, int y) { void InspectableWebContentsImpl::SetIsDocked(bool docked) { view_->SetIsDocked(docked); - is_docked_ = docked; - - auto context = static_cast( - web_contents_->GetBrowserContext()); - context->prefs()->SetBoolean(kIsDockedPref, docked); } void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 913c59323c7..5c030a449f6 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -105,7 +105,6 @@ class InspectableWebContentsImpl : scoped_ptr view_; scoped_refptr agent_host_; - bool is_docked_; DevToolsContentsResizingStrategy contents_resizing_strategy_; scoped_ptr embedder_message_dispatcher_; From 563d6e87ff5dde79a6a383763f6fa5e69cab7c9a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Jul 2014 16:54:04 +0800 Subject: [PATCH 0323/1195] Fix cpplint warning. --- brightray/browser/mac/bry_inspectable_web_contents_view.h | 4 +++- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index d5761bb5eec..53ec00c8f3e 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -10,6 +10,8 @@ namespace brightray { class InspectableWebContentsViewMac; } +using brightray::InspectableWebContentsViewMac; + @interface BRYInspectableWebContentsView : BaseView { @private brightray::InspectableWebContentsViewMac* inspectableWebContentsView_; @@ -21,7 +23,7 @@ class InspectableWebContentsViewMac; DevToolsContentsResizingStrategy strategy_; } -- (instancetype)initWithInspectableWebContentsViewMac:(brightray::InspectableWebContentsViewMac*)inspectableWebContentsView; +- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view; - (void)setDevToolsVisible:(BOOL)visible; - (BOOL)isDevToolsVisible; - (void)setIsDocked:(BOOL)docked; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 64d94ef105b..99c2e4179a0 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -12,16 +12,16 @@ using namespace brightray; @implementation BRYInspectableWebContentsView -- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)inspectableWebContentsView { +- (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view { self = [super init]; if (!self) return nil; - inspectableWebContentsView_ = inspectableWebContentsView; + inspectableWebContentsView_ = view; devtools_visible_ = NO; devtools_docked_ = NO; - auto contents = inspectableWebContentsView->inspectable_web_contents()->GetWebContents(); + auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); auto contentsView = contents->GetView()->GetNativeView(); [contentsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [self addSubview:contentsView]; From 7f5b84fdeaa78f8c87558af3c6c4690a2e7bdbf0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Jul 2014 14:08:43 +0000 Subject: [PATCH 0324/1195] Aura has replaced GTK+ in Linux. --- brightray/brightray.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index b73a7ea0765..e34beb06164 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -80,7 +80,7 @@ }, }, 'conditions': [ - ['OS=="win"', { + ['OS!="mac"', { 'defines': [ 'USE_AURA', 'VIEWS_IMPLEMENTATION', From 7050b7944f86be6ce2bc2f1e969dc65d94a4ac27 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Jul 2014 20:59:51 +0800 Subject: [PATCH 0325/1195] Remove devtools view on Linux. GTK+ has been replaced, we need to rewrite the whole thing. --- .../inspectable_web_contents_view_linux.cc | 250 +----------------- .../inspectable_web_contents_view_linux.h | 26 +- .../mac/bry_inspectable_web_contents_view.h | 1 - 3 files changed, 10 insertions(+), 267 deletions(-) diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc index 58d7507fb43..5cfb7130c25 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.cc @@ -1,6 +1,4 @@ #include "browser/linux/inspectable_web_contents_view_linux.h" -#include -#include #include "base/strings/stringprintf.h" #include "browser/browser_client.h" @@ -10,17 +8,6 @@ namespace brightray { -namespace { - -bool IsWidgetAncestryVisible(GtkWidget* widget) { - GtkWidget* parent = widget; - while (parent && gtk_widget_get_visible(parent)) - parent = gtk_widget_get_parent(parent); - return !parent; -} - -} - InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewLinux(inspectable_web_contents); @@ -28,259 +15,32 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsViewLinux::InspectableWebContentsViewLinux( InspectableWebContentsImpl* inspectable_web_contents) - : inspectable_web_contents_(inspectable_web_contents), - devtools_window_(NULL) { + : inspectable_web_contents_(inspectable_web_contents) { } InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() { - if (devtools_window_) gtk_widget_destroy(devtools_window_); } -#if 0 // some utility functions to debug GTK window hierarchies -static void dump_one(GtkWidget *wat, int indent) { - GtkAllocation alloc; - gtk_widget_get_allocation(wat, &alloc); - fprintf(stderr, "%*s[%p] %s @%d,%d %dx%d", - indent, "", wat, - g_type_name_from_instance(reinterpret_cast(wat)), - alloc.x, alloc.y, alloc.width, alloc.height); - if (GTK_IS_WINDOW(wat)) { - fprintf(stderr, " - \"%s\"", gtk_window_get_title(GTK_WINDOW(wat))); - } - fputc('\n', stderr); -} - -static void dump_the_whole_tree(GtkWidget *wat, int indent) { - if (!wat) { - fprintf(stderr, "(nil)\n"); - return; - } - dump_one(wat, indent); - GList *kids = gtk_container_get_children(GTK_CONTAINER(wat)); - for (GList *p = kids; p; p = p->next) { - dump_the_whole_tree(GTK_WIDGET(p->data), indent+2); - } -} - -static void dump_parents(GtkWidget *wat) { - fprintf(stderr, "Parents:\n"); - for (GtkWidget *p = gtk_widget_get_parent(wat); - p; - p = gtk_widget_get_parent(p)) { - dump_one(p, 2); - } -} -#endif - gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const { auto web_contents = inspectable_web_contents_->GetWebContents(); return web_contents->GetView()->GetNativeView(); } - -/* This code is a little bit hairy. - The dev tools can be in any one of five places: - 1. Unassigned and invisible. This is the default state until someone asks - to 'inspect element' for the first time. In this case, devtools->parent is - NULL. - 2. In an onscreen window, visible. - 3. In the bottom half of a GtkVPaned. - 4. In the right half of a GtkHPaned. - 5. In an offscreen window, invisible. This is where they go once they have - been displayed and the user asks to "close" them. They can't be put back - into the unassigned state. - ShowDevTools() and is responsible for transitioning from any one of these - states to the three visible states, 2-4, as indicated by the contents of the - 'dockside_' variable. The helper functions ShowDevToolsInWindow and - ShowDevToolsInPane focus on transitioning to states 2 and 3+4, respectively. - These helper functions are responsible for the entire transition, including - cleaning up any extraneous containers from the old state. - - Hiding the dev tools is taken care of by CloseDevTools (from paned states - 3+4 to invisible state 5) or by the "delete-event" signal on the - devtools_window_ (from window state 2 to 5). - - Remember that GTK does reference counting, so a view with no refs and no - parent will be freed. Views that have a ref but no parents will lose their - dimensions. So it's best to move the devtools view from place to place with - gtk_widget_reparent whenever possible. Unfortunately, one cannot reparent - things into a GtkPaned, so fairly brittle use of g_object_[un]ref and - gtk_container_remove happens. -*/ - void InspectableWebContentsViewLinux::ShowDevTools() { - auto devtools_web_contents = - inspectable_web_contents()->devtools_web_contents(); - GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView(); - GtkWidget *parent = gtk_widget_get_parent(devtools); - - DLOG(INFO) << base::StringPrintf( - "InspectableWebContentsViewLinux::ShowDevTools - " \ - "parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance(reinterpret_cast(parent)), - parent, - devtools_window_, - dockside_.c_str()); - - if (!parent || GTK_IS_PANED(parent)) { - if (dockside_ == "undocked") ShowDevToolsInWindow(); - else if (dockside_ == "bottom") ShowDevToolsInPane(true); - else if (dockside_ == "right") ShowDevToolsInPane(false); - } else { - DCHECK(parent == devtools_window_); - if (dockside_ == "undocked") gtk_widget_show_all(parent); - else if (dockside_ == "bottom") ShowDevToolsInPane(true); - else if (dockside_ == "right") ShowDevToolsInPane(false); - } } void InspectableWebContentsViewLinux::CloseDevTools() { - auto devtools_web_contents = - inspectable_web_contents()->devtools_web_contents(); - GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView(); - GtkWidget *parent = gtk_widget_get_parent(devtools); - - DLOG(INFO) << base::StringPrintf( - "InspectableWebContentsViewLinux::CloseDevTools - " \ - "parent=%s@%p window=%p dockside=\"%s\"", - g_type_name_from_instance(reinterpret_cast(parent)), - parent, - devtools_window_, - dockside_.c_str()); - - if (!parent) { - return; // Not visible -> nothing to do - } else if (GTK_IS_PANED(parent)) { - GtkWidget *browser = GetBrowserWindow(); - GtkWidget *view = GetNativeView(); - - if (!devtools_window_) MakeDevToolsWindow(); - gtk_widget_reparent(devtools, devtools_window_); - g_object_ref(parent); - gtk_container_remove(GTK_CONTAINER(browser), parent); - gtk_widget_reparent(view, browser); - g_object_unref(parent); - } else { - DCHECK(parent == devtools_window_); - gtk_widget_hide(parent); - } } bool InspectableWebContentsViewLinux::IsDevToolsViewShowing() { - auto devtools_web_contents = - inspectable_web_contents()->devtools_web_contents(); - GtkWidget* devtools = devtools_web_contents->GetView()->GetNativeView(); - return IsWidgetAncestryVisible(devtools); + return false; } -bool InspectableWebContentsViewLinux::SetDockSide(const std::string& side) { - DLOG(INFO) << - "InspectableWebContentsViewLinux::SetDockSide: \"" << side << "\""; - if (side != "undocked" && side != "bottom" && side != "right") - return false; // unsupported display location - if (dockside_ == side) - return true; // no change from current location - - dockside_ = side; - - // If devtools already has a parent, then we're being asked to move it. - auto devtools_web_contents = - inspectable_web_contents()->devtools_web_contents(); - GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView(); - if (gtk_widget_get_parent(devtools)) { - ShowDevTools(); - } - - return true; +void InspectableWebContentsViewLinux::SetIsDocked(bool docked) { } -void InspectableWebContentsViewLinux::ShowDevToolsInWindow() { - auto devtools_web_contents = - inspectable_web_contents()->devtools_web_contents(); - GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView(); - GtkWidget *parent = gtk_widget_get_parent(devtools); - - if (!devtools_window_) - MakeDevToolsWindow(); - if (!parent) { - gtk_container_add(GTK_CONTAINER(devtools_window_), devtools); - } else if (parent != devtools_window_) { - DCHECK(GTK_IS_PANED(parent)); - gtk_widget_reparent(devtools, devtools_window_); - - // Remove the pane. - GtkWidget *view = GetNativeView(); - GtkWidget *browser = GetBrowserWindow(); - g_object_ref(view); - gtk_container_remove(GTK_CONTAINER(parent), view); - gtk_container_remove(GTK_CONTAINER(browser), parent); - gtk_container_add(GTK_CONTAINER(browser), view); - g_object_unref(view); - } - gtk_widget_show_all(devtools_window_); -} - -void InspectableWebContentsViewLinux::MakeDevToolsWindow() { - DCHECK(!devtools_window_); - devtools_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(devtools_window_), "Developer Tools"); - gtk_window_set_default_size(GTK_WINDOW(devtools_window_), 800, 600); - g_signal_connect(GTK_OBJECT(devtools_window_), - "delete-event", - G_CALLBACK(gtk_widget_hide_on_delete), - this); -} - -void InspectableWebContentsViewLinux::ShowDevToolsInPane(bool on_bottom) { - auto devtools_web_contents = - inspectable_web_contents()->devtools_web_contents(); - GtkWidget *devtools = devtools_web_contents->GetView()->GetNativeView(); - GtkWidget *parent = gtk_widget_get_parent(devtools); - GtkWidget *pane = on_bottom ? gtk_vpaned_new() : gtk_hpaned_new(); - GtkWidget *view = GetNativeView(); - GtkWidget *browser = GetBrowserWindow(); - - GtkAllocation alloc; - gtk_widget_get_allocation(browser, &alloc); - gtk_paned_set_position(GTK_PANED(pane), - on_bottom ? alloc.height * 2 / 3 : alloc.width / 2); - if (!parent) { - g_object_ref(view); - gtk_container_remove(GTK_CONTAINER(browser), view); - gtk_paned_add1(GTK_PANED(pane), view); - gtk_paned_add2(GTK_PANED(pane), devtools); - g_object_unref(view); - } else if (GTK_IS_PANED(parent)) { - g_object_ref(view); - g_object_ref(devtools); - gtk_container_remove(GTK_CONTAINER(parent), view); - gtk_container_remove(GTK_CONTAINER(parent), devtools); - gtk_paned_add1(GTK_PANED(pane), view); - gtk_paned_add2(GTK_PANED(pane), devtools); - g_object_unref(view); - g_object_unref(devtools); - gtk_container_remove(GTK_CONTAINER(browser), parent); - } else { - DCHECK(parent == devtools_window_); - g_object_ref(view); - gtk_container_remove(GTK_CONTAINER(devtools_window_), devtools); - gtk_container_remove(GTK_CONTAINER(browser), view); - gtk_paned_add1(GTK_PANED(pane), view); - gtk_paned_add2(GTK_PANED(pane), devtools); - g_object_unref(view); - gtk_widget_hide(devtools_window_); - } - gtk_container_add(GTK_CONTAINER(browser), pane); - gtk_widget_show_all(pane); -} - -GtkWidget *InspectableWebContentsViewLinux::GetBrowserWindow() { - GtkWidget *view = GetNativeView(); - GtkWidget *parent = gtk_widget_get_parent(view); - GtkWidget *browser = - GTK_IS_PANED(parent) ? gtk_widget_get_parent(parent) : parent; - DCHECK(GTK_IS_WINDOW(browser)); - return browser; +void InspectableWebContentsViewLinux::SetContentsResizingStrategy( + const DevToolsContentsResizingStrategy& strategy) { } } // namespace brightray diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/linux/inspectable_web_contents_view_linux.h index 0a802239005..ef00ed5b5de 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.h +++ b/brightray/browser/linux/inspectable_web_contents_view_linux.h @@ -1,6 +1,7 @@ #ifndef BRIGHTRAY_BROWSER_LINUX_INSPECTABLE_WEB_CONTENTS_VIEW_LINUX_H_ #define BRIGHTRAY_BROWSER_LINUX_INSPECTABLE_WEB_CONTENTS_VIEW_LINUX_H_ +#include "browser/devtools_contents_resizing_strategy.h" #include "browser/inspectable_web_contents_view.h" #include "base/compiler_specific.h" @@ -19,36 +20,19 @@ class InspectableWebContentsViewLinux : public InspectableWebContentsView { virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; virtual bool IsDevToolsViewShowing() OVERRIDE; - virtual bool SetDockSide(const std::string& side) OVERRIDE; + virtual void SetIsDocked(bool docked) OVERRIDE; + virtual void SetContentsResizingStrategy( + const DevToolsContentsResizingStrategy& strategy) OVERRIDE; InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; } private: - // Show the dev tools in their own window. If they're already shown - // somewhere else, remove them cleanly and take any GtkPaned out of the - // window. - void ShowDevToolsInWindow(); - - // Show the dev tools in a vpaned (on the bottom) or hpaned (on the - // right). If they're already shown in a pane, move them and remove the - // old pane. If they're already shown in a window, hide (don't delete) - // that window. - void ShowDevToolsInPane(bool on_bottom); - - // Create a new window for dev tools. This function doesn't actually - // put the dev tools in the window or show the window. - void MakeDevToolsWindow(); - - // Get the GtkWindow* that contains this object. - GtkWidget *GetBrowserWindow(); - // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; - std::string dockside_; - GtkWidget *devtools_window_; + DevToolsContentsResizingStrategy strategy_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewLinux); }; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 53ec00c8f3e..977d6fdd939 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -4,7 +4,6 @@ #include "base/mac/scoped_nsobject.h" #include "ui/base/cocoa/base_view.h" -#include "ui/gfx/insets.h" namespace brightray { class InspectableWebContentsViewMac; From bc6237375e0fca3b8792283467da3f5e24176992 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 3 Jul 2014 06:59:14 +0000 Subject: [PATCH 0326/1195] Define TOOLKIT_VIEWS for Linux. --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index e34beb06164..aac531c2dbc 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -82,6 +82,7 @@ 'conditions': [ ['OS!="mac"', { 'defines': [ + 'TOOLKIT_VIEWS', 'USE_AURA', 'VIEWS_IMPLEMENTATION', 'WEBVIEW_IMPLEMENTATION', From d4e81da19a7d0e9eefe8a159500051dc48c79fd5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 3 Jul 2014 08:12:12 +0000 Subject: [PATCH 0327/1195] Make BrowserMainParts's overrides available on all platforms. --- brightray/browser/browser_main_parts.cc | 15 +++++++++++++++ brightray/browser/browser_main_parts.h | 9 ++++++--- brightray/browser/browser_main_parts_mac.mm | 4 ++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index ceee0d51e6a..806faee8610 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -18,6 +18,21 @@ BrowserMainParts::BrowserMainParts() { BrowserMainParts::~BrowserMainParts() { } +void BrowserMainParts::PreEarlyInitialization() { +#if defined(OS_MACOSX) + IncreaseFileDescriptorLimit(); +#endif +} + +void BrowserMainParts::ToolkitInitialized() { +} + +void BrowserMainParts::PreMainMessageLoopStart() { +#if defined(OS_MACOSX) + InitializeMainNib(); +#endif +} + void BrowserMainParts::PreMainMessageLoopRun() { browser_context_.reset(CreateBrowserContext()); browser_context_->Initialize(); diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 79d343ac608..fc0587f41c2 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -26,16 +26,19 @@ class BrowserMainParts : public content::BrowserMainParts { // implementation. The caller takes ownership of the returned object. virtual BrowserContext* CreateBrowserContext(); -#if defined(OS_MACOSX) virtual void PreEarlyInitialization() OVERRIDE; + virtual void ToolkitInitialized() OVERRIDE; virtual void PreMainMessageLoopStart() OVERRIDE; -#endif - virtual void PreMainMessageLoopRun() OVERRIDE; virtual void PostMainMessageLoopRun() OVERRIDE; virtual int PreCreateThreads() OVERRIDE; private: +#if defined(OS_MACOSX) + void IncreaseFileDescriptorLimit(); + void InitializeMainNib(); +#endif + scoped_ptr browser_context_; scoped_ptr web_ui_controller_factory_; diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm index 44b9494374a..a795e80a69d 100644 --- a/brightray/browser/browser_main_parts_mac.mm +++ b/brightray/browser/browser_main_parts_mac.mm @@ -27,7 +27,7 @@ void SetFileDescriptorLimit(rlim_t max_descriptors) { } // namespace -void BrowserMainParts::PreEarlyInitialization() { +void BrowserMainParts::IncreaseFileDescriptorLimit() { // We use quite a few file descriptors for our IPC, and the default limit on the Mac is low (256), // so bump it up. // See http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/chrome_browser_main_posix.cc?revision=244734#l295 @@ -36,7 +36,7 @@ void BrowserMainParts::PreEarlyInitialization() { } // Replicates NSApplicationMain, but doesn't start a run loop. -void BrowserMainParts::PreMainMessageLoopStart() { +void BrowserMainParts::InitializeMainNib() { auto infoDictionary = base::mac::OuterBundle().infoDictionary; auto principalClass = NSClassFromString([infoDictionary objectForKey:@"NSPrincipalClass"]); From 48ed03eb396f0f4d6219360b3e3a2a5b39e856ac Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 3 Jul 2014 08:28:14 +0000 Subject: [PATCH 0328/1195] Initialize Linux UI. --- brightray/browser/browser_main_parts.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 806faee8610..9906302d274 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -10,6 +10,11 @@ #include "ui/gfx/screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h" +#if defined(USE_AURA) && defined(USE_X11) +#include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" +#include "ui/views/linux_ui/linux_ui.h" +#endif + namespace brightray { BrowserMainParts::BrowserMainParts() { @@ -22,9 +27,16 @@ void BrowserMainParts::PreEarlyInitialization() { #if defined(OS_MACOSX) IncreaseFileDescriptorLimit(); #endif + +#if defined(USE_AURA) && defined(USE_X11) + views::LinuxUI::SetInstance(BuildGtk2UI()); +#endif } void BrowserMainParts::ToolkitInitialized() { +#if defined(USE_AURA) && defined(USE_X11) + views::LinuxUI::instance()->Initialize(); +#endif } void BrowserMainParts::PreMainMessageLoopStart() { From d59c0279964345b5e74f011d6d92413f1d36159f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 3 Jul 2014 08:30:26 +0000 Subject: [PATCH 0329/1195] Link with chromiumviews on Linux and Windows. Without using chromiumviews it would be quite hard to setup a fully working environment with Aura on Linux now. --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index aae368994d3..1110946a890 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -101,6 +101,7 @@ 'link_settings': { 'libraries': [ '<(brightray_source_root)/<(libchromiumcontent_library_dir)/libchromiumcontent.so', + '<(brightray_source_root)/<(libchromiumcontent_library_dir)/libchromiumviews.a', '-lpthread', ' Date: Thu, 3 Jul 2014 08:33:42 +0000 Subject: [PATCH 0330/1195] Ignore *_views files on mac. --- brightray/brightray.gypi | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index aac531c2dbc..da6d2a39d39 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -181,6 +181,11 @@ ['exclude', '/mac/'], ['exclude', '_mac\.(mm|h)$'], ], + }, { + 'sources/': [ + ['exclude', '/views/'], + ['exclude', '_views\.(cc|h)$'], + ], }], ['OS!="win"', { 'sources/': [ From bad7b95ed79b01746477763237f3113e07d3f9c5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 3 Jul 2014 08:44:58 +0000 Subject: [PATCH 0331/1195] Add ViewsDelegate, required when using views::Widget on aura. --- brightray/brightray.gyp | 2 + brightray/browser/browser_main_parts.cc | 12 +++ brightray/browser/browser_main_parts.h | 10 +++ brightray/browser/views/views_delegate.cc | 97 +++++++++++++++++++++++ brightray/browser/views/views_delegate.h | 64 +++++++++++++++ 5 files changed, 185 insertions(+) create mode 100644 brightray/browser/views/views_delegate.cc create mode 100644 brightray/browser/views/views_delegate.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 1110946a890..86ac1d0365b 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -75,6 +75,8 @@ 'browser/linux/notification_presenter_linux.cc', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', + 'browser/views/views_delegate.cc', + 'browser/views/views_delegate.h', 'browser/win/devtools_window.cc', 'browser/win/devtools_window.h', 'browser/win/inspectable_web_contents_view_win.cc', diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 9906302d274..69e23e39775 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -15,6 +15,11 @@ #include "ui/views/linux_ui/linux_ui.h" #endif +#if defined(TOOLKIT_VIEWS) +#include "browser/views/views_delegate.h" +#include "ui/wm/core/wm_state.h" +#endif + namespace brightray { BrowserMainParts::BrowserMainParts() { @@ -37,6 +42,13 @@ void BrowserMainParts::ToolkitInitialized() { #if defined(USE_AURA) && defined(USE_X11) views::LinuxUI::instance()->Initialize(); #endif + +#if defined(TOOLKIT_VIEWS) + if (!views::ViewsDelegate::views_delegate) + views::ViewsDelegate::views_delegate = new ViewsDelegate; + + wm_state_.reset(new wm::WMState); +#endif } void BrowserMainParts::PreMainMessageLoopStart() { diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index fc0587f41c2..cbb81006e3e 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -9,6 +9,12 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" +#if defined(TOOLKIT_VIEWS) +namespace wm { +class WMState; +} +#endif + namespace brightray { class BrowserContext; @@ -42,6 +48,10 @@ class BrowserMainParts : public content::BrowserMainParts { scoped_ptr browser_context_; scoped_ptr web_ui_controller_factory_; +#if defined(TOOLKIT_VIEWS) + scoped_ptr wm_state_; +#endif + DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); }; diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc new file mode 100644 index 00000000000..c2649af3bae --- /dev/null +++ b/brightray/browser/views/views_delegate.cc @@ -0,0 +1,97 @@ +// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/views/views_delegate.h" + +#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" + +namespace brightray { + +ViewsDelegate::ViewsDelegate() { +} + +ViewsDelegate::~ViewsDelegate() { +} + +void ViewsDelegate::SaveWindowPlacement(const views::Widget* window, + const std::string& window_name, + const gfx::Rect& bounds, + ui::WindowShowState show_state) { +} + +bool ViewsDelegate::GetSavedWindowPlacement( + const views::Widget* widget, + const std::string& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const { + return false; +} + +void ViewsDelegate::NotifyAccessibilityEvent( + views::View* view, ui::AXEvent event_type) { +} + +void ViewsDelegate::NotifyMenuItemFocused( + const base::string16& menu_name, + const base::string16& menu_item_name, + int item_index, + int item_count, + bool has_submenu) { +} + +#if defined(OS_WIN) +HICON ViewsDelegate::GetDefaultWindowIcon() const { + return NULL; +} + +bool ViewsDelegate::IsWindowInMetro(gfx::NativeWindow window) const { + return false; +} + +#elif defined(OS_LINUX) && !defined(OS_CHROMEOS) +gfx::ImageSkia* ViewsDelegate::GetDefaultWindowIcon() const { + return NULL; +} +#endif + +views::NonClientFrameView* ViewsDelegate::CreateDefaultNonClientFrameView( + views::Widget* widget) { + return NULL; +} + +void ViewsDelegate::AddRef() { +} + +void ViewsDelegate::ReleaseRef() { +} + +content::WebContents* ViewsDelegate::CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) { + return NULL; +} + +void ViewsDelegate::OnBeforeWidgetInit( + views::Widget::InitParams* params, + views::internal::NativeWidgetDelegate* delegate) { + // If we already have a native_widget, we don't have to try to come + // up with one. + if (params->native_widget) + return; + + // The native_widget is required when using aura. + if (params->parent == NULL && params->context == NULL && !params->child) + params->native_widget = new views::DesktopNativeWidgetAura(delegate); +} + + +base::TimeDelta ViewsDelegate::GetDefaultTextfieldObscuredRevealDuration() { + return base::TimeDelta(); +} + +bool ViewsDelegate::WindowManagerProvidesTitleBar(bool maximized) { + return true; +} + +} // namespace brightray diff --git a/brightray/browser/views/views_delegate.h b/brightray/browser/views/views_delegate.h new file mode 100644 index 00000000000..7cd26ef794b --- /dev/null +++ b/brightray/browser/views/views_delegate.h @@ -0,0 +1,64 @@ +// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_VIEWS_VIEWS_DELEGATE_H_ +#define BRIGHTRAY_BROWSER_VIEWS_VIEWS_DELEGATE_H_ + +#include "base/compiler_specific.h" +#include "ui/views/views_delegate.h" + +namespace brightray { + +class ViewsDelegate : public views::ViewsDelegate { + public: + ViewsDelegate(); + virtual ~ViewsDelegate(); + + protected: + // views::ViewsDelegate: + virtual void SaveWindowPlacement(const views::Widget* window, + const std::string& window_name, + const gfx::Rect& bounds, + ui::WindowShowState show_state) OVERRIDE; + virtual bool GetSavedWindowPlacement( + const views::Widget* widget, + const std::string& window_name, + gfx::Rect* bounds, + ui::WindowShowState* show_state) const OVERRIDE; + virtual void NotifyAccessibilityEvent( + views::View* view, ui::AXEvent event_type) OVERRIDE; + virtual void NotifyMenuItemFocused(const base::string16& menu_name, + const base::string16& menu_item_name, + int item_index, + int item_count, + bool has_submenu) OVERRIDE; + +#if defined(OS_WIN) + virtual HICON GetDefaultWindowIcon() const OVERRIDE; + virtual bool IsWindowInMetro(gfx::NativeWindow window) const OVERRIDE; +#elif defined(OS_LINUX) && !defined(OS_CHROMEOS) + virtual gfx::ImageSkia* GetDefaultWindowIcon() const OVERRIDE; +#endif + virtual views::NonClientFrameView* CreateDefaultNonClientFrameView( + views::Widget* widget) OVERRIDE; + virtual void AddRef() OVERRIDE; + virtual void ReleaseRef() OVERRIDE; + virtual content::WebContents* CreateWebContents( + content::BrowserContext* browser_context, + content::SiteInstance* site_instance) OVERRIDE; + virtual void OnBeforeWidgetInit( + views::Widget::InitParams* params, + views::internal::NativeWidgetDelegate* delegate) OVERRIDE; + virtual base::TimeDelta GetDefaultTextfieldObscuredRevealDuration() OVERRIDE; + virtual bool WindowManagerProvidesTitleBar(bool maximized) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(ViewsDelegate); +}; + + + +} // namespace brightray + +#endif // BRIGHTRAY_BROWSER_VIEWS_VIEWS_DELEGATE_H_ From 8f3546ed30dbdb3ca3ec5031a649f68d54982835 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 3 Jul 2014 09:04:03 +0000 Subject: [PATCH 0332/1195] Initialize screen for aura. --- brightray/browser/browser_main_parts.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 69e23e39775..019ad9ed64a 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -10,6 +10,11 @@ #include "ui/gfx/screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h" +#if defined(USE_AURA) +#include "ui/gfx/screen.h" +#include "ui/views/widget/desktop_aura/desktop_screen.h" +#endif + #if defined(USE_AURA) && defined(USE_X11) #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" #include "ui/views/linux_ui/linux_ui.h" @@ -76,6 +81,11 @@ void BrowserMainParts::PostMainMessageLoopRun() { } int BrowserMainParts::PreCreateThreads() { +#if defined(USE_AURA) + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, + views::CreateDesktopScreen()); +#endif + #if defined(OS_WIN) net::ProxyResolverV8::CreateIsolate(); #else From 02f52f7e20b4946570c56d8cac2701aeac64fb6e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 3 Jul 2014 09:18:24 +0000 Subject: [PATCH 0333/1195] Allow override BrowserMainParts::InitProxyResolverV8. --- brightray/browser/browser_main_parts.cc | 14 +++++++++----- brightray/browser/browser_main_parts.h | 12 ++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 019ad9ed64a..68cb5e07a5d 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -86,11 +86,7 @@ int BrowserMainParts::PreCreateThreads() { views::CreateDesktopScreen()); #endif -#if defined(OS_WIN) - net::ProxyResolverV8::CreateIsolate(); -#else - net::ProxyResolverV8::RememberDefaultIsolate(); -#endif + InitProxyResolverV8(); return 0; } @@ -98,4 +94,12 @@ BrowserContext* BrowserMainParts::CreateBrowserContext() { return new BrowserContext; } +void BrowserMainParts::InitProxyResolverV8() { +#if defined(OS_WIN) + net::ProxyResolverV8::CreateIsolate(); +#else + net::ProxyResolverV8::RememberDefaultIsolate(); +#endif +} + } // namespace brightray diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index cbb81006e3e..2d100cdc251 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -28,10 +28,7 @@ class BrowserMainParts : public content::BrowserMainParts { BrowserContext* browser_context() { return browser_context_.get(); } protected: - // Subclasses should override this to provide their own BrowserContxt - // implementation. The caller takes ownership of the returned object. - virtual BrowserContext* CreateBrowserContext(); - + // content::BrowserMainParts: virtual void PreEarlyInitialization() OVERRIDE; virtual void ToolkitInitialized() OVERRIDE; virtual void PreMainMessageLoopStart() OVERRIDE; @@ -39,6 +36,13 @@ class BrowserMainParts : public content::BrowserMainParts { virtual void PostMainMessageLoopRun() OVERRIDE; virtual int PreCreateThreads() OVERRIDE; + // Subclasses should override this to provide their own BrowserContxt + // implementation. The caller takes ownership of the returned object. + virtual BrowserContext* CreateBrowserContext(); + + // Override this to change how ProxyResolverV8 is initialized. + virtual void InitProxyResolverV8(); + private: #if defined(OS_MACOSX) void IncreaseFileDescriptorLimit(); From da5daecb1d23666e71e41db8435e9a11e44d594f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 4 Jul 2014 00:12:05 +0800 Subject: [PATCH 0334/1195] Initialize aura environment. --- brightray/browser/browser_main_parts.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 68cb5e07a5d..588fae1408f 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -11,6 +11,7 @@ #include "ui/views/widget/desktop_aura/desktop_screen.h" #if defined(USE_AURA) +#include "ui/aura/env.h" #include "ui/gfx/screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h" #endif @@ -78,10 +79,14 @@ void BrowserMainParts::PreMainMessageLoopRun() { void BrowserMainParts::PostMainMessageLoopRun() { browser_context_.reset(); +#if defined(USE_AURA) + aura::Env::DeleteInstance(); +#endif } int BrowserMainParts::PreCreateThreads() { #if defined(USE_AURA) + aura::Env::CreateInstance(); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); #endif From 4048d491f0a83cdfc57bdb61df45ba13e3ef0c95 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 4 Jul 2014 11:35:03 +0800 Subject: [PATCH 0335/1195] views: Use chromium's custom frame view. --- brightray/browser/views/views_delegate.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc index c2649af3bae..a33939faba9 100644 --- a/brightray/browser/views/views_delegate.cc +++ b/brightray/browser/views/views_delegate.cc @@ -91,7 +91,7 @@ base::TimeDelta ViewsDelegate::GetDefaultTextfieldObscuredRevealDuration() { } bool ViewsDelegate::WindowManagerProvidesTitleBar(bool maximized) { - return true; + return maximized; } } // namespace brightray From e574bf6d0f2397d6458f2d928badc50da3cf5940 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 4 Jul 2014 16:25:59 +0800 Subject: [PATCH 0336/1195] views: Initial docked devtools implementation. --- brightray/brightray.gyp | 4 +- .../browser/inspectable_web_contents_view.h | 16 ++- .../inspectable_web_contents_view_linux.cc | 46 --------- .../inspectable_web_contents_view_views.cc | 98 +++++++++++++++++++ .../inspectable_web_contents_view_views.h} | 30 ++++-- 5 files changed, 138 insertions(+), 56 deletions(-) delete mode 100644 brightray/browser/linux/inspectable_web_contents_view_linux.cc create mode 100644 brightray/browser/views/inspectable_web_contents_view_views.cc rename brightray/browser/{linux/inspectable_web_contents_view_linux.h => views/inspectable_web_contents_view_views.h} (52%) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 86ac1d0365b..cf5f6599fd7 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -56,8 +56,6 @@ 'browser/inspectable_web_contents_view.h', 'browser/inspectable_web_contents_view_mac.h', 'browser/inspectable_web_contents_view_mac.mm', - 'browser/linux/inspectable_web_contents_view_linux.h', - 'browser/linux/inspectable_web_contents_view_linux.cc', 'browser/mac/bry_application.h', 'browser/mac/bry_application.mm', 'browser/mac/bry_inspectable_web_contents_view.h', @@ -75,6 +73,8 @@ 'browser/linux/notification_presenter_linux.cc', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', + 'browser/views/inspectable_web_contents_view_views.h', + 'browser/views/inspectable_web_contents_view_views.cc', 'browser/views/views_delegate.cc', 'browser/views/views_delegate.h', 'browser/win/devtools_window.cc', diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 251d4337a43..a79205b1170 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -5,14 +5,28 @@ class DevToolsContentsResizingStrategy; +#if defined(TOOLKIT_VIEWS) +namespace views { +class View; +} +#endif + namespace brightray { class InspectableWebContentsView { public: virtual ~InspectableWebContentsView() {} - virtual gfx::NativeView GetNativeView() const = 0; +#if defined(TOOLKIT_VIEWS) + // Returns the container control, which has devtools view attached. + virtual views::View* GetView() = 0; + // Returns the web view control, which can be used by the + // GetInitiallyFocusedView() to set initial focus to web view. + virtual views::View* GetWebView() = 0; +#endif + + virtual gfx::NativeView GetNativeView() const = 0; virtual void ShowDevTools() = 0; // Hide the DevTools view. virtual void CloseDevTools() = 0; diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.cc b/brightray/browser/linux/inspectable_web_contents_view_linux.cc deleted file mode 100644 index 5cfb7130c25..00000000000 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.cc +++ /dev/null @@ -1,46 +0,0 @@ -#include "browser/linux/inspectable_web_contents_view_linux.h" - -#include "base/strings/stringprintf.h" -#include "browser/browser_client.h" -#include "browser/inspectable_web_contents_impl.h" - -#include "content/public/browser/web_contents_view.h" - -namespace brightray { - -InspectableWebContentsView* CreateInspectableContentsView( - InspectableWebContentsImpl* inspectable_web_contents) { - return new InspectableWebContentsViewLinux(inspectable_web_contents); -} - -InspectableWebContentsViewLinux::InspectableWebContentsViewLinux( - InspectableWebContentsImpl* inspectable_web_contents) - : inspectable_web_contents_(inspectable_web_contents) { -} - -InspectableWebContentsViewLinux::~InspectableWebContentsViewLinux() { -} - -gfx::NativeView InspectableWebContentsViewLinux::GetNativeView() const { - auto web_contents = inspectable_web_contents_->GetWebContents(); - return web_contents->GetView()->GetNativeView(); -} - -void InspectableWebContentsViewLinux::ShowDevTools() { -} - -void InspectableWebContentsViewLinux::CloseDevTools() { -} - -bool InspectableWebContentsViewLinux::IsDevToolsViewShowing() { - return false; -} - -void InspectableWebContentsViewLinux::SetIsDocked(bool docked) { -} - -void InspectableWebContentsViewLinux::SetContentsResizingStrategy( - const DevToolsContentsResizingStrategy& strategy) { -} - -} // namespace brightray diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc new file mode 100644 index 00000000000..9092d79a3e7 --- /dev/null +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -0,0 +1,98 @@ +#include "browser/views/inspectable_web_contents_view_views.h" + +#include "browser/inspectable_web_contents_impl.h" + +#include "content/public/browser/web_contents_view.h" +#include "ui/views/controls/webview/webview.h" + +namespace brightray { + +InspectableWebContentsView* CreateInspectableContentsView( + InspectableWebContentsImpl* inspectable_web_contents) { + return new InspectableWebContentsViewViews(inspectable_web_contents); +} + +InspectableWebContentsViewViews::InspectableWebContentsViewViews( + InspectableWebContentsImpl* inspectable_web_contents) + : inspectable_web_contents_(inspectable_web_contents), + contents_web_view_(new views::WebView(NULL)), + devtools_web_view_(new views::WebView(NULL)) { + set_owned_by_client(); + + devtools_web_view_->SetVisible(false); + contents_web_view_->SetWebContents(inspectable_web_contents_->GetWebContents()); + AddChildView(devtools_web_view_); + AddChildView(contents_web_view_); +} + +InspectableWebContentsViewViews::~InspectableWebContentsViewViews() { +} + +views::View* InspectableWebContentsViewViews::GetView() { + return this; +} + +views::View* InspectableWebContentsViewViews::GetWebView() { + return contents_web_view_; +} + +gfx::NativeView InspectableWebContentsViewViews::GetNativeView() const { + return inspectable_web_contents_->GetWebContents()->GetView()->GetNativeView(); +} + +void InspectableWebContentsViewViews::ShowDevTools() { + if (devtools_web_view_->visible()) + return; + + devtools_web_view_->SetVisible(true); + devtools_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents()); + Layout(); +} + +void InspectableWebContentsViewViews::CloseDevTools() { + if (!devtools_web_view_->visible()) + return; + + devtools_web_view_->SetVisible(false); + devtools_web_view_->SetWebContents(NULL); + Layout(); +} + +bool InspectableWebContentsViewViews::IsDevToolsViewShowing() { + return devtools_web_view_->visible(); +} + +void InspectableWebContentsViewViews::SetIsDocked(bool docked) { +} + +void InspectableWebContentsViewViews::SetContentsResizingStrategy( + const DevToolsContentsResizingStrategy& strategy) { + strategy_.CopyFrom(strategy); + Layout(); +} + +void InspectableWebContentsViewViews::Layout() { + if (!devtools_web_view_->visible()) { + contents_web_view_->SetBoundsRect(GetContentsBounds()); + return; + } + + gfx::Size container_size(width(), height()); + gfx::Rect old_devtools_bounds(devtools_web_view_->bounds()); + gfx::Rect old_contents_bounds(contents_web_view_->bounds()); + gfx::Rect new_devtools_bounds; + gfx::Rect new_contents_bounds; + ApplyDevToolsContentsResizingStrategy(strategy_, container_size, + old_devtools_bounds, old_contents_bounds, + &new_devtools_bounds, &new_contents_bounds); + + // DevTools cares about the specific position, so we have to compensate RTL + // layout here. + new_devtools_bounds.set_x(GetMirroredXForRect(new_devtools_bounds)); + new_contents_bounds.set_x(GetMirroredXForRect(new_contents_bounds)); + + devtools_web_view_->SetBoundsRect(new_devtools_bounds); + contents_web_view_->SetBoundsRect(new_contents_bounds); +} + +} // namespace brightray diff --git a/brightray/browser/linux/inspectable_web_contents_view_linux.h b/brightray/browser/views/inspectable_web_contents_view_views.h similarity index 52% rename from brightray/browser/linux/inspectable_web_contents_view_linux.h rename to brightray/browser/views/inspectable_web_contents_view_views.h index ef00ed5b5de..91d31de6f49 100644 --- a/brightray/browser/linux/inspectable_web_contents_view_linux.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -1,21 +1,31 @@ -#ifndef BRIGHTRAY_BROWSER_LINUX_INSPECTABLE_WEB_CONTENTS_VIEW_LINUX_H_ -#define BRIGHTRAY_BROWSER_LINUX_INSPECTABLE_WEB_CONTENTS_VIEW_LINUX_H_ +#ifndef BROWSER_VIEWS_INSPECTABLE_WEB_CONTENTS_VIEW_VIEWS_H_ +#define BROWSER_VIEWS_INSPECTABLE_WEB_CONTENTS_VIEW_VIEWS_H_ #include "browser/devtools_contents_resizing_strategy.h" #include "browser/inspectable_web_contents_view.h" #include "base/compiler_specific.h" +#include "ui/views/view.h" + +namespace views { +class WebView; +class Widget; +} namespace brightray { class InspectableWebContentsImpl; -class InspectableWebContentsViewLinux : public InspectableWebContentsView { +class InspectableWebContentsViewViews : public InspectableWebContentsView, + public views::View { public: - explicit InspectableWebContentsViewLinux( + explicit InspectableWebContentsViewViews( InspectableWebContentsImpl* inspectable_web_contents_impl); - ~InspectableWebContentsViewLinux(); + ~InspectableWebContentsViewViews(); + // InspectableWebContentsView: + virtual views::View* GetView() OVERRIDE; + virtual views::View* GetWebView() OVERRIDE; virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; @@ -29,14 +39,20 @@ class InspectableWebContentsViewLinux : public InspectableWebContentsView { } private: + // views::View: + virtual void Layout() OVERRIDE; + // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; + views::WebView* contents_web_view_; + views::WebView* devtools_web_view_; + DevToolsContentsResizingStrategy strategy_; - DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewLinux); + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewViews); }; } // namespace brightray -#endif +#endif // BROWSER_VIEWS_INSPECTABLE_WEB_CONTENTS_VIEW_VIEWS_H_ From 4fb4b2d7babc637a4077e2ce857e0072b1f1157e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 4 Jul 2014 20:26:59 +0800 Subject: [PATCH 0337/1195] views: Implement undocked devtools. --- .../inspectable_web_contents_view_views.cc | 101 ++++++++++++++++-- .../inspectable_web_contents_view_views.h | 3 + 2 files changed, 94 insertions(+), 10 deletions(-) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 9092d79a3e7..b2013dc85e7 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -2,11 +2,57 @@ #include "browser/inspectable_web_contents_impl.h" +#include "base/strings/utf_string_conversions.h" #include "content/public/browser/web_contents_view.h" #include "ui/views/controls/webview/webview.h" +#include "ui/views/widget/widget.h" +#include "ui/views/widget/widget_delegate.h" +#include "ui/views/window/client_view.h" namespace brightray { +namespace { + +class DevToolsWindowDelegate : public views::ClientView, + public views::WidgetDelegate { + public: + DevToolsWindowDelegate(InspectableWebContentsViewViews* shell, + views::View* view, + views::Widget* widget) + : views::ClientView(widget_, view), + shell_(shell), + view_(view), + widget_(widget), + title_(base::ASCIIToUTF16("Developer Tools")) {} + virtual ~DevToolsWindowDelegate() {} + + // views::WidgetDelegate: + virtual views::View* GetInitiallyFocusedView() OVERRIDE { return view_; } + virtual bool CanResize() const OVERRIDE { return true; } + virtual bool CanMaximize() const OVERRIDE { return true; } + virtual base::string16 GetWindowTitle() const OVERRIDE { return title_; } + virtual views::Widget* GetWidget() OVERRIDE { return widget_; } + virtual const views::Widget* GetWidget() const OVERRIDE { return widget_; } + virtual views::View* GetContentsView() OVERRIDE { return view_; } + virtual views::ClientView* CreateClientView(views::Widget* widget) { return this; } + + // views::ClientView: + virtual bool CanClose() OVERRIDE { + shell_->inspectable_web_contents()->CloseDevTools(); + return false; + } + + private: + InspectableWebContentsViewViews* shell_; + views::View* view_; + views::Widget* widget_; + base::string16 title_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsWindowDelegate); +}; + +} // namespace + InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents) { return new InspectableWebContentsViewViews(inspectable_web_contents); @@ -15,8 +61,10 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsViewViews::InspectableWebContentsViewViews( InspectableWebContentsImpl* inspectable_web_contents) : inspectable_web_contents_(inspectable_web_contents), + devtools_window_web_view_(NULL), contents_web_view_(new views::WebView(NULL)), - devtools_web_view_(new views::WebView(NULL)) { + devtools_web_view_(new views::WebView(NULL)), + devtools_visible_(false) { set_owned_by_client(); devtools_web_view_->SetVisible(false); @@ -41,28 +89,61 @@ gfx::NativeView InspectableWebContentsViewViews::GetNativeView() const { } void InspectableWebContentsViewViews::ShowDevTools() { - if (devtools_web_view_->visible()) + if (devtools_visible_) return; - devtools_web_view_->SetVisible(true); - devtools_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents()); - Layout(); + devtools_visible_ = true; + if (devtools_window_) { + devtools_window_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents()); + devtools_window_->CenterWindow(gfx::Size(800, 600)); + devtools_window_->Show(); + } else { + devtools_web_view_->SetVisible(true); + devtools_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents()); + devtools_web_view_->RequestFocus(); + Layout(); + } } void InspectableWebContentsViewViews::CloseDevTools() { - if (!devtools_web_view_->visible()) + if (!devtools_visible_) return; - devtools_web_view_->SetVisible(false); - devtools_web_view_->SetWebContents(NULL); - Layout(); + devtools_visible_ = false; + if (devtools_window_) { + devtools_window_.reset(); + devtools_window_web_view_ = NULL; + } else { + devtools_web_view_->SetVisible(false); + devtools_web_view_->SetWebContents(NULL); + Layout(); + } } bool InspectableWebContentsViewViews::IsDevToolsViewShowing() { - return devtools_web_view_->visible(); + return devtools_visible_; } void InspectableWebContentsViewViews::SetIsDocked(bool docked) { + CloseDevTools(); + + if (!docked) { + devtools_window_.reset(new views::Widget); + devtools_window_web_view_ = new views::WebView(NULL); + + views::Widget::InitParams params; + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; + // The delegate is also a ClientView, so it would deleted when the view + // destructs, no need to delete it in DeleteDelegate. + params.delegate = new DevToolsWindowDelegate(this, + devtools_window_web_view_, + devtools_window_.get()); + params.top_level = true; + params.remove_standard_frame = true; + devtools_window_->Init(params); + } + + ShowDevTools(); } void InspectableWebContentsViewViews::SetContentsResizingStrategy( diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index 91d31de6f49..319f1bd6c02 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -45,10 +45,13 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; + scoped_ptr devtools_window_; + views::WebView* devtools_window_web_view_; views::WebView* contents_web_view_; views::WebView* devtools_web_view_; DevToolsContentsResizingStrategy strategy_; + bool devtools_visible_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewViews); }; From 651ebdde65ce1e75ac2161655bfd8dfc02e9a0b1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 4 Jul 2014 21:34:47 +0800 Subject: [PATCH 0338/1195] views: Remember bounds of devtools window. --- .../browser/inspectable_web_contents_impl.cc | 40 ++++++++++++++++++- .../browser/inspectable_web_contents_impl.h | 6 +++ .../mac/bry_inspectable_web_contents_view.mm | 2 +- .../inspectable_web_contents_view_views.cc | 7 +++- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 26fcc2b0f0f..79143aa122c 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -15,6 +15,7 @@ #include "base/prefs/pref_service.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" +#include "base/values.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_http_handler.h" @@ -27,22 +28,45 @@ namespace brightray { namespace { const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?can_dock=true"; -const char kIsDockedPref[] = "brightray.devtools.isDocked"; +const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; +void RectToDictionary(const gfx::Rect& bounds, base::DictionaryValue* dict) { + dict->SetInteger("x", bounds.x()); + dict->SetInteger("y", bounds.y()); + dict->SetInteger("width", bounds.width()); + dict->SetInteger("height", bounds.height()); } +void DictionaryToRect(const base::DictionaryValue& dict, gfx::Rect* bounds) { + int x = 0, y = 0, width = 800, height = 600; + dict.GetInteger("x", &x); + dict.GetInteger("y", &y); + dict.GetInteger("width", &width); + dict.GetInteger("height", &height); + *bounds = gfx::Rect(x, y, width, height); +} + +} // namespace + // Implemented separately on each platform. InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents_impl); void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { - registry->RegisterBooleanPref(kIsDockedPref, true); + scoped_ptr bounds_dict(new base::DictionaryValue); + RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get()); + registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release()); } InspectableWebContentsImpl::InspectableWebContentsImpl( content::WebContents* web_contents) : web_contents_(web_contents), delegate_(nullptr) { + auto context = static_cast(web_contents_->GetBrowserContext()); + auto bounds_dict = context->prefs()->GetDictionary(kDevToolsBoundsPref); + if (bounds_dict) + DictionaryToRect(*bounds_dict, &devtools_bounds_); + view_.reset(CreateInspectableContentsView(this)); } @@ -102,6 +126,18 @@ bool InspectableWebContentsImpl::IsDevToolsViewShowing() { return devtools_web_contents_ && view_->IsDevToolsViewShowing(); } +gfx::Rect InspectableWebContentsImpl::GetDevToolsBounds() const { + return devtools_bounds_; +} + +void InspectableWebContentsImpl::SaveDevToolsBounds(const gfx::Rect& bounds) { + auto context = static_cast(web_contents_->GetBrowserContext()); + base::DictionaryValue bounds_dict; + RectToDictionary(bounds, &bounds_dict); + context->prefs()->Set(kDevToolsBoundsPref, bounds_dict); + devtools_bounds_ = bounds; +} + void InspectableWebContentsImpl::ActivateWindow() { } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 5c030a449f6..d02fd75400f 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -14,6 +14,7 @@ #include "content/public/browser/devtools_frontend_host_delegate.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" +#include "ui/gfx/rect.h" class PrefRegistrySimple; @@ -46,6 +47,10 @@ class InspectableWebContentsImpl : virtual void CloseDevTools() OVERRIDE; virtual bool IsDevToolsViewShowing() OVERRIDE; + // Return the last position and size of devtools window. + gfx::Rect GetDevToolsBounds() const; + void SaveDevToolsBounds(const gfx::Rect& bounds); + virtual void SetDelegate(InspectableWebContentsDelegate* delegate) { delegate_ = delegate; } @@ -106,6 +111,7 @@ class InspectableWebContentsImpl : scoped_refptr agent_host_; DevToolsContentsResizingStrategy contents_resizing_strategy_; + gfx::Rect devtools_bounds_; scoped_ptr embedder_message_dispatcher_; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 99c2e4179a0..045f389f72b 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -95,7 +95,7 @@ using namespace brightray; backing:NSBackingStoreBuffered defer:YES]); [devtools_window_ setDelegate:self]; - [devtools_window_ setFrameAutosaveName:@"brightray.developer.tools"]; + [devtools_window_ setFrameAutosaveName:@"brightray.devtools"]; [devtools_window_ setTitle:@"Developer Tools"]; [devtools_window_ setReleasedWhenClosed:NO]; [devtools_window_ setAutorecalculatesContentBorderThickness:NO forEdge:NSMaxYEdge]; diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index b2013dc85e7..03a052b1f79 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -29,7 +29,7 @@ class DevToolsWindowDelegate : public views::ClientView, // views::WidgetDelegate: virtual views::View* GetInitiallyFocusedView() OVERRIDE { return view_; } virtual bool CanResize() const OVERRIDE { return true; } - virtual bool CanMaximize() const OVERRIDE { return true; } + virtual bool CanMaximize() const OVERRIDE { return false; } virtual base::string16 GetWindowTitle() const OVERRIDE { return title_; } virtual views::Widget* GetWidget() OVERRIDE { return widget_; } virtual const views::Widget* GetWidget() const OVERRIDE { return widget_; } @@ -74,6 +74,8 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews( } InspectableWebContentsViewViews::~InspectableWebContentsViewViews() { + if (devtools_window_) + inspectable_web_contents()->SaveDevToolsBounds(devtools_window_->GetWindowBoundsInScreen()); } views::View* InspectableWebContentsViewViews::GetView() { @@ -95,7 +97,7 @@ void InspectableWebContentsViewViews::ShowDevTools() { devtools_visible_ = true; if (devtools_window_) { devtools_window_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents()); - devtools_window_->CenterWindow(gfx::Size(800, 600)); + devtools_window_->SetBounds(inspectable_web_contents()->GetDevToolsBounds()); devtools_window_->Show(); } else { devtools_web_view_->SetVisible(true); @@ -111,6 +113,7 @@ void InspectableWebContentsViewViews::CloseDevTools() { devtools_visible_ = false; if (devtools_window_) { + inspectable_web_contents()->SaveDevToolsBounds(devtools_window_->GetWindowBoundsInScreen()); devtools_window_.reset(); devtools_window_web_view_ = NULL; } else { From 7a196933bb5a76631c60673feddcf8f650027b60 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 4 Jul 2014 21:41:22 +0800 Subject: [PATCH 0339/1195] views: Don't leak ViewsDelegate. --- brightray/browser/browser_main_parts.cc | 4 +--- brightray/browser/browser_main_parts.h | 5 +++++ brightray/browser/views/views_delegate.cc | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 588fae1408f..a866caed688 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -50,9 +50,7 @@ void BrowserMainParts::ToolkitInitialized() { #endif #if defined(TOOLKIT_VIEWS) - if (!views::ViewsDelegate::views_delegate) - views::ViewsDelegate::views_delegate = new ViewsDelegate; - + views_delegate_.reset(new ViewsDelegate); wm_state_.reset(new wm::WMState); #endif } diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 2d100cdc251..f170ab589c7 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -10,6 +10,10 @@ #include "content/public/browser/browser_main_parts.h" #if defined(TOOLKIT_VIEWS) +namespace brightray { +class ViewsDelegate; +} + namespace wm { class WMState; } @@ -53,6 +57,7 @@ class BrowserMainParts : public content::BrowserMainParts { scoped_ptr web_ui_controller_factory_; #if defined(TOOLKIT_VIEWS) + scoped_ptr views_delegate_; scoped_ptr wm_state_; #endif diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc index a33939faba9..6ade87e338e 100644 --- a/brightray/browser/views/views_delegate.cc +++ b/brightray/browser/views/views_delegate.cc @@ -9,9 +9,13 @@ namespace brightray { ViewsDelegate::ViewsDelegate() { + DCHECK(!views::ViewsDelegate::views_delegate); + views::ViewsDelegate::views_delegate = this; } ViewsDelegate::~ViewsDelegate() { + DCHECK_EQ(views::ViewsDelegate::views_delegate, this); + views::ViewsDelegate::views_delegate = NULL; } void ViewsDelegate::SaveWindowPlacement(const views::Widget* window, From 0a7b1fdd8722fb1a82edf844873553feeb48d6f2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Jul 2014 15:58:38 +0800 Subject: [PATCH 0340/1195] Add new devtools messages in Chrome 35. --- .../devtools_embedder_message_dispatcher.cc | 15 +++++++++++++++ .../devtools_embedder_message_dispatcher.h | 6 ++++++ .../browser/inspectable_web_contents_impl.cc | 16 ++++++++++++++++ .../browser/inspectable_web_contents_impl.h | 6 ++++++ 4 files changed, 43 insertions(+) diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index 98e4732208b..31351778f89 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -198,6 +198,9 @@ DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher( RegisterHandler("setContentsResizingStrategy", BindToListParser(base::Bind(&Delegate::SetContentsResizingStrategy, base::Unretained(delegate)))); + RegisterHandler("inspectElementCompleted", + BindToListParser(base::Bind(&Delegate::InspectElementCompleted, + base::Unretained(delegate)))); RegisterHandler("moveWindowBy", BindToListParser(base::Bind(&Delegate::MoveWindow, base::Unretained(delegate)))); @@ -222,6 +225,9 @@ DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher( RegisterHandler("removeFileSystem", BindToListParser(base::Bind(&Delegate::RemoveFileSystem, base::Unretained(delegate)))); + RegisterHandler("upgradeDraggedFileSystemPermissions", + BindToListParser(base::Bind(&Delegate::UpgradeDraggedFileSystemPermissions, + base::Unretained(delegate)))); RegisterHandler("indexPath", BindToListParser(base::Bind(&Delegate::IndexPath, base::Unretained(delegate)))); @@ -231,6 +237,15 @@ DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher( RegisterHandler("searchInPath", BindToListParser(base::Bind(&Delegate::SearchInPath, base::Unretained(delegate)))); + RegisterHandler("zoomIn", + BindToListParser(base::Bind(&Delegate::ZoomIn, + base::Unretained(delegate)))); + RegisterHandler("zoomOut", + BindToListParser(base::Bind(&Delegate::ZoomOut, + base::Unretained(delegate)))); + RegisterHandler("resetZoom", + BindToListParser(base::Bind(&Delegate::ResetZoom, + base::Unretained(delegate)))); } DevToolsEmbedderMessageDispatcher::~DevToolsEmbedderMessageDispatcher() {} diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index 1f4a6e5d00c..e43abff5285 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -34,6 +34,7 @@ class DevToolsEmbedderMessageDispatcher { virtual void CloseWindow() = 0; virtual void SetContentsResizingStrategy( const gfx::Insets& insets, const gfx::Size& min_size) = 0; + virtual void InspectElementCompleted() = 0; virtual void MoveWindow(int x, int y) = 0; virtual void SetIsDocked(bool docked) = 0; virtual void OpenInNewTab(const std::string& url) = 0; @@ -45,12 +46,17 @@ class DevToolsEmbedderMessageDispatcher { virtual void RequestFileSystems() = 0; virtual void AddFileSystem() = 0; virtual void RemoveFileSystem(const std::string& file_system_path) = 0; + virtual void UpgradeDraggedFileSystemPermissions( + const std::string& file_system_url) = 0; virtual void IndexPath(int request_id, const std::string& file_system_path) = 0; virtual void StopIndexing(int request_id) = 0; virtual void SearchInPath(int request_id, const std::string& file_system_path, const std::string& query) = 0; + virtual void ZoomIn() = 0; + virtual void ZoomOut() = 0; + virtual void ResetZoom() = 0; }; explicit DevToolsEmbedderMessageDispatcher(Delegate* delegate); diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 79143aa122c..38278f265af 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -155,6 +155,9 @@ void InspectableWebContentsImpl::SetContentsResizingStrategy( view_->SetContentsResizingStrategy(contents_resizing_strategy_); } +void InspectableWebContentsImpl::InspectElementCompleted() { +} + void InspectableWebContentsImpl::MoveWindow(int x, int y) { } @@ -187,6 +190,10 @@ void InspectableWebContentsImpl::RemoveFileSystem( const std::string& file_system_path) { } +void InspectableWebContentsImpl::UpgradeDraggedFileSystemPermissions( + const std::string& file_system_url) { +} + void InspectableWebContentsImpl::IndexPath( int request_id, const std::string& file_system_path) { } @@ -200,6 +207,15 @@ void InspectableWebContentsImpl::SearchInPath( const std::string& query) { } +void InspectableWebContentsImpl::ZoomIn() { +} + +void InspectableWebContentsImpl::ZoomOut() { +} + +void InspectableWebContentsImpl::ResetZoom() { +} + void InspectableWebContentsImpl::DispatchOnEmbedder( const std::string& message) { embedder_message_dispatcher_->Dispatch(message); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index d02fd75400f..1fcfff55379 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -66,6 +66,7 @@ class InspectableWebContentsImpl : virtual void CloseWindow() OVERRIDE; virtual void SetContentsResizingStrategy( const gfx::Insets& insets, const gfx::Size& min_size) OVERRIDE; + virtual void InspectElementCompleted() OVERRIDE; virtual void MoveWindow(int x, int y) OVERRIDE; virtual void SetIsDocked(bool docked) OVERRIDE; virtual void OpenInNewTab(const std::string& url) OVERRIDE; @@ -77,12 +78,17 @@ class InspectableWebContentsImpl : virtual void RequestFileSystems() OVERRIDE; virtual void AddFileSystem() OVERRIDE; virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; + virtual void UpgradeDraggedFileSystemPermissions( + const std::string& file_system_url) OVERRIDE; virtual void IndexPath(int request_id, const std::string& file_system_path) OVERRIDE; virtual void StopIndexing(int request_id) OVERRIDE; virtual void SearchInPath(int request_id, const std::string& file_system_path, const std::string& query) OVERRIDE; + virtual void ZoomIn() OVERRIDE; + virtual void ZoomOut() OVERRIDE; + virtual void ResetZoom() OVERRIDE; // content::DevToolsFrontendHostDelegate From 81d31b1d49510768299346fe53b57da904a63104 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Jul 2014 10:32:27 +0800 Subject: [PATCH 0341/1195] Remove Windows's devtools implementation. --- brightray/brightray.gyp | 4 - brightray/browser/browser_main_parts.cc | 6 - brightray/browser/win/devtools_window.cc | 66 ------ brightray/browser/win/devtools_window.h | 37 ---- .../win/inspectable_web_contents_view_win.cc | 201 ------------------ .../win/inspectable_web_contents_view_win.h | 61 ------ 6 files changed, 375 deletions(-) delete mode 100644 brightray/browser/win/devtools_window.cc delete mode 100644 brightray/browser/win/devtools_window.h delete mode 100644 brightray/browser/win/inspectable_web_contents_view_win.cc delete mode 100644 brightray/browser/win/inspectable_web_contents_view_win.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index cf5f6599fd7..3c50d2b6681 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -77,10 +77,6 @@ 'browser/views/inspectable_web_contents_view_views.cc', 'browser/views/views_delegate.cc', 'browser/views/views_delegate.h', - 'browser/win/devtools_window.cc', - 'browser/win/devtools_window.h', - 'browser/win/inspectable_web_contents_view_win.cc', - 'browser/win/inspectable_web_contents_view_win.h', 'browser/web_ui_controller_factory.cc', 'browser/web_ui_controller_factory.h', 'common/application_info.h', diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index a866caed688..d66a9f0b287 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -7,8 +7,6 @@ #include "browser/browser_context.h" #include "browser/web_ui_controller_factory.h" #include "net/proxy/proxy_resolver_v8.h" -#include "ui/gfx/screen.h" -#include "ui/views/widget/desktop_aura/desktop_screen.h" #if defined(USE_AURA) #include "ui/aura/env.h" @@ -69,10 +67,6 @@ void BrowserMainParts::PreMainMessageLoopRun() { new WebUIControllerFactory(browser_context_.get())); content::WebUIControllerFactory::RegisterFactory( web_ui_controller_factory_.get()); - -#if defined(OS_WIN) - gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); -#endif } void BrowserMainParts::PostMainMessageLoopRun() { diff --git a/brightray/browser/win/devtools_window.cc b/brightray/browser/win/devtools_window.cc deleted file mode 100644 index 59857057d5a..00000000000 --- a/brightray/browser/win/devtools_window.cc +++ /dev/null @@ -1,66 +0,0 @@ -#include "browser/win/devtools_window.h" - -#include "browser/inspectable_web_contents_impl.h" -#include "browser/win/inspectable_web_contents_view_win.h" - -#include "content/public/browser/web_contents_view.h" -#include "ui/views/layout/fill_layout.h" -#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" -#include "ui/views/widget/widget_delegate.h" - -namespace brightray { - -namespace { - -class WidgetDelegateView : public views::WidgetDelegateView { - public: - WidgetDelegateView() { - SetLayoutManager(new views::FillLayout); - } - - virtual void DeleteDelegate() OVERRIDE { delete this; } - virtual views::View* GetContentsView() OVERRIDE { return this; } - virtual bool CanResize() const OVERRIDE { return true; } - virtual bool CanMaximize() const OVERRIDE { return true; } - virtual base::string16 GetWindowTitle() const OVERRIDE { return L"Developer Tools"; } - virtual gfx::Size GetPreferredSize() OVERRIDE { return gfx::Size(800, 600); } - virtual gfx::Size GetMinimumSize() OVERRIDE { return gfx::Size(100, 100); } -}; - -} // namespace - -DevToolsWindow* DevToolsWindow::Create( - InspectableWebContentsViewWin* controller) { - return new DevToolsWindow(controller); -} - -DevToolsWindow::DevToolsWindow(InspectableWebContentsViewWin* controller) - : controller_(controller), - widget_(new views::Widget) { - auto delegate_view = new WidgetDelegateView; - views::Widget::InitParams params; - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.top_level = true; - params.native_widget = new views::DesktopNativeWidgetAura(widget_.get()); - params.delegate = delegate_view; - widget_->Init(params); - delegate_view->AddChildView(controller->GetView()); - delegate_view->Layout(); -} - -DevToolsWindow::~DevToolsWindow() { -} - -void DevToolsWindow::Show() { - widget_->Show(); -} - -void DevToolsWindow::Close() { - widget_->Hide(); -} - -void DevToolsWindow::Destroy() { - delete this; -} - -} // namespace brightray diff --git a/brightray/browser/win/devtools_window.h b/brightray/browser/win/devtools_window.h deleted file mode 100644 index 33c1a4120bc..00000000000 --- a/brightray/browser/win/devtools_window.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ -#define BRIGHTRAY_BROWSER_WIN_DEVTOOLS_WINDOW_H_ - -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" - -namespace views { -class Widget; -} - -namespace brightray { - -class InspectableWebContentsViewWin; - -class DevToolsWindow : public base::SupportsWeakPtr { - public: - static DevToolsWindow* Create( - InspectableWebContentsViewWin* inspectable_web_contents_view_win); - - void Show(); - void Close(); - void Destroy(); - - private: - explicit DevToolsWindow( - InspectableWebContentsViewWin* inspectable_web_contents_view_win); - ~DevToolsWindow(); - - InspectableWebContentsViewWin* controller_; - scoped_ptr widget_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsWindow); -}; - -} // namespace brightray - -#endif diff --git a/brightray/browser/win/inspectable_web_contents_view_win.cc b/brightray/browser/win/inspectable_web_contents_view_win.cc deleted file mode 100644 index 641725889bf..00000000000 --- a/brightray/browser/win/inspectable_web_contents_view_win.cc +++ /dev/null @@ -1,201 +0,0 @@ -#include "browser/win/inspectable_web_contents_view_win.h" - -#include "browser/browser_client.h" -#include "browser/inspectable_web_contents_impl.h" -#include "browser/win/devtools_window.h" - -#include "content/public/browser/web_contents_view.h" -#include "ui/gfx/win/hwnd_util.h" -#include "ui/views/controls/single_split_view.h" -#include "ui/views/controls/webview/webview.h" -#include "ui/views/view.h" - -namespace brightray { - -namespace { - -const int kWindowInset = 100; - -} - -class ContainerView : public views::View { - public: - explicit ContainerView(InspectableWebContentsViewWin* web_contents_view) - : container_view_created_(false), - dockside_("none"), // "none" is treated as "bottom". - web_view_(new views::WebView(NULL)), - web_contents_view_(web_contents_view) { - set_owned_by_client(); - web_view_->set_owned_by_client(); - web_view_->SetWebContents( - web_contents_view_->inspectable_web_contents()->GetWebContents()); - } - - views::View* GetWebView() const { - return web_view_.get(); - } - - void ShowDevTools() { - if (IsDevToolsViewShowing()) - return; - - RemoveChildView(web_view_.get()); - devtools_view_ = new views::WebView(NULL); - devtools_view_->SetWebContents(web_contents_view_-> - inspectable_web_contents()->devtools_web_contents()); - split_view_.reset(new views::SingleSplitView( - web_view_.get(), - devtools_view_, - GetSplitViewOrientation(), - NULL)); - split_view_->set_divider_offset(GetSplitVievDividerOffset()); - AddChildView(split_view_.get()); - Layout(); - - devtools_view_->RequestFocus(); - } - - void CloseDevTools() { - if (!IsDevToolsViewShowing()) - return; - - RemoveChildView(split_view_.get()); - split_view_.reset(); - AddChildView(web_view_.get()); - Layout(); - } - - bool IsDevToolsViewShowing() { - return split_view_; - } - - void SetDockSide(const std::string& side) { - if (dockside_ == side) - return; // no change from current location - - dockside_ = side; - if (!IsDevToolsViewShowing()) - return; - - split_view_->set_orientation(GetSplitViewOrientation()); - split_view_->set_divider_offset(GetSplitVievDividerOffset()); - split_view_->Layout(); - return; - } - - private: - // views::View: - virtual void Layout() OVERRIDE { - if (split_view_) - split_view_->SetBounds(0, 0, width(), height()); - else - web_view_->SetBounds(0, 0, width(), height()); - } - - virtual void ViewHierarchyChanged( - const ViewHierarchyChangedDetails& details) OVERRIDE { - View::ViewHierarchyChanged(details); - // We're not using child == this because a Widget may not be - // available when this is added to the hierarchy. - if (details.is_add && GetWidget() && !container_view_created_) { - container_view_created_ = true; - AddChildView(web_view_.get()); - } - } - - views::SingleSplitView::Orientation GetSplitViewOrientation() const { - if (dockside_ == "right") - return views::SingleSplitView::HORIZONTAL_SPLIT; - else - return views::SingleSplitView::VERTICAL_SPLIT; - } - - int GetSplitVievDividerOffset() const { - if (dockside_ == "right") - return width() * 2 / 3; - else - return height() * 2 / 3; - } - - // True if the container view has already been created, or false otherwise. - bool container_view_created_; - - std::string dockside_; - - scoped_ptr web_view_; - scoped_ptr split_view_; - views::WebView* devtools_view_; // Owned by split_view_. - - InspectableWebContentsViewWin* web_contents_view_; -}; - -InspectableWebContentsView* CreateInspectableContentsView( - InspectableWebContentsImpl* inspectable_web_contents) { - return new InspectableWebContentsViewWin(inspectable_web_contents); -} - -InspectableWebContentsViewWin::InspectableWebContentsViewWin( - InspectableWebContentsImpl* inspectable_web_contents) - : inspectable_web_contents_(inspectable_web_contents), - undocked_(false), - container_(new ContainerView(this)) { -} - -InspectableWebContentsViewWin::~InspectableWebContentsViewWin() { - if (devtools_window_) - devtools_window_->Destroy(); -} - -views::View* InspectableWebContentsViewWin::GetView() const { - return container_.get(); -} - -views::View* InspectableWebContentsViewWin::GetWebView() const { - return container_->GetWebView(); -} - -gfx::NativeView InspectableWebContentsViewWin::GetNativeView() const { - auto web_contents = inspectable_web_contents_->GetWebContents(); - return web_contents->GetView()->GetNativeView(); -} - -void InspectableWebContentsViewWin::ShowDevTools() { - if (undocked_) { - if (!devtools_window_) - devtools_window_ = DevToolsWindow::Create(this)->AsWeakPtr(); - - devtools_window_->Show(); - } else { - container_->ShowDevTools(); - } -} - -void InspectableWebContentsViewWin::CloseDevTools() { - if (undocked_) - devtools_window_->Close(); - else - container_->CloseDevTools(); -} - -bool InspectableWebContentsViewWin::IsDevToolsViewShowing() { - return container_->IsDevToolsViewShowing() || devtools_window_; -} - -bool InspectableWebContentsViewWin::SetDockSide(const std::string& side) { - if (side == "undocked") { - undocked_ = true; - container_->CloseDevTools(); - } else if (side == "right" || side == "bottom") { - undocked_ = false; - if (devtools_window_) - devtools_window_->Close(); - container_->SetDockSide(side); - } else { - return false; - } - - ShowDevTools(); - return true; -} - -} // namespace brightray diff --git a/brightray/browser/win/inspectable_web_contents_view_win.h b/brightray/browser/win/inspectable_web_contents_view_win.h deleted file mode 100644 index 5f1321ae418..00000000000 --- a/brightray/browser/win/inspectable_web_contents_view_win.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef BRIGHTRAY_BROWSER_WIN_INSPECTABLE_WEB_CONTENTS_VIEW_WIN_H_ -#define BRIGHTRAY_BROWSER_WIN_INSPECTABLE_WEB_CONTENTS_VIEW_WIN_H_ - -#include "browser/inspectable_web_contents_view.h" - -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" - -namespace views { -class View; -} - -namespace brightray { - -class ContainerView; -class DevToolsWindow; -class InspectableWebContentsImpl; - -class InspectableWebContentsViewWin : public InspectableWebContentsView { - public: - explicit InspectableWebContentsViewWin( - InspectableWebContentsImpl* inspectable_web_contents_impl); - ~InspectableWebContentsViewWin(); - - // Returns the container control, which has devtools view attached. Unlike - // GetNativeView(), this returns a views::View instead of HWND, and can only - // be used by applications that use the views library, if you don't use the - // views library, you probably want to set dock side to "undocked" before - // showing the devtools, because devtools is showed attached by default and - // attached devtools is currently only supported when using views library. - views::View* GetView() const; - - // Returns the web view control, which can be used by the - // GetInitiallyFocusedView() to set initial focus to web view. - views::View* GetWebView() const; - - virtual gfx::NativeView GetNativeView() const OVERRIDE; - virtual void ShowDevTools() OVERRIDE; - virtual void CloseDevTools() OVERRIDE; - virtual bool IsDevToolsViewShowing() OVERRIDE; - virtual bool SetDockSide(const std::string& side) OVERRIDE; - - InspectableWebContentsImpl* inspectable_web_contents() { - return inspectable_web_contents_; - } - - private: - // Owns us. - InspectableWebContentsImpl* inspectable_web_contents_; - - bool undocked_; - scoped_ptr container_; - base::WeakPtr devtools_window_; - - DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewWin); -}; - -} // namespace brightray - -#endif From 9747ee4411645e403f5f006624d8413b637117df Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Jul 2014 10:38:00 +0800 Subject: [PATCH 0342/1195] Fix cpplint warning for obj-c header. --- brightray/script/cpplint | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/script/cpplint b/brightray/script/cpplint index 58a6a5e0b5c..ff09db9e7d0 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -11,7 +11,7 @@ CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'google-styleguide', 'trunk', 'cpp LINE_LENGTH = 100 IGNORED_FILES = [ - os.path.join('browser', 'mac', 'bry_inspectable_web_contents_view_private.h'), + os.path.join('browser', 'mac', 'bry_inspectable_web_contents_view.h'), ] FILTERS = [ From a5bb24284e3ebb48e273f2302b593c0e4874a929 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Jul 2014 11:01:19 +0800 Subject: [PATCH 0343/1195] views: Follow WidgetDelegateView's convention on deleting self. It could avoid invoking WidgetDelegate's methods when the delegate has been deleted as a view. --- .../browser/views/inspectable_web_contents_view_views.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 03a052b1f79..903c448e42f 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -23,10 +23,14 @@ class DevToolsWindowDelegate : public views::ClientView, shell_(shell), view_(view), widget_(widget), - title_(base::ASCIIToUTF16("Developer Tools")) {} + title_(base::ASCIIToUTF16("Developer Tools")) { + // A WidgetDelegate should be deleted on DeleteDelegate. + set_owned_by_client(); + } virtual ~DevToolsWindowDelegate() {} // views::WidgetDelegate: + virtual void DeleteDelegate() OVERRIDE { delete this; } virtual views::View* GetInitiallyFocusedView() OVERRIDE { return view_; } virtual bool CanResize() const OVERRIDE { return true; } virtual bool CanMaximize() const OVERRIDE { return false; } @@ -136,8 +140,6 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { views::Widget::InitParams params; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - // The delegate is also a ClientView, so it would deleted when the view - // destructs, no need to delete it in DeleteDelegate. params.delegate = new DevToolsWindowDelegate(this, devtools_window_web_view_, devtools_window_.get()); From 1fbeb113715617a9b9588c87d0deaadbf38ef6e5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Jul 2014 15:34:10 +0800 Subject: [PATCH 0344/1195] Send message ack to devtools. --- .../devtools_embedder_message_dispatcher.cc | 31 ++++------------- .../devtools_embedder_message_dispatcher.h | 2 +- .../browser/inspectable_web_contents_impl.cc | 33 ++++++++++++++++++- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index 31351778f89..c4e87fcf7e6 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -5,16 +5,12 @@ #include "browser/devtools_embedder_message_dispatcher.h" #include "base/bind.h" -#include "base/json/json_reader.h" #include "base/values.h" namespace brightray { namespace { -static const char kFrontendHostMethod[] = "method"; -static const char kFrontendHostParams[] = "params"; - bool GetValue(const base::ListValue& list, int pos, std::string& value) { return list.GetString(pos, &value); } @@ -250,30 +246,15 @@ DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher( DevToolsEmbedderMessageDispatcher::~DevToolsEmbedderMessageDispatcher() {} -void DevToolsEmbedderMessageDispatcher::Dispatch(const std::string& message) { - std::string method; - base::ListValue empty_params; - base::ListValue* params = &empty_params; - - base::DictionaryValue* dict; - scoped_ptr parsed_message(base::JSONReader::Read(message)); - if (!parsed_message || - !parsed_message->GetAsDictionary(&dict) || - !dict->GetString(kFrontendHostMethod, &method) || - (dict->HasKey(kFrontendHostParams) && - !dict->GetList(kFrontendHostParams, ¶ms))) { - LOG(ERROR) << "Cannot parse frontend host message: " << message; - return; - } - +std::string DevToolsEmbedderMessageDispatcher::Dispatch( + const std::string& method, base::ListValue* params) { HandlerMap::iterator it = handlers_.find(method); - if (it == handlers_.end()) { - LOG(ERROR) << "Unsupported frontend host method: " << message; - return; - } + if (it == handlers_.end()) + return "Unsupported frontend host method: " + method; if (!it->second.Run(*params)) - LOG(ERROR) << "Invalid frontend host message parameters: " << message; + return "Invalid frontend host message parameters: " + method; + return ""; } void DevToolsEmbedderMessageDispatcher::RegisterHandler( diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index e43abff5285..0448f86aa16 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -63,7 +63,7 @@ class DevToolsEmbedderMessageDispatcher { ~DevToolsEmbedderMessageDispatcher(); - void Dispatch(const std::string& message); + std::string Dispatch(const std::string& method, base::ListValue* params); private: typedef base::Callback Handler; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 38278f265af..7e595ba0db7 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -11,6 +11,7 @@ #include "browser/inspectable_web_contents_delegate.h" #include "browser/inspectable_web_contents_view.h" +#include "base/json/json_reader.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/strings/stringprintf.h" @@ -21,6 +22,7 @@ #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_manager.h" #include "content/public/browser/web_contents_view.h" +#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" namespace brightray { @@ -30,6 +32,10 @@ namespace { const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?can_dock=true"; const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; +const char kFrontendHostId[] = "id"; +const char kFrontendHostMethod[] = "method"; +const char kFrontendHostParams[] = "params"; + void RectToDictionary(const gfx::Rect& bounds, base::DictionaryValue* dict) { dict->SetInteger("x", bounds.x()); dict->SetInteger("y", bounds.y()); @@ -181,6 +187,8 @@ void InspectableWebContentsImpl::AppendToFile( } void InspectableWebContentsImpl::RequestFileSystems() { + devtools_web_contents()->GetMainFrame()->ExecuteJavaScript( + base::ASCIIToUTF16("InspectorFrontendAPI.fileSystemsLoaded([])")); } void InspectableWebContentsImpl::AddFileSystem() { @@ -218,7 +226,30 @@ void InspectableWebContentsImpl::ResetZoom() { void InspectableWebContentsImpl::DispatchOnEmbedder( const std::string& message) { - embedder_message_dispatcher_->Dispatch(message); + std::string method; + base::ListValue empty_params; + base::ListValue* params = &empty_params; + + base::DictionaryValue* dict = NULL; + scoped_ptr parsed_message(base::JSONReader::Read(message)); + if (!parsed_message || + !parsed_message->GetAsDictionary(&dict) || + !dict->GetString(kFrontendHostMethod, &method) || + (dict->HasKey(kFrontendHostParams) && + !dict->GetList(kFrontendHostParams, ¶ms))) { + LOG(ERROR) << "Invalid message was sent to embedder: " << message; + return; + } + + int id = 0; + dict->GetInteger(kFrontendHostId, &id); + + std::string error = embedder_message_dispatcher_->Dispatch(method, params); + if (id) { + std::string ack = base::StringPrintf( + "InspectorFrontendAPI.embedderMessageAck(%d, \"%s\");", id, error.c_str()); + devtools_web_contents()->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(ack)); + } } void InspectableWebContentsImpl::InspectedContentsClosing() { From d5283b23375329a22789af6688eb374632341164 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Jul 2014 15:38:53 +0800 Subject: [PATCH 0345/1195] Allow access FileSystem api in devtools. It is required by the load/save feature of profilers. --- brightray/browser/browser_client.cc | 8 ++++++++ brightray/browser/browser_client.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index fabd51cc74c..f96e7f057e0 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -9,6 +9,8 @@ #include "browser/media/media_capture_devices_dispatcher.h" #include "browser/notification_presenter.h" +#include "content/public/common/url_constants.h" + namespace brightray { namespace { @@ -88,4 +90,10 @@ content::MediaObserver* BrowserClient::GetMediaObserver() { return MediaCaptureDevicesDispatcher::GetInstance(); } +void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( + std::vector* additional_schemes) { + additional_schemes->push_back(content::kChromeDevToolsScheme); + additional_schemes->push_back(content::kChromeUIScheme); +} + } // namespace brightray diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 42a7380a63c..41b15ea9716 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -51,6 +51,8 @@ class BrowserClient : public content::ContentBrowserClient { int render_view_id, int notification_id) OVERRIDE; virtual content::MediaObserver* GetMediaObserver() OVERRIDE; + virtual void GetAdditionalAllowedSchemesForFileSystem( + std::vector* additional_schemes) OVERRIDE; BrowserMainParts* browser_main_parts_; scoped_ptr notification_presenter_; From aba65c23f61a27d8faef056dafd5016252b33b58 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Jul 2014 17:07:00 +0800 Subject: [PATCH 0346/1195] Give user a chance to override child process and framework path. --- brightray/common/main_delegate.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 0c5107327f7..1a6b243a408 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -38,6 +38,14 @@ class MainDelegate : public content::ContentMainDelegate { // included in the ui::ResourceBundle. virtual void AddPakPaths(std::vector* pak_paths) {} +#if defined(OS_MACOSX) + // Subclasses can override this to custom the paths of child process and + // framework bundle. + virtual base::FilePath GetResourcesPakFilePath(); + virtual void OverrideChildProcessPath(); + virtual void OverrideFrameworkBundlePath(); +#endif + virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; virtual void PreSandboxStartup() OVERRIDE; @@ -45,11 +53,6 @@ class MainDelegate : public content::ContentMainDelegate { virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE; void InitializeResourceBundle(); -#if defined(OS_MACOSX) - static base::FilePath GetResourcesPakFilePath(); - static void OverrideChildProcessPath(); - static void OverrideFrameworkBundlePath(); -#endif scoped_ptr content_client_; scoped_ptr browser_client_; From a0ee4a9bf15b05d0ad6d8691e09dca4a9d12ee6f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Jul 2014 20:04:30 +0800 Subject: [PATCH 0347/1195] Ignore C4819 warning in VS. --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index da6d2a39d39..08ed02d4ffe 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -268,6 +268,7 @@ 4481, # nonstandard extension used: override specifier 'override' 4512, # assignment operator could not be generated 4702, # unreachable code + 4819, # The file contains a character that cannot be represented in the current code page ], }, }], From 739b352de6534b00d547afa9696c45743de50150 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Jul 2014 20:05:02 +0800 Subject: [PATCH 0348/1195] Only init WMState on Linux. --- brightray/browser/browser_main_parts.cc | 4 ++-- brightray/browser/browser_main_parts.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index d66a9f0b287..85180664567 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -17,11 +17,11 @@ #if defined(USE_AURA) && defined(USE_X11) #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" #include "ui/views/linux_ui/linux_ui.h" +#include "ui/wm/core/wm_state.h" #endif #if defined(TOOLKIT_VIEWS) #include "browser/views/views_delegate.h" -#include "ui/wm/core/wm_state.h" #endif namespace brightray { @@ -45,11 +45,11 @@ void BrowserMainParts::PreEarlyInitialization() { void BrowserMainParts::ToolkitInitialized() { #if defined(USE_AURA) && defined(USE_X11) views::LinuxUI::instance()->Initialize(); + wm_state_.reset(new wm::WMState); #endif #if defined(TOOLKIT_VIEWS) views_delegate_.reset(new ViewsDelegate); - wm_state_.reset(new wm::WMState); #endif } diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index f170ab589c7..42fd4e382bd 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -13,7 +13,9 @@ namespace brightray { class ViewsDelegate; } +#endif +#if defined(USE_AURA) && defined(USE_X11) namespace wm { class WMState; } @@ -58,6 +60,9 @@ class BrowserMainParts : public content::BrowserMainParts { #if defined(TOOLKIT_VIEWS) scoped_ptr views_delegate_; +#endif + +#if defined(USE_AURA) && defined(USE_X11) scoped_ptr wm_state_; #endif From 24c1544ca5debc2a99cbe9a572b022957c238877 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Jul 2014 20:14:49 +0800 Subject: [PATCH 0349/1195] Upgrade libchromiumcontent to 4b4bcec11a02d1c7981562cf0b8a4670c338992b. --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 331dbed4467..4b4bcec11a0 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 331dbed44676c534faf21f7db1985e796260649a +Subproject commit 4b4bcec11a02d1c7981562cf0b8a4670c338992b From 88e168ada4397d88c2218d30bdd3323d6a8afbbb Mon Sep 17 00:00:00 2001 From: Ted Nyman Date: Fri, 11 Jul 2014 00:39:21 -0700 Subject: [PATCH 0350/1195] Time goes on --- brightray/LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/LICENSE b/brightray/LICENSE index 4fb14d4add8..fe24a3c65fb 100644 --- a/brightray/LICENSE +++ b/brightray/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013 Adam Roben +Copyright (c) 2013-2014 Adam Roben Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in From e553e112266d662a11ab0ca1b1e563acd61ccd5a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 11 Jul 2014 21:55:57 +0800 Subject: [PATCH 0351/1195] Use shortcut way to create scoped_ptr. --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 7e595ba0db7..d9e988cac3d 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -59,7 +59,7 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents_impl); void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { - scoped_ptr bounds_dict(new base::DictionaryValue); + auto bounds_dict = make_scoped_ptr(new base::DictionaryValue); RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get()); registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release()); } From de08cc1d524e55e7b21caab6b4fbcf9452b219e7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 11 Jul 2014 22:22:03 +0800 Subject: [PATCH 0352/1195] No need for custom dealloc. --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 4 ---- 1 file changed, 4 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 045f389f72b..a070d8e405d 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -29,10 +29,6 @@ using namespace brightray; return self; } -- (void)dealloc { - [super dealloc]; -} - - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { [self adjustSubviews]; } From 891b7434dbeb1d2272404618de61eb0e5cb18841 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 11 Jul 2014 22:22:23 +0800 Subject: [PATCH 0353/1195] Separate the message parsing into a new function. --- .../browser/inspectable_web_contents_impl.cc | 46 +++++++++++++------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index d9e988cac3d..e7a15181103 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -52,6 +52,34 @@ void DictionaryToRect(const base::DictionaryValue& dict, gfx::Rect* bounds) { *bounds = gfx::Rect(x, y, width, height); } +bool ParseMessage(const std::string& message, + std::string* method, + base::ListValue* params, + int* id) { + scoped_ptr parsed_message(base::JSONReader::Read(message)); + if (!parsed_message) + return false; + + base::DictionaryValue* dict = NULL; + if (!parsed_message->GetAsDictionary(&dict)) + return false; + if (!dict->GetString(kFrontendHostMethod, method)) + return false; + + // "params" is optional. + if (dict->HasKey(kFrontendHostParams)) { + base::ListValue* internal_params; + if (dict->GetList(kFrontendHostParams, &internal_params)) + params->Swap(internal_params); + else + return false; + } + + *id = 0; + dict->GetInteger(kFrontendHostId, id); + return true; +} + } // namespace // Implemented separately on each platform. @@ -227,24 +255,14 @@ void InspectableWebContentsImpl::ResetZoom() { void InspectableWebContentsImpl::DispatchOnEmbedder( const std::string& message) { std::string method; - base::ListValue empty_params; - base::ListValue* params = &empty_params; - - base::DictionaryValue* dict = NULL; - scoped_ptr parsed_message(base::JSONReader::Read(message)); - if (!parsed_message || - !parsed_message->GetAsDictionary(&dict) || - !dict->GetString(kFrontendHostMethod, &method) || - (dict->HasKey(kFrontendHostParams) && - !dict->GetList(kFrontendHostParams, ¶ms))) { + base::ListValue params; + int id; + if (!ParseMessage(message, &method, ¶ms, &id)) { LOG(ERROR) << "Invalid message was sent to embedder: " << message; return; } - int id = 0; - dict->GetInteger(kFrontendHostId, &id); - - std::string error = embedder_message_dispatcher_->Dispatch(method, params); + std::string error = embedder_message_dispatcher_->Dispatch(method, ¶ms); if (id) { std::string ack = base::StringPrintf( "InspectorFrontendAPI.embedderMessageAck(%d, \"%s\");", id, error.c_str()); From 52c521f8b00886a5b9c29240ec2c799b5339433c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 11 Jul 2014 23:10:57 +0800 Subject: [PATCH 0354/1195] Remove duplicate library. --- brightray/brightray.gyp | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 3c50d2b6681..4fa374b3ded 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -117,7 +117,6 @@ 'link_settings': { 'libraries': [ '<(brightray_source_root)/<(libchromiumcontent_library_dir)/base_static.lib', - '<(brightray_source_root)/<(libchromiumcontent_library_dir)/chromiumviews.lib', '<(brightray_source_root)/<(libchromiumcontent_library_dir)/chromiumcontent.dll.lib', '<(brightray_source_root)/<(libchromiumcontent_library_dir)/chromiumviews.lib', '<(brightray_source_root)/<(libchromiumcontent_library_dir)/sandbox_static.lib', From 4b57e1f4f8adb7cfcb52db1f2bdbafc3da7aefec Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 11 Jul 2014 23:14:20 +0800 Subject: [PATCH 0355/1195] Warn about using GetNativeView() in views. --- brightray/browser/views/inspectable_web_contents_view_views.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 903c448e42f..95cf85eda87 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -91,6 +91,8 @@ views::View* InspectableWebContentsViewViews::GetWebView() { } gfx::NativeView InspectableWebContentsViewViews::GetNativeView() const { + NOTREACHED() << "GetNativeView() shouldn't be used when having views library, " + "use GetView() instead"; return inspectable_web_contents_->GetWebContents()->GetView()->GetNativeView(); } From a080d2c5bbeaa72f157b6ff3d44cf2e5a3241b73 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 11 Jul 2014 23:32:00 +0800 Subject: [PATCH 0356/1195] Remove GetNativeView() when compiled with views toolkit. --- brightray/browser/inspectable_web_contents_view.h | 3 ++- .../browser/views/inspectable_web_contents_view_views.cc | 6 ------ .../browser/views/inspectable_web_contents_view_views.h | 1 - 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index a79205b1170..1675ec73688 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -24,9 +24,10 @@ class InspectableWebContentsView { // Returns the web view control, which can be used by the // GetInitiallyFocusedView() to set initial focus to web view. virtual views::View* GetWebView() = 0; +#else + virtual gfx::NativeView GetNativeView() const = 0; #endif - virtual gfx::NativeView GetNativeView() const = 0; virtual void ShowDevTools() = 0; // Hide the DevTools view. virtual void CloseDevTools() = 0; diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 95cf85eda87..46c337515c0 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -90,12 +90,6 @@ views::View* InspectableWebContentsViewViews::GetWebView() { return contents_web_view_; } -gfx::NativeView InspectableWebContentsViewViews::GetNativeView() const { - NOTREACHED() << "GetNativeView() shouldn't be used when having views library, " - "use GetView() instead"; - return inspectable_web_contents_->GetWebContents()->GetView()->GetNativeView(); -} - void InspectableWebContentsViewViews::ShowDevTools() { if (devtools_visible_) return; diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index 319f1bd6c02..4875980a389 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -26,7 +26,6 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, // InspectableWebContentsView: virtual views::View* GetView() OVERRIDE; virtual views::View* GetWebView() OVERRIDE; - virtual gfx::NativeView GetNativeView() const OVERRIDE; virtual void ShowDevTools() OVERRIDE; virtual void CloseDevTools() OVERRIDE; virtual bool IsDevToolsViewShowing() OVERRIDE; From 0f5b4276488b962fc2facb2c6ea8d2faa070b9c2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 12 Jul 2014 11:45:24 +0800 Subject: [PATCH 0357/1195] Always shows window frame except for maximized window on Unity. --- brightray/browser/views/views_delegate.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc index 6ade87e338e..8da35dea806 100644 --- a/brightray/browser/views/views_delegate.cc +++ b/brightray/browser/views/views_delegate.cc @@ -6,6 +6,10 @@ #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" +#if defined(OS_LINUX) +#include "ui/views/linux_ui/linux_ui.h" +#endif + namespace brightray { ViewsDelegate::ViewsDelegate() { @@ -95,7 +99,14 @@ base::TimeDelta ViewsDelegate::GetDefaultTextfieldObscuredRevealDuration() { } bool ViewsDelegate::WindowManagerProvidesTitleBar(bool maximized) { - return maximized; +#if defined(OS_LINUX) + // On Ubuntu Unity, the system always provides a title bar for maximized + // windows. + views::LinuxUI* ui = views::LinuxUI::instance(); + return maximized && ui && ui->UnityIsRunning(); +#else + return false; +#endif } } // namespace brightray From 8d3f615e61b519c2a1c738a212dd0e3b75b24edc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 12 Jul 2014 19:46:26 +0800 Subject: [PATCH 0358/1195] win: Setup font. --- brightray/browser/browser_main_parts.cc | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 85180664567..0dd21b4f660 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -24,8 +24,29 @@ #include "browser/views/views_delegate.h" #endif +#if defined(OS_WIN) +#include "ui/base/l10n/l10n_util.h" +#include "ui/base/l10n/l10n_util_win.h" +#include "ui/gfx/platform_font_win.h" +#endif + namespace brightray { +#if defined(OS_WIN) +namespace { + +// gfx::Font callbacks +void AdjustUIFont(LOGFONT* logfont) { + l10n_util::AdjustUIFont(logfont); +} + +int GetMinimumFontSize() { + return 10; +} + +} // namespace +#endif + BrowserMainParts::BrowserMainParts() { } @@ -51,6 +72,11 @@ void BrowserMainParts::ToolkitInitialized() { #if defined(TOOLKIT_VIEWS) views_delegate_.reset(new ViewsDelegate); #endif + +#if defined(OS_WIN) + gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; + gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; +#endif } void BrowserMainParts::PreMainMessageLoopStart() { From cf1009ab3019a7119aefbd3b5b65d3be57735efe Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 12 Jul 2014 21:16:13 +0800 Subject: [PATCH 0359/1195] Refactor the AddPakPaths to make it possible to set pak's scale factor. This is needed when adding high DPI resources. --- brightray/common/main_delegate.cc | 8 +------- brightray/common/main_delegate.h | 9 ++++++--- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index ea0cbdddb5a..cf0a16fb273 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -49,13 +49,7 @@ void MainDelegate::InitializeResourceBundle() { #endif ui::ResourceBundle::InitSharedInstanceWithPakPath(path); - - std::vector pak_paths; - AddPakPaths(&pak_paths); - for (auto it = pak_paths.begin(), end = pak_paths.end(); it != end; ++it) { - ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( - *it, ui::SCALE_FACTOR_NONE); - } + AddDataPackFromPath(&ui::ResourceBundle::GetSharedInstance(), path.DirName()); } content::ContentBrowserClient* MainDelegate::CreateContentBrowserClient() { diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 1a6b243a408..7cfd7758d91 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -5,8 +5,6 @@ #ifndef BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ #define BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ -#include - #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "content/public/app/content_main_delegate.h" @@ -15,6 +13,10 @@ namespace base { class FilePath; } +namespace ui { +class ResourceBundle; +} + namespace brightray { class BrowserClient; @@ -36,7 +38,8 @@ class MainDelegate : public content::ContentMainDelegate { // Subclasses can override this to provide additional .pak files to be // included in the ui::ResourceBundle. - virtual void AddPakPaths(std::vector* pak_paths) {} + virtual void AddDataPackFromPath( + ui::ResourceBundle* bundle, const base::FilePath& pak_dir) {} #if defined(OS_MACOSX) // Subclasses can override this to custom the paths of child process and From 9d4e977c014840d9f2ba33803ddc0f2921e0066b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 12 Jul 2014 21:26:29 +0800 Subject: [PATCH 0360/1195] win: Fix window frame on detached window. --- .../browser/views/inspectable_web_contents_view_views.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 46c337515c0..4032ef08ece 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -140,7 +140,11 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { devtools_window_web_view_, devtools_window_.get()); params.top_level = true; + params.bounds = inspectable_web_contents()->GetDevToolsBounds(); +#if defined(USE_X11) + // In X11 the window frame is drawn by the application. params.remove_standard_frame = true; +#endif devtools_window_->Init(params); } From 46e765f79b208d2d5fbf561ba8abbb28d8de9802 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 13 Jul 2014 10:08:28 +0800 Subject: [PATCH 0361/1195] Fix crash when closing docked devtools by clicking close button. We need to send ack for the close message, so we should destroy web contents after the beforeunload event has fired. --- brightray/browser/inspectable_web_contents_impl.cc | 6 +++++- brightray/browser/inspectable_web_contents_impl.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index e7a15181103..69eda184943 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -176,7 +176,7 @@ void InspectableWebContentsImpl::ActivateWindow() { } void InspectableWebContentsImpl::CloseWindow() { - CloseDevTools(); + devtools_web_contents()->GetMainFrame()->DispatchBeforeUnload(false); } void InspectableWebContentsImpl::SetContentsResizingStrategy( @@ -305,4 +305,8 @@ void InspectableWebContentsImpl::HandleKeyboardEvent( delegate->HandleKeyboardEvent(source, event); } +void InspectableWebContentsImpl::CloseContents(content::WebContents* source) { + CloseDevTools(); +} + } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 1fcfff55379..dd115cdd1e7 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -109,6 +109,7 @@ class InspectableWebContentsImpl : virtual void HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; + virtual void CloseContents(content::WebContents* source) OVERRIDE; scoped_ptr web_contents_; scoped_ptr frontend_host_; From a318b1c5d1da651d6da71b85dbfb3f55f676e6da Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 14 Jul 2014 15:56:04 +0800 Subject: [PATCH 0362/1195] views: Use DesktopNativeWidgetAura for menu view. --- brightray/browser/views/views_delegate.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc index 8da35dea806..7f2a2249df3 100644 --- a/brightray/browser/views/views_delegate.cc +++ b/brightray/browser/views/views_delegate.cc @@ -89,7 +89,8 @@ void ViewsDelegate::OnBeforeWidgetInit( return; // The native_widget is required when using aura. - if (params->parent == NULL && params->context == NULL && !params->child) + if (params->type == views::Widget::InitParams::TYPE_MENU || + (params->parent == NULL && params->context == NULL && !params->child)) params->native_widget = new views::DesktopNativeWidgetAura(delegate); } From 8c38a7547baf1832c7b46b1bf25daf3d6bf33cdc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Jul 2014 08:08:27 +0000 Subject: [PATCH 0363/1195] Upgrade libchromiumcontent to chrome36. --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 4b4bcec11a0..97faf47ecd5 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 4b4bcec11a02d1c7981562cf0b8a4670c338992b +Subproject commit 97faf47ecd5e403f3ef465235f8f27a352a51e91 From 4e63780e4ae779f5444881183f6d52c5eec35fcc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Jul 2014 10:27:19 +0000 Subject: [PATCH 0364/1195] Prototype of WebContentsDestroyed has changed. --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- brightray/browser/inspectable_web_contents_impl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 69eda184943..24dfee3b520 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -289,7 +289,7 @@ void InspectableWebContentsImpl::DidFinishLoad(int64 frame_id, view_->ShowDevTools(); } -void InspectableWebContentsImpl::WebContentsDestroyed(content::WebContents*) { +void InspectableWebContentsImpl::WebContentsDestroyed() { content::DevToolsManager::GetInstance()->ClientHostClosing( frontend_host_.get()); Observe(nullptr); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index dd115cdd1e7..73ba40d7e4a 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -103,7 +103,7 @@ class InspectableWebContentsImpl : const GURL& validated_url, bool is_main_frame, content::RenderViewHost*) OVERRIDE; - virtual void WebContentsDestroyed(content::WebContents*) OVERRIDE; + virtual void WebContentsDestroyed() OVERRIDE; // content::WebContentsDelegate From 6dd580526e35e3eb3353ba3e4da0446927db8d22 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Jul 2014 10:27:41 +0000 Subject: [PATCH 0365/1195] Refactor notification presenter for new desktop notification interface. --- brightray/browser/browser_client.cc | 20 +-- brightray/browser/browser_client.h | 10 +- .../linux/notification_presenter_linux.cc | 152 +++++++----------- .../linux/notification_presenter_linux.h | 20 ++- brightray/browser/notification_presenter.h | 11 +- 5 files changed, 82 insertions(+), 131 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index f96e7f057e0..0f558a15ea7 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -66,24 +66,12 @@ net::URLRequestContextGetter* BrowserClient::CreateRequestContext( void BrowserClient::ShowDesktopNotification( const content::ShowDesktopNotificationHostMsgParams& params, - int render_process_id, - int render_view_id, - bool worker) { + content::RenderFrameHost* render_frame_host, + content::DesktopNotificationDelegate* delegate, + base::Closure* cancel_callback) { auto presenter = notification_presenter(); if (!presenter) - return; - presenter->ShowNotification(params, render_process_id, render_view_id); -} - -void BrowserClient::CancelDesktopNotification( - int render_process_id, - int render_view_id, - int notification_id) { - auto presenter = notification_presenter(); - if (!presenter) - return; - presenter->CancelNotification( - render_process_id, render_view_id, notification_id); + presenter->ShowNotification(params, delegate, cancel_callback); } content::MediaObserver* BrowserClient::GetMediaObserver() { diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 41b15ea9716..b6ff42acd41 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -43,13 +43,9 @@ class BrowserClient : public content::ContentBrowserClient { const content::MainFunctionParams&) OVERRIDE; virtual void ShowDesktopNotification( const content::ShowDesktopNotificationHostMsgParams&, - int render_process_id, - int render_view_id, - bool worker) OVERRIDE; - virtual void CancelDesktopNotification( - int render_process_id, - int render_view_id, - int notification_id) OVERRIDE; + content::RenderFrameHost* render_frame_host, + content::DesktopNotificationDelegate* delegate, + base::Closure* cancel_callback) OVERRIDE; virtual content::MediaObserver* GetMediaObserver() OVERRIDE; virtual void GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) OVERRIDE; diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 06a9d0d42d0..f7347998092 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -3,13 +3,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include - #include "browser/linux/notification_presenter_linux.h" -#include "base/strings/stringprintf.h" +#include "base/bind.h" +#include "base/logging.h" #include "base/strings/utf_string_conversions.h" -#include "content/public/browser/render_view_host.h" +#include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/show_desktop_notification_params.h" #include "common/application_info.h" @@ -17,13 +16,7 @@ namespace brightray { namespace { -const char *kRenderProcessIDKey = "RenderProcessID"; -const char *kRenderViewIDKey = "RenderViewID"; -const char *kNotificationIDKey = "NotificationID"; - -void log_and_clear_error(GError *error, const char *context) { - if (!error) return; - +void log_and_clear_error(GError* error, const char* context) { LOG(ERROR) << context << ": domain=" << error->domain << " code=" << error->code @@ -31,38 +24,15 @@ void log_and_clear_error(GError *error, const char *context) { g_error_free(error); } -int GetObjectInt(NotifyNotification *noti, const char *key) { - return GPOINTER_TO_INT(g_object_get_data(G_OBJECT(noti), key)); -} - -void SetObjectInt(NotifyNotification *noti, const char *key, int value) { - g_object_set_data(G_OBJECT(noti), key, GINT_TO_POINTER(value)); -} - - -void NotificationClosedCallback(NotifyNotification *noti, NotificationPresenterLinux *obj) { - int render_process_id = GetObjectInt(noti, kRenderProcessIDKey); - int render_view_id = GetObjectInt(noti, kRenderViewIDKey); - int notification_id = GetObjectInt(noti, kNotificationIDKey); - - auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); - if (host) host->DesktopNotificationPostClose(notification_id, false); - obj->RemoveNotification(noti); -} - -void NotificationViewCallback(NotifyNotification *noti, const char *action, - NotificationPresenterLinux *obj) { - int render_process_id = GetObjectInt(noti, kRenderProcessIDKey); - int render_view_id = GetObjectInt(noti, kRenderViewIDKey); - int notification_id = GetObjectInt(noti, kNotificationIDKey); - - auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); - if (host) host->DesktopNotificationPostClick(notification_id); - obj->RemoveNotification(noti); +content::DesktopNotificationDelegate* GetDelegateFromNotification( + NotifyNotification* notification) { + return static_cast( + g_object_get_data(G_OBJECT(notification), "delegate")); } } // namespace +// static NotificationPresenter* NotificationPresenter::Create() { if (!notify_is_initted()) { notify_init(GetApplicationName().c_str()); @@ -70,79 +40,71 @@ NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterLinux; } -NotificationPresenterLinux::NotificationPresenterLinux() : notifications_(nullptr) { } +NotificationPresenterLinux::NotificationPresenterLinux() + : notifications_(nullptr) { +} NotificationPresenterLinux::~NotificationPresenterLinux() { // unref any outstanding notifications, and then free the list. - if (!notifications_) return; - - for (GList *p = notifications_; p != nullptr; p = p->next) { - g_object_unref(G_OBJECT(p->data)); - } - g_list_free(notifications_); + if (notifications_) + g_list_free_full(notifications_, g_object_unref); } void NotificationPresenterLinux::ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, - int render_process_id, - int render_view_id) { + content::DesktopNotificationDelegate* delegate, + base::Closure* cancel_callback) { std::string title = base::UTF16ToUTF8(params.title); std::string body = base::UTF16ToUTF8(params.body); - NotifyNotification *noti = notify_notification_new(title.c_str(), body.c_str(), nullptr); - SetObjectInt(noti, kRenderProcessIDKey, render_process_id); - SetObjectInt(noti, kRenderViewIDKey, render_view_id); - SetObjectInt(noti, kNotificationIDKey, params.notification_id); - g_signal_connect(noti, "closed", - G_CALLBACK(NotificationClosedCallback), this); - notify_notification_add_action(noti, "default", "View", - (NotifyActionCallback)NotificationViewCallback, this, nullptr); + NotifyNotification* notification = notify_notification_new(title.c_str(), body.c_str(), nullptr); - notifications_ = g_list_append(notifications_, noti); + g_object_set_data(G_OBJECT(notification), "delegate", delegate); + g_signal_connect(notification, "closed", G_CALLBACK(OnNotificationClosedThunk), this); + notify_notification_add_action(notification, "default", "View", OnNotificationViewThunk, this, + nullptr); - GError *error = nullptr; - notify_notification_show(noti, &error); - log_and_clear_error(error, "notify_notification_show"); - - auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); - if (!host) + GError* error = nullptr; + notify_notification_show(notification, &error); + if (error) { + log_and_clear_error(error, "notify_notification_show"); + delegate->NotificationError(); return; - - host->DesktopNotificationPostDisplay(params.notification_id); -} - -void NotificationPresenterLinux::CancelNotification( - int render_process_id, - int render_view_id, - int notification_id) { - NotifyNotification *noti = nullptr; - for (GList *p = notifications_; p != nullptr; p = p->next) { - int rpid = GetObjectInt(noti, kRenderProcessIDKey); - int rvid = GetObjectInt(noti, kRenderViewIDKey); - int nid = GetObjectInt(noti, kNotificationIDKey); - if (render_process_id == rpid && render_view_id == rvid && notification_id == nid) { - noti = reinterpret_cast(p->data); - notifications_ = g_list_delete_link(notifications_, p); - break; - } } - if (!noti) - return; - GError *error = nullptr; - notify_notification_close(noti, &error); - log_and_clear_error(error, "notify_notification_close"); - g_object_unref(noti); + notifications_ = g_list_append(notifications_, notification); + delegate->NotificationDisplayed(); - auto host = content::RenderViewHost::FromID(render_process_id, render_view_id); - if (!host) - return; - - host->DesktopNotificationPostClose(notification_id, false); + if (cancel_callback) + *cancel_callback = base::Bind( + &NotificationPresenterLinux::CancelNotification, + base::Unretained(this), + notification); } -void NotificationPresenterLinux::RemoveNotification(NotifyNotification *noti) { - notifications_ = g_list_remove(notifications_, noti); - g_object_unref(noti); +void NotificationPresenterLinux::CancelNotification(NotifyNotification* notification) { + GError* error = nullptr; + notify_notification_close(notification, &error); + if (error) + log_and_clear_error(error, "notify_notification_close"); + + GetDelegateFromNotification(notification)->NotificationClosed(false); + DeleteNotification(notification); +} + +void NotificationPresenterLinux::DeleteNotification(NotifyNotification* notification) { + notifications_ = g_list_remove(notifications_, notification); + g_object_unref(notification); +} + +void NotificationPresenterLinux::OnNotificationClosed(NotifyNotification* notification) { + GetDelegateFromNotification(notification)->NotificationClosed(false); + DeleteNotification(notification); +} + +void NotificationPresenterLinux::OnNotificationView( + NotifyNotification* notification, char* action) { + GetDelegateFromNotification(notification)->NotificationClick(); + DeleteNotification(notification); } } // namespace brightray diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index dc868917e36..07e628e29a4 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -7,10 +7,12 @@ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_LINUX_H_ #include + #include #include "base/compiler_specific.h" #include "browser/notification_presenter.h" +#include "ui/base/glib/glib_signal.h" namespace brightray { @@ -22,14 +24,18 @@ class NotificationPresenterLinux : public NotificationPresenter { void RemoveNotification(NotifyNotification *notification); private: + // NotificationPresenter: virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams&, - int render_process_id, - int render_view_id) OVERRIDE; - virtual void CancelNotification( - int render_process_id, - int render_view_id, - int notification_id) OVERRIDE; + content::DesktopNotificationDelegate* delegate, + base::Closure* cancel_callback) OVERRIDE; + + void CancelNotification(NotifyNotification* notification); + void DeleteNotification(NotifyNotification* notification); + + CHROMEG_CALLBACK_0(NotificationPresenterLinux, void, OnNotificationClosed, NotifyNotification*); + CHROMEG_CALLBACK_1(NotificationPresenterLinux, void, OnNotificationView, NotifyNotification*, + char*); // A list of all open NotifyNotification objects. // We do lookups here both by NotifyNotification object (when the user @@ -38,7 +44,7 @@ class NotificationPresenterLinux : public NotificationPresenter { // a map. // Entries in this list count as refs, so removal from this list should // always go with g_object_unref(). - GList *notifications_; + GList* notifications_; }; } // namespace brightray diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index db925f5e927..23420fb9cf5 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -1,7 +1,10 @@ #ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_ +#include "base/callback_forward.h" + namespace content { +class DesktopNotificationDelegate; struct ShowDesktopNotificationHostMsgParams; } @@ -15,12 +18,8 @@ class NotificationPresenter { virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams&, - int render_process_id, - int render_view_id) = 0; - virtual void CancelNotification( - int render_process_id, - int render_view_id, - int notification_id) = 0; + content::DesktopNotificationDelegate* delegate, + base::Closure* cancel_callback) = 0; }; } // namespace brightray From bb87492897a0ac9ebece62bd5ec799f4c9a7fb41 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Jul 2014 10:32:09 +0000 Subject: [PATCH 0366/1195] No more need to init aura::Env. --- brightray/browser/browser_main_parts.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 0dd21b4f660..4a461acc653 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -9,7 +9,6 @@ #include "net/proxy/proxy_resolver_v8.h" #if defined(USE_AURA) -#include "ui/aura/env.h" #include "ui/gfx/screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h" #endif @@ -97,14 +96,10 @@ void BrowserMainParts::PreMainMessageLoopRun() { void BrowserMainParts::PostMainMessageLoopRun() { browser_context_.reset(); -#if defined(USE_AURA) - aura::Env::DeleteInstance(); -#endif } int BrowserMainParts::PreCreateThreads() { #if defined(USE_AURA) - aura::Env::CreateInstance(); gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, views::CreateDesktopScreen()); #endif From 8bf3e084f102b4b4a885e7d04ac29eefb1b88a42 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Jul 2014 10:35:55 +0000 Subject: [PATCH 0367/1195] Interface of ProxyResolverV8 has changed. --- brightray/browser/browser_main_parts.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 4a461acc653..e428ba4a5c2 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -113,11 +113,7 @@ BrowserContext* BrowserMainParts::CreateBrowserContext() { } void BrowserMainParts::InitProxyResolverV8() { -#if defined(OS_WIN) - net::ProxyResolverV8::CreateIsolate(); -#else - net::ProxyResolverV8::RememberDefaultIsolate(); -#endif + net::ProxyResolverV8::EnsureIsolateCreated(); } } // namespace brightray From a98199511a8167df4c30e942e1d5622f906c4532 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Jul 2014 10:44:39 +0000 Subject: [PATCH 0368/1195] Implement GetGuestManagerDelegate. --- brightray/browser/browser_context.cc | 4 ++++ brightray/browser/browser_context.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index d82f4bc256e..9628dc6b386 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -204,4 +204,8 @@ quota::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() { return nullptr; } +content::BrowserPluginGuestManagerDelegate* BrowserContext::GetGuestManagerDelegate() { + return nullptr; +} + } // namespace brightray diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index a43d2380da1..e59c72ab92d 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -80,6 +80,8 @@ class BrowserContext : public content::BrowserContext { GetDownloadManagerDelegate() OVERRIDE; virtual content::GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; + virtual content::BrowserPluginGuestManagerDelegate* + GetGuestManagerDelegate() OVERRIDE; virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; From 9821cd1f585b6f58919807406f7757f6d88091ce Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Jul 2014 10:44:58 +0000 Subject: [PATCH 0369/1195] web_contents_view.h has been hidden from user. --- brightray/browser/inspectable_web_contents.cc | 7 ------- brightray/browser/inspectable_web_contents_impl.cc | 3 +-- .../browser/views/inspectable_web_contents_view_views.cc | 1 - 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.cc b/brightray/browser/inspectable_web_contents.cc index 5090011a203..74aeac67113 100644 --- a/brightray/browser/inspectable_web_contents.cc +++ b/brightray/browser/inspectable_web_contents.cc @@ -2,18 +2,11 @@ #include "browser/inspectable_web_contents_impl.h" -#include "content/public/browser/web_contents_view.h" - namespace brightray { InspectableWebContents* InspectableWebContents::Create( const content::WebContents::CreateParams& create_params) { auto contents = content::WebContents::Create(create_params); -#if defined(OS_MACOSX) - // Work around http://crbug.com/279472. - contents->GetView()->SetAllowOverlappingViews(true); -#endif - return Create(contents); } diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 24dfee3b520..e8893d5dff4 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -21,7 +21,6 @@ #include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_manager.h" -#include "content/public/browser/web_contents_view.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" @@ -152,7 +151,7 @@ void InspectableWebContentsImpl::CloseDevTools() { if (devtools_web_contents_) { view_->CloseDevTools(); devtools_web_contents_.reset(); - web_contents_->GetView()->Focus(); + web_contents_->Focus(); } } diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 4032ef08ece..e642c48e5b2 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -3,7 +3,6 @@ #include "browser/inspectable_web_contents_impl.h" #include "base/strings/utf_string_conversions.h" -#include "content/public/browser/web_contents_view.h" #include "ui/views/controls/webview/webview.h" #include "ui/views/widget/widget.h" #include "ui/views/widget/widget_delegate.h" From 8d6a879707cc0b828346d9512bc112d30e103d63 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Jul 2014 11:07:58 +0000 Subject: [PATCH 0370/1195] Update libchromiumcontent to include mojo headers. --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 97faf47ecd5..e944624160d 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 97faf47ecd5e403f3ef465235f8f27a352a51e91 +Subproject commit e944624160d8c0ff43ad8171caff11f9a58c6c63 From d47a94b1fe3be9cf88cec6ceb93fdfb48c81bcb8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Jul 2014 11:18:15 +0000 Subject: [PATCH 0371/1195] DispatchBeforeUnload is now a method of WebContents. --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index e8893d5dff4..1449bde5765 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -175,7 +175,7 @@ void InspectableWebContentsImpl::ActivateWindow() { } void InspectableWebContentsImpl::CloseWindow() { - devtools_web_contents()->GetMainFrame()->DispatchBeforeUnload(false); + devtools_web_contents()->DispatchBeforeUnload(false); } void InspectableWebContentsImpl::SetContentsResizingStrategy( From edbce1c167c24d8bd29543d86050fcbc9a0b3041 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 27 Jul 2014 14:18:46 +0000 Subject: [PATCH 0372/1195] Update libchromiumcontent to fix gfx::display link errors. --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index e944624160d..a88222442d2 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit e944624160d8c0ff43ad8171caff11f9a58c6c63 +Subproject commit a88222442d2a85345d9a208c23456956c208571d From e52a089ec20f0d05ef65f9c1bc6a641ed5261905 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 28 Jul 2014 09:34:13 +0800 Subject: [PATCH 0373/1195] mac: Remove usages of WebContentsView. --- .../browser/inspectable_web_contents_view_mac.mm | 2 -- .../mac/bry_inspectable_web_contents_view.mm | 15 ++++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index 89eb8ec0746..698e6883a43 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -5,8 +5,6 @@ #include "browser/inspectable_web_contents.h" #import "browser/mac/bry_inspectable_web_contents_view.h" -#include "content/public/browser/web_contents_view.h" - namespace brightray { InspectableWebContentsView* CreateInspectableContentsView(InspectableWebContentsImpl* inspectable_web_contents) { diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index a070d8e405d..afc2f723dbf 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -4,7 +4,6 @@ #include "browser/inspectable_web_contents_view_mac.h" #include "content/public/browser/render_widget_host_view.h" -#include "content/public/browser/web_contents_view.h" #import "ui/base/cocoa/underlay_opengl_hosting_window.h" #include "ui/gfx/mac/scoped_ns_disable_screen_updates.h" @@ -22,7 +21,9 @@ using namespace brightray; devtools_docked_ = NO; auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); - auto contentsView = contents->GetView()->GetNativeView(); + contents->SetAllowOverlappingViews(true); + + auto contentsView = contents->GetNativeView(); [contentsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [self addSubview:contentsView]; @@ -42,7 +43,7 @@ using namespace brightray; return; auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); - auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); + auto devToolsView = devToolsWebContents->GetNativeView(); devtools_visible_ = visible; if (devtools_docked_) { @@ -53,7 +54,7 @@ using namespace brightray; [self update]; } else { gfx::ScopedNSDisableScreenUpdates disabler; - devToolsWebContents->GetView()->RemoveOverlayView(); + devToolsWebContents->RemoveOverlayView(); [devToolsView removeFromSuperview]; [self adjustSubviews]; } @@ -79,7 +80,7 @@ using namespace brightray; devtools_docked_ = docked; if (!docked) { auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); - auto devToolsView = devToolsWebContents->GetView()->GetNativeView(); + auto devToolsView = devToolsWebContents->GetNativeView(); auto styleMask = NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask | @@ -119,8 +120,8 @@ using namespace brightray; auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); gfx::ScopedNSDisableScreenUpdates disabler; - devToolsWebContents->GetView()->SetOverlayView( - contents->GetView(), + devToolsWebContents->SetOverlayView( + contents, gfx::Point(strategy_.insets().left(), strategy_.insets().top())); [self adjustSubviews]; } From f552dc7ba4091c2f46218010194af04cc102b33e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 28 Jul 2014 11:52:26 +0800 Subject: [PATCH 0374/1195] mac: Fix the notification presenter of new API. --- brightray/browser/browser_client.cc | 2 +- .../browser/notification_presenter_mac.h | 28 ++- .../browser/notification_presenter_mac.mm | 171 ++++++++---------- 3 files changed, 93 insertions(+), 108 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 0f558a15ea7..be69a349a7f 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -70,7 +70,7 @@ void BrowserClient::ShowDesktopNotification( content::DesktopNotificationDelegate* delegate, base::Closure* cancel_callback) { auto presenter = notification_presenter(); - if (!presenter) + if (presenter) presenter->ShowNotification(params, delegate, cancel_callback); } diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index e4656b98f02..9c7a3a3c276 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -22,17 +22,27 @@ class NotificationPresenterMac : public NotificationPresenter { virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams&, - int render_process_id, - int render_view_id) OVERRIDE; - virtual void CancelNotification( - int render_process_id, - int render_view_id, - int notification_id) OVERRIDE; + content::DesktopNotificationDelegate* delegate, + base::Closure* cancel_callback) OVERRIDE; + + // Get the delegate accroding from the notification object. + content::DesktopNotificationDelegate* GetDelegateFromNotification( + NSUserNotification* notification); + + // Remove the notification object accroding to its delegate. + void RemoveNotification(content::DesktopNotificationDelegate* delegate); private: - typedef std::map> - NotificationMap; - NotificationMap notification_map_; + void CancelNotification(content::DesktopNotificationDelegate* delegate); + + // The userInfo of NSUserNotification can not store pointers (because they are + // not in property list), so we have to track them in a C++ map. + // Also notice that the delegate acts as "ID" or "Key", because it is certain + // that each notification has a unique delegate. + typedef std::map> + NotificationsMap; + NotificationsMap notifications_map_; + base::scoped_nsobject delegate_; }; diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index dc2ad9231fb..2bb595ed55c 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -5,146 +5,121 @@ #import "browser/notification_presenter_mac.h" -#import "base/strings/stringprintf.h" -#import "base/strings/sys_string_conversions.h" -#import "content/public/browser/render_view_host.h" -#import "content/public/common/show_desktop_notification_params.h" +#include "base/bind.h" +#include "base/stl_util.h" +#include "base/strings/sys_string_conversions.h" +#include "content/public/browser/desktop_notification_delegate.h" +#include "content/public/common/show_desktop_notification_params.h" #import -@interface BRYUserNotificationCenterDelegate : NSObject +@interface BRYUserNotificationCenterDelegate : NSObject { + @private + brightray::NotificationPresenterMac* presenter_; +} +- (instancetype)initWithNotificationPresenter:(brightray::NotificationPresenterMac*)presenter; @end namespace brightray { namespace { -NSString * const kRenderProcessIDKey = @"RenderProcessID"; -NSString * const kRenderViewIDKey = @"RenderViewID"; -NSString * const kNotificationIDKey = @"NotificationID"; - -struct NotificationID { - NotificationID( - int render_process_id, - int render_view_id, - int notification_id) - : render_process_id(render_process_id), - render_view_id(render_view_id), - notification_id(notification_id) { - } - - NotificationID(NSUserNotification* notification) - : render_process_id([[notification.userInfo objectForKey:kRenderProcessIDKey] intValue]), - render_view_id([[notification.userInfo objectForKey:kRenderViewIDKey] intValue]), - notification_id([[notification.userInfo objectForKey:kNotificationIDKey] intValue]) { - } - - std::string GetID() { - return base::StringPrintf("%d:%d:%d", render_process_id, render_view_id, notification_id); - } - - NSDictionary* GetUserInfo() { - return @{ - kRenderProcessIDKey: @(render_process_id), - kRenderViewIDKey: @(render_view_id), - kNotificationIDKey: @(notification_id), - }; - } - - int render_process_id; - int render_view_id; - int notification_id; -}; - -base::scoped_nsobject CreateUserNotification( - const content::ShowDesktopNotificationHostMsgParams& params, - int render_process_id, - int render_view_id) { - auto notification = [[NSUserNotification alloc] init]; - notification.title = base::SysUTF16ToNSString(params.title); - notification.informativeText = base::SysUTF16ToNSString(params.body); - notification.userInfo = NotificationID(render_process_id, render_view_id, params.notification_id).GetUserInfo(); - - return base::scoped_nsobject(notification); -} - -} +} // namespace NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterMac; } NotificationPresenterMac::NotificationPresenterMac() - : delegate_([[BRYUserNotificationCenterDelegate alloc] init]) { + : delegate_([[BRYUserNotificationCenterDelegate alloc] initWithNotificationPresenter:this]) { NSUserNotificationCenter.defaultUserNotificationCenter.delegate = delegate_; } NotificationPresenterMac::~NotificationPresenterMac() { + NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil; } void NotificationPresenterMac::ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, - int render_process_id, - int render_view_id) { - auto notification = CreateUserNotification(params, render_process_id, render_view_id); - notification_map_.insert(std::make_pair(NotificationID(notification).GetID(), notification)); + content::DesktopNotificationDelegate* delegate, + base::Closure* cancel_callback) { + auto notification = [[NSUserNotification alloc] init]; + notification.title = base::SysUTF16ToNSString(params.title); + notification.informativeText = base::SysUTF16ToNSString(params.body); + + notifications_map_[delegate].reset(notification); [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; + + if (cancel_callback) + *cancel_callback = base::Bind( + &NotificationPresenterMac::CancelNotification, + base::Unretained(this), + delegate); } -void NotificationPresenterMac::CancelNotification( - int render_process_id, - int render_view_id, - int notification_id) { - auto found = notification_map_.find(NotificationID(render_process_id, render_view_id, notification_id).GetID()); - if (found == notification_map_.end()) +content::DesktopNotificationDelegate* NotificationPresenterMac::GetDelegateFromNotification( + NSUserNotification* notification) { + for (NotificationsMap::const_iterator it = notifications_map_.begin(); + it != notifications_map_.end(); ++it) + if ([it->second isEqual:notification]) + return it->first; + return NULL; +} + +void NotificationPresenterMac::RemoveNotification(content::DesktopNotificationDelegate* delegate) { + if (ContainsKey(notifications_map_, delegate)) + notifications_map_.erase(delegate); +} + +void NotificationPresenterMac::CancelNotification(content::DesktopNotificationDelegate* delegate) { + if (!ContainsKey(notifications_map_, delegate)) return; - auto notification = found->second; - - notification_map_.erase(found); - // Notifications in -deliveredNotifications aren't the same objects we passed to // -deliverNotification:, but they will respond YES to -isEqual:. + auto notification = notifications_map_[delegate]; auto center = NSUserNotificationCenter.defaultUserNotificationCenter; - for (NSUserNotification* deliveredNotification in center.deliveredNotifications) { - if (![notification isEqual:deliveredNotification]) - continue; - [center removeDeliveredNotification:deliveredNotification]; - } + for (NSUserNotification* deliveredNotification in center.deliveredNotifications) + if ([notification isEqual:deliveredNotification]) { + [center removeDeliveredNotification:deliveredNotification]; + delegate->NotificationClosed(false); + break; + } - NotificationID ID(notification); - auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id); - if (!host) - return; - - host->DesktopNotificationPostClose(ID.notification_id, false); + RemoveNotification(delegate); } -} +} // namespace brightray @implementation BRYUserNotificationCenterDelegate -- (void)userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification { - brightray::NotificationID ID(notification); +- (instancetype)initWithNotificationPresenter:(brightray::NotificationPresenterMac*)presenter { + self = [super init]; + if (!self) + return nil; - auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id); - if (!host) - return; - - host->DesktopNotificationPostDisplay(ID.notification_id); + presenter_ = presenter; + return self; } -- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification { - brightray::NotificationID ID(notification); - - auto host = content::RenderViewHost::FromID(ID.render_process_id, ID.render_view_id); - if (!host) - return; - - host->DesktopNotificationPostClick(ID.notification_id); +- (void)userNotificationCenter:(NSUserNotificationCenter*)center + didDeliverNotification:(NSUserNotification*)notification { + auto delegate = presenter_->GetDelegateFromNotification(notification); + if (delegate) + delegate->NotificationDisplayed(); } -- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification { +- (void)userNotificationCenter:(NSUserNotificationCenter*)center + didActivateNotification:(NSUserNotification *)notification { + auto delegate = presenter_->GetDelegateFromNotification(notification); + if (delegate) { + delegate->NotificationClick(); + presenter_->RemoveNotification(delegate); + } +} + +- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center + shouldPresentNotification:(NSUserNotification*)notification { // Display notifications even if the app is active. return YES; } From 8ff2683ae80b6a4d6ffd12833f5093062ab40f69 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 28 Jul 2014 12:12:14 +0800 Subject: [PATCH 0375/1195] Ignore warning 4189 on Windows. The warning comes from mojo/public/cpp/system/core.h. --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 08ed02d4ffe..c155782c7d0 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -259,6 +259,7 @@ 'msvs_disabled_warnings': [ 4100, # unreferenced formal parameter 4127, # conditional expression is constant + 4189, # local variable is initialized but not referenced 4244, # 'initializing' : conversion from 'double' to 'size_t', possible loss of data 4245, # 'initializing' : conversion from 'int' to 'const net::QuicVersionTag', signed/unsigned mismatch 4251, # class 'std::xx' needs to have dll-interface. From a8e879d0c5176bccfcfad52bb8a5867a92e19188 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 28 Jul 2014 12:40:38 +0800 Subject: [PATCH 0376/1195] mac: Fix blank page after devtools is opened. --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index afc2f723dbf..084389dd92c 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -27,6 +27,9 @@ using namespace brightray; [contentsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [self addSubview:contentsView]; + // See https://code.google.com/p/chromium/issues/detail?id=348490. + [self setWantsLayer:YES]; + return self; } From a866718b49678f9fb2abb2bbfe7c6441d32fef41 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 28 Jul 2014 15:28:38 +0800 Subject: [PATCH 0377/1195] Initialize ProxyResolverV8 at very early phrase. In atom-shell we need to ensure node environment is initialized after the ProxyResolverV8 has been initialized. --- brightray/browser/browser_main_parts.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index e428ba4a5c2..f5153a78456 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -60,6 +60,8 @@ void BrowserMainParts::PreEarlyInitialization() { #if defined(USE_AURA) && defined(USE_X11) views::LinuxUI::SetInstance(BuildGtk2UI()); #endif + + InitProxyResolverV8(); } void BrowserMainParts::ToolkitInitialized() { @@ -104,7 +106,6 @@ int BrowserMainParts::PreCreateThreads() { views::CreateDesktopScreen()); #endif - InitProxyResolverV8(); return 0; } From 7b6fbff40d870709af226399577f17458b926b9a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 28 Jul 2014 17:48:55 +0800 Subject: [PATCH 0378/1195] Implement BrowserClient::GetDefaultDownloadDirectory(). --- brightray/browser/browser_client.cc | 11 +++++++++++ brightray/browser/browser_client.h | 1 + 2 files changed, 12 insertions(+) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index be69a349a7f..3c7377d6d9a 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -9,6 +9,8 @@ #include "browser/media/media_capture_devices_dispatcher.h" #include "browser/notification_presenter.h" +#include "base/base_paths.h" +#include "base/path_service.h" #include "content/public/common/url_constants.h" namespace brightray { @@ -84,4 +86,13 @@ void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( additional_schemes->push_back(content::kChromeUIScheme); } +base::FilePath BrowserClient::GetDefaultDownloadDirectory() { + // ~/Downloads + base::FilePath path; + if (PathService::Get(base::DIR_HOME, &path)) + path = path.Append(FILE_PATH_LITERAL("Downloads")); + + return path; +} + } // namespace brightray diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index b6ff42acd41..6d1944ca026 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -49,6 +49,7 @@ class BrowserClient : public content::ContentBrowserClient { virtual content::MediaObserver* GetMediaObserver() OVERRIDE; virtual void GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) OVERRIDE; + virtual base::FilePath GetDefaultDownloadDirectory() OVERRIDE; BrowserMainParts* browser_main_parts_; scoped_ptr notification_presenter_; From 5a5c92ad2dd0d2ff833e548808f72b1c0fe663ce Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Wed, 30 Jul 2014 11:40:17 +0800 Subject: [PATCH 0379/1195] Add remote debugging support. --- brightray/brightray.gyp | 2 + brightray/browser/browser_main_parts.cc | 9 ++ brightray/browser/browser_main_parts.h | 2 + brightray/browser/devtools_delegate.cc | 197 ++++++++++++++++++++++++ brightray/browser/devtools_delegate.h | 54 +++++++ 5 files changed, 264 insertions(+) create mode 100644 brightray/browser/devtools_delegate.cc create mode 100644 brightray/browser/devtools_delegate.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 4fa374b3ded..a30281b1fdc 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -42,6 +42,8 @@ 'browser/default_web_contents_delegate_mac.mm', 'browser/devtools_contents_resizing_strategy.cc', 'browser/devtools_contents_resizing_strategy.h', + 'browser/devtools_delegate.cc', + 'browser/devtools_delegate.h', 'browser/devtools_embedder_message_dispatcher.cc', 'browser/devtools_embedder_message_dispatcher.h', 'browser/devtools_ui.cc', diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index f5153a78456..e90a2f8a1c9 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -4,8 +4,11 @@ #include "browser/browser_main_parts.h" +#include "base/command_line.h" #include "browser/browser_context.h" +#include "browser/devtools_delegate.h" #include "browser/web_ui_controller_factory.h" +#include "content/public/common/content_switches.h" #include "net/proxy/proxy_resolver_v8.h" #if defined(USE_AURA) @@ -64,6 +67,7 @@ void BrowserMainParts::PreEarlyInitialization() { InitProxyResolverV8(); } + void BrowserMainParts::ToolkitInitialized() { #if defined(USE_AURA) && defined(USE_X11) views::LinuxUI::instance()->Initialize(); @@ -94,6 +98,11 @@ void BrowserMainParts::PreMainMessageLoopRun() { new WebUIControllerFactory(browser_context_.get())); content::WebUIControllerFactory::RegisterFactory( web_ui_controller_factory_.get()); + if (CommandLine::ForCurrentProcess()->HasSwitch( + switches::kRemoteDebuggingPort)) { + devtools_delegate_.reset(new brightray::DevToolsDelegate( + browser_context())); + } } void BrowserMainParts::PostMainMessageLoopRun() { diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 42fd4e382bd..16cf9165e18 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -25,6 +25,7 @@ namespace brightray { class BrowserContext; class WebUIControllerFactory; +class DevToolsDelegate; class BrowserMainParts : public content::BrowserMainParts { public: @@ -57,6 +58,7 @@ class BrowserMainParts : public content::BrowserMainParts { scoped_ptr browser_context_; scoped_ptr web_ui_controller_factory_; + scoped_ptr devtools_delegate_; #if defined(TOOLKIT_VIEWS) scoped_ptr views_delegate_; diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_delegate.cc new file mode 100644 index 00000000000..682f06a2f40 --- /dev/null +++ b/brightray/browser/devtools_delegate.cc @@ -0,0 +1,197 @@ +// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/devtools_delegate.h" + +#include + +#include "base/bind.h" +#include "base/command_line.h" +#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 "browser/inspectable_web_contents.h" +#include "browser/default_web_contents_delegate.h" +#include "browser/inspectable_web_contents_delegate.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/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/socket/tcp_listen_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 { + +// A hack here: +// Copy from grit/shell_resources.h of chromium repository +// since libcontentchromium doesn't expose content_shell resources. +const int kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE = 25500; + +const char kTargetTypePage[] = "page"; + +net::StreamListenSocketFactory* CreateSocketFactory() { + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + // See if the user specified a port on the command line (useful for + // automation). If not, use an ephemeral port by specifying 0. + int port = 0; + if (command_line.HasSwitch(switches::kRemoteDebuggingPort)) { + int temp_port; + std::string port_str = + command_line.GetSwitchValueASCII(switches::kRemoteDebuggingPort); + if (base::StringToInt(port_str, &temp_port) && + temp_port > 0 && temp_port < 65535) { + port = temp_port; + } else { + DLOG(WARNING) << "Invalid http debugger port number " << temp_port; + } + } + return new net::TCPListenSocketFactory("127.0.0.1", port); +} + +class Target : public content::DevToolsTarget { + public: + explicit Target(WebContents* web_contents); + + virtual std::string GetId() const OVERRIDE { return id_; } + virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } + virtual std::string GetTitle() const OVERRIDE { return title_; } + virtual std::string GetDescription() const OVERRIDE { return std::string(); } + virtual GURL GetURL() const OVERRIDE { return url_; } + virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } + virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { + return last_activity_time_; + } + virtual bool IsAttached() const OVERRIDE { + return agent_host_->IsAttached(); + } + virtual scoped_refptr GetAgentHost() const OVERRIDE { + return agent_host_; + } + virtual bool Activate() const OVERRIDE; + virtual bool Close() const OVERRIDE; + + private: + scoped_refptr agent_host_; + std::string id_; + std::string title_; + GURL url_; + GURL favicon_url_; + base::TimeTicks last_activity_time_; +}; + +Target::Target(WebContents* web_contents) { + agent_host_ = + DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost()); + id_ = agent_host_->GetId(); + title_ = base::UTF16ToUTF8(web_contents->GetTitle()); + url_ = web_contents->GetURL(); + 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 { + RenderViewHost* rvh = agent_host_->GetRenderViewHost(); + if (!rvh) + return false; + WebContents* web_contents = WebContents::FromRenderViewHost(rvh); + if (!web_contents) + return false; + web_contents->GetDelegate()->ActivateContents(web_contents); + return true; +} + +bool Target::Close() const { + RenderViewHost* rvh = agent_host_->GetRenderViewHost(); + if (!rvh) + return false; + rvh->ClosePage(); + return true; +} + +} // namespace + +namespace brightray { + +DevToolsDelegate::DevToolsDelegate( + content::BrowserContext* browser_context) + : browser_context_(browser_context) { + std::string frontend_url; + devtools_http_handler_ = + DevToolsHttpHandler::Start(CreateSocketFactory(), frontend_url, this); +} + +DevToolsDelegate::~DevToolsDelegate() { + LOG(ERROR) << "delete!"; +} + +void DevToolsDelegate::Stop() { + // The call below destroys this. + devtools_http_handler_->Stop(); +} + +std::string DevToolsDelegate::GetDiscoveryPageHTML() { + return ResourceBundle::GetSharedInstance().GetRawDataResource( + kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); +} + +bool DevToolsDelegate::BundlesFrontendResources() { + return true; +} + +base::FilePath DevToolsDelegate::GetDebugFrontendDir() { + return base::FilePath(); +} + +std::string DevToolsDelegate::GetPageThumbnailData(const GURL& url) { + return std::string(); +} + +scoped_ptr +DevToolsDelegate::CreateNewTarget(const GURL& url) { + content::WebContents::CreateParams create_params( + new brightray::BrowserContext()); + brightray::InspectableWebContents* web_contents = + brightray::InspectableWebContents::Create(create_params); + web_contents->SetDelegate(new brightray::InspectableWebContentsDelegate()); + return scoped_ptr(new Target(web_contents->GetWebContents())); +} + +void DevToolsDelegate::EnumerateTargets(TargetCallback callback) { + TargetList targets; + std::vector rvh_list = + content::DevToolsAgentHost::GetValidRenderViewHosts(); + for (std::vector::iterator it = rvh_list.begin(); + it != rvh_list.end(); ++it) { + WebContents* web_contents = WebContents::FromRenderViewHost(*it); + if (web_contents) + targets.push_back(new Target(web_contents)); + } + callback.Run(targets); +} + +scoped_ptr +DevToolsDelegate::CreateSocketForTethering( + net::StreamListenSocket::Delegate* delegate, + std::string* name) { + return scoped_ptr(); +} + +} // namespace brightray diff --git a/brightray/browser/devtools_delegate.h b/brightray/browser/devtools_delegate.h new file mode 100644 index 00000000000..5c8580a625c --- /dev/null +++ b/brightray/browser/devtools_delegate.h @@ -0,0 +1,54 @@ +// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_DEVTOOLS_DELEGATE_H_ +#define BRIGHTRAY_DEVTOOLS_DELEGATE_H_ + +#include + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "content/public/browser/devtools_http_handler_delegate.h" + +namespace content { +class BrowserContext; +class DevToolsHttpHandler; +} + +namespace brightray { + +class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { + public: + explicit DevToolsDelegate(content::BrowserContext* browser_context); + virtual ~DevToolsDelegate(); + + // Stops http server. + void Stop(); + + // DevToolsHttpProtocolHandler::Delegate overrides. + virtual std::string GetDiscoveryPageHTML() OVERRIDE; + virtual bool BundlesFrontendResources() OVERRIDE; + virtual base::FilePath GetDebugFrontendDir() OVERRIDE; + virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE; + virtual scoped_ptr CreateNewTarget( + const GURL& url) OVERRIDE; + virtual void EnumerateTargets(TargetCallback callback) OVERRIDE; + virtual scoped_ptr CreateSocketForTethering( + net::StreamListenSocket::Delegate* delegate, + std::string* name) OVERRIDE; + + content::DevToolsHttpHandler* devtools_http_handler() { + return devtools_http_handler_; + } + + private: + content::BrowserContext* browser_context_; + content::DevToolsHttpHandler* devtools_http_handler_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); +}; + +} // namespace brightray + +#endif // BRIGHTRAY_DEVTOOLS_DELEGATE_H_ From e5a57b02d806b76b1006da70f584e7beca5e343f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 7 Aug 2014 10:48:02 +0800 Subject: [PATCH 0380/1195] Focus on devtools when it is opened on Mac. --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 084389dd92c..a0e44633810 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -55,6 +55,9 @@ using namespace brightray; // sizes for them until the setContentsResizingStrategy message. [self addSubview:devToolsView positioned:NSWindowBelow relativeTo:nil]; [self update]; + + // Focus on web view. + devToolsWebContents->RestoreFocus(); } else { gfx::ScopedNSDisableScreenUpdates disabler; devToolsWebContents->RemoveOverlayView(); From f455798c055fcbbec8e287589fd4f4354f302575 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 7 Aug 2014 10:50:50 +0800 Subject: [PATCH 0381/1195] Fix cpplint warnings. --- brightray/browser/devtools_delegate.cc | 1 - brightray/browser/devtools_delegate.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_delegate.cc index 682f06a2f40..ded349dce67 100644 --- a/brightray/browser/devtools_delegate.cc +++ b/brightray/browser/devtools_delegate.cc @@ -139,7 +139,6 @@ DevToolsDelegate::DevToolsDelegate( } DevToolsDelegate::~DevToolsDelegate() { - LOG(ERROR) << "delete!"; } void DevToolsDelegate::Stop() { diff --git a/brightray/browser/devtools_delegate.h b/brightray/browser/devtools_delegate.h index 5c8580a625c..b75aeff0461 100644 --- a/brightray/browser/devtools_delegate.h +++ b/brightray/browser/devtools_delegate.h @@ -49,6 +49,6 @@ class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); }; -} // namespace brightray +} // namespace brightray #endif // BRIGHTRAY_DEVTOOLS_DELEGATE_H_ From 4ed7934567a5c758bcf72aaa090dce718c20e3f8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 8 Aug 2014 12:45:26 +0800 Subject: [PATCH 0382/1195] mac: Close devtools when web contents is destroyed. After the BRYInspectableWebContentsView is added as subview to other NSWindow owned by users, the view_ would not be dealloc when the web contents got destroyed, which made the devtools window a ghost. --- brightray/browser/inspectable_web_contents_view_mac.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index 698e6883a43..aeca189b796 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -17,6 +17,7 @@ InspectableWebContentsViewMac::InspectableWebContentsViewMac(InspectableWebConte } InspectableWebContentsViewMac::~InspectableWebContentsViewMac() { + CloseDevTools(); } gfx::NativeView InspectableWebContentsViewMac::GetNativeView() const { From 760f7ed24f3c3d73d50ae690ce1ae2b46e2a68df Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 9 Aug 2014 09:34:06 +0800 Subject: [PATCH 0383/1195] Fix "warning: field 'widget_' is uninitialized when used here". --- brightray/browser/views/inspectable_web_contents_view_views.cc | 2 +- 1 file changed, 1 insertion(+), 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 e642c48e5b2..e810414e0d2 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -18,7 +18,7 @@ class DevToolsWindowDelegate : public views::ClientView, DevToolsWindowDelegate(InspectableWebContentsViewViews* shell, views::View* view, views::Widget* widget) - : views::ClientView(widget_, view), + : views::ClientView(widget, view), shell_(shell), view_(view), widget_(widget), From eafa88875723f4e553362204e0f26dc0ecd071df Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 11 Aug 2014 10:42:50 +0800 Subject: [PATCH 0384/1195] Enable devtools experiments. --- brightray/browser/inspectable_web_contents_impl.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 1449bde5765..cc950244a53 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -28,7 +28,9 @@ namespace brightray { namespace { -const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?can_dock=true"; +const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?" + "can_dock=true&&" + "experiments=true"; const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; const char kFrontendHostId[] = "id"; From f05199d4e40c041c34737d5c9ca04d297115e4dd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 11 Aug 2014 23:22:49 +0800 Subject: [PATCH 0385/1195] Don't be too strict on media requests. --- .../media/media_stream_devices_controller.cc | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index 22fb0d1310d..2b7510939dd 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -47,21 +47,6 @@ MediaStreamDevicesController::~MediaStreamDevicesController() { } bool MediaStreamDevicesController::TakeAction() { - // Tab capture is allowed for extensions only and infobar is not shown for - // extensions. - if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || - request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { - Deny(); - return true; - } - - // Deny the request if the security origin is empty, this happens with - // file access without |--allow-file-access-from-files| flag. - if (request_.security_origin.is_empty()) { - Deny(); - return true; - } - // Deny the request if there is no device attached to the OS. if (!HasAnyAvailableDevice()) { Deny(); From d01aa5168637716037d311140a4c7ac166d362e8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Aug 2014 15:09:26 +0800 Subject: [PATCH 0386/1195] using content::BrowserThread --- brightray/browser/browser_context.cc | 18 ++++++++---------- .../browser/url_request_context_getter.cc | 14 +++++++------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 9628dc6b386..563ad286bd1 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -25,6 +25,8 @@ #include "base/nix/xdg_util.h" #endif +using content::BrowserThread; + namespace brightray { class BrowserContext::ResourceContext : public content::ResourceContext { @@ -79,7 +81,7 @@ void BrowserContext::Initialize() { base::PrefServiceFactory prefs_factory; prefs_factory.SetUserPrefsFile(prefs_path, JsonPrefStore::GetTaskRunnerForFile( - prefs_path, content::BrowserThread::GetBlockingPool())); + prefs_path, BrowserThread::GetBlockingPool())); auto registry = make_scoped_refptr(new PrefRegistrySimple); RegisterInternalPrefs(registry); @@ -89,9 +91,9 @@ void BrowserContext::Initialize() { } BrowserContext::~BrowserContext() { - content::BrowserThread::DeleteSoon(content::BrowserThread::IO, - FROM_HERE, - resource_context_.release()); + BrowserThread::DeleteSoon(BrowserThread::IO, + FROM_HERE, + resource_context_.release()); } void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { @@ -102,14 +104,10 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerScopedVector protocol_interceptors) { DCHECK(!url_request_getter_); - auto io_loop = content::BrowserThread::UnsafeGetMessageLoopForThread( - content::BrowserThread::IO); - auto file_loop = content::BrowserThread::UnsafeGetMessageLoopForThread( - content::BrowserThread::FILE); url_request_getter_ = new URLRequestContextGetter( GetPath(), - io_loop, - file_loop, + BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), + BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), base::Bind(&BrowserContext::CreateNetworkDelegate, base::Unretained(this)), protocol_handlers, protocol_interceptors.Pass()); diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 578f5a3047a..700fe106f6e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -36,6 +36,8 @@ #include "net/url_request/url_request_job_factory_impl.h" #include "webkit/browser/quota/special_storage_policy.h" +using content::BrowserThread; + namespace brightray { URLRequestContextGetter::URLRequestContextGetter( @@ -51,7 +53,7 @@ URLRequestContextGetter::URLRequestContextGetter( network_delegate_factory_(network_delegate_factory), protocol_interceptors_(protocol_interceptors.Pass()) { // Must first be created on the UI thread. - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); std::swap(protocol_handlers_, *protocol_handlers); @@ -67,7 +69,7 @@ net::HostResolver* URLRequestContextGetter::host_resolver() { } net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { - DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext()); @@ -117,8 +119,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { net::CACHE_BACKEND_DEFAULT, cache_path, 0, - content::BrowserThread::GetMessageLoopProxyForThread( - content::BrowserThread::CACHE)); + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); net::HttpNetworkSession::Params network_session_params; network_session_params.cert_verifier = @@ -163,7 +164,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { job_factory->SetProtocolHandler( content::kFileScheme, new net::FileProtocolHandler( - content::BrowserThread::GetBlockingPool()-> + BrowserThread::GetBlockingPool()-> GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); @@ -187,8 +188,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { scoped_refptr URLRequestContextGetter::GetNetworkTaskRunner() const { - return content::BrowserThread::GetMessageLoopProxyForThread( - content::BrowserThread::IO); + return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); } } // namespace brightray From 2d03c983e4f4b00f0160e0eb5f3fb2115225fe0e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Aug 2014 15:48:16 +0800 Subject: [PATCH 0387/1195] Give user a chance to create custom URLRequestJobFactory. --- brightray/browser/browser_context.cc | 8 ++++++++ brightray/browser/browser_context.h | 10 ++++++++++ brightray/browser/url_request_context_getter.cc | 10 ++++++++++ brightray/browser/url_request_context_getter.h | 6 ++++++ 4 files changed, 34 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 563ad286bd1..308e733d422 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -20,6 +20,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" +#include "net/url_request/url_request_job_factory_impl.h" #if defined(OS_LINUX) #include "base/nix/xdg_util.h" @@ -109,6 +110,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), base::Bind(&BrowserContext::CreateNetworkDelegate, base::Unretained(this)), + base::Bind(&BrowserContext::CreateURLRequestJobFactory, base::Unretained(this)), protocol_handlers, protocol_interceptors.Pass()); resource_context_->set_url_request_context_getter(url_request_getter_.get()); @@ -119,6 +121,12 @@ scoped_ptr BrowserContext::CreateNetworkDelegate() { return make_scoped_ptr(new NetworkDelegate).Pass(); } +scoped_ptr BrowserContext::CreateURLRequestJobFactory( + const content::ProtocolHandlerMap& protocol_handlers, + const content::ProtocolHandlerScopedVector& protocol_interceptors) { + return scoped_ptr(); +} + base::FilePath BrowserContext::GetPath() const { return path_; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index e59c72ab92d..1caa216a7ad 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -11,6 +11,10 @@ class PrefRegistrySimple; class PrefService; +namespace browser_context { +class URLRequestJobFactory; +} + namespace brightray { class DownloadManagerDelegate; @@ -38,6 +42,12 @@ class BrowserContext : public content::BrowserContext { // implementation. virtual scoped_ptr CreateNetworkDelegate(); + // Subclasses should override this to provide a custom URLRequestJobFactory + // implementation. + virtual scoped_ptr CreateURLRequestJobFactory( + const content::ProtocolHandlerMap& protocol_handlers, + const content::ProtocolHandlerScopedVector& protocol_interceptors); + virtual base::FilePath GetPath() const OVERRIDE; private: diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 700fe106f6e..80ae8a8e65e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -45,12 +45,14 @@ URLRequestContextGetter::URLRequestContextGetter( base::MessageLoop* io_loop, base::MessageLoop* file_loop, base::Callback(void)> network_delegate_factory, + URLRequestJobFactoryFactory job_factory_factory, content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerScopedVector protocol_interceptors) : base_path_(base_path), io_loop_(io_loop), file_loop_(file_loop), network_delegate_factory_(network_delegate_factory), + job_factory_factory_(job_factory_factory), protocol_interceptors_(protocol_interceptors.Pass()) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -149,6 +151,14 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params, main_backend); storage_->set_http_transaction_factory(main_cache); + // Give user a chance to create their own job factory. + scoped_ptr user_job_factory( + job_factory_factory_.Run(protocol_handlers_, protocol_interceptors_)); + if (user_job_factory) { + storage_->set_job_factory(user_job_factory.release()); + return url_request_context_.get(); + } + scoped_ptr job_factory( new net::URLRequestJobFactoryImpl()); for (auto it = protocol_handlers_.begin(), diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index ad09e2b409c..3f3dfb1d7b4 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -25,6 +25,10 @@ namespace brightray { class NetworkDelegate; +typedef base::Callback( + const content::ProtocolHandlerMap& protocol_handlers, + const content::ProtocolHandlerScopedVector& protocol_interceptors)> URLRequestJobFactoryFactory; + class URLRequestContextGetter : public net::URLRequestContextGetter { public: URLRequestContextGetter( @@ -32,6 +36,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { base::MessageLoop* io_loop, base::MessageLoop* file_loop, base::Callback(void)>, + URLRequestJobFactoryFactory job_factory_factory, content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerScopedVector protocol_interceptors); virtual ~URLRequestContextGetter(); @@ -48,6 +53,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { base::MessageLoop* file_loop_; base::Callback(void)> network_delegate_factory_; + URLRequestJobFactoryFactory job_factory_factory_; scoped_ptr proxy_config_service_; scoped_ptr network_delegate_; From 3f9f7782743c435b4c81b083ab0b08e3fd445b60 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Aug 2014 16:05:22 +0800 Subject: [PATCH 0388/1195] Clean handlers when custom job factory is used. --- brightray/browser/url_request_context_getter.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 80ae8a8e65e..3786ccb7bb9 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -156,6 +156,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { job_factory_factory_.Run(protocol_handlers_, protocol_interceptors_)); if (user_job_factory) { storage_->set_job_factory(user_job_factory.release()); + protocol_handlers_.clear(); + protocol_interceptors_.weak_clear(); return url_request_context_.get(); } From b95b621dfcb38ccd8c85c989f645a9d2ec5acd23 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Aug 2014 16:09:32 +0800 Subject: [PATCH 0389/1195] Add url_request_context_getter getter for BrowserContext. --- brightray/browser/browser_context.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 1caa216a7ad..328ca72cf10 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -5,6 +5,8 @@ #ifndef BRIGHTRAY_BROWSER_BROWSER_CONTEXT_H_ #define BRIGHTRAY_BROWSER_BROWSER_CONTEXT_H_ +#include "browser/url_request_context_getter.h" + #include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" @@ -19,7 +21,6 @@ namespace brightray { class DownloadManagerDelegate; class NetworkDelegate; -class URLRequestContextGetter; class BrowserContext : public content::BrowserContext { public: @@ -32,6 +33,10 @@ class BrowserContext : public content::BrowserContext { content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerScopedVector protocol_interceptors); + net::URLRequestContextGetter* url_request_context_getter() const { + return url_request_getter_.get(); + } + PrefService* prefs() { return prefs_.get(); } protected: From 604361f93d6ef3fd3e0507743d84ccd38784412d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Aug 2014 16:16:01 +0800 Subject: [PATCH 0390/1195] Pass ProtocolHandlerScopedVector by value. --- brightray/browser/browser_context.cc | 2 +- brightray/browser/browser_context.h | 2 +- brightray/browser/url_request_context_getter.cc | 2 +- brightray/browser/url_request_context_getter.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 308e733d422..0973211e08d 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -123,7 +123,7 @@ scoped_ptr BrowserContext::CreateNetworkDelegate() { scoped_ptr BrowserContext::CreateURLRequestJobFactory( const content::ProtocolHandlerMap& protocol_handlers, - const content::ProtocolHandlerScopedVector& protocol_interceptors) { + content::ProtocolHandlerScopedVector protocol_interceptors) { return scoped_ptr(); } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 328ca72cf10..879bfd7f42a 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -51,7 +51,7 @@ class BrowserContext : public content::BrowserContext { // implementation. virtual scoped_ptr CreateURLRequestJobFactory( const content::ProtocolHandlerMap& protocol_handlers, - const content::ProtocolHandlerScopedVector& protocol_interceptors); + content::ProtocolHandlerScopedVector protocol_interceptors); virtual base::FilePath GetPath() const OVERRIDE; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 3786ccb7bb9..6a0a90b2432 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -153,7 +153,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { // Give user a chance to create their own job factory. scoped_ptr user_job_factory( - job_factory_factory_.Run(protocol_handlers_, protocol_interceptors_)); + job_factory_factory_.Run(protocol_handlers_, protocol_interceptors_.Pass())); if (user_job_factory) { storage_->set_job_factory(user_job_factory.release()); protocol_handlers_.clear(); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 3f3dfb1d7b4..e043beb4cfc 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -27,7 +27,7 @@ class NetworkDelegate; typedef base::Callback( const content::ProtocolHandlerMap& protocol_handlers, - const content::ProtocolHandlerScopedVector& protocol_interceptors)> URLRequestJobFactoryFactory; + content::ProtocolHandlerScopedVector protocol_interceptors)> URLRequestJobFactoryFactory; class URLRequestContextGetter : public net::URLRequestContextGetter { public: From da3bafd490c9bc000d90237aa3fe3d046e86f0d6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Aug 2014 17:31:33 +0800 Subject: [PATCH 0391/1195] Pass parameter by pointers when creating job factory. 1. The caller needs to modify protocol_handlers. 2. We need to make sure protocol_handlers and interceptors are not touched if user doesn't create a job factory. --- brightray/browser/browser_context.cc | 4 ++-- brightray/browser/browser_context.h | 4 ++-- brightray/browser/url_request_context_getter.cc | 4 +--- brightray/browser/url_request_context_getter.h | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 0973211e08d..e9ee4046c23 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -122,8 +122,8 @@ scoped_ptr BrowserContext::CreateNetworkDelegate() { } scoped_ptr BrowserContext::CreateURLRequestJobFactory( - const content::ProtocolHandlerMap& protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors) { + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector* protocol_interceptors) { return scoped_ptr(); } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 879bfd7f42a..fb9c107ed11 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -50,8 +50,8 @@ class BrowserContext : public content::BrowserContext { // Subclasses should override this to provide a custom URLRequestJobFactory // implementation. virtual scoped_ptr CreateURLRequestJobFactory( - const content::ProtocolHandlerMap& protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors); + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector* protocol_interceptors); virtual base::FilePath GetPath() const OVERRIDE; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 6a0a90b2432..8c772c81dd9 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -153,11 +153,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { // Give user a chance to create their own job factory. scoped_ptr user_job_factory( - job_factory_factory_.Run(protocol_handlers_, protocol_interceptors_.Pass())); + job_factory_factory_.Run(&protocol_handlers_, &protocol_interceptors_)); if (user_job_factory) { storage_->set_job_factory(user_job_factory.release()); - protocol_handlers_.clear(); - protocol_interceptors_.weak_clear(); return url_request_context_.get(); } diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index e043beb4cfc..716b7e00b75 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -26,8 +26,8 @@ namespace brightray { class NetworkDelegate; typedef base::Callback( - const content::ProtocolHandlerMap& protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors)> URLRequestJobFactoryFactory; + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector* protocol_interceptors)> URLRequestJobFactoryFactory; class URLRequestContextGetter : public net::URLRequestContextGetter { public: From b06970fda053710ee00985fd5f65c743bacbd606 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 13 Aug 2014 17:39:25 +0800 Subject: [PATCH 0392/1195] Remove unneeded headers and declarations. --- brightray/browser/browser_context.cc | 2 -- brightray/browser/browser_context.h | 4 ---- 2 files changed, 6 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index e9ee4046c23..8a5e63e8c74 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -7,7 +7,6 @@ #include "browser/download_manager_delegate.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/network_delegate.h" -#include "browser/url_request_context_getter.h" #include "common/application_info.h" #include "base/environment.h" @@ -20,7 +19,6 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" -#include "net/url_request/url_request_job_factory_impl.h" #if defined(OS_LINUX) #include "base/nix/xdg_util.h" diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index fb9c107ed11..486a9eda903 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -13,10 +13,6 @@ class PrefRegistrySimple; class PrefService; -namespace browser_context { -class URLRequestJobFactory; -} - namespace brightray { class DownloadManagerDelegate; From 052ddd961f6e2c5bb20b4ccec45f2377910790e6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 15 Aug 2014 12:30:50 +0800 Subject: [PATCH 0393/1195] Implement --host-rules switch. --- .../browser/url_request_context_getter.cc | 32 +++++++++++++++++++ .../browser/url_request_context_getter.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 8c772c81dd9..6ca9297b415 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -8,12 +8,14 @@ #include "browser/network_delegate.h" +#include "base/command_line.h" #include "base/strings/string_util.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/cookie_store_factory.h" #include "content/public/common/url_constants.h" +#include "net/base/host_mapping_rules.h" #include "net/cert/cert_verifier.h" #include "net/cookies/cookie_monster.h" #include "net/http/http_auth_handler_factory.h" @@ -40,6 +42,27 @@ using content::BrowserThread; namespace brightray { +namespace { + +// Comma-separated list of rules that control how hostnames are mapped. +// +// For example: +// "MAP * 127.0.0.1" --> Forces all hostnames to be mapped to 127.0.0.1 +// "MAP *.google.com proxy" --> Forces all google.com subdomains to be +// resolved to "proxy". +// "MAP test.com [::1]:77 --> Forces "test.com" to resolve to IPv6 loopback. +// Will also force the port of the resulting +// socket address to be 77. +// "MAP * baz, EXCLUDE www.google.com" --> Remaps everything to "baz", +// except for "www.google.com". +// +// These mappings apply to the endpoint host in a net::URLRequest (the TCP +// connect and host resolver in a direct connection, and the CONNECT in an http +// proxy connection, and the endpoint host in a SOCKS proxy connection). +const char kHostRules[] = "host-rules"; + +} // namespace + URLRequestContextGetter::URLRequestContextGetter( const base::FilePath& base_path, base::MessageLoop* io_loop, @@ -73,6 +96,8 @@ net::HostResolver* URLRequestContextGetter::host_resolver() { net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext()); network_delegate_ = network_delegate_factory_.Run().Pass(); @@ -142,6 +167,13 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { url_request_context_->http_server_properties(); network_session_params.ignore_certificate_errors = false; + // --host-rules + if (command_line.HasSwitch(kHostRules)) { + host_mapping_rules_.reset(new net::HostMappingRules); + host_mapping_rules_->SetRulesFromString(command_line.GetSwitchValueASCII(kHostRules)); + network_session_params.host_mapping_rules = host_mapping_rules_.get(); + } + // Give |storage_| ownership at the end in case it's |mapped_host_resolver|. storage_->set_host_resolver(host_resolver.Pass()); network_session_params.host_resolver = diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 716b7e00b75..e179f4e15ec 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -16,6 +16,7 @@ class MessageLoop; } namespace net { +class HostMappingRules; class HostResolver; class ProxyConfigService; class URLRequestContextStorage; @@ -59,6 +60,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr network_delegate_; scoped_ptr storage_; scoped_ptr url_request_context_; + scoped_ptr host_mapping_rules_; content::ProtocolHandlerMap protocol_handlers_; content::ProtocolHandlerScopedVector protocol_interceptors_; From 8c73e6aba4ea66a1d867b0ac28bc76fdeead071a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 15 Aug 2014 12:41:56 +0800 Subject: [PATCH 0394/1195] Implement --host-resolver-rules switch. --- brightray/browser/url_request_context_getter.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 6ca9297b415..e2169ab5a27 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -14,10 +14,12 @@ #include "base/threading/worker_pool.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/cookie_store_factory.h" +#include "content/public/common/content_switches.h" #include "content/public/common/url_constants.h" #include "net/base/host_mapping_rules.h" #include "net/cert/cert_verifier.h" #include "net/cookies/cookie_monster.h" +#include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_cache.h" #include "net/http/http_server_properties_impl.h" @@ -120,6 +122,15 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { scoped_ptr host_resolver( net::HostResolver::CreateDefaultResolver(NULL)); + // --host-resolver-rules + if (command_line.HasSwitch(switches::kHostResolverRules)) { + scoped_ptr remapped_resolver( + new net::MappedHostResolver(host_resolver.Pass())); + remapped_resolver->SetRulesFromString( + command_line.GetSwitchValueASCII(switches::kHostResolverRules)); + host_resolver = remapped_resolver.PassAs(); + } + net::DhcpProxyScriptFetcherFactory dhcp_factory; storage_->set_proxy_service( net::CreateProxyServiceUsingV8ProxyResolver( From d136c447921c7abfe27142993f30de4d5ae1da8a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 20 Aug 2014 11:44:45 +0800 Subject: [PATCH 0395/1195] Add --no-proxy-server switch. --- .../browser/url_request_context_getter.cc | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index e2169ab5a27..bc6e5d9a3fa 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -61,7 +61,11 @@ namespace { // These mappings apply to the endpoint host in a net::URLRequest (the TCP // connect and host resolver in a direct connection, and the CONNECT in an http // proxy connection, and the endpoint host in a SOCKS proxy connection). -const char kHostRules[] = "host-rules"; +const char kHostRules[] = "host-rules"; + +// Don't use a proxy server, always make direct connections. Overrides any +// other proxy server flags that are passed. +const char kNoProxyServer[] = "no-proxy-server"; } // namespace @@ -132,14 +136,17 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } net::DhcpProxyScriptFetcherFactory dhcp_factory; - storage_->set_proxy_service( - net::CreateProxyServiceUsingV8ProxyResolver( - proxy_config_service_.release(), - new net::ProxyScriptFetcherImpl(url_request_context_.get()), - dhcp_factory.Create(url_request_context_.get()), - host_resolver.get(), - NULL, - url_request_context_->network_delegate())); + if (command_line.HasSwitch(kNoProxyServer)) + storage_->set_proxy_service(net::ProxyService::CreateDirect()); + else + storage_->set_proxy_service( + net::CreateProxyServiceUsingV8ProxyResolver( + proxy_config_service_.release(), + new net::ProxyScriptFetcherImpl(url_request_context_.get()), + dhcp_factory.Create(url_request_context_.get()), + host_resolver.get(), + NULL, + url_request_context_->network_delegate())); storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); storage_->set_transport_security_state(new net::TransportSecurityState); From 44bfa328f18ab426fd82141754f90f6e33938193 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 20 Aug 2014 11:49:18 +0800 Subject: [PATCH 0396/1195] Add --proxy-server switch. --- brightray/browser/url_request_context_getter.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index bc6e5d9a3fa..9a93ac155f0 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -67,6 +67,10 @@ const char kHostRules[] = "host-rules"; // other proxy server flags that are passed. const char kNoProxyServer[] = "no-proxy-server"; +// Uses a specified proxy server, overrides system settings. This switch only +// affects HTTP and HTTPS requests. +const char kProxyServer[] = "proxy-server"; + } // namespace URLRequestContextGetter::URLRequestContextGetter( @@ -138,6 +142,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { net::DhcpProxyScriptFetcherFactory dhcp_factory; if (command_line.HasSwitch(kNoProxyServer)) storage_->set_proxy_service(net::ProxyService::CreateDirect()); + else if (command_line.HasSwitch(kProxyServer)) + storage_->set_proxy_service(net::ProxyService::CreateFixed( + command_line.GetSwitchValueASCII(kProxyServer))); else storage_->set_proxy_service( net::CreateProxyServiceUsingV8ProxyResolver( From c30f11f38c632946a495198ec110e4e97edbffe2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 20 Aug 2014 14:39:09 +0800 Subject: [PATCH 0397/1195] Add Delegate for URLRequestContextGetter. --- brightray/browser/browser_context.cc | 11 +++---- brightray/browser/browser_context.h | 17 ++++------ .../browser/url_request_context_getter.cc | 12 +++---- .../browser/url_request_context_getter.h | 32 +++++++++++-------- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 8a5e63e8c74..3396531ed35 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -104,25 +104,24 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( content::ProtocolHandlerScopedVector protocol_interceptors) { DCHECK(!url_request_getter_); url_request_getter_ = new URLRequestContextGetter( + this, GetPath(), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), - base::Bind(&BrowserContext::CreateNetworkDelegate, base::Unretained(this)), - base::Bind(&BrowserContext::CreateURLRequestJobFactory, base::Unretained(this)), protocol_handlers, protocol_interceptors.Pass()); resource_context_->set_url_request_context_getter(url_request_getter_.get()); return url_request_getter_.get(); } -scoped_ptr BrowserContext::CreateNetworkDelegate() { - return make_scoped_ptr(new NetworkDelegate).Pass(); +net::NetworkDelegate* BrowserContext::CreateNetworkDelegate() { + return new NetworkDelegate; } -scoped_ptr BrowserContext::CreateURLRequestJobFactory( +net::URLRequestJobFactory* BrowserContext::CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerScopedVector* protocol_interceptors) { - return scoped_ptr(); + return NULL; } base::FilePath BrowserContext::GetPath() const { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 486a9eda903..6bd2a1b81d9 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -8,7 +8,6 @@ #include "browser/url_request_context_getter.h" #include "content/public/browser/browser_context.h" -#include "content/public/browser/content_browser_client.h" class PrefRegistrySimple; class PrefService; @@ -16,9 +15,9 @@ class PrefService; namespace brightray { class DownloadManagerDelegate; -class NetworkDelegate; -class BrowserContext : public content::BrowserContext { +class BrowserContext : public content::BrowserContext, + public brightray::URLRequestContextGetter::Delegate { public: BrowserContext(); ~BrowserContext(); @@ -39,15 +38,11 @@ class BrowserContext : public content::BrowserContext { // Subclasses should override this to register custom preferences. virtual void RegisterPrefs(PrefRegistrySimple* pref_registry) {} - // Subclasses should override this to provide a custom NetworkDelegate - // implementation. - virtual scoped_ptr CreateNetworkDelegate(); - - // Subclasses should override this to provide a custom URLRequestJobFactory - // implementation. - virtual scoped_ptr CreateURLRequestJobFactory( + // URLRequestContextGetter::Delegate: + virtual net::NetworkDelegate* CreateNetworkDelegate() OVERRIDE; + virtual net::URLRequestJobFactory* CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector* protocol_interceptors); + content::ProtocolHandlerScopedVector* protocol_interceptors) OVERRIDE; virtual base::FilePath GetPath() const OVERRIDE; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 9a93ac155f0..fba872f5f73 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -74,18 +74,16 @@ const char kProxyServer[] = "proxy-server"; } // namespace URLRequestContextGetter::URLRequestContextGetter( + Delegate* delegate, const base::FilePath& base_path, base::MessageLoop* io_loop, base::MessageLoop* file_loop, - base::Callback(void)> network_delegate_factory, - URLRequestJobFactoryFactory job_factory_factory, content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerScopedVector protocol_interceptors) - : base_path_(base_path), + : delegate_(delegate), + base_path_(base_path), io_loop_(io_loop), file_loop_(file_loop), - network_delegate_factory_(network_delegate_factory), - job_factory_factory_(job_factory_factory), protocol_interceptors_(protocol_interceptors.Pass()) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -110,7 +108,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext()); - network_delegate_ = network_delegate_factory_.Run().Pass(); + network_delegate_.reset(delegate_->CreateNetworkDelegate()); url_request_context_->set_network_delegate(network_delegate_.get()); storage_.reset( new net::URLRequestContextStorage(url_request_context_.get())); @@ -210,7 +208,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { // Give user a chance to create their own job factory. scoped_ptr user_job_factory( - job_factory_factory_.Run(&protocol_handlers_, &protocol_interceptors_)); + delegate_->CreateURLRequestJobFactory(&protocol_handlers_, &protocol_interceptors_)); if (user_job_factory) { storage_->set_job_factory(user_job_factory.release()); return url_request_context_.get(); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index e179f4e15ec..b2dfc1e7abd 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -5,7 +5,6 @@ #ifndef BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_ #define BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_ -#include "base/callback.h" #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/content_browser_client.h" @@ -18,26 +17,34 @@ class MessageLoop; namespace net { class HostMappingRules; class HostResolver; +class NetworkDelegate; class ProxyConfigService; class URLRequestContextStorage; +class URLRequestJobFactory; } namespace brightray { -class NetworkDelegate; - -typedef base::Callback( - content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector* protocol_interceptors)> URLRequestJobFactoryFactory; - class URLRequestContextGetter : public net::URLRequestContextGetter { public: + class Delegate { + public: + Delegate() {} + virtual ~Delegate() {} + + virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; }; + virtual net::URLRequestJobFactory* CreateURLRequestJobFactory( + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector* protocol_interceptors) { + return NULL; + }; + }; + URLRequestContextGetter( + Delegate* delegate, const base::FilePath& base_path, base::MessageLoop* io_loop, base::MessageLoop* file_loop, - base::Callback(void)>, - URLRequestJobFactoryFactory job_factory_factory, content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerScopedVector protocol_interceptors); virtual ~URLRequestContextGetter(); @@ -49,15 +56,14 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual scoped_refptr GetNetworkTaskRunner() const OVERRIDE; + Delegate* delegate_; + base::FilePath base_path_; base::MessageLoop* io_loop_; base::MessageLoop* file_loop_; - base::Callback(void)> network_delegate_factory_; - URLRequestJobFactoryFactory job_factory_factory_; - scoped_ptr proxy_config_service_; - scoped_ptr network_delegate_; + scoped_ptr network_delegate_; scoped_ptr storage_; scoped_ptr url_request_context_; scoped_ptr host_mapping_rules_; From 3fefdcba0de57164df2ef25a6112eea44e230174 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 20 Aug 2014 14:48:02 +0800 Subject: [PATCH 0398/1195] Move creation of URLRequestJobFactoryImpl into default delegate. --- .../browser/url_request_context_getter.cc | 69 ++++++++----------- .../browser/url_request_context_getter.h | 6 +- 2 files changed, 31 insertions(+), 44 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index fba872f5f73..597f8be588a 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -73,6 +73,32 @@ const char kProxyServer[] = "proxy-server"; } // namespace +net::URLRequestJobFactory* URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( + content::ProtocolHandlerMap* protocol_handlers, + content::ProtocolHandlerScopedVector* protocol_interceptors) { + scoped_ptr job_factory(new net::URLRequestJobFactoryImpl); + + for (auto it = protocol_handlers->begin(); it != protocol_handlers->end(); ++it) + job_factory->SetProtocolHandler(it->first, it->second.release()); + protocol_handlers->clear(); + + job_factory->SetProtocolHandler(content::kDataScheme, new net::DataProtocolHandler); + job_factory->SetProtocolHandler(content::kFileScheme, new net::FileProtocolHandler( + BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); + + // Set up interceptors in the reverse order. + scoped_ptr top_job_factory = + job_factory.PassAs(); + for (content::ProtocolHandlerScopedVector::reverse_iterator i = protocol_interceptors->rbegin(); + i != protocol_interceptors->rend(); ++i) + top_job_factory.reset(new net::ProtocolInterceptJobFactory( + top_job_factory.Pass(), make_scoped_ptr(*i))); + protocol_interceptors->weak_clear(); + + return top_job_factory.release(); +} + URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, const base::FilePath& base_path, @@ -137,6 +163,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { host_resolver = remapped_resolver.PassAs(); } + // --proxy-server net::DhcpProxyScriptFetcherFactory dhcp_factory; if (command_line.HasSwitch(kNoProxyServer)) storage_->set_proxy_service(net::ProxyService::CreateDirect()); @@ -206,46 +233,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params, main_backend); storage_->set_http_transaction_factory(main_cache); - // Give user a chance to create their own job factory. - scoped_ptr user_job_factory( - delegate_->CreateURLRequestJobFactory(&protocol_handlers_, &protocol_interceptors_)); - if (user_job_factory) { - storage_->set_job_factory(user_job_factory.release()); - return url_request_context_.get(); - } - - scoped_ptr job_factory( - new net::URLRequestJobFactoryImpl()); - for (auto it = protocol_handlers_.begin(), - end = protocol_handlers_.end(); it != end; ++it) { - bool set_protocol = job_factory->SetProtocolHandler( - it->first, it->second.release()); - DCHECK(set_protocol); - (void)set_protocol; // silence unused-variable warning in Release builds on Windows - } - protocol_handlers_.clear(); - job_factory->SetProtocolHandler( - content::kDataScheme, new net::DataProtocolHandler); - job_factory->SetProtocolHandler( - content::kFileScheme, - new net::FileProtocolHandler( - BrowserThread::GetBlockingPool()-> - GetTaskRunnerWithShutdownBehavior( - base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); - - // Set up interceptors in the reverse order. - scoped_ptr top_job_factory = - job_factory.PassAs(); - for (content::ProtocolHandlerScopedVector::reverse_iterator i = - protocol_interceptors_.rbegin(); - i != protocol_interceptors_.rend(); - ++i) { - top_job_factory.reset(new net::ProtocolInterceptJobFactory( - top_job_factory.Pass(), make_scoped_ptr(*i))); - } - protocol_interceptors_.weak_clear(); - - storage_->set_job_factory(top_job_factory.release()); + storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( + &protocol_handlers_, &protocol_interceptors_)); } return url_request_context_.get(); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index b2dfc1e7abd..b22df64e1fb 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -32,12 +32,10 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { Delegate() {} virtual ~Delegate() {} - virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; }; + virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; } virtual net::URLRequestJobFactory* CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector* protocol_interceptors) { - return NULL; - }; + content::ProtocolHandlerScopedVector* protocol_interceptors); }; URLRequestContextGetter( From 6e420d5137abbb1d60fcb5ac918996b27796ce07 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 20 Aug 2014 15:19:25 +0800 Subject: [PATCH 0399/1195] Cleanup URLRequestContextGetter. In brightray line length limit is 100 so we could make code formatted more tidy. --- .../browser/url_request_context_getter.cc | 65 ++++++++----------- .../browser/url_request_context_getter.h | 8 +-- 2 files changed, 31 insertions(+), 42 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 597f8be588a..da57591ed95 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -116,6 +116,9 @@ URLRequestContextGetter::URLRequestContextGetter( std::swap(protocol_handlers_, *protocol_handlers); + // 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 + // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( io_loop_->message_loop_proxy(), file_loop_)); } @@ -131,28 +134,24 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - if (!url_request_context_.get()) { - url_request_context_.reset(new net::URLRequestContext()); + url_request_context_.reset(new net::URLRequestContext); network_delegate_.reset(delegate_->CreateNetworkDelegate()); url_request_context_->set_network_delegate(network_delegate_.get()); - storage_.reset( - new net::URLRequestContextStorage(url_request_context_.get())); + + storage_.reset(new net::URLRequestContextStorage(url_request_context_.get())); auto cookie_config = content::CookieStoreConfig( base_path_.Append(FILE_PATH_LITERAL("Cookies")), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, - nullptr, - nullptr); + NULL, NULL); storage_->set_cookie_store(content::CreateCookieStore(cookie_config)); storage_->set_server_bound_cert_service(new net::ServerBoundCertService( new net::DefaultServerBoundCertStore(NULL), base::WorkerPool::GetTaskRunner(true))); - storage_->set_http_user_agent_settings( - new net::StaticHttpUserAgentSettings( - "en-us,en", base::EmptyString())); + storage_->set_http_user_agent_settings(new net::StaticHttpUserAgentSettings( + "en-us,en", base::EmptyString())); - scoped_ptr host_resolver( - net::HostResolver::CreateDefaultResolver(NULL)); + scoped_ptr host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); // --host-resolver-rules if (command_line.HasSwitch(switches::kHostResolverRules)) { @@ -189,33 +188,19 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { new net::HttpServerPropertiesImpl); storage_->set_http_server_properties(server_properties.Pass()); - base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); - net::HttpCache::DefaultBackend* main_backend = - new net::HttpCache::DefaultBackend( - net::DISK_CACHE, - net::CACHE_BACKEND_DEFAULT, - cache_path, - 0, - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); - net::HttpNetworkSession::Params network_session_params; - network_session_params.cert_verifier = - url_request_context_->cert_verifier(); + network_session_params.cert_verifier = url_request_context_->cert_verifier(); + network_session_params.proxy_service = url_request_context_->proxy_service(); + network_session_params.ssl_config_service = url_request_context_->ssl_config_service(); + network_session_params.network_delegate = url_request_context_->network_delegate(); + network_session_params.http_server_properties = url_request_context_->http_server_properties(); + network_session_params.ignore_certificate_errors = false; network_session_params.transport_security_state = url_request_context_->transport_security_state(); network_session_params.server_bound_cert_service = url_request_context_->server_bound_cert_service(); - network_session_params.proxy_service = - url_request_context_->proxy_service(); - network_session_params.ssl_config_service = - url_request_context_->ssl_config_service(); network_session_params.http_auth_handler_factory = url_request_context_->http_auth_handler_factory(); - network_session_params.network_delegate = - url_request_context_->network_delegate(); - network_session_params.http_server_properties = - url_request_context_->http_server_properties(); - network_session_params.ignore_certificate_errors = false; // --host-rules if (command_line.HasSwitch(kHostRules)) { @@ -226,12 +211,17 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { // Give |storage_| ownership at the end in case it's |mapped_host_resolver|. storage_->set_host_resolver(host_resolver.Pass()); - network_session_params.host_resolver = - url_request_context_->host_resolver(); + network_session_params.host_resolver = url_request_context_->host_resolver(); - net::HttpCache* main_cache = new net::HttpCache( - network_session_params, main_backend); - storage_->set_http_transaction_factory(main_cache); + base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); + net::HttpCache::DefaultBackend* backend = + new net::HttpCache::DefaultBackend( + net::DISK_CACHE, + net::CACHE_BACKEND_DEFAULT, + cache_path, + 0, + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); + storage_->set_http_transaction_factory(new net::HttpCache(network_session_params, backend)); storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( &protocol_handlers_, &protocol_interceptors_)); @@ -240,8 +230,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { return url_request_context_.get(); } -scoped_refptr - URLRequestContextGetter::GetNetworkTaskRunner() const { +scoped_refptr URLRequestContextGetter::GetNetworkTaskRunner() const { return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); } diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index b22df64e1fb..c7379f2248a 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -47,13 +47,13 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { content::ProtocolHandlerScopedVector protocol_interceptors); virtual ~URLRequestContextGetter(); - net::HostResolver* host_resolver(); + // net::URLRequestContextGetter: virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; + virtual scoped_refptr GetNetworkTaskRunner() const OVERRIDE; + + net::HostResolver* host_resolver(); private: - virtual scoped_refptr - GetNetworkTaskRunner() const OVERRIDE; - Delegate* delegate_; base::FilePath base_path_; From 20efd82c98ac30e7ccad95d872628836b274ecae Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 26 Aug 2014 15:06:51 +0800 Subject: [PATCH 0400/1195] Implement zoom messages for devtools. --- .../browser/inspectable_web_contents_impl.cc | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index cc950244a53..18c755328d2 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -21,6 +21,7 @@ #include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_manager.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" @@ -28,6 +29,12 @@ namespace brightray { namespace { +const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0, + 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, + 5.0 }; + +const char kDevToolsScheme[] = "chrome-devtools"; +const char kDevToolsHost[] = "devtools"; const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?" "can_dock=true&&" "experiments=true"; @@ -81,6 +88,32 @@ bool ParseMessage(const std::string& message, return true; } +double GetZoomLevelForWebContents(content::WebContents* web_contents) { + content::HostZoomMap* host_zoom_map = content::HostZoomMap::GetForBrowserContext( + web_contents->GetBrowserContext()); + return host_zoom_map->GetZoomLevelForHostAndScheme(kDevToolsScheme, kDevToolsHost); +} + +void SetZoomLevelForWebContents(content::WebContents* web_contents, double level) { + content::HostZoomMap* host_zoom_map = content::HostZoomMap::GetForBrowserContext( + web_contents->GetBrowserContext()); + return host_zoom_map->SetZoomLevelForHostAndScheme(kDevToolsScheme, kDevToolsHost, level); +} + +double GetNextZoomLevel(double level, bool out) { + double factor = content::ZoomLevelToZoomFactor(level); + size_t size = arraysize(kPresetZoomFactors); + for (size_t i = 0; i < size; ++i) { + if (!content::ZoomValuesEqual(kPresetZoomFactors[i], factor)) + continue; + if (out && i > 0) + return content::ZoomFactorToZoomLevel(kPresetZoomFactors[i - 1]); + if (!out && i != size - 1) + return content::ZoomFactorToZoomLevel(kPresetZoomFactors[i + 1]); + } + return level; +} + } // namespace // Implemented separately on each platform. @@ -245,12 +278,17 @@ void InspectableWebContentsImpl::SearchInPath( } void InspectableWebContentsImpl::ZoomIn() { + double level = GetZoomLevelForWebContents(devtools_web_contents()); + SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, false)); } void InspectableWebContentsImpl::ZoomOut() { + double level = GetZoomLevelForWebContents(devtools_web_contents()); + SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, true)); } void InspectableWebContentsImpl::ResetZoom() { + SetZoomLevelForWebContents(devtools_web_contents(), 0.); } void InspectableWebContentsImpl::DispatchOnEmbedder( From 47bc6a29a788f7191bdd89a3dc61b821b3943e9b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 28 Aug 2014 12:53:35 +0800 Subject: [PATCH 0401/1195] Print console output of devtools. --- brightray/browser/inspectable_web_contents_impl.cc | 11 +++++++++++ brightray/browser/inspectable_web_contents_impl.h | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 18c755328d2..4938b355db9 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -336,6 +336,17 @@ void InspectableWebContentsImpl::WebContentsDestroyed() { frontend_host_.reset(); } +bool InspectableWebContentsImpl::AddMessageToConsole( + content::WebContents* source, + int32 level, + const base::string16& message, + int32 line_no, + const base::string16& source_id) { + logging::LogMessage("CONSOLE", line_no, level).stream() << "\"" << + message << "\", source: " << source_id << " (" << line_no << ")"; + return true; +} + void InspectableWebContentsImpl::HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 73ba40d7e4a..8bbf70273b2 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -107,6 +107,11 @@ class InspectableWebContentsImpl : // content::WebContentsDelegate + virtual bool AddMessageToConsole(content::WebContents* source, + int32 level, + const base::string16& message, + int32 line_no, + const base::string16& source_id) OVERRIDE; virtual void HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; virtual void CloseContents(content::WebContents* source) OVERRIDE; From bf6722ab4fdee82533d9e223a5e7cad9fd8777b5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 31 Aug 2014 17:44:07 +0800 Subject: [PATCH 0402/1195] Upgrade libchromiumcontent to chrome37. --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index a88222442d2..887f3b7895c 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit a88222442d2a85345d9a208c23456956c208571d +Subproject commit 887f3b7895c55625d20d7ea06fa041dcacdb8b47 From f0e46a472893b0b94543bf9bae592461860008eb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 31 Aug 2014 18:28:53 +0800 Subject: [PATCH 0403/1195] Add skia related defines. --- brightray/brightray.gypi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index c155782c7d0..1856ec978e7 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -62,6 +62,14 @@ 'NDEBUG', 'USING_V8_SHARED', 'WEBKIT_DLL', + # From skia_for_chromium_defines.gypi: + 'SK_SUPPORT_LEGACY_GETTOPDEVICE', + 'SK_SUPPORT_LEGACY_BITMAP_CONFIG', + 'SK_SUPPORT_LEGACY_DEVICE_VIRTUAL_ISOPAQUE', + 'SK_SUPPORT_LEGACY_N32_NAME', + 'SK_SUPPORT_LEGACY_SETCONFIG', + 'SK_IGNORE_ETC1_SUPPORT', + 'SK_IGNORE_GPU_DITHER', ], 'msvs_configuration_attributes': { 'OutputDirectory': '<(DEPTH)\\build\\$(ConfigurationName)', From dca1c51b3214c287914258570d5db406aa1299ec Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 31 Aug 2014 18:43:01 +0800 Subject: [PATCH 0404/1195] Fix API changes of Chrome37. --- brightray/browser/browser_client.cc | 2 +- brightray/browser/browser_client.h | 2 +- brightray/browser/browser_context.cc | 45 +++---------------- brightray/browser/browser_context.h | 36 +++------------ brightray/browser/devtools_delegate.cc | 5 ++- .../browser/inspectable_web_contents_impl.cc | 3 +- .../browser/url_request_context_getter.cc | 16 +++---- .../browser/url_request_context_getter.h | 6 +-- .../inspectable_web_contents_view_views.cc | 1 - 9 files changed, 30 insertions(+), 86 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 3c7377d6d9a..c306bfc26c7 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -61,7 +61,7 @@ content::BrowserMainParts* BrowserClient::CreateBrowserMainParts( net::URLRequestContextGetter* BrowserClient::CreateRequestContext( content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors) { + content::URLRequestInterceptorScopedVector protocol_interceptors) { auto context = static_cast(browser_context); return context->CreateRequestContext(protocol_handlers, protocol_interceptors.Pass()); } diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 6d1944ca026..565ff18cc9c 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -36,7 +36,7 @@ class BrowserClient : public content::ContentBrowserClient { virtual net::URLRequestContextGetter* CreateRequestContext( content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors) OVERRIDE; + content::URLRequestInterceptorScopedVector protocol_interceptors) OVERRIDE; private: virtual content::BrowserMainParts* CreateBrowserMainParts( diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 3396531ed35..26eba048b30 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -101,7 +101,7 @@ void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { net::URLRequestContextGetter* BrowserContext::CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors) { + content::URLRequestInterceptorScopedVector protocol_interceptors) { DCHECK(!url_request_getter_); url_request_getter_ = new URLRequestContextGetter( this, @@ -120,7 +120,7 @@ net::NetworkDelegate* BrowserContext::CreateNetworkDelegate() { net::URLRequestJobFactory* BrowserContext::CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector* protocol_interceptors) { + content::URLRequestInterceptorScopedVector* protocol_interceptors) { return NULL; } @@ -158,36 +158,6 @@ net::URLRequestContextGetter* return GetRequestContext(); } -void BrowserContext::RequestMidiSysExPermission( - int render_process_id, - int render_view_id, - int bridge_id, - const GURL& requesting_frame, - bool user_gesture, - const MidiSysExPermissionCallback& callback) { - callback.Run(false); -} - -void BrowserContext::CancelMidiSysExPermissionRequest( - int render_process_id, - int render_view_id, - int bridge_id, - const GURL& requesting_frame) { -} - -void BrowserContext::RequestProtectedMediaIdentifierPermission( - int render_process_id, - int render_view_id, - int bridge_id, - int group_id, - const GURL& requesting_frame, - const ProtectedMediaIdentifierPermissionCallback& callback) { - callback.Run(false); -} - -void BrowserContext::CancelProtectedMediaIdentifierPermissionRequests(int group_id) { -} - content::ResourceContext* BrowserContext::GetResourceContext() { return resource_context_.get(); } @@ -198,17 +168,16 @@ content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() { return download_manager_delegate_.get(); } -content::GeolocationPermissionContext* - BrowserContext::GetGeolocationPermissionContext() { - return nullptr; +content::BrowserPluginGuestManager* BrowserContext::GetGuestManager() { + return NULL; } quota::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() { - return nullptr; + return NULL; } -content::BrowserPluginGuestManagerDelegate* BrowserContext::GetGuestManagerDelegate() { - return nullptr; +content::PushMessagingService* BrowserContext::GetPushMessagingService() { + return NULL; } } // namespace brightray diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 6bd2a1b81d9..8ed7bc1a3c0 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -26,7 +26,7 @@ class BrowserContext : public content::BrowserContext, net::URLRequestContextGetter* CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors); + content::URLRequestInterceptorScopedVector protocol_interceptors); net::URLRequestContextGetter* url_request_context_getter() const { return url_request_getter_.get(); @@ -42,7 +42,7 @@ class BrowserContext : public content::BrowserContext, virtual net::NetworkDelegate* CreateNetworkDelegate() OVERRIDE; virtual net::URLRequestJobFactory* CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector* protocol_interceptors) OVERRIDE; + content::URLRequestInterceptorScopedVector* protocol_interceptors) OVERRIDE; virtual base::FilePath GetPath() const OVERRIDE; @@ -61,35 +61,11 @@ class BrowserContext : public content::BrowserContext, virtual net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory); - virtual void RequestMidiSysExPermission( - int render_process_id, - int render_view_id, - int bridge_id, - const GURL& requesting_frame, - bool user_gesture, - const MidiSysExPermissionCallback& callback) OVERRIDE; - virtual void CancelMidiSysExPermissionRequest( - int render_process_id, - int render_view_id, - int bridge_id, - const GURL& requesting_frame) OVERRIDE; - virtual void RequestProtectedMediaIdentifierPermission( - int render_process_id, - int render_view_id, - int bridge_id, - int group_id, - const GURL& requesting_frame, - const ProtectedMediaIdentifierPermissionCallback& callback) OVERRIDE; - virtual void CancelProtectedMediaIdentifierPermissionRequests(int group_id) OVERRIDE; virtual content::ResourceContext* GetResourceContext() OVERRIDE; - virtual content::DownloadManagerDelegate* - GetDownloadManagerDelegate() OVERRIDE; - virtual content::GeolocationPermissionContext* - GetGeolocationPermissionContext() OVERRIDE; - virtual content::BrowserPluginGuestManagerDelegate* - GetGuestManagerDelegate() OVERRIDE; - virtual quota::SpecialStoragePolicy* - GetSpecialStoragePolicy() OVERRIDE; + virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; + virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE; + virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; + virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE; base::FilePath path_; scoped_ptr resource_context_; diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_delegate.cc index ded349dce67..d6ef0144711 100644 --- a/brightray/browser/devtools_delegate.cc +++ b/brightray/browser/devtools_delegate.cc @@ -68,6 +68,7 @@ class Target : public content::DevToolsTarget { explicit Target(WebContents* web_contents); virtual std::string GetId() const OVERRIDE { return id_; } + virtual std::string GetParentId() const { return std::string(); } virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } virtual std::string GetTitle() const OVERRIDE { return title_; } virtual std::string GetDescription() const OVERRIDE { return std::string(); } @@ -134,8 +135,8 @@ DevToolsDelegate::DevToolsDelegate( content::BrowserContext* browser_context) : browser_context_(browser_context) { std::string frontend_url; - devtools_http_handler_ = - DevToolsHttpHandler::Start(CreateSocketFactory(), frontend_url, this); + devtools_http_handler_ = DevToolsHttpHandler::Start( + CreateSocketFactory(), frontend_url, this, base::FilePath()); } DevToolsDelegate::~DevToolsDelegate() { diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 4938b355db9..c512d2eb2e9 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -156,8 +156,7 @@ void InspectableWebContentsImpl::ShowDevTools() { embedder_message_dispatcher_.reset( new DevToolsEmbedderMessageDispatcher(this)); - auto create_params = content::WebContents::CreateParams( - web_contents_->GetBrowserContext()); + content::WebContents::CreateParams create_params(web_contents_->GetBrowserContext()); devtools_web_contents_.reset(content::WebContents::Create(create_params)); Observe(devtools_web_contents_.get()); diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index da57591ed95..a366c7918d0 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -15,7 +15,6 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/cookie_store_factory.h" #include "content/public/common/content_switches.h" -#include "content/public/common/url_constants.h" #include "net/base/host_mapping_rules.h" #include "net/cert/cert_verifier.h" #include "net/cookies/cookie_monster.h" @@ -33,11 +32,12 @@ #include "net/ssl/ssl_config_service_defaults.h" #include "net/url_request/data_protocol_handler.h" #include "net/url_request/file_protocol_handler.h" -#include "net/url_request/protocol_intercept_job_factory.h" #include "net/url_request/static_http_user_agent_settings.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_storage.h" +#include "net/url_request/url_request_intercepting_job_factory.h" #include "net/url_request/url_request_job_factory_impl.h" +#include "url/url_constants.h" #include "webkit/browser/quota/special_storage_policy.h" using content::BrowserThread; @@ -75,24 +75,24 @@ const char kProxyServer[] = "proxy-server"; net::URLRequestJobFactory* URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector* protocol_interceptors) { + content::URLRequestInterceptorScopedVector* protocol_interceptors) { scoped_ptr job_factory(new net::URLRequestJobFactoryImpl); for (auto it = protocol_handlers->begin(); it != protocol_handlers->end(); ++it) job_factory->SetProtocolHandler(it->first, it->second.release()); protocol_handlers->clear(); - job_factory->SetProtocolHandler(content::kDataScheme, new net::DataProtocolHandler); - job_factory->SetProtocolHandler(content::kFileScheme, new net::FileProtocolHandler( + job_factory->SetProtocolHandler(url::kDataScheme, new net::DataProtocolHandler); + job_factory->SetProtocolHandler(url::kFileScheme, new net::FileProtocolHandler( BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); // Set up interceptors in the reverse order. scoped_ptr top_job_factory = job_factory.PassAs(); - for (content::ProtocolHandlerScopedVector::reverse_iterator i = protocol_interceptors->rbegin(); + for (content::URLRequestInterceptorScopedVector::reverse_iterator i = protocol_interceptors->rbegin(); i != protocol_interceptors->rend(); ++i) - top_job_factory.reset(new net::ProtocolInterceptJobFactory( + top_job_factory.reset(new net::URLRequestInterceptingJobFactory( top_job_factory.Pass(), make_scoped_ptr(*i))); protocol_interceptors->weak_clear(); @@ -105,7 +105,7 @@ URLRequestContextGetter::URLRequestContextGetter( base::MessageLoop* io_loop, base::MessageLoop* file_loop, content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors) + content::URLRequestInterceptorScopedVector protocol_interceptors) : delegate_(delegate), base_path_(base_path), io_loop_(io_loop), diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index c7379f2248a..970d4b8458a 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -35,7 +35,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; } virtual net::URLRequestJobFactory* CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector* protocol_interceptors); + content::URLRequestInterceptorScopedVector* protocol_interceptors); }; URLRequestContextGetter( @@ -44,7 +44,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { base::MessageLoop* io_loop, base::MessageLoop* file_loop, content::ProtocolHandlerMap* protocol_handlers, - content::ProtocolHandlerScopedVector protocol_interceptors); + content::URLRequestInterceptorScopedVector protocol_interceptors); virtual ~URLRequestContextGetter(); // net::URLRequestContextGetter: @@ -66,7 +66,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr url_request_context_; scoped_ptr host_mapping_rules_; content::ProtocolHandlerMap protocol_handlers_; - content::ProtocolHandlerScopedVector protocol_interceptors_; + content::URLRequestInterceptorScopedVector protocol_interceptors_; DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter); }; diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index e810414e0d2..5a5e1d9ff3e 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -138,7 +138,6 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { params.delegate = new DevToolsWindowDelegate(this, devtools_window_web_view_, devtools_window_.get()); - params.top_level = true; params.bounds = inspectable_web_contents()->GetDevToolsBounds(); #if defined(USE_X11) // In X11 the window frame is drawn by the application. From 6010539914b3eb055f633678786f57b729378a82 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 31 Aug 2014 19:57:15 +0800 Subject: [PATCH 0405/1195] Don't create empty url request job factory. --- brightray/browser/browser_context.cc | 6 ------ brightray/browser/browser_context.h | 3 --- 2 files changed, 9 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 26eba048b30..d539ccbcced 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -118,12 +118,6 @@ net::NetworkDelegate* BrowserContext::CreateNetworkDelegate() { return new NetworkDelegate; } -net::URLRequestJobFactory* BrowserContext::CreateURLRequestJobFactory( - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector* protocol_interceptors) { - return NULL; -} - base::FilePath BrowserContext::GetPath() const { return path_; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 8ed7bc1a3c0..9dfd03d9e2d 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -40,9 +40,6 @@ class BrowserContext : public content::BrowserContext, // URLRequestContextGetter::Delegate: virtual net::NetworkDelegate* CreateNetworkDelegate() OVERRIDE; - virtual net::URLRequestJobFactory* CreateURLRequestJobFactory( - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector* protocol_interceptors) OVERRIDE; virtual base::FilePath GetPath() const OVERRIDE; From f8c8c415ebaf65619e92128f96aedc72df26896e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 31 Aug 2014 20:04:48 +0800 Subject: [PATCH 0406/1195] Fix cpplint warnings. --- brightray/browser/url_request_context_getter.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index a366c7918d0..167228beca5 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -90,8 +90,8 @@ net::URLRequestJobFactory* URLRequestContextGetter::Delegate::CreateURLRequestJo // Set up interceptors in the reverse order. scoped_ptr top_job_factory = job_factory.PassAs(); - for (content::URLRequestInterceptorScopedVector::reverse_iterator i = protocol_interceptors->rbegin(); - i != protocol_interceptors->rend(); ++i) + content::URLRequestInterceptorScopedVector::reverse_iterator i; + for (i = protocol_interceptors->rbegin(); i != protocol_interceptors->rend(); ++i) top_job_factory.reset(new net::URLRequestInterceptingJobFactory( top_job_factory.Pass(), make_scoped_ptr(*i))); protocol_interceptors->weak_clear(); From 410708936377097310d8ae2e9a228618cf095e4b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 1 Sep 2014 19:15:07 +0800 Subject: [PATCH 0407/1195] Use new devtools resizing strategy from Chrome 37. --- .../devtools_contents_resizing_strategy.cc | 62 +++++-------------- .../devtools_contents_resizing_strategy.h | 20 ++---- .../devtools_embedder_message_dispatcher.cc | 31 +++------- .../devtools_embedder_message_dispatcher.h | 4 +- .../browser/inspectable_web_contents_impl.cc | 5 +- .../browser/inspectable_web_contents_impl.h | 3 +- 6 files changed, 35 insertions(+), 90 deletions(-) diff --git a/brightray/browser/devtools_contents_resizing_strategy.cc b/brightray/browser/devtools_contents_resizing_strategy.cc index 15d7a5253f1..30ee028669e 100644 --- a/brightray/browser/devtools_contents_resizing_strategy.cc +++ b/brightray/browser/devtools_contents_resizing_strategy.cc @@ -6,80 +6,48 @@ #include -DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() { -} - -DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( - const gfx::Insets& insets, const gfx::Size& min_size) - : insets_(insets), - min_size_(min_size) { +DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy() + : hide_inspected_contents_(false) { } DevToolsContentsResizingStrategy::DevToolsContentsResizingStrategy( const gfx::Rect& bounds) - : bounds_(bounds) { + : bounds_(bounds), + hide_inspected_contents_(bounds_.IsEmpty() && !bounds_.x() && + !bounds_.y()) { } void DevToolsContentsResizingStrategy::CopyFrom( const DevToolsContentsResizingStrategy& strategy) { - insets_ = strategy.insets(); - min_size_ = strategy.min_size(); bounds_ = strategy.bounds(); + hide_inspected_contents_ = strategy.hide_inspected_contents(); } bool DevToolsContentsResizingStrategy::Equals( const DevToolsContentsResizingStrategy& strategy) { - return insets_ == strategy.insets() && min_size_ == strategy.min_size() && - bounds_ == strategy.bounds(); + return bounds_ == strategy.bounds() && + hide_inspected_contents_ == strategy.hide_inspected_contents(); } void ApplyDevToolsContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy, const gfx::Size& container_size, - const gfx::Rect& old_devtools_bounds, - const gfx::Rect& old_contents_bounds, gfx::Rect* new_devtools_bounds, gfx::Rect* new_contents_bounds) { new_devtools_bounds->SetRect( 0, 0, container_size.width(), container_size.height()); - const gfx::Insets& insets = strategy.insets(); - const gfx::Size& min_size = strategy.min_size(); const gfx::Rect& bounds = strategy.bounds(); - - if (!bounds.size().IsEmpty()) { - int left = std::min(bounds.x(), container_size.width()); - int top = std::min(bounds.y(), container_size.height()); - int width = std::min(bounds.width(), container_size.width() - left); - int height = std::min(bounds.height(), container_size.height() - top); - new_contents_bounds->SetRect(left, top, width, height); + if (bounds.size().IsEmpty() && !strategy.hide_inspected_contents()) { + new_contents_bounds->SetRect( + 0, 0, container_size.width(), container_size.height()); return; } - int width = std::max(0, container_size.width() - insets.width()); - int left = insets.left(); - if (width < min_size.width() && insets.width() > 0) { - int min_width = std::min(min_size.width(), container_size.width()); - int insets_width = container_size.width() - min_width; - int insets_decrease = insets.width() - insets_width; - // Decrease both left and right insets proportionally. - left -= insets_decrease * insets.left() / insets.width(); - width = min_width; - } - left = std::max(0, std::min(container_size.width(), left)); - - int height = std::max(0, container_size.height() - insets.height()); - int top = insets.top(); - if (height < min_size.height() && insets.height() > 0) { - int min_height = std::min(min_size.height(), container_size.height()); - int insets_height = container_size.height() - min_height; - int insets_decrease = insets.height() - insets_height; - // Decrease both top and bottom insets proportionally. - top -= insets_decrease * insets.top() / insets.height(); - height = min_height; - } - top = std::max(0, std::min(container_size.height(), top)); - + int left = std::min(bounds.x(), container_size.width()); + int top = std::min(bounds.y(), container_size.height()); + int width = std::min(bounds.width(), container_size.width() - left); + int height = std::min(bounds.height(), container_size.height() - top); new_contents_bounds->SetRect(left, top, width, height); } diff --git a/brightray/browser/devtools_contents_resizing_strategy.h b/brightray/browser/devtools_contents_resizing_strategy.h index 86ea260c71a..806d78a7156 100644 --- a/brightray/browser/devtools_contents_resizing_strategy.h +++ b/brightray/browser/devtools_contents_resizing_strategy.h @@ -15,28 +15,22 @@ class DevToolsContentsResizingStrategy { public: DevToolsContentsResizingStrategy(); - DevToolsContentsResizingStrategy( - const gfx::Insets& insets, - const gfx::Size& min_size); - explicit DevToolsContentsResizingStrategy(const gfx::Rect& bounds); + explicit DevToolsContentsResizingStrategy( + const gfx::Rect& bounds); void CopyFrom(const DevToolsContentsResizingStrategy& strategy); bool Equals(const DevToolsContentsResizingStrategy& strategy); - const gfx::Insets& insets() const { return insets_; } - const gfx::Size& min_size() const { return min_size_; } const gfx::Rect& bounds() const { return bounds_; } + bool hide_inspected_contents() const { return hide_inspected_contents_; } private: - // Insets of contents inside DevTools. - gfx::Insets insets_; - - // Minimum size of contents. - gfx::Size min_size_; - // Contents bounds. When non-empty, used instead of insets. gfx::Rect bounds_; + // Determines whether inspected contents is visible. + bool hide_inspected_contents_; + DISALLOW_COPY_AND_ASSIGN(DevToolsContentsResizingStrategy); }; @@ -48,8 +42,6 @@ class DevToolsContentsResizingStrategy { void ApplyDevToolsContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy, const gfx::Size& container_size, - const gfx::Rect& old_devtools_bounds, - const gfx::Rect& old_contents_bounds, gfx::Rect* new_devtools_bounds, gfx::Rect* new_contents_bounds); diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index c4e87fcf7e6..bb64846320b 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -23,33 +23,20 @@ bool GetValue(const base::ListValue& list, int pos, bool& value) { return list.GetBoolean(pos, &value); } -bool GetValue(const base::ListValue& list, int pos, gfx::Insets& insets) { - const base::DictionaryValue* dict; - if (!list.GetDictionary(pos, &dict)) - return false; - int top = 0; - int left = 0; - int bottom = 0; - int right = 0; - if (!dict->GetInteger("top", &top) || - !dict->GetInteger("left", &left) || - !dict->GetInteger("bottom", &bottom) || - !dict->GetInteger("right", &right)) - return false; - insets.Set(top, left, bottom, right); - return true; -} - -bool GetValue(const base::ListValue& list, int pos, gfx::Size& size) { +bool GetValue(const base::ListValue& list, int pos, gfx::Rect& rect) { const base::DictionaryValue* dict; if (!list.GetDictionary(pos, &dict)) return false; + int x = 0; + int y = 0; int width = 0; int height = 0; - if (!dict->GetInteger("width", &width) || + if (!dict->GetInteger("x", &x) || + !dict->GetInteger("y", &y) || + !dict->GetInteger("width", &width) || !dict->GetInteger("height", &height)) return false; - size.SetSize(width, height); + rect.SetRect(x, y, width, height); return true; } @@ -191,8 +178,8 @@ DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher( RegisterHandler("closeWindow", BindToListParser(base::Bind(&Delegate::CloseWindow, base::Unretained(delegate)))); - RegisterHandler("setContentsResizingStrategy", - BindToListParser(base::Bind(&Delegate::SetContentsResizingStrategy, + RegisterHandler("setInspectedPageBounds", + BindToListParser(base::Bind(&Delegate::SetInspectedPageBounds, base::Unretained(delegate)))); RegisterHandler("inspectElementCompleted", BindToListParser(base::Bind(&Delegate::InspectElementCompleted, diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index 0448f86aa16..1b0bf9e3a02 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -10,6 +10,7 @@ #include "base/callback.h" #include "ui/gfx/insets.h" +#include "ui/gfx/rect.h" #include "ui/gfx/size.h" namespace base { @@ -32,8 +33,7 @@ class DevToolsEmbedderMessageDispatcher { virtual void ActivateWindow() = 0; virtual void CloseWindow() = 0; - virtual void SetContentsResizingStrategy( - const gfx::Insets& insets, const gfx::Size& min_size) = 0; + virtual void SetInspectedPageBounds(const gfx::Rect& rect) = 0; virtual void InspectElementCompleted() = 0; virtual void MoveWindow(int x, int y) = 0; virtual void SetIsDocked(bool docked) = 0; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c512d2eb2e9..94b1069ebfa 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -212,9 +212,8 @@ void InspectableWebContentsImpl::CloseWindow() { devtools_web_contents()->DispatchBeforeUnload(false); } -void InspectableWebContentsImpl::SetContentsResizingStrategy( - const gfx::Insets& insets, const gfx::Size& min_size) { - DevToolsContentsResizingStrategy strategy(insets, min_size); +void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { + DevToolsContentsResizingStrategy strategy(rect); if (contents_resizing_strategy_.Equals(strategy)) return; diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 8bbf70273b2..bae3cf865f1 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -64,8 +64,7 @@ class InspectableWebContentsImpl : virtual void ActivateWindow() OVERRIDE; virtual void CloseWindow() OVERRIDE; - virtual void SetContentsResizingStrategy( - const gfx::Insets& insets, const gfx::Size& min_size) OVERRIDE; + virtual void SetInspectedPageBounds(const gfx::Rect& rect) OVERRIDE; virtual void InspectElementCompleted() OVERRIDE; virtual void MoveWindow(int x, int y) OVERRIDE; virtual void SetIsDocked(bool docked) OVERRIDE; From 2a8691d98133adc8df2c6dd359f571f7276bc1a4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 1 Sep 2014 19:18:12 +0800 Subject: [PATCH 0408/1195] mac: Use new devtools resizing strategy. --- .../mac/bry_inspectable_web_contents_view.h | 3 --- .../mac/bry_inspectable_web_contents_view.mm | 19 +------------------ 2 files changed, 1 insertion(+), 21 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 977d6fdd939..8cf7540b60f 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -28,7 +28,4 @@ using brightray::InspectableWebContentsViewMac; - (void)setIsDocked:(BOOL)docked; - (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy; -// Adjust docked devtools to the contents resizing strategy. -- (void)update; - @end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index a0e44633810..0fa06f2077d 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -54,13 +54,12 @@ using namespace brightray; // Place the devToolsView under contentsView, notice that we didn't set // sizes for them until the setContentsResizingStrategy message. [self addSubview:devToolsView positioned:NSWindowBelow relativeTo:nil]; - [self update]; + [self adjustSubviews]; // Focus on web view. devToolsWebContents->RestoreFocus(); } else { gfx::ScopedNSDisableScreenUpdates disabler; - devToolsWebContents->RemoveOverlayView(); [devToolsView removeFromSuperview]; [self adjustSubviews]; } @@ -115,20 +114,6 @@ using namespace brightray; - (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy { strategy_.CopyFrom(strategy); - [self update]; -} - -- (void)update { - if (!devtools_docked_) - return; - - auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); - auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); - - gfx::ScopedNSDisableScreenUpdates disabler; - devToolsWebContents->SetOverlayView( - contents, - gfx::Point(strategy_.insets().left(), strategy_.insets().top())); [self adjustSubviews]; } @@ -152,8 +137,6 @@ using namespace brightray; gfx::Rect new_contents_bounds; ApplyDevToolsContentsResizingStrategy( strategy_, gfx::Size(NSSizeToCGSize([self bounds].size)), - [self flipNSRectToRect:[devToolsView bounds]], - [self flipNSRectToRect:[contentsView bounds]], &new_devtools_bounds, &new_contents_bounds); [devToolsView setFrame:[self flipRectToNSRect:new_devtools_bounds]]; [contentsView setFrame:[self flipRectToNSRect:new_contents_bounds]]; From f013a98920a267fbb4262ed07b8c51119ffd2884 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 1 Sep 2014 20:08:31 +0800 Subject: [PATCH 0409/1195] views: Use new devtools resizing strategy. --- brightray/browser/views/inspectable_web_contents_view_views.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 5a5e1d9ff3e..d76e8efafa0 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -162,12 +162,9 @@ void InspectableWebContentsViewViews::Layout() { } gfx::Size container_size(width(), height()); - gfx::Rect old_devtools_bounds(devtools_web_view_->bounds()); - gfx::Rect old_contents_bounds(contents_web_view_->bounds()); gfx::Rect new_devtools_bounds; gfx::Rect new_contents_bounds; ApplyDevToolsContentsResizingStrategy(strategy_, container_size, - old_devtools_bounds, old_contents_bounds, &new_devtools_bounds, &new_contents_bounds); // DevTools cares about the specific position, so we have to compensate RTL From a6627a7286671e5870732ec740885ccb5193f3e4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Sep 2014 15:28:48 +0800 Subject: [PATCH 0410/1195] Add a method in InspectableWebContentDelegate to set icon for devtools window. --- brightray/brightray.gyp | 1 + brightray/browser/inspectable_web_contents.h | 1 + brightray/browser/inspectable_web_contents_delegate.cc | 9 +++++++++ brightray/browser/inspectable_web_contents_delegate.h | 5 +++++ brightray/browser/inspectable_web_contents_impl.h | 3 +++ .../browser/views/inspectable_web_contents_view_views.cc | 9 +++++++++ 6 files changed, 28 insertions(+) create mode 100644 brightray/browser/inspectable_web_contents_delegate.cc diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index a30281b1fdc..8f2488feecc 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -52,6 +52,7 @@ 'browser/download_manager_delegate.h', 'browser/inspectable_web_contents.cc', 'browser/inspectable_web_contents.h', + 'browser/inspectable_web_contents_delegate.cc', 'browser/inspectable_web_contents_delegate.h', 'browser/inspectable_web_contents_impl.cc', 'browser/inspectable_web_contents_impl.h', diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 313e4ebea2c..ea0fc8f13b3 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -29,6 +29,7 @@ class InspectableWebContents { // The delegate manages its own life. virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0; + virtual InspectableWebContentsDelegate* GetDelegate() const = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_delegate.cc b/brightray/browser/inspectable_web_contents_delegate.cc new file mode 100644 index 00000000000..81d395b5db3 --- /dev/null +++ b/brightray/browser/inspectable_web_contents_delegate.cc @@ -0,0 +1,9 @@ +#include "browser/inspectable_web_contents_delegate.h" + +namespace brightray { + +gfx::ImageSkia InspectableWebContentsDelegate::GetDevToolsWindowIcon() { + return gfx::ImageSkia(); +} + +} // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index a6dc5e1c78f..9b9cfa427ec 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -3,12 +3,17 @@ #include +#include "ui/gfx/image/image_skia.h" + namespace brightray { class InspectableWebContentsDelegate { public: virtual ~InspectableWebContentsDelegate() {} + // Returns the icon of devtools window. + virtual gfx::ImageSkia GetDevToolsWindowIcon(); + // Requested by WebContents of devtools. virtual void DevToolsSaveToFile( const std::string& url, const std::string& content, bool save_as) {} diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index bae3cf865f1..4caf9cdac6b 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -54,6 +54,9 @@ class InspectableWebContentsImpl : virtual void SetDelegate(InspectableWebContentsDelegate* delegate) { delegate_ = delegate; } + virtual InspectableWebContentsDelegate* GetDelegate() const { + return delegate_; + } content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index d76e8efafa0..e83c6888daf 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -1,5 +1,6 @@ #include "browser/views/inspectable_web_contents_view_views.h" +#include "browser/inspectable_web_contents_delegate.h" #include "browser/inspectable_web_contents_impl.h" #include "base/strings/utf_string_conversions.h" @@ -25,6 +26,10 @@ class DevToolsWindowDelegate : public views::ClientView, title_(base::ASCIIToUTF16("Developer Tools")) { // A WidgetDelegate should be deleted on DeleteDelegate. set_owned_by_client(); + + InspectableWebContentsDelegate* delegate = shell->inspectable_web_contents()->GetDelegate(); + if (delegate) + icon_ = delegate->GetDevToolsWindowIcon(); } virtual ~DevToolsWindowDelegate() {} @@ -34,6 +39,8 @@ class DevToolsWindowDelegate : public views::ClientView, virtual bool CanResize() const OVERRIDE { return true; } virtual bool CanMaximize() const OVERRIDE { return false; } virtual base::string16 GetWindowTitle() const OVERRIDE { return title_; } + virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE { return GetWindowIcon(); } + virtual gfx::ImageSkia GetWindowIcon() OVERRIDE { return icon_; } virtual views::Widget* GetWidget() OVERRIDE { return widget_; } virtual const views::Widget* GetWidget() const OVERRIDE { return widget_; } virtual views::View* GetContentsView() OVERRIDE { return view_; } @@ -50,6 +57,7 @@ class DevToolsWindowDelegate : public views::ClientView, views::View* view_; views::Widget* widget_; base::string16 title_; + gfx::ImageSkia icon_; DISALLOW_COPY_AND_ASSIGN(DevToolsWindowDelegate); }; @@ -144,6 +152,7 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { params.remove_standard_frame = true; #endif devtools_window_->Init(params); + devtools_window_->UpdateWindowIcon(); } ShowDevTools(); From c58bf15345bf990a739c96ec44efbcc19190f2fb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Sep 2014 17:54:37 +0800 Subject: [PATCH 0411/1195] mac: Send focus/blur event to devtools web contents. --- .../mac/bry_inspectable_web_contents_view.mm | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 0fa06f2077d..4db0d8ac050 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -148,4 +148,30 @@ using namespace brightray; inspectableWebContentsView_->inspectable_web_contents()->CloseDevTools(); } +- (void)windowDidBecomeMain:(NSNotification*)notification { + content::WebContents* web_contents = + inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + if (!web_contents) + return; + + web_contents->RestoreFocus(); + + content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); + if (rwhv) + rwhv->SetActive(true); +} + +- (void)windowDidResignMain:(NSNotification*)notification { + content::WebContents* web_contents = + inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + if (!web_contents) + return; + + web_contents->StoreFocus(); + + content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); + if (rwhv) + rwhv->SetActive(false); +} + @end From 30025fe6efa40c661fd0eb011cf4b3f3c26992cc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Sep 2014 18:28:02 +0800 Subject: [PATCH 0412/1195] Set toolbar color for devtools. --- brightray/browser/inspectable_web_contents_impl.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 94b1069ebfa..2cb8aba6def 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -36,7 +36,9 @@ const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0, const char kDevToolsScheme[] = "chrome-devtools"; const char kDevToolsHost[] = "devtools"; const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?" - "can_dock=true&&" + "can_dock=true&" + "toolbarColor=rgba(223,223,223,1)&" + "textColor=rgba(0,0,0,1)&" "experiments=true"; const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; From ea28f518d35694283ae3519375d6afbbabaf3acf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 1 Oct 2014 11:07:29 +0800 Subject: [PATCH 0413/1195] Add handling of user media requests --- .../media/media_stream_devices_controller.cc | 49 +++++++++++++++++++ .../media/media_stream_devices_controller.h | 3 ++ 2 files changed, 52 insertions(+) diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index 2b7510939dd..fc867f075b5 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -6,6 +6,7 @@ #include "browser/media/media_capture_devices_dispatcher.h" +#include "content/public/browser/desktop_media_id.h" #include "content/public/common/media_stream_request.h" namespace brightray { @@ -47,6 +48,15 @@ MediaStreamDevicesController::~MediaStreamDevicesController() { } bool MediaStreamDevicesController::TakeAction() { + // Do special handling of desktop screen cast. + if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || + request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE || + request_.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE || + request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { + HandleUserMediaRequest(); + return true; + } + // Deny the request if there is no device attached to the OS. if (!HasAnyAvailableDevice()) { Deny(); @@ -147,4 +157,43 @@ void MediaStreamDevicesController::Deny() { scoped_ptr()); } +void MediaStreamDevicesController::HandleUserMediaRequest() { + content::MediaStreamDevices devices; + + if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE) { + devices.push_back(content::MediaStreamDevice( + content::MEDIA_TAB_AUDIO_CAPTURE, "", "")); + } + if (request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE) { + devices.push_back(content::MediaStreamDevice( + content::MEDIA_TAB_VIDEO_CAPTURE, "", "")); + } + if (request_.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE) { + devices.push_back(content::MediaStreamDevice( + content::MEDIA_LOOPBACK_AUDIO_CAPTURE, "loopback", "System Audio")); + } + if (request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { + content::DesktopMediaID screen_id; + // If the device id wasn't specified then this is a screen capture request + // (i.e. chooseDesktopMedia() API wasn't used to generate device id). + if (request_.requested_video_device_id.empty()) { + screen_id = content::DesktopMediaID(content::DesktopMediaID::TYPE_SCREEN, + -1 /* kFullDesktopScreenId */); + } else { + screen_id = + content::DesktopMediaID::Parse(request_.requested_video_device_id); + } + + devices.push_back( + content::MediaStreamDevice(content::MEDIA_DESKTOP_VIDEO_CAPTURE, + screen_id.ToString(), "Screen")); + } + + callback_.Run( + devices, + devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE : + content::MEDIA_DEVICE_OK, + scoped_ptr()); +} + } // namespace brightray diff --git a/brightray/browser/media/media_stream_devices_controller.h b/brightray/browser/media/media_stream_devices_controller.h index 9100fa4e27e..e77af477027 100644 --- a/brightray/browser/media/media_stream_devices_controller.h +++ b/brightray/browser/media/media_stream_devices_controller.h @@ -26,6 +26,9 @@ class MediaStreamDevicesController { void Deny(); private: + // Handle the request of desktop or tab screen cast. + void HandleUserMediaRequest(); + // The original request for access to devices. const content::MediaStreamRequest request_; From 09678cc4857b644c0c5659950dbe3c64b9344a68 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 1 Oct 2014 15:18:34 +0800 Subject: [PATCH 0414/1195] Clean the callback after executed --- .../browser/media/media_capture_devices_dispatcher.cc | 1 - .../browser/media/media_stream_devices_controller.cc | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index 65ea4b94be9..e38770024de 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -159,7 +159,6 @@ void MediaCaptureDevicesDispatcher::OnAudioStreamStopped( void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( int render_process_id, int render_view_id) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); } } // namespace brightray diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index fc867f075b5..b55e73844f9 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -189,11 +189,12 @@ void MediaStreamDevicesController::HandleUserMediaRequest() { screen_id.ToString(), "Screen")); } - callback_.Run( - devices, - devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE : - content::MEDIA_DEVICE_OK, - scoped_ptr()); + content::MediaResponseCallback cb = callback_; + callback_.Reset(); + cb.Run(devices, + devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE : + content::MEDIA_DEVICE_OK, + scoped_ptr()); } } // namespace brightray From f7819f369beb8150fb908051f78963d8258ab9bf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Oct 2014 11:11:05 +0800 Subject: [PATCH 0415/1195] Don't warn about deprecated-register --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 8f2488feecc..3a0aa4f0c57 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -97,6 +97,7 @@ 'conditions': [ ['OS=="linux"', { 'cflags_cc': [ + '-Wno-deprecated-declarations', '-fno-rtti', ], 'link_settings': { From 5c455b6ff901d764450bd45feaa8b8eb7513c7b2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 8 Oct 2014 01:34:01 +0000 Subject: [PATCH 0416/1195] Fix compilation warning on Linux --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 3a0aa4f0c57..c00db1514f4 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -97,7 +97,7 @@ 'conditions': [ ['OS=="linux"', { 'cflags_cc': [ - '-Wno-deprecated-declarations', + '-Wno-deprecated-register', '-fno-rtti', ], 'link_settings': { From 5bec155c812aff461bf3690c48b37c969b03b79e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 11 Oct 2014 16:38:27 +0800 Subject: [PATCH 0417/1195] Adapt to API changes of Chrome 38 --- brightray/browser/browser_client.cc | 4 +- brightray/browser/browser_client.h | 6 +-- brightray/browser/browser_context.cc | 4 ++ brightray/browser/browser_context.h | 1 + brightray/browser/devtools_delegate.cc | 27 +++++------- .../browser/inspectable_web_contents_impl.cc | 41 ++++++++++--------- .../browser/inspectable_web_contents_impl.h | 31 +++++++------- .../media/media_capture_devices_dispatcher.cc | 3 +- .../media/media_capture_devices_dispatcher.h | 4 +- brightray/browser/notification_presenter.h | 3 +- .../browser/notification_presenter_mac.h | 4 +- .../browser/notification_presenter_mac.mm | 10 +++-- .../browser/url_request_context_getter.cc | 12 +++--- 13 files changed, 77 insertions(+), 73 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index c306bfc26c7..a7e2f3f73f8 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -69,11 +69,11 @@ net::URLRequestContextGetter* BrowserClient::CreateRequestContext( void BrowserClient::ShowDesktopNotification( const content::ShowDesktopNotificationHostMsgParams& params, content::RenderFrameHost* render_frame_host, - content::DesktopNotificationDelegate* delegate, + scoped_ptr delegate, base::Closure* cancel_callback) { auto presenter = notification_presenter(); if (presenter) - presenter->ShowNotification(params, delegate, cancel_callback); + presenter->ShowNotification(params, delegate.Pass(), cancel_callback); } content::MediaObserver* BrowserClient::GetMediaObserver() { diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 565ff18cc9c..ca06b739a38 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -42,10 +42,10 @@ class BrowserClient : public content::ContentBrowserClient { virtual content::BrowserMainParts* CreateBrowserMainParts( const content::MainFunctionParams&) OVERRIDE; virtual void ShowDesktopNotification( - const content::ShowDesktopNotificationHostMsgParams&, + const content::ShowDesktopNotificationHostMsgParams& params, content::RenderFrameHost* render_frame_host, - content::DesktopNotificationDelegate* delegate, - base::Closure* cancel_callback) OVERRIDE; + scoped_ptr delegate, + base::Closure* cancel_callback) override; virtual content::MediaObserver* GetMediaObserver() OVERRIDE; virtual void GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) OVERRIDE; diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index d539ccbcced..8d5a926c194 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -174,4 +174,8 @@ content::PushMessagingService* BrowserContext::GetPushMessagingService() { return NULL; } +content::SSLHostStateDelegate* BrowserContext::GetSSLHostStateDelegate() { + return nullptr; +} + } // namespace brightray diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 9dfd03d9e2d..6b477d104ff 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -63,6 +63,7 @@ class BrowserContext : public content::BrowserContext, virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE; virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE; + virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; base::FilePath path_; scoped_ptr resource_context_; diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_delegate.cc index d6ef0144711..e46973505bb 100644 --- a/brightray/browser/devtools_delegate.cc +++ b/brightray/browser/devtools_delegate.cc @@ -96,8 +96,7 @@ class Target : public content::DevToolsTarget { }; Target::Target(WebContents* web_contents) { - agent_host_ = - DevToolsAgentHost::GetOrCreateFor(web_contents->GetRenderViewHost()); + agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); id_ = agent_host_->GetId(); title_ = base::UTF16ToUTF8(web_contents->GetTitle()); url_ = web_contents->GetURL(); @@ -109,10 +108,7 @@ Target::Target(WebContents* web_contents) { } bool Target::Activate() const { - RenderViewHost* rvh = agent_host_->GetRenderViewHost(); - if (!rvh) - return false; - WebContents* web_contents = WebContents::FromRenderViewHost(rvh); + WebContents* web_contents = agent_host_->GetWebContents(); if (!web_contents) return false; web_contents->GetDelegate()->ActivateContents(web_contents); @@ -120,10 +116,10 @@ bool Target::Activate() const { } bool Target::Close() const { - RenderViewHost* rvh = agent_host_->GetRenderViewHost(); - if (!rvh) + WebContents* web_contents = agent_host_->GetWebContents(); + if (!web_contents) return false; - rvh->ClosePage(); + web_contents->GetRenderViewHost()->ClosePage(); return true; } @@ -176,13 +172,12 @@ DevToolsDelegate::CreateNewTarget(const GURL& url) { void DevToolsDelegate::EnumerateTargets(TargetCallback callback) { TargetList targets; - std::vector rvh_list = - content::DevToolsAgentHost::GetValidRenderViewHosts(); - for (std::vector::iterator it = rvh_list.begin(); - it != rvh_list.end(); ++it) { - WebContents* web_contents = WebContents::FromRenderViewHost(*it); - if (web_contents) - targets.push_back(new Target(web_contents)); + std::vector wc_list = + content::DevToolsAgentHost::GetInspectableWebContents(); + for (std::vector::iterator it = wc_list.begin(); + it != wc_list.end(); + ++it) { + targets.push_back(new Target(*it)); } callback.Run(targets); } diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 2cb8aba6def..c195c63dd42 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -164,13 +164,9 @@ void InspectableWebContentsImpl::ShowDevTools() { Observe(devtools_web_contents_.get()); devtools_web_contents_->SetDelegate(this); - agent_host_ = content::DevToolsAgentHost::GetOrCreateFor( - web_contents_->GetRenderViewHost()); - frontend_host_.reset( - content::DevToolsClientHost::CreateDevToolsFrontendHost( - devtools_web_contents_.get(), this)); + agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()); content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( - agent_host_, frontend_host_.get()); + agent_host_, this); GURL devtools_url(kChromeUIDevToolsURL); devtools_web_contents_->GetController().LoadURL( @@ -291,8 +287,7 @@ void InspectableWebContentsImpl::ResetZoom() { SetZoomLevelForWebContents(devtools_web_contents(), 0.); } -void InspectableWebContentsImpl::DispatchOnEmbedder( - const std::string& message) { +void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::string& message) { std::string method; base::ListValue params; int id; @@ -309,31 +304,37 @@ void InspectableWebContentsImpl::DispatchOnEmbedder( } } +void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontendToBackend( + const std::string& message) { + content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend( + this, message); +} + +void InspectableWebContentsImpl::DispatchOnInspectorFrontend( + const std::string& message) { + std::string code = "InspectorFrontendAPI.dispatchMessage(" + message + ");"; + base::string16 javascript = base::UTF8ToUTF16(code); + web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); +} + void InspectableWebContentsImpl::InspectedContentsClosing() { } -void InspectableWebContentsImpl::AboutToNavigateRenderView( - content::RenderViewHost* render_view_host) { - content::DevToolsClientHost::SetupDevToolsFrontendClient( - web_contents()->GetRenderViewHost()); +void InspectableWebContentsImpl::ReplacedWithAnotherClient() { } -void InspectableWebContentsImpl::DidFinishLoad(int64 frame_id, - const GURL& validated_url, - bool is_main_frame, - content::RenderViewHost*) { - if (!is_main_frame) +void InspectableWebContentsImpl::DidFinishLoad(content::RenderFrameHost* render_frame_host, + const GURL& validated_url) { + if (render_frame_host->GetParent()) return; view_->ShowDevTools(); } void InspectableWebContentsImpl::WebContentsDestroyed() { - content::DevToolsManager::GetInstance()->ClientHostClosing( - frontend_host_.get()); + content::DevToolsManager::GetInstance()->ClientHostClosing(this); Observe(nullptr); agent_host_ = nullptr; - frontend_host_.reset(); } bool InspectableWebContentsImpl::AddMessageToConsole( diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 4caf9cdac6b..f0f40e87227 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -11,7 +11,8 @@ #include "browser/devtools_contents_resizing_strategy.h" #include "browser/devtools_embedder_message_dispatcher.h" -#include "content/public/browser/devtools_frontend_host_delegate.h" +#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" #include "ui/gfx/rect.h" @@ -20,7 +21,6 @@ class PrefRegistrySimple; namespace content { class DevToolsAgentHost; -class DevToolsClientHost; } namespace brightray { @@ -30,10 +30,11 @@ class InspectableWebContentsView; class InspectableWebContentsImpl : public InspectableWebContents, - content::DevToolsFrontendHostDelegate, - content::WebContentsObserver, - content::WebContentsDelegate, - DevToolsEmbedderMessageDispatcher::Delegate { + public content::DevToolsFrontendHost::Delegate, + public content::DevToolsClientHost, + public content::WebContentsObserver, + public content::WebContentsDelegate, + public DevToolsEmbedderMessageDispatcher::Delegate { public: static void RegisterPrefs(PrefRegistrySimple* pref_registry); @@ -92,19 +93,19 @@ class InspectableWebContentsImpl : virtual void ZoomOut() OVERRIDE; virtual void ResetZoom() OVERRIDE; - // content::DevToolsFrontendHostDelegate + // content::DevToolsClientHost: + virtual void DispatchOnInspectorFrontend(const std::string& message) override; + virtual void InspectedContentsClosing() override; + virtual void ReplacedWithAnotherClient() override; - virtual void DispatchOnEmbedder(const std::string& message) OVERRIDE; - virtual void InspectedContentsClosing() OVERRIDE; + // content::DevToolsFrontendHostDelegate: + virtual void HandleMessageFromDevToolsFrontend(const std::string& message) override; + virtual void HandleMessageFromDevToolsFrontendToBackend(const std::string& message) override; // content::WebContentsObserver - virtual void AboutToNavigateRenderView( - content::RenderViewHost* render_view_host) OVERRIDE; - virtual void DidFinishLoad(int64 frame_id, - const GURL& validated_url, - bool is_main_frame, - content::RenderViewHost*) OVERRIDE; + virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, + const GURL& validated_url) OVERRIDE; virtual void WebContentsDestroyed() OVERRIDE; // content::WebContentsDelegate diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index e38770024de..ddf1948a18e 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -138,9 +138,8 @@ void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( int render_view_id, int page_request_id, const GURL& security_origin, - const content::MediaStreamDevice& device, + content::MediaStreamType stream_type, content::MediaRequestState state) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); } void MediaCaptureDevicesDispatcher::OnAudioStreamPlaying( diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index 3b29fae4701..b38a6b8a371 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -58,8 +58,8 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { int render_view_id, int page_request_id, const GURL& security_origin, - const content::MediaStreamDevice& device, - content::MediaRequestState state) OVERRIDE; + content::MediaStreamType stream_type, + content::MediaRequestState state) override; virtual void OnAudioStreamPlaying( int render_process_id, int render_frame_id, diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index 23420fb9cf5..6c7def322ae 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -2,6 +2,7 @@ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_ #include "base/callback_forward.h" +#include "base/memory/scoped_ptr.h" namespace content { class DesktopNotificationDelegate; @@ -18,7 +19,7 @@ class NotificationPresenter { virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams&, - content::DesktopNotificationDelegate* delegate, + scoped_ptr delegate, base::Closure* cancel_callback) = 0; }; diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index 9c7a3a3c276..508ad315f01 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -22,8 +22,8 @@ class NotificationPresenterMac : public NotificationPresenter { virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams&, - content::DesktopNotificationDelegate* delegate, - base::Closure* cancel_callback) OVERRIDE; + scoped_ptr delegate, + base::Closure* cancel_callback) override; // Get the delegate accroding from the notification object. content::DesktopNotificationDelegate* GetDelegateFromNotification( diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 2bb595ed55c..78e3cc2fd45 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -41,20 +41,20 @@ NotificationPresenterMac::~NotificationPresenterMac() { void NotificationPresenterMac::ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, - content::DesktopNotificationDelegate* delegate, + scoped_ptr delegate, base::Closure* cancel_callback) { auto notification = [[NSUserNotification alloc] init]; notification.title = base::SysUTF16ToNSString(params.title); notification.informativeText = base::SysUTF16ToNSString(params.body); - notifications_map_[delegate].reset(notification); + notifications_map_[delegate.get()].reset(notification); [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; if (cancel_callback) *cancel_callback = base::Bind( &NotificationPresenterMac::CancelNotification, base::Unretained(this), - delegate); + delegate.release()); } content::DesktopNotificationDelegate* NotificationPresenterMac::GetDelegateFromNotification( @@ -67,8 +67,10 @@ content::DesktopNotificationDelegate* NotificationPresenterMac::GetDelegateFromN } void NotificationPresenterMac::RemoveNotification(content::DesktopNotificationDelegate* delegate) { - if (ContainsKey(notifications_map_, delegate)) + if (ContainsKey(notifications_map_, delegate)) { + delete delegate; notifications_map_.erase(delegate); + } } void NotificationPresenterMac::CancelNotification(content::DesktopNotificationDelegate* delegate) { diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 167228beca5..7010aa464a4 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -27,8 +27,8 @@ #include "net/proxy/proxy_script_fetcher_impl.h" #include "net/proxy/proxy_service.h" #include "net/proxy/proxy_service_v8.h" -#include "net/ssl/default_server_bound_cert_store.h" -#include "net/ssl/server_bound_cert_service.h" +#include "net/ssl/channel_id_service.h" +#include "net/ssl/default_channel_id_store.h" #include "net/ssl/ssl_config_service_defaults.h" #include "net/url_request/data_protocol_handler.h" #include "net/url_request/file_protocol_handler.h" @@ -145,8 +145,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, NULL, NULL); storage_->set_cookie_store(content::CreateCookieStore(cookie_config)); - storage_->set_server_bound_cert_service(new net::ServerBoundCertService( - new net::DefaultServerBoundCertStore(NULL), + storage_->set_channel_id_service(new net::ChannelIDService( + new net::DefaultChannelIDStore(NULL), base::WorkerPool::GetTaskRunner(true))); storage_->set_http_user_agent_settings(new net::StaticHttpUserAgentSettings( "en-us,en", base::EmptyString())); @@ -197,8 +197,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.ignore_certificate_errors = false; network_session_params.transport_security_state = url_request_context_->transport_security_state(); - network_session_params.server_bound_cert_service = - url_request_context_->server_bound_cert_service(); + network_session_params.channel_id_service = + url_request_context_->channel_id_service(); network_session_params.http_auth_handler_factory = url_request_context_->http_auth_handler_factory(); From 733931c7adc99760421dd8fb38958e3da80c57fe Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 11 Oct 2014 19:00:30 +0800 Subject: [PATCH 0418/1195] Fix loading devtools --- brightray/browser/inspectable_web_contents_impl.cc | 11 +++++++++-- brightray/browser/inspectable_web_contents_impl.h | 6 +++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c195c63dd42..b2af61d8f10 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -165,8 +165,9 @@ void InspectableWebContentsImpl::ShowDevTools() { devtools_web_contents_->SetDelegate(this); agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()); - content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( - agent_host_, this); + frontend_host_.reset(content::DevToolsFrontendHost::Create( + web_contents_->GetRenderViewHost(), this)); + content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, this); GURL devtools_url(kChromeUIDevToolsURL); devtools_web_contents_->GetController().LoadURL( @@ -323,6 +324,12 @@ void InspectableWebContentsImpl::InspectedContentsClosing() { void InspectableWebContentsImpl::ReplacedWithAnotherClient() { } +void InspectableWebContentsImpl::AboutToNavigateRenderView( + content::RenderViewHost* render_view_host) { + frontend_host_.reset(content::DevToolsFrontendHost::Create( + render_view_host, this)); +} + void InspectableWebContentsImpl::DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url) { if (render_frame_host->GetParent()) diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index f0f40e87227..1e4ad995e44 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -102,8 +102,8 @@ class InspectableWebContentsImpl : virtual void HandleMessageFromDevToolsFrontend(const std::string& message) override; virtual void HandleMessageFromDevToolsFrontendToBackend(const std::string& message) override; - // content::WebContentsObserver - + // content::WebContentsObserver: + virtual void AboutToNavigateRenderView(content::RenderViewHost* render_view_host) override; virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url) OVERRIDE; virtual void WebContentsDestroyed() OVERRIDE; @@ -120,10 +120,10 @@ class InspectableWebContentsImpl : virtual void CloseContents(content::WebContents* source) OVERRIDE; scoped_ptr web_contents_; - scoped_ptr frontend_host_; scoped_ptr devtools_web_contents_; scoped_ptr view_; scoped_refptr agent_host_; + scoped_ptr frontend_host_; DevToolsContentsResizingStrategy contents_resizing_strategy_; gfx::Rect devtools_bounds_; From 9e12036823a2aa1c0992a0ecd829e8cbecdbe2b9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 11 Oct 2014 19:03:53 +0800 Subject: [PATCH 0419/1195] Upgrade to Chrome 38 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 887f3b7895c..f9abe65eddd 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 887f3b7895c55625d20d7ea06fa041dcacdb8b47 +Subproject commit f9abe65eddd9f233e215151c7487ac19af2a60d9 From 6d62b0960e5d0b07adadf4a3c2b70c86f54a2bd6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 13 Oct 2014 11:02:56 +0800 Subject: [PATCH 0420/1195] Fix building on Linux --- brightray/browser/linux/notification_presenter_linux.cc | 6 ++++-- brightray/browser/linux/notification_presenter_linux.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index f7347998092..c31e3d01e9f 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -52,13 +52,15 @@ NotificationPresenterLinux::~NotificationPresenterLinux() { void NotificationPresenterLinux::ShowNotification( const content::ShowDesktopNotificationHostMsgParams& params, - content::DesktopNotificationDelegate* delegate, + scoped_ptr delegate_ptr, base::Closure* cancel_callback) { std::string title = base::UTF16ToUTF8(params.title); std::string body = base::UTF16ToUTF8(params.body); NotifyNotification* notification = notify_notification_new(title.c_str(), body.c_str(), nullptr); - g_object_set_data(G_OBJECT(notification), "delegate", delegate); + content::DesktopNotificationDelegate* delegate = delegate_ptr.release(); + + g_object_set_data_full(G_OBJECT(notification), "delegate", delegate, operator delete); g_signal_connect(notification, "closed", G_CALLBACK(OnNotificationClosedThunk), this); notify_notification_add_action(notification, "default", "View", OnNotificationViewThunk, this, nullptr); diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index 07e628e29a4..b42e4eb3dbe 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -27,7 +27,7 @@ class NotificationPresenterLinux : public NotificationPresenter { // NotificationPresenter: virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams&, - content::DesktopNotificationDelegate* delegate, + scoped_ptr delegate, base::Closure* cancel_callback) OVERRIDE; void CancelNotification(NotifyNotification* notification); From f809fef22dffce0a5958e2c1c09565e7fe568422 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 23 Oct 2014 11:10:39 +0800 Subject: [PATCH 0421/1195] OVERRIDE => override --- brightray/browser/browser_client.h | 10 ++-- brightray/browser/browser_context.cc | 8 +-- brightray/browser/browser_context.h | 22 +++---- brightray/browser/browser_main_parts.h | 12 ++-- .../browser/default_web_contents_delegate.h | 4 +- brightray/browser/devtools_delegate.cc | 22 +++---- brightray/browser/devtools_delegate.h | 14 ++--- brightray/browser/devtools_ui.cc | 8 +-- .../browser/inspectable_web_contents_impl.h | 58 +++++++++---------- .../inspectable_web_contents_view_mac.h | 12 ++-- .../linux/notification_presenter_linux.h | 2 +- .../media/media_capture_devices_dispatcher.h | 10 ++-- brightray/browser/network_delegate.h | 32 +++++----- .../browser/url_request_context_getter.h | 4 +- .../inspectable_web_contents_view_views.cc | 22 +++---- .../inspectable_web_contents_view_views.h | 16 ++--- brightray/browser/views/views_delegate.h | 28 ++++----- brightray/browser/web_ui_controller_factory.h | 8 +-- brightray/common/content_client.h | 8 +-- brightray/common/main_delegate.h | 6 +- 20 files changed, 153 insertions(+), 153 deletions(-) diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index ca06b739a38..965692e5ff8 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -36,20 +36,20 @@ class BrowserClient : public content::ContentBrowserClient { virtual net::URLRequestContextGetter* CreateRequestContext( content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector protocol_interceptors) OVERRIDE; + content::URLRequestInterceptorScopedVector protocol_interceptors) override; private: virtual content::BrowserMainParts* CreateBrowserMainParts( - const content::MainFunctionParams&) OVERRIDE; + const content::MainFunctionParams&) override; virtual void ShowDesktopNotification( const content::ShowDesktopNotificationHostMsgParams& params, content::RenderFrameHost* render_frame_host, scoped_ptr delegate, base::Closure* cancel_callback) override; - virtual content::MediaObserver* GetMediaObserver() OVERRIDE; + virtual content::MediaObserver* GetMediaObserver() override; virtual void GetAdditionalAllowedSchemesForFileSystem( - std::vector* additional_schemes) OVERRIDE; - virtual base::FilePath GetDefaultDownloadDirectory() OVERRIDE; + std::vector* additional_schemes) override; + virtual base::FilePath GetDefaultDownloadDirectory() override; BrowserMainParts* browser_main_parts_; scoped_ptr notification_presenter_; diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 8d5a926c194..89285f1cb22 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -37,23 +37,23 @@ class BrowserContext::ResourceContext : public content::ResourceContext { } private: - virtual net::HostResolver* GetHostResolver() OVERRIDE { + virtual net::HostResolver* GetHostResolver() override { return getter_->host_resolver(); } - virtual net::URLRequestContext* GetRequestContext() OVERRIDE { + virtual net::URLRequestContext* GetRequestContext() override { return getter_->GetURLRequestContext(); } // FIXME: We should probably allow clients to override this to implement more // restrictive policies. - virtual bool AllowMicAccess(const GURL& origin) OVERRIDE { + virtual bool AllowMicAccess(const GURL& origin) override { return true; } // FIXME: We should probably allow clients to override this to implement more // restrictive policies. - virtual bool AllowCameraAccess(const GURL& origin) OVERRIDE { + virtual bool AllowCameraAccess(const GURL& origin) override { return true; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 6b477d104ff..d2de8b30d89 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -39,30 +39,30 @@ class BrowserContext : public content::BrowserContext, virtual void RegisterPrefs(PrefRegistrySimple* pref_registry) {} // URLRequestContextGetter::Delegate: - virtual net::NetworkDelegate* CreateNetworkDelegate() OVERRIDE; + virtual net::NetworkDelegate* CreateNetworkDelegate() override; - virtual base::FilePath GetPath() const OVERRIDE; + virtual base::FilePath GetPath() const override; private: class ResourceContext; void RegisterInternalPrefs(PrefRegistrySimple* pref_registry); - virtual bool IsOffTheRecord() const OVERRIDE; - virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; + virtual bool IsOffTheRecord() const override; + virtual net::URLRequestContextGetter* GetRequestContext() override; virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( int renderer_child_id); - virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE; + virtual net::URLRequestContextGetter* GetMediaRequestContext() override; virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( - int renderer_child_id) OVERRIDE; + int renderer_child_id) override; virtual net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory); - virtual content::ResourceContext* GetResourceContext() OVERRIDE; - virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() OVERRIDE; - virtual content::BrowserPluginGuestManager* GetGuestManager() OVERRIDE; - virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; - virtual content::PushMessagingService* GetPushMessagingService() OVERRIDE; + virtual content::ResourceContext* GetResourceContext() override; + virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; + virtual content::BrowserPluginGuestManager* GetGuestManager() override; + virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() override; + virtual content::PushMessagingService* GetPushMessagingService() override; virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; base::FilePath path_; diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 16cf9165e18..a959b228f51 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -36,12 +36,12 @@ class BrowserMainParts : public content::BrowserMainParts { protected: // content::BrowserMainParts: - virtual void PreEarlyInitialization() OVERRIDE; - virtual void ToolkitInitialized() OVERRIDE; - virtual void PreMainMessageLoopStart() OVERRIDE; - virtual void PreMainMessageLoopRun() OVERRIDE; - virtual void PostMainMessageLoopRun() OVERRIDE; - virtual int PreCreateThreads() OVERRIDE; + virtual void PreEarlyInitialization() override; + virtual void ToolkitInitialized() override; + virtual void PreMainMessageLoopStart() override; + virtual void PreMainMessageLoopRun() override; + virtual void PostMainMessageLoopRun() override; + virtual int PreCreateThreads() override; // Subclasses should override this to provide their own BrowserContxt // implementation. The caller takes ownership of the returned object. diff --git a/brightray/browser/default_web_contents_delegate.h b/brightray/browser/default_web_contents_delegate.h index 5b16b10f653..e4d177c4af8 100644 --- a/brightray/browser/default_web_contents_delegate.h +++ b/brightray/browser/default_web_contents_delegate.h @@ -16,10 +16,10 @@ class DefaultWebContentsDelegate : public content::WebContentsDelegate { virtual void RequestMediaAccessPermission( content::WebContents*, const content::MediaStreamRequest&, - const content::MediaResponseCallback&) OVERRIDE; + const content::MediaResponseCallback&) override; #if defined(OS_MACOSX) virtual void HandleKeyboardEvent( - content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; + content::WebContents*, const content::NativeWebKeyboardEvent&) override; #endif }; diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_delegate.cc index e46973505bb..a706520cb2e 100644 --- a/brightray/browser/devtools_delegate.cc +++ b/brightray/browser/devtools_delegate.cc @@ -67,24 +67,24 @@ class Target : public content::DevToolsTarget { public: explicit Target(WebContents* web_contents); - virtual std::string GetId() const OVERRIDE { return id_; } + virtual std::string GetId() const override { return id_; } virtual std::string GetParentId() const { return std::string(); } - virtual std::string GetType() const OVERRIDE { return kTargetTypePage; } - virtual std::string GetTitle() const OVERRIDE { return title_; } - virtual std::string GetDescription() const OVERRIDE { return std::string(); } - virtual GURL GetURL() const OVERRIDE { return url_; } - virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } - virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { + virtual std::string GetType() const override { return kTargetTypePage; } + virtual std::string GetTitle() const override { return title_; } + virtual std::string GetDescription() const override { return std::string(); } + virtual GURL GetURL() const override { return url_; } + virtual GURL GetFaviconURL() const override { return favicon_url_; } + virtual base::TimeTicks GetLastActivityTime() const override { return last_activity_time_; } - virtual bool IsAttached() const OVERRIDE { + virtual bool IsAttached() const override { return agent_host_->IsAttached(); } - virtual scoped_refptr GetAgentHost() const OVERRIDE { + virtual scoped_refptr GetAgentHost() const override { return agent_host_; } - virtual bool Activate() const OVERRIDE; - virtual bool Close() const OVERRIDE; + virtual bool Activate() const override; + virtual bool Close() const override; private: scoped_refptr agent_host_; diff --git a/brightray/browser/devtools_delegate.h b/brightray/browser/devtools_delegate.h index b75aeff0461..85b156dd71b 100644 --- a/brightray/browser/devtools_delegate.h +++ b/brightray/browser/devtools_delegate.h @@ -27,16 +27,16 @@ class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { void Stop(); // DevToolsHttpProtocolHandler::Delegate overrides. - virtual std::string GetDiscoveryPageHTML() OVERRIDE; - virtual bool BundlesFrontendResources() OVERRIDE; - virtual base::FilePath GetDebugFrontendDir() OVERRIDE; - virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE; + virtual std::string GetDiscoveryPageHTML() override; + virtual bool BundlesFrontendResources() override; + virtual base::FilePath GetDebugFrontendDir() override; + virtual std::string GetPageThumbnailData(const GURL& url) override; virtual scoped_ptr CreateNewTarget( - const GURL& url) OVERRIDE; - virtual void EnumerateTargets(TargetCallback callback) OVERRIDE; + const GURL& url) override; + virtual void EnumerateTargets(TargetCallback callback) override; virtual scoped_ptr CreateSocketForTethering( net::StreamListenSocket::Delegate* delegate, - std::string* name) OVERRIDE; + std::string* name) override; content::DevToolsHttpHandler* devtools_http_handler() { return devtools_http_handler_; diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index def3ecb4694..43fe2a50e04 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -55,14 +55,14 @@ class BundledDataSource : public content::URLDataSource { } // content::URLDataSource implementation. - virtual std::string GetSource() const OVERRIDE { + virtual std::string GetSource() const override { return kChromeUIDevToolsBundledHost; } virtual void StartDataRequest(const std::string& path, int render_process_id, int render_view_id, - const GotDataCallback& callback) OVERRIDE { + const GotDataCallback& callback) override { std::string filename = PathWithoutParams(path); int resource_id = @@ -77,11 +77,11 @@ class BundledDataSource : public content::URLDataSource { callback.Run(bytes); } - virtual std::string GetMimeType(const std::string& path) const OVERRIDE { + virtual std::string GetMimeType(const std::string& path) const override { return GetMimeTypeForPath(path); } - virtual bool ShouldAddContentSecurityPolicy() const OVERRIDE { + virtual bool ShouldAddContentSecurityPolicy() const override { return false; } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 1e4ad995e44..bc2e8bcfd28 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -41,12 +41,12 @@ class InspectableWebContentsImpl : explicit InspectableWebContentsImpl(content::WebContents*); virtual ~InspectableWebContentsImpl(); - virtual InspectableWebContentsView* GetView() const OVERRIDE; - virtual content::WebContents* GetWebContents() const OVERRIDE; + virtual InspectableWebContentsView* GetView() const override; + virtual content::WebContents* GetWebContents() const override; - virtual void ShowDevTools() OVERRIDE; - virtual void CloseDevTools() OVERRIDE; - virtual bool IsDevToolsViewShowing() OVERRIDE; + virtual void ShowDevTools() override; + virtual void CloseDevTools() override; + virtual bool IsDevToolsViewShowing() override; // Return the last position and size of devtools window. gfx::Rect GetDevToolsBounds() const; @@ -66,32 +66,32 @@ class InspectableWebContentsImpl : private: // DevToolsEmbedderMessageDispacher::Delegate - virtual void ActivateWindow() OVERRIDE; - virtual void CloseWindow() OVERRIDE; - virtual void SetInspectedPageBounds(const gfx::Rect& rect) OVERRIDE; - virtual void InspectElementCompleted() OVERRIDE; - virtual void MoveWindow(int x, int y) OVERRIDE; - virtual void SetIsDocked(bool docked) OVERRIDE; - virtual void OpenInNewTab(const std::string& url) OVERRIDE; + virtual void ActivateWindow() override; + virtual void CloseWindow() override; + virtual void SetInspectedPageBounds(const gfx::Rect& rect) override; + virtual void InspectElementCompleted() override; + virtual void MoveWindow(int x, int y) override; + virtual void SetIsDocked(bool docked) override; + virtual void OpenInNewTab(const std::string& url) override; virtual void SaveToFile(const std::string& url, const std::string& content, - bool save_as) OVERRIDE; + bool save_as) override; virtual void AppendToFile(const std::string& url, - const std::string& content) OVERRIDE; - virtual void RequestFileSystems() OVERRIDE; - virtual void AddFileSystem() OVERRIDE; - virtual void RemoveFileSystem(const std::string& file_system_path) OVERRIDE; + const std::string& content) override; + virtual void RequestFileSystems() override; + virtual void AddFileSystem() override; + virtual void RemoveFileSystem(const std::string& file_system_path) override; virtual void UpgradeDraggedFileSystemPermissions( - const std::string& file_system_url) OVERRIDE; + const std::string& file_system_url) override; virtual void IndexPath(int request_id, - const std::string& file_system_path) OVERRIDE; - virtual void StopIndexing(int request_id) OVERRIDE; + const std::string& file_system_path) override; + virtual void StopIndexing(int request_id) override; virtual void SearchInPath(int request_id, const std::string& file_system_path, - const std::string& query) OVERRIDE; - virtual void ZoomIn() OVERRIDE; - virtual void ZoomOut() OVERRIDE; - virtual void ResetZoom() OVERRIDE; + const std::string& query) override; + virtual void ZoomIn() override; + virtual void ZoomOut() override; + virtual void ResetZoom() override; // content::DevToolsClientHost: virtual void DispatchOnInspectorFrontend(const std::string& message) override; @@ -105,8 +105,8 @@ class InspectableWebContentsImpl : // content::WebContentsObserver: virtual void AboutToNavigateRenderView(content::RenderViewHost* render_view_host) override; virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, - const GURL& validated_url) OVERRIDE; - virtual void WebContentsDestroyed() OVERRIDE; + const GURL& validated_url) override; + virtual void WebContentsDestroyed() override; // content::WebContentsDelegate @@ -114,10 +114,10 @@ class InspectableWebContentsImpl : int32 level, const base::string16& message, int32 line_no, - const base::string16& source_id) OVERRIDE; + const base::string16& source_id) override; virtual void HandleKeyboardEvent( - content::WebContents*, const content::NativeWebKeyboardEvent&) OVERRIDE; - virtual void CloseContents(content::WebContents* source) OVERRIDE; + content::WebContents*, const content::NativeWebKeyboardEvent&) override; + virtual void CloseContents(content::WebContents* source) override; scoped_ptr web_contents_; scoped_ptr devtools_web_contents_; diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 29a55bdd088..6a81d642c8d 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -17,13 +17,13 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView { InspectableWebContentsImpl* inspectable_web_contents_impl); virtual ~InspectableWebContentsViewMac(); - virtual gfx::NativeView GetNativeView() const OVERRIDE; - virtual void ShowDevTools() OVERRIDE; - virtual void CloseDevTools() OVERRIDE; - virtual bool IsDevToolsViewShowing() OVERRIDE; - virtual void SetIsDocked(bool docked) OVERRIDE; + virtual gfx::NativeView GetNativeView() const override; + virtual void ShowDevTools() override; + virtual void CloseDevTools() override; + virtual bool IsDevToolsViewShowing() override; + virtual void SetIsDocked(bool docked) override; virtual void SetContentsResizingStrategy( - const DevToolsContentsResizingStrategy& strategy) OVERRIDE; + const DevToolsContentsResizingStrategy& strategy) override; InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index b42e4eb3dbe..6701d399c41 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -28,7 +28,7 @@ class NotificationPresenterLinux : public NotificationPresenter { virtual void ShowNotification( const content::ShowDesktopNotificationHostMsgParams&, scoped_ptr delegate, - base::Closure* cancel_callback) OVERRIDE; + base::Closure* cancel_callback) override; void CancelNotification(NotifyNotification* notification); void DeleteNotification(NotifyNotification* notification); diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index b38a6b8a371..fb2e7a1c372 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -51,8 +51,8 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { void DisableDeviceEnumerationForTesting(); // Overridden from content::MediaObserver: - virtual void OnAudioCaptureDevicesChanged() OVERRIDE; - virtual void OnVideoCaptureDevicesChanged() OVERRIDE; + virtual void OnAudioCaptureDevicesChanged() override; + virtual void OnVideoCaptureDevicesChanged() override; virtual void OnMediaRequestStateChanged( int render_process_id, int render_view_id, @@ -64,13 +64,13 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { int render_process_id, int render_frame_id, int stream_id, - const ReadPowerAndClipCallback& power_read_callback) OVERRIDE; + const ReadPowerAndClipCallback& power_read_callback) override; virtual void OnAudioStreamStopped( int render_process_id, int render_frame_id, - int stream_id) OVERRIDE; + int stream_id) override; virtual void OnCreatingAudioStream(int render_process_id, - int render_view_id) OVERRIDE; + int render_view_id) override; private: friend struct DefaultSingletonTraits; diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 94be71d9852..2279b3c9815 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -17,44 +17,44 @@ class NetworkDelegate : public net::NetworkDelegate { protected: virtual int OnBeforeURLRequest(net::URLRequest* request, const net::CompletionCallback& callback, - GURL* new_url) OVERRIDE; + GURL* new_url) override; virtual int OnBeforeSendHeaders(net::URLRequest* request, const net::CompletionCallback& callback, - net::HttpRequestHeaders* headers) OVERRIDE; + net::HttpRequestHeaders* headers) override; virtual void OnSendHeaders(net::URLRequest* request, - const net::HttpRequestHeaders& headers) OVERRIDE; + const net::HttpRequestHeaders& headers) override; virtual int OnHeadersReceived( net::URLRequest* request, const net::CompletionCallback& callback, const net::HttpResponseHeaders* original_response_headers, scoped_refptr* override_response_headers, - GURL* allowed_unsafe_redirect_url) OVERRIDE; + GURL* allowed_unsafe_redirect_url) override; virtual void OnBeforeRedirect(net::URLRequest* request, - const GURL& new_location) OVERRIDE; - virtual void OnResponseStarted(net::URLRequest* request) OVERRIDE; + const GURL& new_location) override; + virtual void OnResponseStarted(net::URLRequest* request) override; virtual void OnRawBytesRead(const net::URLRequest& request, - int bytes_read) OVERRIDE; - virtual void OnCompleted(net::URLRequest* request, bool started) OVERRIDE; - virtual void OnURLRequestDestroyed(net::URLRequest* request) OVERRIDE; + int bytes_read) override; + virtual void OnCompleted(net::URLRequest* request, bool started) override; + virtual void OnURLRequestDestroyed(net::URLRequest* request) override; virtual void OnPACScriptError(int line_number, - const base::string16& error) OVERRIDE; + const base::string16& error) override; virtual AuthRequiredResponse OnAuthRequired( net::URLRequest* request, const net::AuthChallengeInfo& auth_info, const AuthCallback& callback, - net::AuthCredentials* credentials) OVERRIDE; + net::AuthCredentials* credentials) override; virtual bool OnCanGetCookies(const net::URLRequest& request, - const net::CookieList& cookie_list) OVERRIDE; + const net::CookieList& cookie_list) override; virtual bool OnCanSetCookie(const net::URLRequest& request, const std::string& cookie_line, - net::CookieOptions* options) OVERRIDE; + net::CookieOptions* options) override; virtual bool OnCanAccessFile(const net::URLRequest& request, - const base::FilePath& path) const OVERRIDE; + const base::FilePath& path) const override; virtual bool OnCanThrottleRequest( - const net::URLRequest& request) const OVERRIDE; + const net::URLRequest& request) const override; virtual int OnBeforeSocketStreamConnect( net::SocketStream* stream, - const net::CompletionCallback& callback) OVERRIDE; + const net::CompletionCallback& callback) override; private: DISALLOW_COPY_AND_ASSIGN(NetworkDelegate); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 970d4b8458a..05588c20ee5 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -48,8 +48,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual ~URLRequestContextGetter(); // net::URLRequestContextGetter: - virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; - virtual scoped_refptr GetNetworkTaskRunner() const OVERRIDE; + virtual net::URLRequestContext* GetURLRequestContext() override; + virtual scoped_refptr GetNetworkTaskRunner() const override; net::HostResolver* host_resolver(); diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index e83c6888daf..57296344ab3 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -34,20 +34,20 @@ class DevToolsWindowDelegate : public views::ClientView, virtual ~DevToolsWindowDelegate() {} // views::WidgetDelegate: - virtual void DeleteDelegate() OVERRIDE { delete this; } - virtual views::View* GetInitiallyFocusedView() OVERRIDE { return view_; } - virtual bool CanResize() const OVERRIDE { return true; } - virtual bool CanMaximize() const OVERRIDE { return false; } - virtual base::string16 GetWindowTitle() const OVERRIDE { return title_; } - virtual gfx::ImageSkia GetWindowAppIcon() OVERRIDE { return GetWindowIcon(); } - virtual gfx::ImageSkia GetWindowIcon() OVERRIDE { return icon_; } - virtual views::Widget* GetWidget() OVERRIDE { return widget_; } - virtual const views::Widget* GetWidget() const OVERRIDE { return widget_; } - virtual views::View* GetContentsView() OVERRIDE { return view_; } + virtual void DeleteDelegate() override { delete this; } + virtual views::View* GetInitiallyFocusedView() override { return view_; } + virtual bool CanResize() const override { return true; } + virtual bool CanMaximize() const override { return false; } + virtual base::string16 GetWindowTitle() const override { return title_; } + virtual gfx::ImageSkia GetWindowAppIcon() override { return GetWindowIcon(); } + virtual gfx::ImageSkia GetWindowIcon() override { return icon_; } + virtual views::Widget* GetWidget() override { return widget_; } + virtual const views::Widget* GetWidget() const override { return widget_; } + virtual views::View* GetContentsView() override { return view_; } virtual views::ClientView* CreateClientView(views::Widget* widget) { return this; } // views::ClientView: - virtual bool CanClose() OVERRIDE { + virtual bool CanClose() override { shell_->inspectable_web_contents()->CloseDevTools(); return false; } diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index 4875980a389..80934755692 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -24,14 +24,14 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, ~InspectableWebContentsViewViews(); // InspectableWebContentsView: - virtual views::View* GetView() OVERRIDE; - virtual views::View* GetWebView() OVERRIDE; - virtual void ShowDevTools() OVERRIDE; - virtual void CloseDevTools() OVERRIDE; - virtual bool IsDevToolsViewShowing() OVERRIDE; - virtual void SetIsDocked(bool docked) OVERRIDE; + virtual views::View* GetView() override; + virtual views::View* GetWebView() override; + virtual void ShowDevTools() override; + virtual void CloseDevTools() override; + virtual bool IsDevToolsViewShowing() override; + virtual void SetIsDocked(bool docked) override; virtual void SetContentsResizingStrategy( - const DevToolsContentsResizingStrategy& strategy) OVERRIDE; + const DevToolsContentsResizingStrategy& strategy) override; InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; @@ -39,7 +39,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, private: // views::View: - virtual void Layout() OVERRIDE; + virtual void Layout() override; // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; diff --git a/brightray/browser/views/views_delegate.h b/brightray/browser/views/views_delegate.h index 7cd26ef794b..27d64207281 100644 --- a/brightray/browser/views/views_delegate.h +++ b/brightray/browser/views/views_delegate.h @@ -20,38 +20,38 @@ class ViewsDelegate : public views::ViewsDelegate { virtual void SaveWindowPlacement(const views::Widget* window, const std::string& window_name, const gfx::Rect& bounds, - ui::WindowShowState show_state) OVERRIDE; + ui::WindowShowState show_state) override; virtual bool GetSavedWindowPlacement( const views::Widget* widget, const std::string& window_name, gfx::Rect* bounds, - ui::WindowShowState* show_state) const OVERRIDE; + ui::WindowShowState* show_state) const override; virtual void NotifyAccessibilityEvent( - views::View* view, ui::AXEvent event_type) OVERRIDE; + views::View* view, ui::AXEvent event_type) override; virtual void NotifyMenuItemFocused(const base::string16& menu_name, const base::string16& menu_item_name, int item_index, int item_count, - bool has_submenu) OVERRIDE; + bool has_submenu) override; #if defined(OS_WIN) - virtual HICON GetDefaultWindowIcon() const OVERRIDE; - virtual bool IsWindowInMetro(gfx::NativeWindow window) const OVERRIDE; + virtual HICON GetDefaultWindowIcon() const override; + virtual bool IsWindowInMetro(gfx::NativeWindow window) const override; #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) - virtual gfx::ImageSkia* GetDefaultWindowIcon() const OVERRIDE; + virtual gfx::ImageSkia* GetDefaultWindowIcon() const override; #endif virtual views::NonClientFrameView* CreateDefaultNonClientFrameView( - views::Widget* widget) OVERRIDE; - virtual void AddRef() OVERRIDE; - virtual void ReleaseRef() OVERRIDE; + views::Widget* widget) override; + virtual void AddRef() override; + virtual void ReleaseRef() override; virtual content::WebContents* CreateWebContents( content::BrowserContext* browser_context, - content::SiteInstance* site_instance) OVERRIDE; + content::SiteInstance* site_instance) override; virtual void OnBeforeWidgetInit( views::Widget::InitParams* params, - views::internal::NativeWidgetDelegate* delegate) OVERRIDE; - virtual base::TimeDelta GetDefaultTextfieldObscuredRevealDuration() OVERRIDE; - virtual bool WindowManagerProvidesTitleBar(bool maximized) OVERRIDE; + views::internal::NativeWidgetDelegate* delegate) override; + virtual base::TimeDelta GetDefaultTextfieldObscuredRevealDuration() override; + virtual bool WindowManagerProvidesTitleBar(bool maximized) override; private: DISALLOW_COPY_AND_ASSIGN(ViewsDelegate); diff --git a/brightray/browser/web_ui_controller_factory.h b/brightray/browser/web_ui_controller_factory.h index 74db390746d..ed99e3247c5 100644 --- a/brightray/browser/web_ui_controller_factory.h +++ b/brightray/browser/web_ui_controller_factory.h @@ -19,14 +19,14 @@ class WebUIControllerFactory : public content::WebUIControllerFactory { virtual ~WebUIControllerFactory(); virtual content::WebUI::TypeID GetWebUIType( - content::BrowserContext* browser_context, const GURL& url) const OVERRIDE; + content::BrowserContext* browser_context, const GURL& url) const override; virtual bool UseWebUIForURL(content::BrowserContext* browser_context, - const GURL& url) const OVERRIDE; + const GURL& url) const override; virtual bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, - const GURL& url) const OVERRIDE; + const GURL& url) const override; virtual content::WebUIController* CreateWebUIControllerForURL( content::WebUI* web_ui, - const GURL& url) const OVERRIDE; + const GURL& url) const override; static WebUIControllerFactory* GetInstance(); diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index 11ad7e0aea2..56654718675 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -16,11 +16,11 @@ class ContentClient : public content::ContentClient { ~ContentClient(); private: - virtual std::string GetProduct() const OVERRIDE; - virtual std::string GetUserAgent() const OVERRIDE; + virtual std::string GetProduct() const override; + virtual std::string GetUserAgent() const override; virtual base::StringPiece GetDataResource(int resource_id, - ui::ScaleFactor) const OVERRIDE; - virtual gfx::Image& GetNativeImageNamed(int resource_id) const OVERRIDE; + ui::ScaleFactor) const override; + virtual gfx::Image& GetNativeImageNamed(int resource_id) const override; DISALLOW_COPY_AND_ASSIGN(ContentClient); }; diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 7cfd7758d91..153013b3c21 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -49,11 +49,11 @@ class MainDelegate : public content::ContentMainDelegate { virtual void OverrideFrameworkBundlePath(); #endif - virtual bool BasicStartupComplete(int* exit_code) OVERRIDE; - virtual void PreSandboxStartup() OVERRIDE; + virtual bool BasicStartupComplete(int* exit_code) override; + virtual void PreSandboxStartup() override; private: - virtual content::ContentBrowserClient* CreateContentBrowserClient() OVERRIDE; + virtual content::ContentBrowserClient* CreateContentBrowserClient() override; void InitializeResourceBundle(); From 7b3967321529272c3b507a5b67725c45e66b69a5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 27 Oct 2014 16:37:51 +0800 Subject: [PATCH 0422/1195] No need for "virtual" when "override" is used --- .../browser/inspectable_web_contents_impl.h | 94 +++++++++---------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index bc2e8bcfd28..989abb340f8 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -41,12 +41,12 @@ class InspectableWebContentsImpl : explicit InspectableWebContentsImpl(content::WebContents*); virtual ~InspectableWebContentsImpl(); - virtual InspectableWebContentsView* GetView() const override; - virtual content::WebContents* GetWebContents() const override; + InspectableWebContentsView* GetView() const override; + content::WebContents* GetWebContents() const override; - virtual void ShowDevTools() override; - virtual void CloseDevTools() override; - virtual bool IsDevToolsViewShowing() override; + void ShowDevTools() override; + void CloseDevTools() override; + bool IsDevToolsViewShowing() override; // Return the last position and size of devtools window. gfx::Rect GetDevToolsBounds() const; @@ -65,59 +65,57 @@ class InspectableWebContentsImpl : private: // DevToolsEmbedderMessageDispacher::Delegate - - virtual void ActivateWindow() override; - virtual void CloseWindow() override; - virtual void SetInspectedPageBounds(const gfx::Rect& rect) override; - virtual void InspectElementCompleted() override; - virtual void MoveWindow(int x, int y) override; - virtual void SetIsDocked(bool docked) override; - virtual void OpenInNewTab(const std::string& url) override; - virtual void SaveToFile(const std::string& url, - const std::string& content, - bool save_as) override; - virtual void AppendToFile(const std::string& url, - const std::string& content) override; - virtual void RequestFileSystems() override; - virtual void AddFileSystem() override; - virtual void RemoveFileSystem(const std::string& file_system_path) override; - virtual void UpgradeDraggedFileSystemPermissions( + void ActivateWindow() override; + void CloseWindow() override; + void SetInspectedPageBounds(const gfx::Rect& rect) override; + void InspectElementCompleted() override; + void MoveWindow(int x, int y) override; + void SetIsDocked(bool docked) override; + void OpenInNewTab(const std::string& url) override; + void SaveToFile(const std::string& url, + const std::string& content, + bool save_as) override; + void AppendToFile(const std::string& url, + const std::string& content) override; + void RequestFileSystems() override; + void AddFileSystem() override; + void RemoveFileSystem(const std::string& file_system_path) override; + void UpgradeDraggedFileSystemPermissions( const std::string& file_system_url) override; - virtual void IndexPath(int request_id, - const std::string& file_system_path) override; - virtual void StopIndexing(int request_id) override; - virtual void SearchInPath(int request_id, - const std::string& file_system_path, - const std::string& query) override; - virtual void ZoomIn() override; - virtual void ZoomOut() override; - virtual void ResetZoom() override; + void IndexPath(int request_id, + const std::string& file_system_path) override; + void StopIndexing(int request_id) override; + void SearchInPath(int request_id, + const std::string& file_system_path, + const std::string& query) override; + void ZoomIn() override; + void ZoomOut() override; + void ResetZoom() override; // content::DevToolsClientHost: - virtual void DispatchOnInspectorFrontend(const std::string& message) override; - virtual void InspectedContentsClosing() override; - virtual void ReplacedWithAnotherClient() override; + void DispatchOnInspectorFrontend(const std::string& message) override; + void InspectedContentsClosing() override; + void ReplacedWithAnotherClient() override; // content::DevToolsFrontendHostDelegate: - virtual void HandleMessageFromDevToolsFrontend(const std::string& message) override; - virtual void HandleMessageFromDevToolsFrontendToBackend(const std::string& message) override; + void HandleMessageFromDevToolsFrontend(const std::string& message) override; + void HandleMessageFromDevToolsFrontendToBackend(const std::string& message) override; // content::WebContentsObserver: - virtual void AboutToNavigateRenderView(content::RenderViewHost* render_view_host) override; - virtual void DidFinishLoad(content::RenderFrameHost* render_frame_host, - const GURL& validated_url) override; - virtual void WebContentsDestroyed() override; + void AboutToNavigateRenderView(content::RenderViewHost* render_view_host) override; + void DidFinishLoad(content::RenderFrameHost* render_frame_host, + const GURL& validated_url) override; + void WebContentsDestroyed() override; // content::WebContentsDelegate - - virtual bool AddMessageToConsole(content::WebContents* source, - int32 level, - const base::string16& message, - int32 line_no, - const base::string16& source_id) override; - virtual void HandleKeyboardEvent( + bool AddMessageToConsole(content::WebContents* source, + int32 level, + const base::string16& message, + int32 line_no, + const base::string16& source_id) override; + void HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent&) override; - virtual void CloseContents(content::WebContents* source) override; + void CloseContents(content::WebContents* source) override; scoped_ptr web_contents_; scoped_ptr devtools_web_contents_; From 6b49e23312486e6989e0ded3a89698505955cf81 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 27 Oct 2014 16:42:54 +0800 Subject: [PATCH 0423/1195] Fix leaking WebContents from devtools. --- brightray/browser/inspectable_web_contents_impl.cc | 11 +++++++++++ brightray/browser/inspectable_web_contents_impl.h | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index b2af61d8f10..f05e1ac8a8a 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -355,6 +355,17 @@ bool InspectableWebContentsImpl::AddMessageToConsole( return true; } +bool InspectableWebContentsImpl::ShouldCreateWebContents( + content::WebContents* web_contents, + int route_id, + WindowContainerType window_container_type, + const base::string16& frame_name, + const GURL& target_url, + const std::string& partition_id, + content::SessionStorageNamespace* session_storage_namespace) { + return false; +} + void InspectableWebContentsImpl::HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 989abb340f8..db24bc95daf 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -113,6 +113,14 @@ class InspectableWebContentsImpl : const base::string16& message, int32 line_no, const base::string16& source_id) override; + bool ShouldCreateWebContents( + content::WebContents* web_contents, + int route_id, + WindowContainerType window_container_type, + const base::string16& frame_name, + const GURL& target_url, + const std::string& partition_id, + content::SessionStorageNamespace* session_storage_namespace) override; void HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent&) override; void CloseContents(content::WebContents* source) override; From 2bbfdea8bbf4e858b38704f4cab12583f56da064 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 31 Oct 2014 19:42:06 +0800 Subject: [PATCH 0424/1195] Handle localized string --- brightray/common/content_client.cc | 5 +++++ brightray/common/content_client.h | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index 9d42e350191..9b38e9304f7 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -9,6 +9,7 @@ #include "base/strings/stringprintf.h" #include "base/strings/string_util.h" #include "content/public/common/user_agent.h" +#include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" namespace brightray { @@ -30,6 +31,10 @@ std::string ContentClient::GetUserAgent() const { return content::BuildUserAgentFromProduct(GetProduct()); } +base::string16 ContentClient::GetLocalizedString(int message_id) const { + return l10n_util::GetStringUTF16(message_id); +} + base::StringPiece ContentClient::GetDataResource( int resource_id, ui::ScaleFactor scale_factor) const { return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index 56654718675..e5433cd6a2c 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -16,11 +16,12 @@ class ContentClient : public content::ContentClient { ~ContentClient(); private: - virtual std::string GetProduct() const override; - virtual std::string GetUserAgent() const override; - virtual base::StringPiece GetDataResource(int resource_id, - ui::ScaleFactor) const override; - virtual gfx::Image& GetNativeImageNamed(int resource_id) const override; + std::string GetProduct() const override; + std::string GetUserAgent() const override; + base::string16 GetLocalizedString(int message_id) const; + base::StringPiece GetDataResource(int resource_id, + ui::ScaleFactor) const override; + gfx::Image& GetNativeImageNamed(int resource_id) const override; DISALLOW_COPY_AND_ASSIGN(ContentClient); }; From 74025ee9858e14c6e8269499667afc3d05076b7c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 3 Nov 2014 21:32:11 +0800 Subject: [PATCH 0425/1195] Enable setting devtools to not able to dock --- brightray/browser/inspectable_web_contents.h | 1 + .../browser/inspectable_web_contents_impl.cc | 15 ++++++++++++--- brightray/browser/inspectable_web_contents_impl.h | 2 ++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index ea0fc8f13b3..b0a05d48b38 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -22,6 +22,7 @@ class InspectableWebContents { virtual InspectableWebContentsView* GetView() const = 0; virtual content::WebContents* GetWebContents() const = 0; + virtual void SetCanDock(bool can_dock) = 0; virtual void ShowDevTools() = 0; // Close the DevTools completely instead of just hide it. virtual void CloseDevTools() = 0; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index f05e1ac8a8a..30462804531 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -36,7 +36,7 @@ const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0, const char kDevToolsScheme[] = "chrome-devtools"; const char kDevToolsHost[] = "devtools"; const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?" - "can_dock=true&" + "can_dock=%s&" "toolbarColor=rgba(223,223,223,1)&" "textColor=rgba(0,0,0,1)&" "experiments=true"; @@ -131,6 +131,7 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { InspectableWebContentsImpl::InspectableWebContentsImpl( content::WebContents* web_contents) : web_contents_(web_contents), + can_dock_(true), delegate_(nullptr) { auto context = static_cast(web_contents_->GetBrowserContext()); auto bounds_dict = context->prefs()->GetDictionary(kDevToolsBoundsPref); @@ -151,6 +152,10 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const { return web_contents_.get(); } +void InspectableWebContentsImpl::SetCanDock(bool can_dock) { + can_dock_ = can_dock; +} + void InspectableWebContentsImpl::ShowDevTools() { // Show devtools only after it has done loading, this is to make sure the // SetIsDocked is called *BEFORE* ShowDevTools. @@ -169,7 +174,7 @@ void InspectableWebContentsImpl::ShowDevTools() { web_contents_->GetRenderViewHost(), this)); content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, this); - GURL devtools_url(kChromeUIDevToolsURL); + GURL devtools_url(base::StringPrintf(kChromeUIDevToolsURL, can_dock_ ? "true" : "")); devtools_web_contents_->GetController().LoadURL( devtools_url, content::Referrer(), @@ -315,7 +320,7 @@ void InspectableWebContentsImpl::DispatchOnInspectorFrontend( const std::string& message) { std::string code = "InspectorFrontendAPI.dispatchMessage(" + message + ");"; base::string16 javascript = base::UTF8ToUTF16(code); - web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); + devtools_web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); } void InspectableWebContentsImpl::InspectedContentsClosing() { @@ -336,6 +341,10 @@ void InspectableWebContentsImpl::DidFinishLoad(content::RenderFrameHost* render_ return; view_->ShowDevTools(); + + // If the devtools can dock, "SetIsDocked" will be called by devtools itself. + if (!can_dock_) + SetIsDocked(false); } void InspectableWebContentsImpl::WebContentsDestroyed() { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index db24bc95daf..753db492b52 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -44,6 +44,7 @@ class InspectableWebContentsImpl : InspectableWebContentsView* GetView() const override; content::WebContents* GetWebContents() const override; + void SetCanDock(bool can_dock) override; void ShowDevTools() override; void CloseDevTools() override; bool IsDevToolsViewShowing() override; @@ -133,6 +134,7 @@ class InspectableWebContentsImpl : DevToolsContentsResizingStrategy contents_resizing_strategy_; gfx::Rect devtools_bounds_; + bool can_dock_; scoped_ptr embedder_message_dispatcher_; From 92244500c6bf8fd18e25d037005782bfb20288a2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 3 Nov 2014 21:46:59 +0800 Subject: [PATCH 0426/1195] mac: Clean delegate after closing window --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 4db0d8ac050..94fba05f186 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -145,6 +145,7 @@ using namespace brightray; #pragma mark - NSWindowDelegate - (void)windowWillClose:(NSNotification*)notification { + [devtools_window_ setDelegate:nil]; inspectableWebContentsView_->inspectable_web_contents()->CloseDevTools(); } From b75dc9b08d7487649c60b1df78940c7299b0409d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 3 Nov 2014 22:05:16 +0800 Subject: [PATCH 0427/1195] mac: Close the devtools window before releasing it Sometime simply releasing it may leave it open for a while. --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 94fba05f186..a5f8a522816 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -68,6 +68,7 @@ using namespace brightray; [devtools_window_ makeKeyAndOrderFront:nil]; } else { [[self window] makeKeyAndOrderFront:nil]; + [devtools_window_ close]; devtools_window_.reset(); } } From dbfa9b5660fd8d52ea58e1a78fc387e88c0babb5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 3 Nov 2014 22:12:33 +0800 Subject: [PATCH 0428/1195] mac: Clean delegate before releasing window --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index a5f8a522816..9efe560afa6 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -68,6 +68,7 @@ using namespace brightray; [devtools_window_ makeKeyAndOrderFront:nil]; } else { [[self window] makeKeyAndOrderFront:nil]; + [devtools_window_ setDelegate:nil]; [devtools_window_ close]; devtools_window_.reset(); } @@ -146,7 +147,6 @@ using namespace brightray; #pragma mark - NSWindowDelegate - (void)windowWillClose:(NSNotification*)notification { - [devtools_window_ setDelegate:nil]; inspectableWebContentsView_->inspectable_web_contents()->CloseDevTools(); } From 513d84cd3ef3f0f5e9af5170df2fdf709dc82c04 Mon Sep 17 00:00:00 2001 From: Frank Hale Date: Mon, 3 Nov 2014 11:10:14 -0500 Subject: [PATCH 0429/1195] Make devtools window maximizable --- brightray/browser/views/inspectable_web_contents_view_views.cc | 2 +- 1 file changed, 1 insertion(+), 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 57296344ab3..9aa4d0f748a 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -37,7 +37,7 @@ class DevToolsWindowDelegate : public views::ClientView, virtual void DeleteDelegate() override { delete this; } virtual views::View* GetInitiallyFocusedView() override { return view_; } virtual bool CanResize() const override { return true; } - virtual bool CanMaximize() const override { return false; } + virtual bool CanMaximize() const override { return true; } virtual base::string16 GetWindowTitle() const override { return title_; } virtual gfx::ImageSkia GetWindowAppIcon() override { return GetWindowIcon(); } virtual gfx::ImageSkia GetWindowIcon() override { return icon_; } From c4aebe3ba13603beb954e5da7cb55fe8024f0973 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 6 Nov 2014 19:04:50 +0800 Subject: [PATCH 0430/1195] No need to write "virtual" when we have "override" --- .../inspectable_web_contents_view_views.cc | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 9aa4d0f748a..3fd18243387 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -34,20 +34,20 @@ class DevToolsWindowDelegate : public views::ClientView, virtual ~DevToolsWindowDelegate() {} // views::WidgetDelegate: - virtual void DeleteDelegate() override { delete this; } - virtual views::View* GetInitiallyFocusedView() override { return view_; } - virtual bool CanResize() const override { return true; } - virtual bool CanMaximize() const override { return true; } - virtual base::string16 GetWindowTitle() const override { return title_; } - virtual gfx::ImageSkia GetWindowAppIcon() override { return GetWindowIcon(); } - virtual gfx::ImageSkia GetWindowIcon() override { return icon_; } - virtual views::Widget* GetWidget() override { return widget_; } - virtual const views::Widget* GetWidget() const override { return widget_; } - virtual views::View* GetContentsView() override { return view_; } - virtual views::ClientView* CreateClientView(views::Widget* widget) { return this; } + void DeleteDelegate() override { delete this; } + views::View* GetInitiallyFocusedView() override { return view_; } + bool CanResize() const override { return true; } + bool CanMaximize() const override { return true; } + base::string16 GetWindowTitle() const override { return title_; } + gfx::ImageSkia GetWindowAppIcon() override { return GetWindowIcon(); } + gfx::ImageSkia GetWindowIcon() override { return icon_; } + views::Widget* GetWidget() override { return widget_; } + const views::Widget* GetWidget() const override { return widget_; } + views::View* GetContentsView() override { return view_; } + views::ClientView* CreateClientView(views::Widget* widget) { return this; } // views::ClientView: - virtual bool CanClose() override { + bool CanClose() override { shell_->inspectable_web_contents()->CloseDevTools(); return false; } From 601ee75bcf3d51fc4cbc149106b102e99bd33b54 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 6 Nov 2014 19:06:32 +0800 Subject: [PATCH 0431/1195] linux: Use native window frame for devtools Fixes atom/atom-shell#646. --- .../browser/views/inspectable_web_contents_view_views.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 3fd18243387..38711fa0dff 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -147,10 +147,6 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { devtools_window_web_view_, devtools_window_.get()); params.bounds = inspectable_web_contents()->GetDevToolsBounds(); -#if defined(USE_X11) - // In X11 the window frame is drawn by the application. - params.remove_standard_frame = true; -#endif devtools_window_->Init(params); devtools_window_->UpdateWindowIcon(); } From 06eff5cd8c2c4c8f3db46cd8ce2dfdee1b20194f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 24 Nov 2014 16:03:55 +0800 Subject: [PATCH 0432/1195] linux: Add a way to set WM_CLASS for devtools window --- brightray/browser/inspectable_web_contents_delegate.h | 6 ++++++ .../browser/views/inspectable_web_contents_view_views.cc | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index 9b9cfa427ec..082343f2f64 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -19,6 +19,12 @@ class InspectableWebContentsDelegate { const std::string& url, const std::string& content, bool save_as) {} virtual void DevToolsAppendToFile( const std::string& url, const std::string& content) {} + +#if defined(USE_X11) + // Called when creating devtools window. + virtual void GetDevToolsWindowWMClass( + std::string* name, std::string* class_name) {} +#endif }; } // namespace brightray diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 38711fa0dff..b3350ff4671 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -147,6 +147,14 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { devtools_window_web_view_, devtools_window_.get()); params.bounds = inspectable_web_contents()->GetDevToolsBounds(); + +#if defined(USE_X11) + params.wm_role_name = "devtools"; + InspectableWebContentsDelegate* delegate = inspectable_web_contents()->GetDelegate(); + if (delegate) + delegate->GetDevToolsWindowWMClass(¶ms.wm_class_name, ¶ms.wm_class_class); +#endif + devtools_window_->Init(params); devtools_window_->UpdateWindowIcon(); } From f617eb5810af14999db3ebbc948669e18f1109a9 Mon Sep 17 00:00:00 2001 From: Ryan Prichard Date: Mon, 24 Nov 2014 03:27:11 -0800 Subject: [PATCH 0433/1195] Move Linux pkg-config dependencies from atom-shell to brightray. --- brightray/brightray.gyp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index c00db1514f4..8ba0acf7ba2 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -101,11 +101,14 @@ '-fno-rtti', ], 'link_settings': { + 'ldflags': [ + ' Date: Fri, 28 Nov 2014 19:45:25 +0300 Subject: [PATCH 0434/1195] Same as https://github.com/atom/atom-shell/pull/867 Indeed there are two places worth changing. After these two changes i am able to build Atom-Shell using Pyhon installed by default (without adding to paths) --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 8ba0acf7ba2..41dec3e1a52 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -3,7 +3,7 @@ 'brightray.gypi', ], 'variables': { - 'brightray_source_root': ' Date: Sun, 7 Dec 2014 21:24:23 -0800 Subject: [PATCH 0435/1195] Fix the default framework name to be 'Product Framework.framework', not 'Product.framework' --- brightray/common/main_delegate_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index c710fa1da21..42f6e818e17 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -33,7 +33,7 @@ base::FilePath MainDelegate::GetResourcesPakFilePath() { } void MainDelegate::OverrideFrameworkBundlePath() { - base::FilePath helper_path = GetFrameworksPath().Append(GetApplicationName() + ".framework"); + base::FilePath helper_path = GetFrameworksPath().Append(GetApplicationName() + " Framework.framework"); base::mac::SetOverrideFrameworkBundlePath(helper_path); } From 8ec5b5ad200ab152621a89f715cffae6197d5770 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Dec 2014 14:31:02 -0800 Subject: [PATCH 0436/1195] DevToolsClientHost is discarded --- brightray/browser/browser_context.cc | 2 +- brightray/browser/browser_context.h | 27 +++++++-------- .../browser/inspectable_web_contents_impl.cc | 34 ++++++------------- .../browser/inspectable_web_contents_impl.h | 15 ++++---- 4 files changed, 33 insertions(+), 45 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 89285f1cb22..42f28358ac9 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -166,7 +166,7 @@ content::BrowserPluginGuestManager* BrowserContext::GetGuestManager() { return NULL; } -quota::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() { +storage::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() { return NULL; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index d2de8b30d89..eb2279db7a7 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -48,22 +48,21 @@ class BrowserContext : public content::BrowserContext, void RegisterInternalPrefs(PrefRegistrySimple* pref_registry); - virtual bool IsOffTheRecord() const override; - virtual net::URLRequestContextGetter* GetRequestContext() override; - virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( + bool IsOffTheRecord() const override; + net::URLRequestContextGetter* GetRequestContext() override; + net::URLRequestContextGetter* GetRequestContextForRenderProcess( int renderer_child_id); - virtual net::URLRequestContextGetter* GetMediaRequestContext() override; - virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( + net::URLRequestContextGetter* GetMediaRequestContext() override; + net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( int renderer_child_id) override; - virtual net::URLRequestContextGetter* - GetMediaRequestContextForStoragePartition( - const base::FilePath& partition_path, bool in_memory); - virtual content::ResourceContext* GetResourceContext() override; - virtual content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; - virtual content::BrowserPluginGuestManager* GetGuestManager() override; - virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() override; - virtual content::PushMessagingService* GetPushMessagingService() override; - virtual content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; + net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( + const base::FilePath& partition_path, bool in_memory) override; + content::ResourceContext* GetResourceContext() override; + content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; + content::BrowserPluginGuestManager* GetGuestManager() override; + storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; + content::PushMessagingService* GetPushMessagingService() override; + content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; base::FilePath path_; scoped_ptr resource_context_; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 30462804531..4fae3a1ae12 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -17,10 +17,7 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" -#include "content/public/browser/devtools_agent_host.h" -#include "content/public/browser/devtools_client_host.h" #include "content/public/browser/devtools_http_handler.h" -#include "content/public/browser/devtools_manager.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" @@ -33,8 +30,6 @@ const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0, 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 5.0 }; -const char kDevToolsScheme[] = "chrome-devtools"; -const char kDevToolsHost[] = "devtools"; const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?" "can_dock=%s&" "toolbarColor=rgba(223,223,223,1)&" @@ -91,15 +86,11 @@ bool ParseMessage(const std::string& message, } double GetZoomLevelForWebContents(content::WebContents* web_contents) { - content::HostZoomMap* host_zoom_map = content::HostZoomMap::GetForBrowserContext( - web_contents->GetBrowserContext()); - return host_zoom_map->GetZoomLevelForHostAndScheme(kDevToolsScheme, kDevToolsHost); + return content::HostZoomMap::GetZoomLevel(web_contents); } void SetZoomLevelForWebContents(content::WebContents* web_contents, double level) { - content::HostZoomMap* host_zoom_map = content::HostZoomMap::GetForBrowserContext( - web_contents->GetBrowserContext()); - return host_zoom_map->SetZoomLevelForHostAndScheme(kDevToolsScheme, kDevToolsHost, level); + content::HostZoomMap::SetZoomLevel(web_contents, level); } double GetNextZoomLevel(double level, bool out) { @@ -172,13 +163,13 @@ void InspectableWebContentsImpl::ShowDevTools() { agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()); frontend_host_.reset(content::DevToolsFrontendHost::Create( web_contents_->GetRenderViewHost(), this)); - content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor(agent_host_, this); + agent_host_->AttachClient(this); GURL devtools_url(base::StringPrintf(kChromeUIDevToolsURL, can_dock_ ? "true" : "")); devtools_web_contents_->GetController().LoadURL( devtools_url, content::Referrer(), - content::PAGE_TRANSITION_AUTO_TOPLEVEL, + ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); } else { view_->ShowDevTools(); @@ -312,21 +303,18 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::st void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontendToBackend( const std::string& message) { - content::DevToolsManager::GetInstance()->DispatchOnInspectorBackend( - this, message); + agent_host_->DispatchProtocolMessage(message); } -void InspectableWebContentsImpl::DispatchOnInspectorFrontend( - const std::string& message) { +void InspectableWebContentsImpl::DispatchProtocolMessage( + content::DevToolsAgentHost* agent_host, const std::string& message) { std::string code = "InspectorFrontendAPI.dispatchMessage(" + message + ");"; base::string16 javascript = base::UTF8ToUTF16(code); - devtools_web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); + web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); } -void InspectableWebContentsImpl::InspectedContentsClosing() { -} - -void InspectableWebContentsImpl::ReplacedWithAnotherClient() { +void InspectableWebContentsImpl::AgentHostClosed( + content::DevToolsAgentHost* agent_host, bool replaced) { } void InspectableWebContentsImpl::AboutToNavigateRenderView( @@ -348,7 +336,7 @@ void InspectableWebContentsImpl::DidFinishLoad(content::RenderFrameHost* render_ } void InspectableWebContentsImpl::WebContentsDestroyed() { - content::DevToolsManager::GetInstance()->ClientHostClosing(this); + agent_host_->DetachClient(); Observe(nullptr); agent_host_ = nullptr; } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 753db492b52..9c80be071d6 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -11,7 +11,7 @@ #include "browser/devtools_contents_resizing_strategy.h" #include "browser/devtools_embedder_message_dispatcher.h" -#include "content/public/browser/devtools_client_host.h" +#include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" @@ -31,7 +31,7 @@ class InspectableWebContentsView; class InspectableWebContentsImpl : public InspectableWebContents, public content::DevToolsFrontendHost::Delegate, - public content::DevToolsClientHost, + public content::DevToolsAgentHostClient, public content::WebContentsObserver, public content::WebContentsDelegate, public DevToolsEmbedderMessageDispatcher::Delegate { @@ -93,15 +93,16 @@ class InspectableWebContentsImpl : void ZoomOut() override; void ResetZoom() override; - // content::DevToolsClientHost: - void DispatchOnInspectorFrontend(const std::string& message) override; - void InspectedContentsClosing() override; - void ReplacedWithAnotherClient() override; - // content::DevToolsFrontendHostDelegate: void HandleMessageFromDevToolsFrontend(const std::string& message) override; void HandleMessageFromDevToolsFrontendToBackend(const std::string& message) override; + // content::DevToolsAgentHostClient: + void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host, + const std::string& message) override; + void AgentHostClosed(content::DevToolsAgentHost* agent_host, + bool replaced) override; + // content::WebContentsObserver: void AboutToNavigateRenderView(content::RenderViewHost* render_view_host) override; void DidFinishLoad(content::RenderFrameHost* render_frame_host, From 289d3b54f301caef0cc48388feaaa969e0adfaa4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Dec 2014 15:37:11 -0800 Subject: [PATCH 0437/1195] Add DevToolsManagerDelegateA --- brightray/browser/devtools_delegate.cc | 170 +++++++++++++++---------- brightray/browser/devtools_delegate.h | 39 ++++-- 2 files changed, 129 insertions(+), 80 deletions(-) diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_delegate.cc index a706520cb2e..3cf57c4810e 100644 --- a/brightray/browser/devtools_delegate.cc +++ b/brightray/browser/devtools_delegate.cc @@ -12,9 +12,6 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "browser/browser_context.h" -#include "browser/inspectable_web_contents.h" -#include "browser/default_web_contents_delegate.h" -#include "browser/inspectable_web_contents_delegate.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_http_handler.h" #include "content/public/browser/devtools_target.h" @@ -25,7 +22,7 @@ #include "content/public/common/content_switches.h" #include "content/public/common/url_constants.h" #include "content/public/common/user_agent.h" -#include "net/socket/tcp_listen_socket.h" +#include "net/socket/tcp_server_socket.h" #include "ui/base/resource/resource_bundle.h" using content::DevToolsAgentHost; @@ -43,8 +40,28 @@ namespace { const int kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE = 25500; const char kTargetTypePage[] = "page"; +const char kTargetTypeServiceWorker[] = "service_worker"; +const char kTargetTypeOther[] = "other"; -net::StreamListenSocketFactory* CreateSocketFactory() { +class TCPServerSocketFactory + : public content::DevToolsHttpHandler::ServerSocketFactory { + public: + TCPServerSocketFactory(const std::string& address, int port, int backlog) + : content::DevToolsHttpHandler::ServerSocketFactory( + address, port, backlog) {} + + private: + // content::DevToolsHttpHandler::ServerSocketFactory. + scoped_ptr Create() const override { + return scoped_ptr( + new net::TCPServerSocket(NULL, net::NetLog::Source())); + } + + DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); +}; + +scoped_ptr +CreateSocketFactory() { const CommandLine& command_line = *CommandLine::ForCurrentProcess(); // See if the user specified a port on the command line (useful for // automation). If not, use an ephemeral port by specifying 0. @@ -60,75 +77,77 @@ net::StreamListenSocketFactory* CreateSocketFactory() { DLOG(WARNING) << "Invalid http debugger port number " << temp_port; } } - return new net::TCPListenSocketFactory("127.0.0.1", port); + return scoped_ptr( + new TCPServerSocketFactory("127.0.0.1", port, 1)); } class Target : public content::DevToolsTarget { public: - explicit Target(WebContents* web_contents); + explicit Target(scoped_refptr agent_host); - virtual std::string GetId() const override { return id_; } - virtual std::string GetParentId() const { return std::string(); } - virtual std::string GetType() const override { return kTargetTypePage; } - virtual std::string GetTitle() const override { return title_; } - virtual std::string GetDescription() const override { return std::string(); } - virtual GURL GetURL() const override { return url_; } - virtual GURL GetFaviconURL() const override { return favicon_url_; } - virtual base::TimeTicks GetLastActivityTime() const override { + virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); } + virtual std::string GetParentId() const OVERRIDE { return std::string(); } + virtual 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; + } + virtual std::string GetTitle() const OVERRIDE { + return agent_host_->GetTitle(); + } + virtual std::string GetDescription() const OVERRIDE { return std::string(); } + virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); } + virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } + virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { return last_activity_time_; } - virtual bool IsAttached() const override { + virtual bool IsAttached() const OVERRIDE { return agent_host_->IsAttached(); } - virtual scoped_refptr GetAgentHost() const override { + virtual scoped_refptr GetAgentHost() const OVERRIDE { return agent_host_; } - virtual bool Activate() const override; - virtual bool Close() const override; + virtual bool Activate() const OVERRIDE; + virtual bool Close() const OVERRIDE; private: scoped_refptr agent_host_; - std::string id_; - std::string title_; - GURL url_; GURL favicon_url_; base::TimeTicks last_activity_time_; }; -Target::Target(WebContents* web_contents) { - agent_host_ = DevToolsAgentHost::GetOrCreateFor(web_contents); - id_ = agent_host_->GetId(); - title_ = base::UTF16ToUTF8(web_contents->GetTitle()); - url_ = web_contents->GetURL(); - 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(); +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 { - WebContents* web_contents = agent_host_->GetWebContents(); - if (!web_contents) - return false; - web_contents->GetDelegate()->ActivateContents(web_contents); - return true; + return agent_host_->Activate(); } bool Target::Close() const { - WebContents* web_contents = agent_host_->GetWebContents(); - if (!web_contents) - return false; - web_contents->GetRenderViewHost()->ClosePage(); - return true; + return agent_host_->Close(); } } // namespace namespace brightray { -DevToolsDelegate::DevToolsDelegate( - content::BrowserContext* browser_context) +// DevToolsDelegate -------------------------------------------------------- + +DevToolsDelegate::DevToolsDelegate(content::BrowserContext* browser_context) : browser_context_(browser_context) { std::string frontend_url; devtools_http_handler_ = DevToolsHttpHandler::Start( @@ -156,32 +175,6 @@ base::FilePath DevToolsDelegate::GetDebugFrontendDir() { return base::FilePath(); } -std::string DevToolsDelegate::GetPageThumbnailData(const GURL& url) { - return std::string(); -} - -scoped_ptr -DevToolsDelegate::CreateNewTarget(const GURL& url) { - content::WebContents::CreateParams create_params( - new brightray::BrowserContext()); - brightray::InspectableWebContents* web_contents = - brightray::InspectableWebContents::Create(create_params); - web_contents->SetDelegate(new brightray::InspectableWebContentsDelegate()); - return scoped_ptr(new Target(web_contents->GetWebContents())); -} - -void DevToolsDelegate::EnumerateTargets(TargetCallback callback) { - TargetList targets; - std::vector wc_list = - content::DevToolsAgentHost::GetInspectableWebContents(); - for (std::vector::iterator it = wc_list.begin(); - it != wc_list.end(); - ++it) { - targets.push_back(new Target(*it)); - } - callback.Run(targets); -} - scoped_ptr DevToolsDelegate::CreateSocketForTethering( net::StreamListenSocket::Delegate* delegate, @@ -189,4 +182,41 @@ DevToolsDelegate::CreateSocketForTethering( return scoped_ptr(); } +// DevToolsManagerDelegate --------------------------------------------------- + +DevToolsManagerDelegate::DevToolsManagerDelegate( + content::BrowserContext* browser_context) + : browser_context_(browser_context) { +} + +DevToolsManagerDelegate::~DevToolsManagerDelegate() { +} + +base::DictionaryValue* DevToolsManagerDelegate::HandleCommand( + content::DevToolsAgentHost* agent_host, + base::DictionaryValue* command) { + 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; + content::DevToolsAgentHost::List agents = + content::DevToolsAgentHost::GetOrCreateAll(); + for (content::DevToolsAgentHost::List::iterator it = agents.begin(); + it != agents.end(); ++it) { + targets.push_back(new Target(*it)); + } + callback.Run(targets); +} + } // namespace brightray diff --git a/brightray/browser/devtools_delegate.h b/brightray/browser/devtools_delegate.h index 85b156dd71b..b7fcc7b60c9 100644 --- a/brightray/browser/devtools_delegate.h +++ b/brightray/browser/devtools_delegate.h @@ -5,11 +5,10 @@ #ifndef BRIGHTRAY_DEVTOOLS_DELEGATE_H_ #define BRIGHTRAY_DEVTOOLS_DELEGATE_H_ -#include - #include "base/basictypes.h" #include "base/compiler_specific.h" #include "content/public/browser/devtools_http_handler_delegate.h" +#include "content/public/browser/devtools_manager_delegate.h" namespace content { class BrowserContext; @@ -27,14 +26,10 @@ class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { void Stop(); // DevToolsHttpProtocolHandler::Delegate overrides. - virtual std::string GetDiscoveryPageHTML() override; - virtual bool BundlesFrontendResources() override; - virtual base::FilePath GetDebugFrontendDir() override; - virtual std::string GetPageThumbnailData(const GURL& url) override; - virtual scoped_ptr CreateNewTarget( - const GURL& url) override; - virtual void EnumerateTargets(TargetCallback callback) override; - virtual scoped_ptr CreateSocketForTethering( + std::string GetDiscoveryPageHTML() override; + bool BundlesFrontendResources() override; + base::FilePath GetDebugFrontendDir() override; + scoped_ptr CreateSocketForTethering( net::StreamListenSocket::Delegate* delegate, std::string* name) override; @@ -49,6 +44,30 @@ class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); }; +class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { + public: + explicit DevToolsManagerDelegate(content::BrowserContext* browser_context); + virtual ~DevToolsManagerDelegate(); + + // DevToolsManagerDelegate implementation. + void Inspect(content::BrowserContext* browser_context, + content::DevToolsAgentHost* agent_host) override {} + void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host, + 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: + content::BrowserContext* browser_context_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsManagerDelegate); +}; + } // namespace brightray #endif // BRIGHTRAY_DEVTOOLS_DELEGATE_H_ From 2c81fb47197bb0efbc7fb89569bed873e6cc70eb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 6 Dec 2014 22:16:00 -0800 Subject: [PATCH 0438/1195] Fix compilation warnings due to API changes --- brightray/browser/browser_context.cc | 22 +++++-------------- brightray/browser/devtools_ui.cc | 9 ++++---- .../mac/bry_inspectable_web_contents_view.mm | 10 +++++++-- .../media/media_capture_devices_dispatcher.cc | 13 ----------- .../media/media_capture_devices_dispatcher.h | 9 -------- .../browser/url_request_context_getter.cc | 4 ++-- 6 files changed, 20 insertions(+), 47 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 42f28358ac9..c3820de64be 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -45,18 +45,6 @@ class BrowserContext::ResourceContext : public content::ResourceContext { return getter_->GetURLRequestContext(); } - // FIXME: We should probably allow clients to override this to implement more - // restrictive policies. - virtual bool AllowMicAccess(const GURL& origin) override { - return true; - } - - // FIXME: We should probably allow clients to override this to implement more - // restrictive policies. - virtual bool AllowCameraAccess(const GURL& origin) override { - return true; - } - URLRequestContextGetter* getter_; }; @@ -80,13 +68,13 @@ void BrowserContext::Initialize() { base::PrefServiceFactory prefs_factory; prefs_factory.SetUserPrefsFile(prefs_path, JsonPrefStore::GetTaskRunnerForFile( - prefs_path, BrowserThread::GetBlockingPool())); + prefs_path, BrowserThread::GetBlockingPool()).get()); auto registry = make_scoped_refptr(new PrefRegistrySimple); - RegisterInternalPrefs(registry); - RegisterPrefs(registry); + RegisterInternalPrefs(registry.get()); + RegisterPrefs(registry.get()); - prefs_ = prefs_factory.Create(registry); + prefs_ = prefs_factory.Create(registry.get()); } BrowserContext::~BrowserContext() { @@ -102,7 +90,7 @@ void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { net::URLRequestContextGetter* BrowserContext::CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors) { - DCHECK(!url_request_getter_); + DCHECK(!url_request_getter_.get()); url_request_getter_ = new URLRequestContextGetter( this, GetPath(), diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 43fe2a50e04..42769b53c30 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -68,13 +68,14 @@ class BundledDataSource : public content::URLDataSource { int resource_id = content::DevToolsHttpHandler::GetFrontendResourceId(filename); - DLOG_IF(WARNING, -1 == resource_id) << "Unable to find dev tool resource: " - << filename << ". If you compiled with debug_devtools=1, try running" - " with --debug-devtools."; + 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)); - callback.Run(bytes); + callback.Run(bytes.get()); } virtual std::string GetMimeType(const std::string& path) const override { diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 9efe560afa6..bb2e065d337 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -21,8 +21,6 @@ using namespace brightray; devtools_docked_ = NO; auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); - contents->SetAllowOverlappingViews(true); - auto contentsView = contents->GetNativeView(); [contentsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [self addSubview:contentsView]; @@ -45,9 +43,17 @@ using namespace brightray; if (visible == devtools_visible_) return; + auto webContents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); auto devToolsView = devToolsWebContents->GetNativeView(); + if (visible && devtools_docked_) { + webContents->SetAllowOtherViews(true); + devToolsWebContents->SetAllowOtherViews(true); + } else { + webContents->SetAllowOtherViews(false); + } + devtools_visible_ = visible; if (devtools_docked_) { if (visible) { diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index ddf1948a18e..1c99d89765a 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -142,19 +142,6 @@ void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged( content::MediaRequestState state) { } -void MediaCaptureDevicesDispatcher::OnAudioStreamPlaying( - int render_process_id, - int render_frame_id, - int stream_id, - const ReadPowerAndClipCallback& power_read_callback) { -} - -void MediaCaptureDevicesDispatcher::OnAudioStreamStopped( - int render_process_id, - int render_frame_id, - int stream_id) { -} - void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( int render_process_id, int render_view_id) { diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index fb2e7a1c372..f89f9b02203 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -60,15 +60,6 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { const GURL& security_origin, content::MediaStreamType stream_type, content::MediaRequestState state) override; - virtual void OnAudioStreamPlaying( - int render_process_id, - int render_frame_id, - int stream_id, - const ReadPowerAndClipCallback& power_read_callback) override; - virtual void OnAudioStreamStopped( - int render_process_id, - int render_frame_id, - int stream_id) override; virtual void OnCreatingAudioStream(int render_process_id, int render_view_id) override; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 7010aa464a4..44a0f6cbcd4 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -38,7 +38,7 @@ #include "net/url_request/url_request_intercepting_job_factory.h" #include "net/url_request/url_request_job_factory_impl.h" #include "url/url_constants.h" -#include "webkit/browser/quota/special_storage_policy.h" +#include "storage/browser/quota/special_storage_policy.h" using content::BrowserThread; @@ -120,7 +120,7 @@ URLRequestContextGetter::URLRequestContextGetter( // must synchronously run on the glib message loop. This will be passed to // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( - io_loop_->message_loop_proxy(), file_loop_)); + io_loop_->message_loop_proxy(), file_loop_->message_loop_proxy())); } URLRequestContextGetter::~URLRequestContextGetter() { From c25dfcb71df553cbdcb6eaa3e5321c076492c3b1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 6 Dec 2014 22:17:14 -0800 Subject: [PATCH 0439/1195] Upgrade libchromiumcontent to 39.0.2171.65 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index f9abe65eddd..e4b283c2223 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit f9abe65eddd9f233e215151c7487ac19af2a60d9 +Subproject commit e4b283c22236560fd289fe59c03e50adf39e7c4b From 01fde4029918b6e41ea3e4e7c7436115687219a7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 10 Dec 2014 12:40:39 -0800 Subject: [PATCH 0440/1195] Fix compilation warning on Windows --- brightray/brightray.gypi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 1856ec978e7..978ec372fd5 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -275,7 +275,9 @@ 4355, # 'this' : used in base member initializer list 4480, # nonstandard extension used: specifying underlying type for enum 4481, # nonstandard extension used: override specifier 'override' + 4510, # default constructor could not be generated 4512, # assignment operator could not be generated + 4610, # user defined constructor required 4702, # unreachable code 4819, # The file contains a character that cannot be represented in the current code page ], From 779c44424fbd4162263db6d41917d10cdcfd5d43 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 12 Dec 2014 14:48:16 -0800 Subject: [PATCH 0441/1195] Upgrade libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index e4b283c2223..7b360df11d8 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit e4b283c22236560fd289fe59c03e50adf39e7c4b +Subproject commit 7b360df11d8797769930b616e48feccf74978359 From dc86ab58a96298b9fc7b88cf98ec6ae055ce1437 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 17 Dec 2014 13:13:19 -0800 Subject: [PATCH 0442/1195] Remove DownloadManagerDelegate Having a partial implemented DownloadManagerDelegate will cause crashes under certain places. --- brightray/brightray.gyp | 2 -- brightray/browser/browser_context.cc | 11 ++++------- brightray/browser/browser_context.h | 3 --- .../browser/download_manager_delegate.cc | 11 ----------- brightray/browser/download_manager_delegate.h | 19 ------------------- 5 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 brightray/browser/download_manager_delegate.cc delete mode 100644 brightray/browser/download_manager_delegate.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 41dec3e1a52..45b7bb5e4d0 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -48,8 +48,6 @@ 'browser/devtools_embedder_message_dispatcher.h', 'browser/devtools_ui.cc', 'browser/devtools_ui.h', - 'browser/download_manager_delegate.cc', - 'browser/download_manager_delegate.h', 'browser/inspectable_web_contents.cc', 'browser/inspectable_web_contents.h', 'browser/inspectable_web_contents_delegate.cc', diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index c3820de64be..05f127755c1 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -4,7 +4,6 @@ #include "browser/browser_context.h" -#include "browser/download_manager_delegate.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/network_delegate.h" #include "common/application_info.h" @@ -145,21 +144,19 @@ content::ResourceContext* BrowserContext::GetResourceContext() { } content::DownloadManagerDelegate* BrowserContext::GetDownloadManagerDelegate() { - if (!download_manager_delegate_) - download_manager_delegate_.reset(new DownloadManagerDelegate); - return download_manager_delegate_.get(); + return nullptr; } content::BrowserPluginGuestManager* BrowserContext::GetGuestManager() { - return NULL; + return nullptr; } storage::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() { - return NULL; + return nullptr; } content::PushMessagingService* BrowserContext::GetPushMessagingService() { - return NULL; + return nullptr; } content::SSLHostStateDelegate* BrowserContext::GetSSLHostStateDelegate() { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index eb2279db7a7..90cefbcf795 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -14,8 +14,6 @@ class PrefService; namespace brightray { -class DownloadManagerDelegate; - class BrowserContext : public content::BrowserContext, public brightray::URLRequestContextGetter::Delegate { public: @@ -68,7 +66,6 @@ class BrowserContext : public content::BrowserContext, scoped_ptr resource_context_; scoped_refptr url_request_getter_; scoped_ptr prefs_; - scoped_ptr download_manager_delegate_; DISALLOW_COPY_AND_ASSIGN(BrowserContext); }; diff --git a/brightray/browser/download_manager_delegate.cc b/brightray/browser/download_manager_delegate.cc deleted file mode 100644 index f241f8441bc..00000000000 --- a/brightray/browser/download_manager_delegate.cc +++ /dev/null @@ -1,11 +0,0 @@ -#include "browser/download_manager_delegate.h" - -namespace brightray { - -DownloadManagerDelegate::DownloadManagerDelegate() { -} - -DownloadManagerDelegate::~DownloadManagerDelegate() { -} - -} diff --git a/brightray/browser/download_manager_delegate.h b/brightray/browser/download_manager_delegate.h deleted file mode 100644 index 95ac7d5a817..00000000000 --- a/brightray/browser/download_manager_delegate.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef BRIGHTRAY_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ -#define BRIGHTRAY_BROWSER_DOWNLOAD_MANAGER_DELEGATE_H_ - -#include "content/public/browser/download_manager_delegate.h" - -namespace brightray { - -class DownloadManagerDelegate : public content::DownloadManagerDelegate { - public: - DownloadManagerDelegate(); - ~DownloadManagerDelegate(); - - private: - DISALLOW_COPY_AND_ASSIGN(DownloadManagerDelegate); -}; - -} // namespace brightray - -#endif From 51ef072de5b2e30ace4f02a4e053f24434fab9fb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 2 Jan 2015 15:18:24 -0800 Subject: [PATCH 0443/1195] Implement GetDevToolsManagerDelegate, fixes atom/atom-shell#969 --- brightray/browser/browser_client.cc | 5 +++++ brightray/browser/browser_client.h | 13 +++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index a7e2f3f73f8..70a6790dfd8 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -6,6 +6,7 @@ #include "browser/browser_context.h" #include "browser/browser_main_parts.h" +#include "browser/devtools_delegate.h" #include "browser/media/media_capture_devices_dispatcher.h" #include "browser/notification_presenter.h" @@ -95,4 +96,8 @@ base::FilePath BrowserClient::GetDefaultDownloadDirectory() { return path; } +content::DevToolsManagerDelegate* BrowserClient::GetDevToolsManagerDelegate() { + return new DevToolsManagerDelegate(browser_context()); +} + } // namespace brightray diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 965692e5ff8..9163d6c7021 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -33,23 +33,24 @@ class BrowserClient : public content::ContentBrowserClient { // Subclasses that override this (e.g., to provide their own protocol // handlers) should call this implementation after doing their own work. - virtual net::URLRequestContextGetter* CreateRequestContext( + net::URLRequestContextGetter* CreateRequestContext( content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors) override; private: - virtual content::BrowserMainParts* CreateBrowserMainParts( + content::BrowserMainParts* CreateBrowserMainParts( const content::MainFunctionParams&) override; - virtual void ShowDesktopNotification( + void ShowDesktopNotification( const content::ShowDesktopNotificationHostMsgParams& params, content::RenderFrameHost* render_frame_host, scoped_ptr delegate, base::Closure* cancel_callback) override; - virtual content::MediaObserver* GetMediaObserver() override; - virtual void GetAdditionalAllowedSchemesForFileSystem( + content::MediaObserver* GetMediaObserver() override; + void GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) override; - virtual base::FilePath GetDefaultDownloadDirectory() override; + base::FilePath GetDefaultDownloadDirectory() override; + content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override; BrowserMainParts* browser_main_parts_; scoped_ptr notification_presenter_; From ff0afc688db39903f273866ce6711fba03a8371e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 4 Jan 2015 22:32:00 -0800 Subject: [PATCH 0444/1195] Fix devtools window can not minimize Closes atom/atom-shell#941. --- brightray/browser/views/inspectable_web_contents_view_views.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index b3350ff4671..05344daf550 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -38,6 +38,7 @@ class DevToolsWindowDelegate : public views::ClientView, views::View* GetInitiallyFocusedView() override { return view_; } bool CanResize() const override { return true; } bool CanMaximize() const override { return true; } + bool CanMinimize() const override { return true; } base::string16 GetWindowTitle() const override { return title_; } gfx::ImageSkia GetWindowAppIcon() override { return GetWindowIcon(); } gfx::ImageSkia GetWindowIcon() override { return icon_; } From 1166a56ceb1491633d602a9e036deda297fb4703 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 5 Jan 2015 13:29:16 -0800 Subject: [PATCH 0445/1195] Add a way to custom http cache backend --- .../browser/url_request_context_getter.cc | 21 +++++++++++-------- .../browser/url_request_context_getter.h | 3 +++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 44a0f6cbcd4..7f2f6d878ee 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -20,7 +20,6 @@ #include "net/cookies/cookie_monster.h" #include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_handler_factory.h" -#include "net/http/http_cache.h" #include "net/http/http_server_properties_impl.h" #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" #include "net/proxy/proxy_config_service.h" @@ -99,6 +98,17 @@ net::URLRequestJobFactory* URLRequestContextGetter::Delegate::CreateURLRequestJo return top_job_factory.release(); } +net::HttpCache::BackendFactory* +URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(const base::FilePath& base_path) { + base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache")); + return new net::HttpCache::DefaultBackend( + net::DISK_CACHE, + net::CACHE_BACKEND_DEFAULT, + cache_path, + 0, + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); +} + URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, const base::FilePath& base_path, @@ -213,14 +223,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_host_resolver(host_resolver.Pass()); network_session_params.host_resolver = url_request_context_->host_resolver(); - base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); - net::HttpCache::DefaultBackend* backend = - new net::HttpCache::DefaultBackend( - net::DISK_CACHE, - net::CACHE_BACKEND_DEFAULT, - cache_path, - 0, - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); + net::HttpCache::BackendFactory* backend = delegate_->CreateHttpCacheBackendFactory(base_path_); storage_->set_http_transaction_factory(new net::HttpCache(network_session_params, backend)); storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 05588c20ee5..85ed014422a 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -8,6 +8,7 @@ #include "base/files/file_path.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/content_browser_client.h" +#include "net/http/http_cache.h" #include "net/url_request/url_request_context_getter.h" namespace base { @@ -36,6 +37,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual net::URLRequestJobFactory* CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector* protocol_interceptors); + virtual net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory( + const base::FilePath& base_path); }; URLRequestContextGetter( From 0e0079956c27b7e7f7cfac634a15f7b9a7b59f71 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 6 Jan 2015 20:36:20 -0800 Subject: [PATCH 0446/1195] Add support for --ignore-certificate-errors --- brightray/browser/url_request_context_getter.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 7f2f6d878ee..c2aadeba08b 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -212,6 +212,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.http_auth_handler_factory = url_request_context_->http_auth_handler_factory(); + // --ignore-certificate-errors + if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) + network_session_params.ignore_certificate_errors = true; + // --host-rules if (command_line.HasSwitch(kHostRules)) { host_mapping_rules_.reset(new net::HostMappingRules); From 167995119a5a7636eb69803388ab0443727d1c0b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 15 Jan 2015 15:30:04 -0800 Subject: [PATCH 0447/1195] Use current exe's icon as default window icon. Fixes atom/atom-shell#863. --- brightray/browser/views/views_delegate.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc index 7f2a2249df3..a1078d41cb7 100644 --- a/brightray/browser/views/views_delegate.cc +++ b/brightray/browser/views/views_delegate.cc @@ -50,7 +50,8 @@ void ViewsDelegate::NotifyMenuItemFocused( #if defined(OS_WIN) HICON ViewsDelegate::GetDefaultWindowIcon() const { - return NULL; + // Use current exe's icon as default window icon. + return LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(1 /* IDR_MAINFRAME */)); } bool ViewsDelegate::IsWindowInMetro(gfx::NativeWindow window) const { From 964e1d6bb6f53dc535e05ef67eeef4bf2eafc3a9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 18 Jan 2015 16:42:32 -0800 Subject: [PATCH 0448/1195] Override DIR_APP_DATA on Linux --- brightray/browser/browser_context.cc | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 05f127755c1..7a9b56c0525 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -27,6 +27,23 @@ using content::BrowserThread; namespace brightray { +namespace { + +#if defined(OS_LINUX) +void OverrideLinuxAppDataPath() { + base::FilePath path; + if (PathService::Get(base::DIR_APP_DATA, &path)) + return; + scoped_ptr env(base::Environment::Create()); + path = base::nix::GetXDGDirectory(env.get(), + base::nix::kXdgConfigHomeEnvVar, + base::nix::kDotConfigDir); + PathService::Override(base::DIR_APP_DATA, path); +} +#endif + +} // namespace + class BrowserContext::ResourceContext : public content::ResourceContext { public: ResourceContext() : getter_(nullptr) {} @@ -51,16 +68,12 @@ BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { } void BrowserContext::Initialize() { - base::FilePath path; #if defined(OS_LINUX) - scoped_ptr env(base::Environment::Create()); - path = base::nix::GetXDGDirectory(env.get(), - base::nix::kXdgConfigHomeEnvVar, - base::nix::kDotConfigDir); -#else - CHECK(PathService::Get(base::DIR_APP_DATA, &path)); + OverrideLinuxAppDataPath(); #endif + base::FilePath path; + PathService::Get(base::DIR_APP_DATA, &path); path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); From 5b4e5a7e55954b176d9c480561840d29490fc199 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 18 Jan 2015 16:59:57 -0800 Subject: [PATCH 0449/1195] Override DIR_USER_DATA as data path --- brightray/brightray.gyp | 1 + brightray/browser/brightray_paths.h | 20 ++++++++++++++++++++ brightray/browser/browser_context.cc | 9 ++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 brightray/browser/brightray_paths.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 45b7bb5e4d0..ad90b1def86 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -30,6 +30,7 @@ ], }, 'sources': [ + 'browser/brightray_paths.h', 'browser/browser_client.cc', 'browser/browser_client.h', 'browser/browser_context.cc', diff --git a/brightray/browser/brightray_paths.h b/brightray/browser/brightray_paths.h new file mode 100644 index 00000000000..f856337e9f9 --- /dev/null +++ b/brightray/browser/brightray_paths.h @@ -0,0 +1,20 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BROWSER_BRIGHTRAY_PATHS_H_ +#define BROWSER_BRIGHTRAY_PATHS_H_ + +namespace brightray { + +enum { + PATH_START = 1000, + + DIR_USER_DATA = PATH_START, // Directory where user data can be written. + + PATH_END +}; + +} // namespace brightray + +#endif // BROWSER_BRIGHTRAY_PATHS_H_ diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 7a9b56c0525..ed4d9f5d185 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -4,6 +4,7 @@ #include "browser/browser_context.h" +#include "browser/brightray_paths.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/network_delegate.h" #include "common/application_info.h" @@ -72,9 +73,11 @@ void BrowserContext::Initialize() { OverrideLinuxAppDataPath(); #endif - base::FilePath path; - PathService::Get(base::DIR_APP_DATA, &path); - path_ = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); + if (!PathService::Get(DIR_USER_DATA, &path_)) { + PathService::Get(base::DIR_APP_DATA, &path_); + path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); + PathService::Override(DIR_USER_DATA, path_); + } auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); base::PrefServiceFactory prefs_factory; From 76e3d567605bd62edf8243ddbb4a24ac1d15c08d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 18 Jan 2015 17:19:25 -0800 Subject: [PATCH 0450/1195] Make DIR_APP_DATA available on Linux --- brightray/browser/brightray_paths.h | 14 ++++++++++++++ brightray/browser/browser_context.cc | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/brightray/browser/brightray_paths.h b/brightray/browser/brightray_paths.h index f856337e9f9..83a3a9f1cdb 100644 --- a/brightray/browser/brightray_paths.h +++ b/brightray/browser/brightray_paths.h @@ -5,6 +5,14 @@ #ifndef BROWSER_BRIGHTRAY_PATHS_H_ #define BROWSER_BRIGHTRAY_PATHS_H_ +#include "base/compiler_specific.h" + +#if defined(OS_WIN) +#include "base/base_paths_win.h" +#elif defined(OS_MACOSX) +#include "base/base_paths_mac.h" +#endif + namespace brightray { enum { @@ -12,6 +20,12 @@ enum { DIR_USER_DATA = PATH_START, // Directory where user data can be written. +#if defined(OS_LINUX) + DIR_APP_DATA, // Application Data directory under the user profile. +#else + DIR_APP_DATA = base::DIR_APP_DATA, +#endif + PATH_END }; diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index ed4d9f5d185..d07c591ca78 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -33,13 +33,13 @@ namespace { #if defined(OS_LINUX) void OverrideLinuxAppDataPath() { base::FilePath path; - if (PathService::Get(base::DIR_APP_DATA, &path)) + if (PathService::Get(DIR_APP_DATA, &path)) return; scoped_ptr env(base::Environment::Create()); path = base::nix::GetXDGDirectory(env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir); - PathService::Override(base::DIR_APP_DATA, path); + PathService::Override(DIR_APP_DATA, path); } #endif @@ -74,7 +74,7 @@ void BrowserContext::Initialize() { #endif if (!PathService::Get(DIR_USER_DATA, &path_)) { - PathService::Get(base::DIR_APP_DATA, &path_); + PathService::Get(DIR_APP_DATA, &path_); path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); PathService::Override(DIR_USER_DATA, path_); } From c9463d815c703cab66be965b925fe33ee4efba5f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 18 Jan 2015 17:34:36 -0800 Subject: [PATCH 0451/1195] linux: Override DIR_APP_DATA before loading .js --- brightray/browser/browser_context.cc | 26 ---------------------- brightray/browser/browser_main_parts.cc | 29 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index d07c591ca78..cb374ff4c94 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -9,7 +9,6 @@ #include "browser/network_delegate.h" #include "common/application_info.h" -#include "base/environment.h" #include "base/files/file_path.h" #include "base/path_service.h" #include "base/prefs/json_pref_store.h" @@ -20,31 +19,10 @@ #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" -#if defined(OS_LINUX) -#include "base/nix/xdg_util.h" -#endif - using content::BrowserThread; namespace brightray { -namespace { - -#if defined(OS_LINUX) -void OverrideLinuxAppDataPath() { - base::FilePath path; - if (PathService::Get(DIR_APP_DATA, &path)) - return; - scoped_ptr env(base::Environment::Create()); - path = base::nix::GetXDGDirectory(env.get(), - base::nix::kXdgConfigHomeEnvVar, - base::nix::kDotConfigDir); - PathService::Override(DIR_APP_DATA, path); -} -#endif - -} // namespace - class BrowserContext::ResourceContext : public content::ResourceContext { public: ResourceContext() : getter_(nullptr) {} @@ -69,10 +47,6 @@ BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { } void BrowserContext::Initialize() { -#if defined(OS_LINUX) - OverrideLinuxAppDataPath(); -#endif - if (!PathService::Get(DIR_USER_DATA, &path_)) { PathService::Get(DIR_APP_DATA, &path_); path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index e90a2f8a1c9..67d50d92306 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -26,6 +26,13 @@ #include "browser/views/views_delegate.h" #endif +#if defined(OS_LINUX) +#include "base/environment.h" +#include "base/path_service.h" +#include "base/nix/xdg_util.h" +#include "browser/brightray_paths.h" +#endif + #if defined(OS_WIN) #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" @@ -34,9 +41,9 @@ namespace brightray { -#if defined(OS_WIN) namespace { +#if defined(OS_WIN) // gfx::Font callbacks void AdjustUIFont(LOGFONT* logfont) { l10n_util::AdjustUIFont(logfont); @@ -45,9 +52,22 @@ void AdjustUIFont(LOGFONT* logfont) { int GetMinimumFontSize() { return 10; } +#endif + +#if defined(OS_LINUX) +void OverrideLinuxAppDataPath() { + base::FilePath path; + if (PathService::Get(DIR_APP_DATA, &path)) + return; + scoped_ptr env(base::Environment::Create()); + path = base::nix::GetXDGDirectory(env.get(), + base::nix::kXdgConfigHomeEnvVar, + base::nix::kDotConfigDir); + PathService::Override(DIR_APP_DATA, path); +} +#endif } // namespace -#endif BrowserMainParts::BrowserMainParts() { } @@ -64,10 +84,13 @@ void BrowserMainParts::PreEarlyInitialization() { views::LinuxUI::SetInstance(BuildGtk2UI()); #endif +#if defined(OS_LINUX) + OverrideLinuxAppDataPath(); +#endif + InitProxyResolverV8(); } - void BrowserMainParts::ToolkitInitialized() { #if defined(USE_AURA) && defined(USE_X11) views::LinuxUI::instance()->Initialize(); From 4bbe026d481190ce1d66b9c9aef5c4489f9ba5cb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 18 Jan 2015 21:00:47 -0800 Subject: [PATCH 0452/1195] register DIR_CACHE and DIR_USER_CACHE in path service --- brightray/browser/brightray_paths.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/brightray/browser/brightray_paths.h b/brightray/browser/brightray_paths.h index 83a3a9f1cdb..91e95f9791b 100644 --- a/brightray/browser/brightray_paths.h +++ b/brightray/browser/brightray_paths.h @@ -13,12 +13,17 @@ #include "base/base_paths_mac.h" #endif +#if defined(OS_POSIX) +#include "base/base_paths_posix.h" +#endif + namespace brightray { enum { PATH_START = 1000, DIR_USER_DATA = PATH_START, // Directory where user data can be written. + DIR_USER_CACHE, // Directory where user cache can be written. #if defined(OS_LINUX) DIR_APP_DATA, // Application Data directory under the user profile. @@ -26,6 +31,12 @@ enum { DIR_APP_DATA = base::DIR_APP_DATA, #endif +#if defined(OS_POSIX) + DIR_CACHE = base::DIR_CACHE, // Directory where to put cache data. +#else + DIR_CACHE = base::DIR_APP_DATA, +#endif + PATH_END }; From 98bf5bf3edcd05c258862110df434db5e9c41a36 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 23 Jan 2015 15:12:24 -0800 Subject: [PATCH 0453/1195] Implement CheckMediaAccessPermission Part of the fixes for #1017. --- brightray/browser/default_web_contents_delegate.cc | 7 +++++++ brightray/browser/default_web_contents_delegate.h | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/brightray/browser/default_web_contents_delegate.cc b/brightray/browser/default_web_contents_delegate.cc index 05bdac399ad..4c7051ba182 100644 --- a/brightray/browser/default_web_contents_delegate.cc +++ b/brightray/browser/default_web_contents_delegate.cc @@ -10,6 +10,13 @@ DefaultWebContentsDelegate::DefaultWebContentsDelegate() { DefaultWebContentsDelegate::~DefaultWebContentsDelegate() { } +bool DefaultWebContentsDelegate::CheckMediaAccessPermission( + content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type) { + return true; +} + void DefaultWebContentsDelegate::RequestMediaAccessPermission( content::WebContents*, const content::MediaStreamRequest& request, diff --git a/brightray/browser/default_web_contents_delegate.h b/brightray/browser/default_web_contents_delegate.h index e4d177c4af8..2e1ce681a7c 100644 --- a/brightray/browser/default_web_contents_delegate.h +++ b/brightray/browser/default_web_contents_delegate.h @@ -13,12 +13,15 @@ class DefaultWebContentsDelegate : public content::WebContentsDelegate { ~DefaultWebContentsDelegate(); protected: - virtual void RequestMediaAccessPermission( + bool CheckMediaAccessPermission(content::WebContents* web_contents, + const GURL& security_origin, + content::MediaStreamType type) override; + void RequestMediaAccessPermission( content::WebContents*, const content::MediaStreamRequest&, const content::MediaResponseCallback&) override; #if defined(OS_MACOSX) - virtual void HandleKeyboardEvent( + void HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent&) override; #endif }; From f922419f034f006740c5e15f28adf60ba6a11091 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 26 Jan 2015 22:38:01 +0800 Subject: [PATCH 0454/1195] Use libc++ on mac. --- brightray/brightray.gypi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 978ec372fd5..59e20227750 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -35,8 +35,8 @@ 'xcode_settings': { 'ALWAYS_SEARCH_USER_PATHS': 'NO', 'ARCHS': ['x86_64'], - 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11', - 'CLANG_CXX_LIBRARY': 'libstdc++', + 'CLANG_CXX_LANGUAGE_STANDARD': 'c++11', + 'CLANG_CXX_LIBRARY': 'libc++', 'COMBINE_HIDPI_IMAGES': 'YES', 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', 'GCC_ENABLE_CPP_RTTI': 'NO', From 9aa2fd9119ca9176ec24ea17a8b92b606b58a2ea Mon Sep 17 00:00:00 2001 From: DC Date: Fri, 30 Jan 2015 03:54:30 -0800 Subject: [PATCH 0455/1195] Fix the build on Linux See https://github.com/atom/atom-shell/issues/1074 for details --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 59e20227750..35b564358bc 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -203,6 +203,7 @@ }], ['OS=="linux"', { 'cflags_cc': [ + '-D__STRICT_ANSI__', '-std=gnu++11', '-fno-rtti', ' Date: Tue, 3 Feb 2015 10:42:52 -0800 Subject: [PATCH 0456/1195] Upgrade libchromiumcontent to 40.0.2214.91 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 7b360df11d8..3f108160ede 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 7b360df11d8797769930b616e48feccf74978359 +Subproject commit 3f108160eded696b3e843c2fbb4e5e2ac696555e From 02d632c4f70eb2ed84ba47783490dcf6885daf37 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 9 Jan 2015 16:00:26 -0800 Subject: [PATCH 0457/1195] Fix change of ShowDesktopNotification API --- brightray/browser/browser_client.cc | 3 ++- brightray/browser/browser_client.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 70a6790dfd8..a1c6d2f7719 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -69,7 +69,8 @@ net::URLRequestContextGetter* BrowserClient::CreateRequestContext( void BrowserClient::ShowDesktopNotification( const content::ShowDesktopNotificationHostMsgParams& params, - content::RenderFrameHost* render_frame_host, + content::BrowserContext* browser_context, + int render_process_id, scoped_ptr delegate, base::Closure* cancel_callback) { auto presenter = notification_presenter(); diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 9163d6c7021..e3e256249de 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -43,7 +43,8 @@ class BrowserClient : public content::ContentBrowserClient { const content::MainFunctionParams&) override; void ShowDesktopNotification( const content::ShowDesktopNotificationHostMsgParams& params, - content::RenderFrameHost* render_frame_host, + content::BrowserContext* browser_context, + int render_process_id, scoped_ptr delegate, base::Closure* cancel_callback) override; content::MediaObserver* GetMediaObserver() override; From dc01ba5a7237b8d70dc3551a079695919b42dc4a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 9 Jan 2015 16:02:57 -0800 Subject: [PATCH 0458/1195] scoped_ptr.PassAs is deprecated --- brightray/browser/url_request_context_getter.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index c2aadeba08b..5cafb8aed79 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -87,8 +87,7 @@ net::URLRequestJobFactory* URLRequestContextGetter::Delegate::CreateURLRequestJo base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); // Set up interceptors in the reverse order. - scoped_ptr top_job_factory = - job_factory.PassAs(); + scoped_ptr top_job_factory = job_factory.Pass(); content::URLRequestInterceptorScopedVector::reverse_iterator i; for (i = protocol_interceptors->rbegin(); i != protocol_interceptors->rend(); ++i) top_job_factory.reset(new net::URLRequestInterceptingJobFactory( @@ -169,7 +168,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { new net::MappedHostResolver(host_resolver.Pass())); remapped_resolver->SetRulesFromString( command_line.GetSwitchValueASCII(switches::kHostResolverRules)); - host_resolver = remapped_resolver.PassAs(); + host_resolver = remapped_resolver.Pass(); } // --proxy-server From c874219101b188cd2e4f615fdb7753f47ad5aea3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 9 Jan 2015 17:14:52 -0800 Subject: [PATCH 0459/1195] Use the new devtools API --- brightray/brightray.gyp | 6 +- brightray/browser/browser_client.cc | 4 +- brightray/browser/browser_main_parts.cc | 21 +++-- brightray/browser/browser_main_parts.h | 4 +- brightray/browser/devtools_delegate.h | 73 ---------------- ...legate.cc => devtools_manager_delegate.cc} | 87 ++++++++++--------- brightray/browser/devtools_manager_delegate.h | 43 +++++++++ brightray/browser/remote_debugging_server.cc | 44 ++++++++++ brightray/browser/remote_debugging_server.h | 31 +++++++ 9 files changed, 189 insertions(+), 124 deletions(-) delete mode 100644 brightray/browser/devtools_delegate.h rename brightray/browser/{devtools_delegate.cc => devtools_manager_delegate.cc} (75%) create mode 100644 brightray/browser/devtools_manager_delegate.h create mode 100644 brightray/browser/remote_debugging_server.cc create mode 100644 brightray/browser/remote_debugging_server.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index ad90b1def86..736d169ec6c 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -43,10 +43,10 @@ 'browser/default_web_contents_delegate_mac.mm', 'browser/devtools_contents_resizing_strategy.cc', 'browser/devtools_contents_resizing_strategy.h', - 'browser/devtools_delegate.cc', - 'browser/devtools_delegate.h', 'browser/devtools_embedder_message_dispatcher.cc', 'browser/devtools_embedder_message_dispatcher.h', + 'browser/devtools_manager_delegate.cc', + 'browser/devtools_manager_delegate.h', 'browser/devtools_ui.cc', 'browser/devtools_ui.h', 'browser/inspectable_web_contents.cc', @@ -73,6 +73,8 @@ 'browser/notification_presenter_mac.mm', 'browser/linux/notification_presenter_linux.h', 'browser/linux/notification_presenter_linux.cc', + 'browser/remote_debugging_server.cc', + 'browser/remote_debugging_server.h', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', 'browser/views/inspectable_web_contents_view_views.h', diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index a1c6d2f7719..b391cffaf8d 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -6,7 +6,7 @@ #include "browser/browser_context.h" #include "browser/browser_main_parts.h" -#include "browser/devtools_delegate.h" +#include "browser/devtools_manager_delegate.h" #include "browser/media/media_capture_devices_dispatcher.h" #include "browser/notification_presenter.h" @@ -98,7 +98,7 @@ base::FilePath BrowserClient::GetDefaultDownloadDirectory() { } content::DevToolsManagerDelegate* BrowserClient::GetDevToolsManagerDelegate() { - return new DevToolsManagerDelegate(browser_context()); + return new DevToolsManagerDelegate; } } // namespace brightray diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 67d50d92306..351bee9c988 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -4,10 +4,12 @@ #include "browser/browser_main_parts.h" -#include "base/command_line.h" #include "browser/browser_context.h" -#include "browser/devtools_delegate.h" +#include "browser/remote_debugging_server.h" #include "browser/web_ui_controller_factory.h" + +#include "base/command_line.h" +#include "base/strings/string_number_conversions.h" #include "content/public/common/content_switches.h" #include "net/proxy/proxy_resolver_v8.h" @@ -121,10 +123,17 @@ void BrowserMainParts::PreMainMessageLoopRun() { new WebUIControllerFactory(browser_context_.get())); content::WebUIControllerFactory::RegisterFactory( web_ui_controller_factory_.get()); - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kRemoteDebuggingPort)) { - devtools_delegate_.reset(new brightray::DevToolsDelegate( - browser_context())); + + // --remote-debugging-port + base::CommandLine* command_line = CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kRemoteDebuggingPort)) { + std::string port_str = command_line->GetSwitchValueASCII(switches::kRemoteDebuggingPort); + int port; + if (base::StringToInt(port_str, &port) && port >= 0 && port < 65535) + remote_debugging_server_.reset( + new RemoteDebuggingServer("127.0.0.1", static_cast(port))); + else + DLOG(WARNING) << "Invalid http debugger port number " << port; } } diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index a959b228f51..3e52af4bd50 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -25,7 +25,7 @@ namespace brightray { class BrowserContext; class WebUIControllerFactory; -class DevToolsDelegate; +class RemoteDebuggingServer; class BrowserMainParts : public content::BrowserMainParts { public: @@ -58,7 +58,7 @@ class BrowserMainParts : public content::BrowserMainParts { scoped_ptr browser_context_; scoped_ptr web_ui_controller_factory_; - scoped_ptr devtools_delegate_; + scoped_ptr remote_debugging_server_; #if defined(TOOLKIT_VIEWS) scoped_ptr views_delegate_; diff --git a/brightray/browser/devtools_delegate.h b/brightray/browser/devtools_delegate.h deleted file mode 100644 index b7fcc7b60c9..00000000000 --- a/brightray/browser/devtools_delegate.h +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE-CHROMIUM file. - -#ifndef BRIGHTRAY_DEVTOOLS_DELEGATE_H_ -#define BRIGHTRAY_DEVTOOLS_DELEGATE_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "content/public/browser/devtools_http_handler_delegate.h" -#include "content/public/browser/devtools_manager_delegate.h" - -namespace content { -class BrowserContext; -class DevToolsHttpHandler; -} - -namespace brightray { - -class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { - public: - explicit DevToolsDelegate(content::BrowserContext* browser_context); - virtual ~DevToolsDelegate(); - - // Stops http server. - void Stop(); - - // DevToolsHttpProtocolHandler::Delegate overrides. - std::string GetDiscoveryPageHTML() override; - bool BundlesFrontendResources() override; - base::FilePath GetDebugFrontendDir() override; - scoped_ptr CreateSocketForTethering( - net::StreamListenSocket::Delegate* delegate, - std::string* name) override; - - content::DevToolsHttpHandler* devtools_http_handler() { - return devtools_http_handler_; - } - - private: - content::BrowserContext* browser_context_; - content::DevToolsHttpHandler* devtools_http_handler_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); -}; - -class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { - public: - explicit DevToolsManagerDelegate(content::BrowserContext* browser_context); - virtual ~DevToolsManagerDelegate(); - - // DevToolsManagerDelegate implementation. - void Inspect(content::BrowserContext* browser_context, - content::DevToolsAgentHost* agent_host) override {} - void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host, - 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: - content::BrowserContext* browser_context_; - - DISALLOW_COPY_AND_ASSIGN(DevToolsManagerDelegate); -}; - -} // namespace brightray - -#endif // BRIGHTRAY_DEVTOOLS_DELEGATE_H_ diff --git a/brightray/browser/devtools_delegate.cc b/brightray/browser/devtools_manager_delegate.cc similarity index 75% rename from brightray/browser/devtools_delegate.cc rename to brightray/browser/devtools_manager_delegate.cc index 3cf57c4810e..2165b9c8524 100644 --- a/brightray/browser/devtools_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include "browser/devtools_delegate.h" +#include "browser/devtools_manager_delegate.h" #include #include "base/bind.h" #include "base/command_line.h" +#include "base/files/file_path.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" @@ -32,6 +33,8 @@ using content::BrowserContext; using content::DevToolsTarget; using content::DevToolsHttpHandler; +namespace brightray { + namespace { // A hack here: @@ -85,9 +88,9 @@ class Target : public content::DevToolsTarget { public: explicit Target(scoped_refptr agent_host); - virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); } - virtual std::string GetParentId() const OVERRIDE { return std::string(); } - virtual std::string GetType() const OVERRIDE { + 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; @@ -98,23 +101,19 @@ class Target : public content::DevToolsTarget { } return kTargetTypeOther; } - virtual std::string GetTitle() const OVERRIDE { - return agent_host_->GetTitle(); - } - virtual std::string GetDescription() const OVERRIDE { return std::string(); } - virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); } - virtual GURL GetFaviconURL() const OVERRIDE { return favicon_url_; } - virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { + 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_; } - virtual bool IsAttached() const OVERRIDE { - return agent_host_->IsAttached(); - } - virtual scoped_refptr GetAgentHost() const OVERRIDE { + bool IsAttached() const override { return agent_host_->IsAttached(); } + scoped_refptr GetAgentHost() const override { return agent_host_; } - virtual bool Activate() const OVERRIDE; - virtual bool Close() const OVERRIDE; + bool Activate() const override; + bool Close() const override; private: scoped_refptr agent_host_; @@ -141,27 +140,31 @@ bool Target::Close() const { return agent_host_->Close(); } -} // namespace - -namespace brightray { - // DevToolsDelegate -------------------------------------------------------- -DevToolsDelegate::DevToolsDelegate(content::BrowserContext* browser_context) - : browser_context_(browser_context) { - std::string frontend_url; - devtools_http_handler_ = DevToolsHttpHandler::Start( - CreateSocketFactory(), frontend_url, this, base::FilePath()); +class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { + public: + DevToolsDelegate(); + virtual ~DevToolsDelegate(); + + // content::DevToolsHttpHandlerDelegate. + std::string GetDiscoveryPageHTML() override; + bool BundlesFrontendResources() override; + base::FilePath GetDebugFrontendDir() override; + scoped_ptr CreateSocketForTethering( + net::StreamListenSocket::Delegate* delegate, + std::string* name) override; + + private: + DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); +}; + +DevToolsDelegate::DevToolsDelegate() { } DevToolsDelegate::~DevToolsDelegate() { } -void DevToolsDelegate::Stop() { - // The call below destroys this. - devtools_http_handler_->Stop(); -} - std::string DevToolsDelegate::GetDiscoveryPageHTML() { return ResourceBundle::GetSharedInstance().GetRawDataResource( kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); @@ -182,11 +185,20 @@ DevToolsDelegate::CreateSocketForTethering( return scoped_ptr(); } +} // namespace + // DevToolsManagerDelegate --------------------------------------------------- -DevToolsManagerDelegate::DevToolsManagerDelegate( - content::BrowserContext* browser_context) - : browser_context_(browser_context) { +// static +content::DevToolsHttpHandler* +DevToolsManagerDelegate::CreateHttpHandler() { + return DevToolsHttpHandler::Start(CreateSocketFactory(), + std::string(), + new DevToolsDelegate, + base::FilePath()); +} + +DevToolsManagerDelegate::DevToolsManagerDelegate() { } DevToolsManagerDelegate::~DevToolsManagerDelegate() { @@ -210,11 +222,8 @@ DevToolsManagerDelegate::CreateNewTarget(const GURL& url) { void DevToolsManagerDelegate::EnumerateTargets(TargetCallback callback) { TargetList targets; - content::DevToolsAgentHost::List agents = - content::DevToolsAgentHost::GetOrCreateAll(); - for (content::DevToolsAgentHost::List::iterator it = agents.begin(); - it != agents.end(); ++it) { - targets.push_back(new Target(*it)); + for (const auto& agent_host : DevToolsAgentHost::GetOrCreateAll()) { + targets.push_back(new Target(agent_host)); } callback.Run(targets); } diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h new file mode 100644 index 00000000000..529f1ff7b89 --- /dev/null +++ b/brightray/browser/devtools_manager_delegate.h @@ -0,0 +1,43 @@ +// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_ +#define BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "content/public/browser/devtools_http_handler_delegate.h" +#include "content/public/browser/devtools_manager_delegate.h" + +namespace content { +class DevToolsHttpHandler; +} + +namespace brightray { + +class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { + public: + static content::DevToolsHttpHandler* CreateHttpHandler(); + + DevToolsManagerDelegate(); + virtual ~DevToolsManagerDelegate(); + + // DevToolsManagerDelegate implementation. + void Inspect(content::BrowserContext* browser_context, + content::DevToolsAgentHost* agent_host) override {} + void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host, + 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); +}; + +} // namespace brightray + +#endif // BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_ diff --git a/brightray/browser/remote_debugging_server.cc b/brightray/browser/remote_debugging_server.cc new file mode 100644 index 00000000000..9aa004c313a --- /dev/null +++ b/brightray/browser/remote_debugging_server.cc @@ -0,0 +1,44 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/remote_debugging_server.h" + +#include "browser/devtools_manager_delegate.h" + +#include "base/files/file_util.h" +#include "content/public/browser/devtools_http_handler.h" +#include "net/socket/tcp_server_socket.h" + +namespace brightray { + +namespace { + +class TCPServerSocketFactory + : public content::DevToolsHttpHandler::ServerSocketFactory { + public: + TCPServerSocketFactory(const std::string& address, uint16 port, int backlog) + : content::DevToolsHttpHandler::ServerSocketFactory(address, port, backlog) {} + + private: + // content::DevToolsHttpHandler::ServerSocketFactory: + scoped_ptr Create() const override { + return scoped_ptr(new net::TCPServerSocket(NULL, net::NetLog::Source())); + } + + DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); +}; + +} // namespace + +RemoteDebuggingServer::RemoteDebuggingServer(const std::string& ip, uint16 port) { + scoped_ptr factory( + new TCPServerSocketFactory(ip, port, 1)); + devtools_http_handler_ = DevToolsManagerDelegate::CreateHttpHandler(); +} + +RemoteDebuggingServer::~RemoteDebuggingServer() { + devtools_http_handler_->Stop(); +} + +} // namespace brightray diff --git a/brightray/browser/remote_debugging_server.h b/brightray/browser/remote_debugging_server.h new file mode 100644 index 00000000000..ff0e5bcf497 --- /dev/null +++ b/brightray/browser/remote_debugging_server.h @@ -0,0 +1,31 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BROWSER_REMOTE_DEBUGGING_SERVER_H_ +#define BROWSER_REMOTE_DEBUGGING_SERVER_H_ + +#include + +#include "base/basictypes.h" + +namespace content { +class DevToolsHttpHandler; +} + +namespace brightray { + +class RemoteDebuggingServer { +public: + RemoteDebuggingServer(const std::string& ip, uint16 port); + virtual ~RemoteDebuggingServer(); + +private: + content::DevToolsHttpHandler* devtools_http_handler_; + + DISALLOW_COPY_AND_ASSIGN(RemoteDebuggingServer); +}; + +} // namespace brightray + +#endif // BROWSER_REMOTE_DEBUGGING_SERVER_H_ From 1c65f5d7d9a01a544fa20ad1a5ef55c31853158e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 9 Jan 2015 17:27:30 -0800 Subject: [PATCH 0460/1195] Fix cpplint warning --- brightray/browser/remote_debugging_server.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/remote_debugging_server.h b/brightray/browser/remote_debugging_server.h index ff0e5bcf497..89faf65730f 100644 --- a/brightray/browser/remote_debugging_server.h +++ b/brightray/browser/remote_debugging_server.h @@ -16,11 +16,11 @@ class DevToolsHttpHandler; namespace brightray { class RemoteDebuggingServer { -public: + public: RemoteDebuggingServer(const std::string& ip, uint16 port); virtual ~RemoteDebuggingServer(); -private: + private: content::DevToolsHttpHandler* devtools_http_handler_; DISALLOW_COPY_AND_ASSIGN(RemoteDebuggingServer); From 5e4c90f2648ce226c0a0d2686defbbada2776560 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 27 Jan 2015 17:18:46 -0800 Subject: [PATCH 0461/1195] NotificationError is discarded --- brightray/browser/linux/notification_presenter_linux.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index c31e3d01e9f..193e80c76d6 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -69,7 +69,7 @@ void NotificationPresenterLinux::ShowNotification( notify_notification_show(notification, &error); if (error) { log_and_clear_error(error, "notify_notification_show"); - delegate->NotificationError(); + g_object_unref(notification); return; } From b23da34ce97952c7962f8fac3b8589123b0beffe Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 12 Feb 2015 10:43:31 +0800 Subject: [PATCH 0462/1195] Upgrade to latest gyp --- brightray/vendor/gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/gyp b/brightray/vendor/gyp index 81cdff9bb79..e0ee72ddc7f 160000 --- a/brightray/vendor/gyp +++ b/brightray/vendor/gyp @@ -1 +1 @@ -Subproject commit 81cdff9bb79bff2fcfe51ba4637fe8ebdd4ffb7f +Subproject commit e0ee72ddc7fb97eb33d530cf684efcbe4d27ecb3 From 33f0b2ad895d662ee5bccb6f84680e2585c9b3b8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 4 Mar 2015 18:15:08 -0800 Subject: [PATCH 0463/1195] Upgrade to Chrome 41 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 3f108160ede..531d92bd1c5 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 3f108160eded696b3e843c2fbb4e5e2ac696555e +Subproject commit 531d92bd1c52e54376b09ee20e128a5e284cceb2 From c0356f0269486d1df60b75d81af064d3773e0b56 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Mar 2015 19:02:38 -0700 Subject: [PATCH 0464/1195] Fix ui/gfx/geometry headers --- brightray/browser/devtools_contents_resizing_strategy.h | 6 +++--- brightray/browser/devtools_embedder_message_dispatcher.h | 6 +++--- brightray/browser/inspectable_web_contents_impl.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/brightray/browser/devtools_contents_resizing_strategy.h b/brightray/browser/devtools_contents_resizing_strategy.h index 806d78a7156..9c82c060b1e 100644 --- a/brightray/browser/devtools_contents_resizing_strategy.h +++ b/brightray/browser/devtools_contents_resizing_strategy.h @@ -6,9 +6,9 @@ #define BRIGHTRAY_BROWSER_DEVTOOLS_CONTENTS_RESIZING_STRATEGY_H_ #include "base/basictypes.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" +#include "ui/gfx/geometry/insets.h" +#include "ui/gfx/geometry/rect.h" +#include "ui/gfx/geometry/size.h" // This class knows how to resize both DevTools and inspected WebContents // inside a browser window hierarchy. diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index 1b0bf9e3a02..defe16c1f43 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -9,9 +9,9 @@ #include #include "base/callback.h" -#include "ui/gfx/insets.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" +#include "ui/gfx/geometry/insets.h" +#include "ui/gfx/geometry/rect.h" +#include "ui/gfx/geometry/size.h" namespace base { class ListValue; diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 9c80be071d6..075ee320d9e 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -15,7 +15,7 @@ #include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" -#include "ui/gfx/rect.h" +#include "ui/gfx/geometry/rect.h" class PrefRegistrySimple; From 8467fee8d8e2a235d2604c6e6d20497e550c3338 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Mar 2015 19:07:53 -0700 Subject: [PATCH 0465/1195] Fix devtools_manager_delegate.cc --- brightray/browser/devtools_manager_delegate.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index 2165b9c8524..014a3d825c4 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -24,6 +24,7 @@ #include "content/public/common/url_constants.h" #include "content/public/common/user_agent.h" #include "net/socket/tcp_server_socket.h" +#include "net/socket/stream_socket.h" #include "ui/base/resource/resource_bundle.h" using content::DevToolsAgentHost; @@ -65,7 +66,7 @@ class TCPServerSocketFactory scoped_ptr CreateSocketFactory() { - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + auto& command_line = *base::CommandLine::ForCurrentProcess(); // See if the user specified a port on the command line (useful for // automation). If not, use an ephemeral port by specifying 0. int port = 0; @@ -151,8 +152,7 @@ class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { std::string GetDiscoveryPageHTML() override; bool BundlesFrontendResources() override; base::FilePath GetDebugFrontendDir() override; - scoped_ptr CreateSocketForTethering( - net::StreamListenSocket::Delegate* delegate, + scoped_ptr CreateSocketForTethering( std::string* name) override; private: @@ -178,11 +178,9 @@ base::FilePath DevToolsDelegate::GetDebugFrontendDir() { return base::FilePath(); } -scoped_ptr -DevToolsDelegate::CreateSocketForTethering( - net::StreamListenSocket::Delegate* delegate, +scoped_ptr DevToolsDelegate::CreateSocketForTethering( std::string* name) { - return scoped_ptr(); + return scoped_ptr(); } } // namespace From 99e2dbd6e88624e3b6b66c34b6664ecdaa3c8df4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Mar 2015 19:13:17 -0700 Subject: [PATCH 0466/1195] Fix inspectable_web_contents_impl.h --- brightray/browser/inspectable_web_contents_impl.cc | 10 ++++++---- brightray/browser/inspectable_web_contents_impl.h | 3 ++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 4fae3a1ae12..0e09fba1a3f 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -317,10 +317,11 @@ void InspectableWebContentsImpl::AgentHostClosed( content::DevToolsAgentHost* agent_host, bool replaced) { } -void InspectableWebContentsImpl::AboutToNavigateRenderView( - content::RenderViewHost* render_view_host) { - frontend_host_.reset(content::DevToolsFrontendHost::Create( - render_view_host, this)); +void InspectableWebContentsImpl::AboutToNavigateRenderFrame( + content::RenderFrameHost* new_host) { + if (new_host->GetParent()) + return; + frontend_host_.reset(content::DevToolsFrontendHost::Create(new_host, this)); } void InspectableWebContentsImpl::DidFinishLoad(content::RenderFrameHost* render_frame_host, @@ -355,6 +356,7 @@ bool InspectableWebContentsImpl::AddMessageToConsole( bool InspectableWebContentsImpl::ShouldCreateWebContents( content::WebContents* web_contents, int route_id, + int main_frame_route_id, WindowContainerType window_container_type, const base::string16& frame_name, const GURL& target_url, diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 075ee320d9e..7e249e8aa65 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -104,7 +104,7 @@ class InspectableWebContentsImpl : bool replaced) override; // content::WebContentsObserver: - void AboutToNavigateRenderView(content::RenderViewHost* render_view_host) override; + void AboutToNavigateRenderFrame(content::RenderFrameHost* new_host) override; void DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url) override; void WebContentsDestroyed() override; @@ -118,6 +118,7 @@ class InspectableWebContentsImpl : bool ShouldCreateWebContents( content::WebContents* web_contents, int route_id, + int main_frame_route_id, WindowContainerType window_container_type, const base::string16& frame_name, const GURL& target_url, From a5026907e47f0b89900fbee2bc7a3a517dfc26f6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Mar 2015 19:37:13 -0700 Subject: [PATCH 0467/1195] Implement PlatformNotificationService --- brightray/brightray.gyp | 2 + brightray/browser/browser_client.cc | 25 ++------ brightray/browser/browser_client.h | 10 +-- brightray/browser/notification_presenter.h | 4 +- .../browser/notification_presenter_mac.h | 2 +- .../browser/notification_presenter_mac.mm | 8 +-- .../platform_notification_service_impl.cc | 64 +++++++++++++++++++ .../platform_notification_service_impl.h | 61 ++++++++++++++++++ 8 files changed, 140 insertions(+), 36 deletions(-) create mode 100644 brightray/browser/platform_notification_service_impl.cc create mode 100644 brightray/browser/platform_notification_service_impl.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 736d169ec6c..17057574e68 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -71,6 +71,8 @@ 'browser/notification_presenter.h', 'browser/notification_presenter_mac.h', 'browser/notification_presenter_mac.mm', + 'browser/platform_notification_service_impl.cc', + 'browser/platform_notification_service_impl.h', 'browser/linux/notification_presenter_linux.h', 'browser/linux/notification_presenter_linux.cc', 'browser/remote_debugging_server.cc', diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index b391cffaf8d..b884cdcdbf1 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -8,7 +8,7 @@ #include "browser/browser_main_parts.h" #include "browser/devtools_manager_delegate.h" #include "browser/media/media_capture_devices_dispatcher.h" -#include "browser/notification_presenter.h" +#include "browser/platform_notification_service_impl.h" #include "base/base_paths.h" #include "base/path_service.h" @@ -39,14 +39,6 @@ BrowserContext* BrowserClient::browser_context() { return browser_main_parts_->browser_context(); } -NotificationPresenter* BrowserClient::notification_presenter() { -#if defined(OS_MACOSX) || defined(OS_LINUX) - if (!notification_presenter_) - notification_presenter_.reset(NotificationPresenter::Create()); -#endif - return notification_presenter_.get(); -} - BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts( const content::MainFunctionParams&) { return new BrowserMainParts; @@ -67,21 +59,14 @@ net::URLRequestContextGetter* BrowserClient::CreateRequestContext( return context->CreateRequestContext(protocol_handlers, protocol_interceptors.Pass()); } -void BrowserClient::ShowDesktopNotification( - const content::ShowDesktopNotificationHostMsgParams& params, - content::BrowserContext* browser_context, - int render_process_id, - scoped_ptr delegate, - base::Closure* cancel_callback) { - auto presenter = notification_presenter(); - if (presenter) - presenter->ShowNotification(params, delegate.Pass(), cancel_callback); -} - content::MediaObserver* BrowserClient::GetMediaObserver() { return MediaCaptureDevicesDispatcher::GetInstance(); } +content::PlatformNotificationService* BrowserClient::GetPlatformNotificationService() { + return PlatformNotificationServiceImpl::GetInstance(); +} + void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) { additional_schemes->push_back(content::kChromeDevToolsScheme); diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index e3e256249de..fad326e10bc 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -11,7 +11,6 @@ namespace brightray { class BrowserContext; class BrowserMainParts; -class NotificationPresenter; class BrowserClient : public content::ContentBrowserClient { public: @@ -22,7 +21,6 @@ class BrowserClient : public content::ContentBrowserClient { BrowserContext* browser_context(); BrowserMainParts* browser_main_parts() { return browser_main_parts_; } - NotificationPresenter* notification_presenter(); protected: // Subclasses should override this to provide their own BrowserMainParts @@ -41,20 +39,14 @@ class BrowserClient : public content::ContentBrowserClient { private: content::BrowserMainParts* CreateBrowserMainParts( const content::MainFunctionParams&) override; - void ShowDesktopNotification( - const content::ShowDesktopNotificationHostMsgParams& params, - content::BrowserContext* browser_context, - int render_process_id, - scoped_ptr delegate, - base::Closure* cancel_callback) override; content::MediaObserver* GetMediaObserver() override; + content::PlatformNotificationService* GetPlatformNotificationService() override; void GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) override; base::FilePath GetDefaultDownloadDirectory() override; content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override; BrowserMainParts* browser_main_parts_; - scoped_ptr notification_presenter_; DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index 6c7def322ae..ad17cdb3c53 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -6,7 +6,7 @@ namespace content { class DesktopNotificationDelegate; -struct ShowDesktopNotificationHostMsgParams; +struct PlatformNotificationData; } namespace brightray { @@ -18,7 +18,7 @@ class NotificationPresenter { static NotificationPresenter* Create(); virtual void ShowNotification( - const content::ShowDesktopNotificationHostMsgParams&, + const content::PlatformNotificationData&, scoped_ptr delegate, base::Closure* cancel_callback) = 0; }; diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index 508ad315f01..0ba7fe7c35e 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -21,7 +21,7 @@ class NotificationPresenterMac : public NotificationPresenter { ~NotificationPresenterMac(); virtual void ShowNotification( - const content::ShowDesktopNotificationHostMsgParams&, + const content::PlatformNotificationData&, scoped_ptr delegate, base::Closure* cancel_callback) override; diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 78e3cc2fd45..f0a08d75974 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -8,8 +8,8 @@ #include "base/bind.h" #include "base/stl_util.h" #include "base/strings/sys_string_conversions.h" +#include "content/public/common/platform_notification_data.h" #include "content/public/browser/desktop_notification_delegate.h" -#include "content/public/common/show_desktop_notification_params.h" #import @@ -40,12 +40,12 @@ NotificationPresenterMac::~NotificationPresenterMac() { } void NotificationPresenterMac::ShowNotification( - const content::ShowDesktopNotificationHostMsgParams& params, + const content::PlatformNotificationData& data, scoped_ptr delegate, base::Closure* cancel_callback) { auto notification = [[NSUserNotification alloc] init]; - notification.title = base::SysUTF16ToNSString(params.title); - notification.informativeText = base::SysUTF16ToNSString(params.body); + notification.title = base::SysUTF16ToNSString(data.title); + notification.informativeText = base::SysUTF16ToNSString(data.body); notifications_map_[delegate.get()].reset(notification); [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service_impl.cc new file mode 100644 index 00000000000..f47d3851198 --- /dev/null +++ b/brightray/browser/platform_notification_service_impl.cc @@ -0,0 +1,64 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/platform_notification_service_impl.h" + +#include "browser/notification_presenter.h" + +#include "content/public/browser/desktop_notification_delegate.h" + +namespace brightray { + +// static +PlatformNotificationServiceImpl* +PlatformNotificationServiceImpl::GetInstance() { + return Singleton::get(); +} + +PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {} +PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} + +NotificationPresenter* PlatformNotificationServiceImpl::notification_presenter() { +#if defined(OS_MACOSX) || defined(OS_LINUX) + if (!notification_presenter_) + notification_presenter_.reset(NotificationPresenter::Create()); +#endif + return notification_presenter_.get(); +} + +blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermission( + content::ResourceContext* resource_context, + const GURL& origin, + int render_process_id) { + return blink::WebNotificationPermissionAllowed; +} + +void PlatformNotificationServiceImpl::DisplayNotification( + content::BrowserContext* browser_context, + const GURL& origin, + const SkBitmap& icon, + const content::PlatformNotificationData& notification_data, + scoped_ptr delegate, + int render_process_id, + base::Closure* cancel_callback) { + auto presenter = notification_presenter(); + if (presenter) + presenter->ShowNotification(notification_data, delegate.Pass(), cancel_callback); +} + +void PlatformNotificationServiceImpl::DisplayPersistentNotification( + content::BrowserContext* browser_context, + int64 service_worker_registration_id, + const GURL& origin, + const SkBitmap& icon, + const content::PlatformNotificationData& notification_data, + int render_process_id) { +} + +void PlatformNotificationServiceImpl::ClosePersistentNotification( + content::BrowserContext* browser_context, + const std::string& persistent_notification_id) { +} + +} // namespace brightray diff --git a/brightray/browser/platform_notification_service_impl.h b/brightray/browser/platform_notification_service_impl.h new file mode 100644 index 00000000000..1a542bcc89b --- /dev/null +++ b/brightray/browser/platform_notification_service_impl.h @@ -0,0 +1,61 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ +#define BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ + +#include "base/memory/singleton.h" +#include "content/public/browser/platform_notification_service.h" + +namespace brightray { + +class NotificationPresenter; + +class PlatformNotificationServiceImpl + : public content::PlatformNotificationService { + public: + // Returns the active instance of the service in the browser process. Safe to + // be called from any thread. + static PlatformNotificationServiceImpl* GetInstance(); + + NotificationPresenter* notification_presenter(); + + private: + friend struct DefaultSingletonTraits; + + PlatformNotificationServiceImpl(); + ~PlatformNotificationServiceImpl() override; + + // content::PlatformNotificationService: + virtual blink::WebNotificationPermission CheckPermission( + content::ResourceContext* resource_context, + const GURL& origin, + int render_process_id) override; + virtual void DisplayNotification( + content::BrowserContext* browser_context, + const GURL& origin, + const SkBitmap& icon, + const content::PlatformNotificationData& notification_data, + scoped_ptr delegate, + int render_process_id, + base::Closure* cancel_callback) override; + virtual void DisplayPersistentNotification( + content::BrowserContext* browser_context, + int64 service_worker_registration_id, + const GURL& origin, + const SkBitmap& icon, + const content::PlatformNotificationData& notification_data, + int render_process_id) override; + virtual void ClosePersistentNotification( + content::BrowserContext* browser_context, + const std::string& persistent_notification_id) override; + + scoped_ptr notification_presenter_; + + DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); +}; + +} // namespace brightray + +#endif // BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ From 95f0f25dc473fe2b340b31ed12af236ddd31087e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Mar 2015 19:38:40 -0700 Subject: [PATCH 0468/1195] Fix inspectable_web_contents_impl.cc --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 0e09fba1a3f..ba85417f59c 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -162,7 +162,7 @@ void InspectableWebContentsImpl::ShowDevTools() { agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()); frontend_host_.reset(content::DevToolsFrontendHost::Create( - web_contents_->GetRenderViewHost(), this)); + web_contents_->GetMainFrame(), this)); agent_host_->AttachClient(this); GURL devtools_url(base::StringPrintf(kChromeUIDevToolsURL, can_dock_ ? "true" : "")); From 2837b730f2138637ad28c735d81c444cf6f56fa1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Mar 2015 19:47:12 -0700 Subject: [PATCH 0469/1195] Fix network_delegate.cc --- brightray/browser/network_delegate.cc | 29 +++++++++-- brightray/browser/network_delegate.h | 73 +++++++++++++++------------ 2 files changed, 67 insertions(+), 35 deletions(-) diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index ec019a5f281..a065a6ebf06 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -21,6 +21,15 @@ int NetworkDelegate::OnBeforeURLRequest( return net::OK; } +void NetworkDelegate::OnResolveProxy(const GURL& url, + int load_flags, + const net::ProxyService& proxy_service, + net::ProxyInfo* result) { +} + +void NetworkDelegate::OnProxyFallback(const net::ProxyServer& bad_proxy, int net_error) { +} + int NetworkDelegate::OnBeforeSendHeaders( net::URLRequest* request, const net::CompletionCallback& callback, @@ -28,6 +37,11 @@ int NetworkDelegate::OnBeforeSendHeaders( return net::OK; } +void NetworkDelegate::OnBeforeSendProxyHeaders(net::URLRequest* request, + const net::ProxyInfo& proxy_info, + net::HttpRequestHeaders* headers) { +} + void NetworkDelegate::OnSendHeaders( net::URLRequest* request, const net::HttpRequestHeaders& headers) { @@ -92,10 +106,17 @@ bool NetworkDelegate::OnCanThrottleRequest( return false; } -int NetworkDelegate::OnBeforeSocketStreamConnect( - net::SocketStream* socket, - const net::CompletionCallback& callback) { - return net::OK; +bool NetworkDelegate::OnCanEnablePrivacyMode( + const GURL& url, + const GURL& first_party_for_cookies) const { + return false; +} + +bool NetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( + const net::URLRequest& request, + const GURL& target_url, + const GURL& referrer_url) const { + return false; } } // namespace brightray diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 2279b3c9815..fcfbdbb8927 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -15,46 +15,57 @@ class NetworkDelegate : public net::NetworkDelegate { virtual ~NetworkDelegate(); protected: - virtual int OnBeforeURLRequest(net::URLRequest* request, - const net::CompletionCallback& callback, - GURL* new_url) override; - virtual int OnBeforeSendHeaders(net::URLRequest* request, - const net::CompletionCallback& callback, - net::HttpRequestHeaders* headers) override; - virtual void OnSendHeaders(net::URLRequest* request, - const net::HttpRequestHeaders& headers) override; - virtual int OnHeadersReceived( + int OnBeforeURLRequest(net::URLRequest* request, + const net::CompletionCallback& callback, + GURL* new_url) override; + void OnResolveProxy(const GURL& url, + int load_flags, + const net::ProxyService& proxy_service, + net::ProxyInfo* result) override; + void OnProxyFallback(const net::ProxyServer& bad_proxy, int net_error) override; + int OnBeforeSendHeaders(net::URLRequest* request, + const net::CompletionCallback& callback, + net::HttpRequestHeaders* headers) override; + void OnBeforeSendProxyHeaders(net::URLRequest* request, + const net::ProxyInfo& proxy_info, + net::HttpRequestHeaders* headers) override; + void OnSendHeaders(net::URLRequest* request, + const net::HttpRequestHeaders& headers) override; + int OnHeadersReceived( net::URLRequest* request, const net::CompletionCallback& callback, const net::HttpResponseHeaders* original_response_headers, scoped_refptr* override_response_headers, GURL* allowed_unsafe_redirect_url) override; - virtual void OnBeforeRedirect(net::URLRequest* request, - const GURL& new_location) override; - virtual void OnResponseStarted(net::URLRequest* request) override; - virtual void OnRawBytesRead(const net::URLRequest& request, - int bytes_read) override; - virtual void OnCompleted(net::URLRequest* request, bool started) override; - virtual void OnURLRequestDestroyed(net::URLRequest* request) override; - virtual void OnPACScriptError(int line_number, - const base::string16& error) override; - virtual AuthRequiredResponse OnAuthRequired( + void OnBeforeRedirect(net::URLRequest* request, + const GURL& new_location) override; + void OnResponseStarted(net::URLRequest* request) override; + void OnRawBytesRead(const net::URLRequest& request, + int bytes_read) override; + void OnCompleted(net::URLRequest* request, bool started) override; + void OnURLRequestDestroyed(net::URLRequest* request) override; + void OnPACScriptError(int line_number, + const base::string16& error) override; + AuthRequiredResponse OnAuthRequired( net::URLRequest* request, const net::AuthChallengeInfo& auth_info, const AuthCallback& callback, net::AuthCredentials* credentials) override; - virtual bool OnCanGetCookies(const net::URLRequest& request, - const net::CookieList& cookie_list) override; - virtual bool OnCanSetCookie(const net::URLRequest& request, - const std::string& cookie_line, - net::CookieOptions* options) override; - virtual bool OnCanAccessFile(const net::URLRequest& request, - const base::FilePath& path) const override; - virtual bool OnCanThrottleRequest( - const net::URLRequest& request) const override; - virtual int OnBeforeSocketStreamConnect( - net::SocketStream* stream, - const net::CompletionCallback& callback) override; + bool OnCanGetCookies(const net::URLRequest& request, + const net::CookieList& cookie_list) override; + bool OnCanSetCookie(const net::URLRequest& request, + const std::string& cookie_line, + net::CookieOptions* options) override; + bool OnCanAccessFile(const net::URLRequest& request, + const base::FilePath& path) const override; + bool OnCanThrottleRequest(const net::URLRequest& request) const override; + bool OnCanEnablePrivacyMode( + const GURL& url, + const GURL& first_party_for_cookies) const override; + bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( + const net::URLRequest& request, + const GURL& target_url, + const GURL& referrer_url) const override; private: DISALLOW_COPY_AND_ASSIGN(NetworkDelegate); From f04ee342ea057b655f965d580da4112bfe56f08c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Mar 2015 19:53:37 -0700 Subject: [PATCH 0470/1195] Remove RemoteDebuggingServer class --- brightray/brightray.gyp | 2 - brightray/browser/browser_main_parts.cc | 16 +++---- brightray/browser/browser_main_parts.h | 7 +++- brightray/browser/remote_debugging_server.cc | 44 -------------------- brightray/browser/remote_debugging_server.h | 31 -------------- 5 files changed, 10 insertions(+), 90 deletions(-) delete mode 100644 brightray/browser/remote_debugging_server.cc delete mode 100644 brightray/browser/remote_debugging_server.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 17057574e68..df52343db24 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -75,8 +75,6 @@ 'browser/platform_notification_service_impl.h', 'browser/linux/notification_presenter_linux.h', 'browser/linux/notification_presenter_linux.cc', - 'browser/remote_debugging_server.cc', - 'browser/remote_debugging_server.h', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', 'browser/views/inspectable_web_contents_view_views.h', diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 351bee9c988..de938eacd99 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -5,11 +5,12 @@ #include "browser/browser_main_parts.h" #include "browser/browser_context.h" -#include "browser/remote_debugging_server.h" +#include "browser/devtools_manager_delegate.h" #include "browser/web_ui_controller_factory.h" #include "base/command_line.h" #include "base/strings/string_number_conversions.h" +#include "content/public/browser/devtools_http_handler.h" #include "content/public/common/content_switches.h" #include "net/proxy/proxy_resolver_v8.h" @@ -125,16 +126,9 @@ void BrowserMainParts::PreMainMessageLoopRun() { web_ui_controller_factory_.get()); // --remote-debugging-port - base::CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (command_line->HasSwitch(switches::kRemoteDebuggingPort)) { - std::string port_str = command_line->GetSwitchValueASCII(switches::kRemoteDebuggingPort); - int port; - if (base::StringToInt(port_str, &port) && port >= 0 && port < 65535) - remote_debugging_server_.reset( - new RemoteDebuggingServer("127.0.0.1", static_cast(port))); - else - DLOG(WARNING) << "Invalid http debugger port number " << port; - } + auto command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(switches::kRemoteDebuggingPort)) + devtools_http_handler_.reset(DevToolsManagerDelegate::CreateHttpHandler()); } void BrowserMainParts::PostMainMessageLoopRun() { diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 3e52af4bd50..59674ef2e53 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -9,6 +9,10 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" +namespace content { +class DevToolsHttpHandler; +} + #if defined(TOOLKIT_VIEWS) namespace brightray { class ViewsDelegate; @@ -25,7 +29,6 @@ namespace brightray { class BrowserContext; class WebUIControllerFactory; -class RemoteDebuggingServer; class BrowserMainParts : public content::BrowserMainParts { public: @@ -58,7 +61,7 @@ class BrowserMainParts : public content::BrowserMainParts { scoped_ptr browser_context_; scoped_ptr web_ui_controller_factory_; - scoped_ptr remote_debugging_server_; + scoped_ptr devtools_http_handler_; #if defined(TOOLKIT_VIEWS) scoped_ptr views_delegate_; diff --git a/brightray/browser/remote_debugging_server.cc b/brightray/browser/remote_debugging_server.cc deleted file mode 100644 index 9aa004c313a..00000000000 --- a/brightray/browser/remote_debugging_server.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE-CHROMIUM file. - -#include "browser/remote_debugging_server.h" - -#include "browser/devtools_manager_delegate.h" - -#include "base/files/file_util.h" -#include "content/public/browser/devtools_http_handler.h" -#include "net/socket/tcp_server_socket.h" - -namespace brightray { - -namespace { - -class TCPServerSocketFactory - : public content::DevToolsHttpHandler::ServerSocketFactory { - public: - TCPServerSocketFactory(const std::string& address, uint16 port, int backlog) - : content::DevToolsHttpHandler::ServerSocketFactory(address, port, backlog) {} - - private: - // content::DevToolsHttpHandler::ServerSocketFactory: - scoped_ptr Create() const override { - return scoped_ptr(new net::TCPServerSocket(NULL, net::NetLog::Source())); - } - - DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); -}; - -} // namespace - -RemoteDebuggingServer::RemoteDebuggingServer(const std::string& ip, uint16 port) { - scoped_ptr factory( - new TCPServerSocketFactory(ip, port, 1)); - devtools_http_handler_ = DevToolsManagerDelegate::CreateHttpHandler(); -} - -RemoteDebuggingServer::~RemoteDebuggingServer() { - devtools_http_handler_->Stop(); -} - -} // namespace brightray diff --git a/brightray/browser/remote_debugging_server.h b/brightray/browser/remote_debugging_server.h deleted file mode 100644 index 89faf65730f..00000000000 --- a/brightray/browser/remote_debugging_server.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2015 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE-CHROMIUM file. - -#ifndef BROWSER_REMOTE_DEBUGGING_SERVER_H_ -#define BROWSER_REMOTE_DEBUGGING_SERVER_H_ - -#include - -#include "base/basictypes.h" - -namespace content { -class DevToolsHttpHandler; -} - -namespace brightray { - -class RemoteDebuggingServer { - public: - RemoteDebuggingServer(const std::string& ip, uint16 port); - virtual ~RemoteDebuggingServer(); - - private: - content::DevToolsHttpHandler* devtools_http_handler_; - - DISALLOW_COPY_AND_ASSIGN(RemoteDebuggingServer); -}; - -} // namespace brightray - -#endif // BROWSER_REMOTE_DEBUGGING_SERVER_H_ From 5e1a4e122226309ad16583e38156040200a8d1f8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Mar 2015 19:54:27 -0700 Subject: [PATCH 0471/1195] Fix url_request_context_getter.cc --- brightray/browser/url_request_context_getter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 5cafb8aed79..8a142939818 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -142,7 +142,7 @@ net::HostResolver* URLRequestContextGetter::host_resolver() { net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + auto& command_line = *base::CommandLine::ForCurrentProcess(); if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext); network_delegate_.reset(delegate_->CreateNetworkDelegate()); From bb8da7ec7e8ae82ec7a65c41e7ef6fc86afdf1fa Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Mar 2015 19:56:45 -0700 Subject: [PATCH 0472/1195] Fix browser_context.cc --- brightray/browser/browser_context.cc | 5 +++++ brightray/browser/browser_context.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index cb374ff4c94..6d2a378be80 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -99,6 +99,11 @@ base::FilePath BrowserContext::GetPath() const { return path_; } +scoped_ptr BrowserContext::CreateZoomLevelDelegate( + const base::FilePath& partition_path) { + return scoped_ptr(); +} + bool BrowserContext::IsOffTheRecord() const { return false; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 90cefbcf795..ec1dd095b23 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -46,6 +46,8 @@ class BrowserContext : public content::BrowserContext, void RegisterInternalPrefs(PrefRegistrySimple* pref_registry); + scoped_ptr CreateZoomLevelDelegate( + const base::FilePath& partition_path) override; bool IsOffTheRecord() const override; net::URLRequestContextGetter* GetRequestContext() override; net::URLRequestContextGetter* GetRequestContextForRenderProcess( From 56a16915884868fc39d5d3ca0696ec15c4680078 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 8 Mar 2015 20:04:25 -0700 Subject: [PATCH 0473/1195] MEDIA_LOOPBACK_AUDIO_CAPTURE renamed to MEDIA_DESKTOP_AUDIO_CAPTURE --- .../browser/media/media_stream_devices_controller.cc | 12 ++++++------ .../browser/media/media_stream_devices_controller.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index b55e73844f9..3d4f4cc3328 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -51,7 +51,7 @@ bool MediaStreamDevicesController::TakeAction() { // Do special handling of desktop screen cast. if (request_.audio_type == content::MEDIA_TAB_AUDIO_CAPTURE || request_.video_type == content::MEDIA_TAB_VIDEO_CAPTURE || - request_.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE || + request_.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE || request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { HandleUserMediaRequest(); return true; @@ -59,7 +59,7 @@ bool MediaStreamDevicesController::TakeAction() { // Deny the request if there is no device attached to the OS. if (!HasAnyAvailableDevice()) { - Deny(); + Deny(content::MEDIA_DEVICE_NO_HARDWARE); return true; } @@ -149,11 +149,11 @@ void MediaStreamDevicesController::Accept() { cb.Run(devices, content::MEDIA_DEVICE_OK, scoped_ptr()); } -void MediaStreamDevicesController::Deny() { +void MediaStreamDevicesController::Deny(content::MediaStreamRequestResult result) { content::MediaResponseCallback cb = callback_; callback_.Reset(); cb.Run(content::MediaStreamDevices(), - content::MEDIA_DEVICE_PERMISSION_DENIED, + result, scoped_ptr()); } @@ -168,9 +168,9 @@ void MediaStreamDevicesController::HandleUserMediaRequest() { devices.push_back(content::MediaStreamDevice( content::MEDIA_TAB_VIDEO_CAPTURE, "", "")); } - if (request_.audio_type == content::MEDIA_LOOPBACK_AUDIO_CAPTURE) { + if (request_.audio_type == content::MEDIA_DESKTOP_AUDIO_CAPTURE) { devices.push_back(content::MediaStreamDevice( - content::MEDIA_LOOPBACK_AUDIO_CAPTURE, "loopback", "System Audio")); + content::MEDIA_DESKTOP_AUDIO_CAPTURE, "loopback", "System Audio")); } if (request_.video_type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) { content::DesktopMediaID screen_id; diff --git a/brightray/browser/media/media_stream_devices_controller.h b/brightray/browser/media/media_stream_devices_controller.h index e77af477027..47aacfb66b6 100644 --- a/brightray/browser/media/media_stream_devices_controller.h +++ b/brightray/browser/media/media_stream_devices_controller.h @@ -23,7 +23,7 @@ class MediaStreamDevicesController { // Explicitly accept or deny the request. void Accept(); - void Deny(); + void Deny(content::MediaStreamRequestResult result); private: // Handle the request of desktop or tab screen cast. From 1a53e293ddcf9be340fea2b44166a0fc889dfe63 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 11 Mar 2015 14:51:37 -0700 Subject: [PATCH 0474/1195] Use DevToolsAPI instead of InspectorFrontendAPI Now InspectorFrontendAPI is available in the iframe, we have to call DevToolsAPI which delegates the call. --- brightray/browser/inspectable_web_contents_impl.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index ba85417f59c..88ed18dc1f9 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -243,7 +243,7 @@ void InspectableWebContentsImpl::AppendToFile( void InspectableWebContentsImpl::RequestFileSystems() { devtools_web_contents()->GetMainFrame()->ExecuteJavaScript( - base::ASCIIToUTF16("InspectorFrontendAPI.fileSystemsLoaded([])")); + base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])")); } void InspectableWebContentsImpl::AddFileSystem() { @@ -296,7 +296,7 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::st std::string error = embedder_message_dispatcher_->Dispatch(method, ¶ms); if (id) { std::string ack = base::StringPrintf( - "InspectorFrontendAPI.embedderMessageAck(%d, \"%s\");", id, error.c_str()); + "DevToolsAPI.embedderMessageAck(%d, \"%s\");", id, error.c_str()); devtools_web_contents()->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(ack)); } } @@ -308,7 +308,7 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontendToBackend( void InspectableWebContentsImpl::DispatchProtocolMessage( content::DevToolsAgentHost* agent_host, const std::string& message) { - std::string code = "InspectorFrontendAPI.dispatchMessage(" + message + ");"; + std::string code = "DevToolsAPI.dispatchMessage(" + message + ");"; base::string16 javascript = base::UTF8ToUTF16(code); web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); } From 6033e5bea39b35c141588fd600a872de6265eb57 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 13 Mar 2015 16:33:48 -0700 Subject: [PATCH 0475/1195] Upgrade libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 531d92bd1c5..f3f2a0aa429 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 531d92bd1c52e54376b09ee20e128a5e284cceb2 +Subproject commit f3f2a0aa429523a45dfb943c05106fa68fb26c44 From 54e58ae255824c7d210d823d9c2ec98753bee227 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 14 Mar 2015 18:34:53 +0000 Subject: [PATCH 0476/1195] Fix compilation on Linux --- brightray/browser/linux/notification_presenter_linux.cc | 8 ++++---- brightray/browser/linux/notification_presenter_linux.h | 4 ++-- brightray/browser/notification_presenter_mac.h | 3 ++- brightray/vendor/libchromiumcontent | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 193e80c76d6..a3d72bc8faa 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -9,7 +9,7 @@ #include "base/logging.h" #include "base/strings/utf_string_conversions.h" #include "content/public/browser/desktop_notification_delegate.h" -#include "content/public/common/show_desktop_notification_params.h" +#include "content/public/common/platform_notification_data.h" #include "common/application_info.h" namespace brightray { @@ -51,11 +51,11 @@ NotificationPresenterLinux::~NotificationPresenterLinux() { } void NotificationPresenterLinux::ShowNotification( - const content::ShowDesktopNotificationHostMsgParams& params, + const content::PlatformNotificationData& data, scoped_ptr delegate_ptr, base::Closure* cancel_callback) { - std::string title = base::UTF16ToUTF8(params.title); - std::string body = base::UTF16ToUTF8(params.body); + std::string title = base::UTF16ToUTF8(data.title); + std::string body = base::UTF16ToUTF8(data.body); NotifyNotification* notification = notify_notification_new(title.c_str(), body.c_str(), nullptr); content::DesktopNotificationDelegate* delegate = delegate_ptr.release(); diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index 6701d399c41..384e2d2f8c7 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -25,8 +25,8 @@ class NotificationPresenterLinux : public NotificationPresenter { private: // NotificationPresenter: - virtual void ShowNotification( - const content::ShowDesktopNotificationHostMsgParams&, + void ShowNotification( + const content::PlatformNotificationData&, scoped_ptr delegate, base::Closure* cancel_callback) override; diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index 0ba7fe7c35e..fd9dd737d9e 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -20,7 +20,8 @@ class NotificationPresenterMac : public NotificationPresenter { NotificationPresenterMac(); ~NotificationPresenterMac(); - virtual void ShowNotification( + // NotificationPresenter: + void ShowNotification( const content::PlatformNotificationData&, scoped_ptr delegate, base::Closure* cancel_callback) override; diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index f3f2a0aa429..84b0897b6bf 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit f3f2a0aa429523a45dfb943c05106fa68fb26c44 +Subproject commit 84b0897b6bf21d75ff03a1916513259aeb284252 From ac77c9df54555a8818f2d7f07430fff583d68c67 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 17 Mar 2015 11:24:10 -0700 Subject: [PATCH 0477/1195] Update URLs for new atom org location --- brightray/.gitmodules | 2 +- brightray/README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/brightray/.gitmodules b/brightray/.gitmodules index 17120b4cdf6..b1e57ad74f0 100644 --- a/brightray/.gitmodules +++ b/brightray/.gitmodules @@ -1,6 +1,6 @@ [submodule "vendor/libchromiumcontent"] path = vendor/libchromiumcontent - url = https://github.com/brightray/libchromiumcontent + url = https://github.com/atom/libchromiumcontent [submodule "vendor/gyp"] path = vendor/gyp url = https://github.com/svn2github/gyp diff --git a/brightray/README.md b/brightray/README.md index deac3f13e71..2c118f5cabc 100644 --- a/brightray/README.md +++ b/brightray/README.md @@ -1,12 +1,12 @@ # Brightray Brightray is a static library that makes -[libchromiumcontent](https://github.com/brightray/libchromiumcontent) easier to +[libchromiumcontent](https://github.com/atom/libchromiumcontent) easier to use in applications. ## Using it in your app -See [brightray_example](https://github.com/brightray/brightray_example) for a +See [brightray_example](https://github.com/atom/brightray_example) for a sample application written using Brightray. ## Development @@ -34,7 +34,7 @@ You must previously have built and uploaded libchromiumcontent using its Building Brightray on its own isn’t all that interesting, since it’s just a static library. Building it into an application (like -[brightray_example](https://github.com/brightray/brightray_example)) is the only +[brightray_example](https://github.com/atom/brightray_example)) is the only way to test it. ## License From 21ee1f257fee3ce56e69088f8b1ebd3b1d1151df Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 18 Mar 2015 09:55:13 +0800 Subject: [PATCH 0478/1195] Upgrade libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 84b0897b6bf..5e41ab5d654 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 84b0897b6bf21d75ff03a1916513259aeb284252 +Subproject commit 5e41ab5d654a5250014f2d751a2e118c540bdff2 From 4e14c8634b2aa87bf5d6dd2a7e8db62b82e0dd88 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 18 Mar 2015 12:55:02 +0800 Subject: [PATCH 0479/1195] Fix building on Windows --- brightray/browser/views/views_delegate.cc | 4 ++++ brightray/browser/views/views_delegate.h | 1 + brightray/vendor/libchromiumcontent | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc index a1078d41cb7..0d28ddcc321 100644 --- a/brightray/browser/views/views_delegate.cc +++ b/brightray/browser/views/views_delegate.cc @@ -54,6 +54,10 @@ HICON ViewsDelegate::GetDefaultWindowIcon() const { return LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(1 /* IDR_MAINFRAME */)); } +HICON ViewsDelegate::GetSmallWindowIcon() const { + return GetDefaultWindowIcon(); +} + bool ViewsDelegate::IsWindowInMetro(gfx::NativeWindow window) const { return false; } diff --git a/brightray/browser/views/views_delegate.h b/brightray/browser/views/views_delegate.h index 27d64207281..bd1e7bc2b6b 100644 --- a/brightray/browser/views/views_delegate.h +++ b/brightray/browser/views/views_delegate.h @@ -36,6 +36,7 @@ class ViewsDelegate : public views::ViewsDelegate { #if defined(OS_WIN) virtual HICON GetDefaultWindowIcon() const override; + virtual HICON GetSmallWindowIcon() const override; virtual bool IsWindowInMetro(gfx::NativeWindow window) const override; #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) virtual gfx::ImageSkia* GetDefaultWindowIcon() const override; diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 5e41ab5d654..78ddaee2158 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 5e41ab5d654a5250014f2d751a2e118c540bdff2 +Subproject commit 78ddaee2158886da53d0801db572be38230fd814 From 6090358f1662d33e3f9692456bdda77c4c5d1cc4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Mar 2015 08:29:44 +0000 Subject: [PATCH 0480/1195] Update libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 78ddaee2158..bb327098c5e 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 78ddaee2158886da53d0801db572be38230fd814 +Subproject commit bb327098c5e365f478a66f101044b8fdd4e79aa6 From 0eae030f6764abf36e7653c557aa0dc339ee44a0 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sun, 29 Mar 2015 16:33:51 +0800 Subject: [PATCH 0481/1195] Enable webui in content layer. Allow to access Chrome's webuis(chrome://gpu, chrome://tracing) in Atom Shell. --- brightray/common/content_client.cc | 5 +++++ brightray/common/content_client.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index 9b38e9304f7..3867ed6fe3f 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -46,4 +46,9 @@ gfx::Image& ContentClient::GetNativeImageNamed(int resource_id) const { resource_id); } +base::RefCountedStaticMemory* ContentClient::GetDataResourceBytes( + int resource_id) const { + return ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id); +} + } // namespace brightray diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index e5433cd6a2c..5d22e55ab9d 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -22,6 +22,8 @@ class ContentClient : public content::ContentClient { base::StringPiece GetDataResource(int resource_id, ui::ScaleFactor) const override; gfx::Image& GetNativeImageNamed(int resource_id) const override; + base::RefCountedStaticMemory* GetDataResourceBytes( + int resource_id) const override; DISALLOW_COPY_AND_ASSIGN(ContentClient); }; From 4ae52721c45bde809183b55628267042b92bbb92 Mon Sep 17 00:00:00 2001 From: Robo Date: Tue, 31 Mar 2015 21:17:28 +0530 Subject: [PATCH 0482/1195] detecting focus on devtools webcontents --- brightray/browser/inspectable_web_contents_delegate.h | 1 + brightray/browser/inspectable_web_contents_impl.cc | 6 ++++++ brightray/browser/inspectable_web_contents_impl.h | 1 + 3 files changed, 8 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index 082343f2f64..d32b139ba94 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -19,6 +19,7 @@ class InspectableWebContentsDelegate { const std::string& url, const std::string& content, bool save_as) {} virtual void DevToolsAppendToFile( const std::string& url, const std::string& content) {} + virtual void DevToolsFocused() {} #if defined(USE_X11) // Called when creating devtools window. diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 88ed18dc1f9..9def5ad8630 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -241,6 +241,12 @@ void InspectableWebContentsImpl::AppendToFile( delegate_->DevToolsAppendToFile(url, content); } +void InspectableWebContentsImpl::WebContentsFocused( + content::WebContents* contents) { + if (delegate_) + delegate_->DevToolsFocused(); +} + void InspectableWebContentsImpl::RequestFileSystems() { devtools_web_contents()->GetMainFrame()->ExecuteJavaScript( base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])")); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 7e249e8aa65..a7e248d575d 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -127,6 +127,7 @@ class InspectableWebContentsImpl : void HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent&) override; void CloseContents(content::WebContents* source) override; + void WebContentsFocused(content::WebContents* contents) override; scoped_ptr web_contents_; scoped_ptr devtools_web_contents_; From 19198a579a882db8855b3f24c377afdd5286a06d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 2 Apr 2015 13:46:16 +0800 Subject: [PATCH 0483/1195] Upgrade libchromiumcontent for component build --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index bb327098c5e..cb8ec5790c0 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit bb327098c5e365f478a66f101044b8fdd4e79aa6 +Subproject commit cb8ec5790c07bad7c11e8fb16e767ccef7f50ecb From 7e41b9e44de0c26969fd853575545576a9f9c014 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 2 Apr 2015 14:05:43 +0800 Subject: [PATCH 0484/1195] Link with component build shared libraries --- brightray/brightray.gyp | 18 ++++----- brightray/brightray.gypi | 7 +++- brightray/script/bootstrap | 49 ++++++++++++------------ brightray/tools/brightray_source_root.py | 9 ----- brightray/vendor/libchromiumcontent | 2 +- 5 files changed, 39 insertions(+), 46 deletions(-) delete mode 100644 brightray/tools/brightray_source_root.py diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index df52343db24..6da645c5471 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -2,9 +2,6 @@ 'includes': [ 'brightray.gypi', ], - 'variables': { - 'brightray_source_root': ' Date: Thu, 2 Apr 2015 15:11:15 +0800 Subject: [PATCH 0485/1195] Only do component build in Debug mode --- brightray/brightray.gyp | 8 +++++--- brightray/brightray.gypi | 9 +++++++++ brightray/vendor/libchromiumcontent | 2 +- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 6da645c5471..2ce86b93ad2 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -93,6 +93,11 @@ 'common/main_delegate_mac.mm', ], 'conditions': [ + ['libchromiumcontent_component_build', { + 'link_settings': { + 'libraries': [ '<@(libchromiumcontent_shared_libraries)' ] + }, + }], ['OS=="linux"', { 'cflags_cc': [ '-Wno-deprecated-register', @@ -103,7 +108,6 @@ ' Date: Thu, 2 Apr 2015 22:14:18 +0800 Subject: [PATCH 0486/1195] Set libraries' path according to libchromiumcontent_component variable --- brightray/brightray.gyp | 40 +++--- brightray/brightray.gypi | 188 +++++++++++++++------------- brightray/vendor/libchromiumcontent | 2 +- 3 files changed, 119 insertions(+), 111 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 2ce86b93ad2..9c5bbbfcffb 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -8,22 +8,22 @@ 'type': 'static_library', 'include_dirs': [ '.', - '<(libchromiumcontent_include_dir)', - '<(libchromiumcontent_include_dir)/skia/config', - '<(libchromiumcontent_include_dir)/third_party/skia/include/core', - '<(libchromiumcontent_include_dir)/third_party/WebKit', - '<(libchromiumcontent_library_dir)/gen', + '<(libchromiumcontent_src_dir)', + '<(libchromiumcontent_src_dir)/skia/config', + '<(libchromiumcontent_src_dir)/third_party/skia/include/core', + '<(libchromiumcontent_src_dir)/third_party/WebKit', + '<(libchromiumcontent_dir)/gen', ], 'direct_dependent_settings': { 'include_dirs': [ '.', '..', - '<(libchromiumcontent_include_dir)', - '<(libchromiumcontent_include_dir)/skia/config', - '<(libchromiumcontent_include_dir)/third_party/skia/include/core', - '<(libchromiumcontent_include_dir)/third_party/icu/source/common', - '<(libchromiumcontent_include_dir)/third_party/WebKit', - '<(libchromiumcontent_library_dir)/gen', + '<(libchromiumcontent_src_dir)', + '<(libchromiumcontent_src_dir)/skia/config', + '<(libchromiumcontent_src_dir)/third_party/skia/include/core', + '<(libchromiumcontent_src_dir)/third_party/icu/source/common', + '<(libchromiumcontent_src_dir)/third_party/WebKit', + '<(libchromiumcontent_dir)/gen', ], }, 'sources': [ @@ -92,12 +92,10 @@ 'common/main_delegate.h', 'common/main_delegate_mac.mm', ], + 'link_settings': { + 'libraries': [ '<@(libchromiumcontent_libraries)' ] + }, 'conditions': [ - ['libchromiumcontent_component_build', { - 'link_settings': { - 'libraries': [ '<@(libchromiumcontent_shared_libraries)' ] - }, - }], ['OS=="linux"', { 'cflags_cc': [ '-Wno-deprecated-register', @@ -108,7 +106,7 @@ ' Date: Fri, 3 Apr 2015 09:56:03 +0800 Subject: [PATCH 0487/1195] mac: Link with all necessary system libraries --- brightray/brightray.gyp | 32 ++++++++++++++++++++++++++++++++ brightray/brightray.gypi | 15 ++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 9c5bbbfcffb..92b9b9998c6 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -119,6 +119,38 @@ ], }, }], + ['OS=="mac" and libchromiumcontent_component==0', { + 'link_settings': { + 'libraries': [ + # ui_base.gypi: + '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', + # net.gypi: + '$(SDKROOT)/System/Library/Frameworks/Foundation.framework', + '$(SDKROOT)/System/Library/Frameworks/Security.framework', + '$(SDKROOT)/System/Library/Frameworks/SystemConfiguration.framework', + '$(SDKROOT)/usr/lib/libresolv.dylib', + # media.gyp: + '$(SDKROOT)/System/Library/Frameworks/AudioToolbox.framework', + '$(SDKROOT)/System/Library/Frameworks/AudioUnit.framework', + '$(SDKROOT)/System/Library/Frameworks/CoreAudio.framework', + '$(SDKROOT)/System/Library/Frameworks/CoreMIDI.framework', + '$(SDKROOT)/System/Library/Frameworks/CoreVideo.framework', + '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', + '$(SDKROOT)/System/Library/Frameworks/QTKit.framework', + # surface.gyp: + '$(SDKROOT)/System/Library/Frameworks/IOSurface.framework', + # content_common.gypi: + '$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework', + # base.gyp: + '$(SDKROOT)/System/Library/Frameworks/ApplicationServices.framework', + '$(SDKROOT)/System/Library/Frameworks/Carbon.framework', + '$(SDKROOT)/System/Library/Frameworks/CoreFoundation.framework', + '$(SDKROOT)/System/Library/Frameworks/IOKit.framework', + # content_browser.gypi: + '$(SDKROOT)/usr/lib/libbsm.dylib', + ], + }, + }], ['OS=="win"', { 'link_settings': { 'libraries': [ diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 6ce2a25e13d..ed3328c6805 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -73,12 +73,8 @@ 'Common_Base': { 'abstract': 1, 'defines': [ - 'COMPONENT_BUILD', - 'GURL_DLL', - 'SKIA_DLL', + # We are using Release version libchromiumcontent: 'NDEBUG', - 'USING_V8_SHARED', - 'WEBKIT_DLL', # From skia_for_chromium_defines.gypi: 'SK_SUPPORT_LEGACY_GETTOPDEVICE', 'SK_SUPPORT_LEGACY_BITMAP_CONFIG', @@ -239,6 +235,15 @@ ], }, 'conditions': [ + ['libchromiumcontent_component', { + 'defines': [ + 'COMPONENT_BUILD', + 'GURL_DLL', + 'SKIA_DLL', + 'USING_V8_SHARED', + 'WEBKIT_DLL', + ], + }], ['OS=="linux" and linux_clang==1', { 'make_global_settings': [ ['CC', '/usr/bin/clang'], From d9056135d7f914fc90b0d3413122a01df3693d46 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 3 Apr 2015 11:37:27 +0800 Subject: [PATCH 0488/1195] Link with libboringssl.dylib --- brightray/brightray.gyp | 3 +++ brightray/brightray.gypi | 2 -- brightray/vendor/libchromiumcontent | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 92b9b9998c6..01ba60a6483 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -122,6 +122,9 @@ ['OS=="mac" and libchromiumcontent_component==0', { 'link_settings': { 'libraries': [ + # This library is built as shared library to avoid symbols + # conflict with Node. + '<(libchromiumcontent_dir)/libboringssl.dylib', # ui_base.gypi: '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', # net.gypi: diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index ed3328c6805..ac77770221a 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -10,11 +10,9 @@ ['libchromiumcontent_component', { 'libchromiumcontent_dir%': '<(libchromiumcontent_root_dir)/shared_library', 'libchromiumcontent_libraries%': '<(libchromiumcontent_shared_libraries)', - 'libchromiumcontent_shared_libraries': [], }, { 'libchromiumcontent_dir%': '<(libchromiumcontent_root_dir)/static_library', 'libchromiumcontent_libraries%': '<(libchromiumcontent_static_libraries)', - 'libchromiumcontent_static_libraries': [], }], ], diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index cbc562c7a9c..846a13ae223 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit cbc562c7a9c6a2a56f3a6ba08652f5e475898d48 +Subproject commit 846a13ae2234490d78568a68f07f5be95c24c0c3 From 5ef7a0d1da5ebd379bda1f3b26c96d3dbea4cb18 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 3 Apr 2015 11:39:03 +0800 Subject: [PATCH 0489/1195] Use "D" and "R" as short names --- brightray/brightray.gypi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index ac77770221a..43a17795fb2 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -116,7 +116,7 @@ }, 'conditions': [ ['libchromiumcontent_component', { - 'RealDebug': { + 'D': { 'inherit_from': [ 'Common_Base', ], @@ -160,7 +160,7 @@ }, }, }, { - 'RealRelease': { + 'R': { 'inherit_from': [ 'Common_Base', ], From 0ed4626776bb29a4bcb69908ab57de008995c87c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 5 Apr 2015 22:28:00 +0800 Subject: [PATCH 0490/1195] Download static_library build of libchromiumcontent --- brightray/script/bootstrap | 14 ++++++++++---- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index e865c1644ad..23b33ca62df 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -15,13 +15,15 @@ DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download') def main(): args = parse_args() return (update_submodules() or - download_libchromiumcontent(args.commit, args.url)) + download_libchromiumcontent(args.dev, args.commit, args.url)) def parse_args(): parser = argparse.ArgumentParser(description='Bootstrap this project') parser.add_argument('-c', '--commit', nargs='?', default='HEAD', help='The commit of libchromiumcontent to download.') + parser.add_argument('-d', '--dev', action='store_true', + help='Do not download static_library build') parser.add_argument('url', help='The base URL from which to download ' 'libchromiumcontent (i.e., the URL you passed to ' 'libchromiumcontent\'s script/upload script') @@ -35,12 +37,16 @@ def update_submodules(): '--recursive'])) -def download_libchromiumcontent(commit, url): +def download_libchromiumcontent(is_dev, commit, url): mkdir_p(DOWNLOAD_DIR) download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', 'download') - return subprocess.call([sys.executable, download, '-f', '-c', commit, url, - os.path.join(DOWNLOAD_DIR, 'libchromiumcontent')]) + target = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') + subprocess.check_call([sys.executable, download, '-f', '-c', commit, url, + target]) + if not is_dev: + subprocess.check_call([sys.executable, download, '-s', '-f', '-c', commit, + url, target]) def mkdir_p(path): diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 846a13ae223..1b7aec028cf 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 846a13ae2234490d78568a68f07f5be95c24c0c3 +Subproject commit 1b7aec028cf86463bc6c00ce15e294cdd157b5c1 From f9f891bd039cc845823c1cbf580ef24a8f9ef080 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 5 Apr 2015 22:51:38 +0800 Subject: [PATCH 0491/1195] win: Fix libchromiumcontent_src_dir not defined --- brightray/brightray.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 43a17795fb2..48b0fe9a106 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -3,7 +3,7 @@ 'vendor/download/libchromiumcontent/filenames.gypi', ], 'variables': { - 'libchromiumcontent_src_dir%': '<(libchromiumcontent_root_dir)/src', + 'libchromiumcontent_src_dir': '<(libchromiumcontent_root_dir)/src', 'libchromiumcontent_component%': 1, 'conditions': [ # The "libchromiumcontent_component" is defined when calling "gyp". From 9fd0f7e78e71782d56ae82541a6da7143bfd9c04 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 5 Apr 2015 23:03:34 +0800 Subject: [PATCH 0492/1195] win: Add configurations for x64 build --- brightray/brightray.gypi | 181 ++++++++++++++++++++++----------------- 1 file changed, 103 insertions(+), 78 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 48b0fe9a106..70a9f587160 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -113,90 +113,115 @@ ], }], ], - }, + }, # Common_Base + 'Debug_Base': { + 'msvs_settings': { + 'VCCLCompilerTool': { + 'Optimization': '<(win_debug_Optimization)', + 'BasicRuntimeChecks': '<(win_debug_RuntimeChecks)', + # We use Release to match the version of chromiumcontent.dll we + # link against. + 'RuntimeLibrary': '<(win_release_RuntimeLibrary)', + 'conditions': [ + # According to MSVS, InlineFunctionExpansion=0 means + # "default inlining", not "/Ob0". + # Thus, we have to handle InlineFunctionExpansion==0 separately. + ['win_debug_InlineFunctionExpansion==0', { + 'AdditionalOptions': ['/Ob0'], + }], + ['win_debug_InlineFunctionExpansion!=""', { + 'InlineFunctionExpansion': + '<(win_debug_InlineFunctionExpansion)', + }], + # if win_debug_OmitFramePointers is blank, leave as default + ['win_debug_OmitFramePointers==1', { + 'OmitFramePointers': 'true', + }], + ['win_debug_OmitFramePointers==0', { + 'OmitFramePointers': 'false', + # The above is not sufficient (http://crbug.com/106711): it + # simply eliminates an explicit "/Oy", but both /O2 and /Ox + # perform FPO regardless, so we must explicitly disable. + # We still want the false setting above to avoid having + # "/Oy /Oy-" and warnings about overriding. + 'AdditionalOptions': ['/Oy-'], + }], + ], + }, + }, + 'xcode_settings': { + 'COPY_PHASE_STRIP': 'NO', + 'GCC_OPTIMIZATION_LEVEL': '0', + }, + }, # Debug_Base + 'Release_Base': { + 'msvs_settings': { + 'VCCLCompilerTool': { + 'Optimization': '<(win_release_Optimization)', + 'RuntimeLibrary': '<(win_release_RuntimeLibrary)', + 'conditions': [ + # According to MSVS, InlineFunctionExpansion=0 means + # "default inlining", not "/Ob0". + # Thus, we have to handle InlineFunctionExpansion==0 separately. + ['win_release_InlineFunctionExpansion==0', { + 'AdditionalOptions': ['/Ob0'], + }], + ['win_release_InlineFunctionExpansion!=""', { + 'InlineFunctionExpansion': + '<(win_release_InlineFunctionExpansion)', + }], + # if win_release_OmitFramePointers is blank, leave as default + ['win_release_OmitFramePointers==1', { + 'OmitFramePointers': 'true', + }], + ['win_release_OmitFramePointers==0', { + 'OmitFramePointers': 'false', + # The above is not sufficient (http://crbug.com/106711): it + # simply eliminates an explicit "/Oy", but both /O2 and /Ox + # perform FPO regardless, so we must explicitly disable. + # We still want the false setting above to avoid having + # "/Oy /Oy-" and warnings about overriding. + 'AdditionalOptions': ['/Oy-'], + }], + ], + }, + }, + }, # Release_Base 'conditions': [ + ['OS=="win"', { + 'x64_Base': { + 'abstract': 1, + 'msvs_configuration_platform': 'x64', + 'msvs_settings': { + 'VCLinkerTool': { + # Make sure to understand http://crbug.com/361720 if you want to + # increase this. + 'MinimumRequiredVersion': '5.02', # Server 2003. + 'TargetMachine': '17', # x86 - 64 + # Doesn't exist x64 SDK. Should use oleaut32 in any case. + 'IgnoreDefaultLibraryNames': [ 'olepro32.lib' ], + }, + 'VCLibrarianTool': { + 'TargetMachine': '17', # x64 + }, + }, + }, + }], # OS=="win" ['libchromiumcontent_component', { 'D': { - 'inherit_from': [ - 'Common_Base', - ], - 'msvs_settings': { - 'VCCLCompilerTool': { - 'Optimization': '<(win_debug_Optimization)', - 'BasicRuntimeChecks': '<(win_debug_RuntimeChecks)', - # We use Release to match the version of chromiumcontent.dll we - # link against. - 'RuntimeLibrary': '<(win_release_RuntimeLibrary)', - 'conditions': [ - # According to MSVS, InlineFunctionExpansion=0 means - # "default inlining", not "/Ob0". - # Thus, we have to handle InlineFunctionExpansion==0 separately. - ['win_debug_InlineFunctionExpansion==0', { - 'AdditionalOptions': ['/Ob0'], - }], - ['win_debug_InlineFunctionExpansion!=""', { - 'InlineFunctionExpansion': - '<(win_debug_InlineFunctionExpansion)', - }], - # if win_debug_OmitFramePointers is blank, leave as default - ['win_debug_OmitFramePointers==1', { - 'OmitFramePointers': 'true', - }], - ['win_debug_OmitFramePointers==0', { - 'OmitFramePointers': 'false', - # The above is not sufficient (http://crbug.com/106711): it - # simply eliminates an explicit "/Oy", but both /O2 and /Ox - # perform FPO regardless, so we must explicitly disable. - # We still want the false setting above to avoid having - # "/Oy /Oy-" and warnings about overriding. - 'AdditionalOptions': ['/Oy-'], - }], - ], - }, - }, - 'xcode_settings': { - 'COPY_PHASE_STRIP': 'NO', - 'GCC_OPTIMIZATION_LEVEL': '0', - }, + 'inherit_from': ['Common_Base', 'Debug_Base'], }, - }, { + 'D_x64': { + 'inherit_from': ['Common_Base', 'x64_Base', 'Debug_Base'], + }, + }, { # libchromiumcontent_component==1 'R': { - 'inherit_from': [ - 'Common_Base', - ], - 'msvs_settings': { - 'VCCLCompilerTool': { - 'Optimization': '<(win_release_Optimization)', - 'RuntimeLibrary': '<(win_release_RuntimeLibrary)', - 'conditions': [ - # According to MSVS, InlineFunctionExpansion=0 means - # "default inlining", not "/Ob0". - # Thus, we have to handle InlineFunctionExpansion==0 separately. - ['win_release_InlineFunctionExpansion==0', { - 'AdditionalOptions': ['/Ob0'], - }], - ['win_release_InlineFunctionExpansion!=""', { - 'InlineFunctionExpansion': - '<(win_release_InlineFunctionExpansion)', - }], - # if win_release_OmitFramePointers is blank, leave as default - ['win_release_OmitFramePointers==1', { - 'OmitFramePointers': 'true', - }], - ['win_release_OmitFramePointers==0', { - 'OmitFramePointers': 'false', - # The above is not sufficient (http://crbug.com/106711): it - # simply eliminates an explicit "/Oy", but both /O2 and /Ox - # perform FPO regardless, so we must explicitly disable. - # We still want the false setting above to avoid having - # "/Oy /Oy-" and warnings about overriding. - 'AdditionalOptions': ['/Oy-'], - }], - ], - }, - }, + 'inherit_from': ['Common_Base', 'Release_Base'], }, - }], + 'R_x64': { + 'inherit_from': ['Common_Base', 'x64_Base', 'Release_Base'], + }, + }], # libchromiumcontent_component==0 ], }, 'conditions': [ From ed5660909bc73126c3b711cb5da072b92402b656 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Apr 2015 12:03:22 +0800 Subject: [PATCH 0493/1195] win: Link with sandbox and base_static under component build --- brightray/brightray.gyp | 12 +++++------- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 01ba60a6483..b8b21787ac9 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -116,15 +116,15 @@ 'link_settings': { 'libraries': [ '$(SDKROOT)/System/Library/Frameworks/AppKit.framework', + # This library is built as shared library to avoid symbols + # conflict with Node. + '<(libchromiumcontent_dir)/libboringssl.dylib', ], }, }], ['OS=="mac" and libchromiumcontent_component==0', { 'link_settings': { 'libraries': [ - # This library is built as shared library to avoid symbols - # conflict with Node. - '<(libchromiumcontent_dir)/libboringssl.dylib', # ui_base.gypi: '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', # net.gypi: @@ -154,13 +154,11 @@ ], }, }], - ['OS=="win"', { + ['OS=="win" and libchromiumcontent_component', { 'link_settings': { 'libraries': [ '<(libchromiumcontent_dir)/base_static.lib', - '<(libchromiumcontent_dir)/chromiumcontent.dll.lib', - '<(libchromiumcontent_dir)/chromiumviews.lib', - '<(libchromiumcontent_dir)/sandbox_static.lib', + '<(libchromiumcontent_dir)/sandbox.lib', ], }, }], diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 1b7aec028cf..fa70c1a296d 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 1b7aec028cf86463bc6c00ce15e294cdd157b5c1 +Subproject commit fa70c1a296d9b8f89a4e42bd3116ac36a831169c From 7b7a94140d898253427a83ea72f0ca513a371a31 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Apr 2015 14:19:28 +0800 Subject: [PATCH 0494/1195] win: Fix defines under component build --- brightray/brightray.gypi | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 70a9f587160..a82345d666f 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -103,8 +103,6 @@ 'defines': [ 'TOOLKIT_VIEWS', 'USE_AURA', - 'VIEWS_IMPLEMENTATION', - 'WEBVIEW_IMPLEMENTATION', ], }], ['OS not in ["mac", "win"]', { @@ -259,13 +257,15 @@ }, 'conditions': [ ['libchromiumcontent_component', { - 'defines': [ - 'COMPONENT_BUILD', - 'GURL_DLL', - 'SKIA_DLL', - 'USING_V8_SHARED', - 'WEBKIT_DLL', - ], + 'target_defaults': { + 'defines': [ + 'COMPONENT_BUILD', + 'GURL_DLL', + 'SKIA_DLL', + 'USING_V8_SHARED', + 'WEBKIT_DLL', + ], + }, }], ['OS=="linux" and linux_clang==1', { 'make_global_settings': [ From 4c36b747e0fb5626fc01354f31412388c78d7a7b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Apr 2015 15:03:53 +0800 Subject: [PATCH 0495/1195] win: Fix linking with ffmepg --- brightray/brightray.gyp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b8b21787ac9..c522fb75fae 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -161,6 +161,19 @@ '<(libchromiumcontent_dir)/sandbox.lib', ], }, + }, { + 'link_settings': { + 'libraries': [ + '<(libchromiumcontent_dir)/ffmpegsumo.lib', + ], + 'msvs_settings': { + 'VCLinkerTool': { + 'DelayLoadDLLs': [ + 'ffmpegsumo.dll', + ], + }, + }, + }, }], ], }, From 3b5edb461ae83f289ffc6bc88998f7e3cc009e2c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Apr 2015 15:04:07 +0800 Subject: [PATCH 0496/1195] win: Fix linking with libyuv --- brightray/brightray.gyp | 1 + brightray/brightray.gypi | 2 ++ brightray/vendor/libchromiumcontent | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index c522fb75fae..1f2da5c1c06 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -165,6 +165,7 @@ 'link_settings': { 'libraries': [ '<(libchromiumcontent_dir)/ffmpegsumo.lib', + '<(libchromiumcontent_dir)/libyuv.lib', ], 'msvs_settings': { 'VCLinkerTool': { diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index a82345d666f..2f74e911639 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -91,10 +91,12 @@ 'VCLinkerTool': { 'AdditionalDependencies': [ 'advapi32.lib', + 'dbghelp.lib', 'dwmapi.lib', 'gdi32.lib', 'oleacc.lib', 'user32.lib', + 'winspool.lib', ], }, }, diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index fa70c1a296d..424b9b8437a 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit fa70c1a296d9b8f89a4e42bd3116ac36a831169c +Subproject commit 424b9b8437a6d3233d35c5754d78716f7f5e2a71 From f1a508f6438f0ca85c97032be73b0324f252bb71 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Apr 2015 15:14:57 +0800 Subject: [PATCH 0497/1195] win: Link with boringssl.dll --- brightray/brightray.gyp | 1 + brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 1f2da5c1c06..30b3db50da1 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -164,6 +164,7 @@ }, { 'link_settings': { 'libraries': [ + '<(libchromiumcontent_dir)/boringssl.dll', '<(libchromiumcontent_dir)/ffmpegsumo.lib', '<(libchromiumcontent_dir)/libyuv.lib', ], diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 424b9b8437a..301d2d617c6 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 424b9b8437a6d3233d35c5754d78716f7f5e2a71 +Subproject commit 301d2d617c64ed020bf787d541b9a7d5e10941a8 From d522443c7551fb864f47959556e20bed475fac15 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Apr 2015 15:20:27 +0800 Subject: [PATCH 0498/1195] win: Import system libraries in content_common.gypi --- brightray/brightray.gyp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 30b3db50da1..925bf0fc5aa 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -167,11 +167,24 @@ '<(libchromiumcontent_dir)/boringssl.dll', '<(libchromiumcontent_dir)/ffmpegsumo.lib', '<(libchromiumcontent_dir)/libyuv.lib', + # content_common.gypi: + '-ld3d11.lib', + '-ldxva2.lib', + '-lstrmiids.lib', + '-lmf.lib', + '-lmfplat.lib', + '-lmfuuid.lib', ], 'msvs_settings': { 'VCLinkerTool': { 'DelayLoadDLLs': [ 'ffmpegsumo.dll', + # content_common.gypi: + 'd3d9.dll', + 'd3d11.dll', + 'dxva2.dll', + 'mf.dll', + 'mfplat.dll', ], }, }, From 99349859748a7de5e43f41d2f5867af5ba11184a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Apr 2015 16:01:31 +0800 Subject: [PATCH 0499/1195] win: Link with libraries from other places --- brightray/brightray.gyp | 8 ++++++-- brightray/brightray.gypi | 11 ++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 925bf0fc5aa..41db0f50443 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -167,13 +167,18 @@ '<(libchromiumcontent_dir)/boringssl.dll', '<(libchromiumcontent_dir)/ffmpegsumo.lib', '<(libchromiumcontent_dir)/libyuv.lib', + # content_browser.gypi: + '-lsensorsapi.lib', + '-lportabledeviceguids.lib', # content_common.gypi: - '-ld3d11.lib', + '-ld3d9.lib', '-ldxva2.lib', '-lstrmiids.lib', '-lmf.lib', '-lmfplat.lib', '-lmfuuid.lib', + # media.gyp: + '-lmfreadwrite.lib', ], 'msvs_settings': { 'VCLinkerTool': { @@ -181,7 +186,6 @@ 'ffmpegsumo.dll', # content_common.gypi: 'd3d9.dll', - 'd3d11.dll', 'dxva2.dll', 'mf.dll', 'mfplat.dll', diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 2f74e911639..7d03a5efe7e 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -22,9 +22,6 @@ # Build with clang under Linux. 'linux_clang%': 1, - 'win_release_RuntimeLibrary%': '2', # /MD (nondebug DLL) - 'win_debug_RuntimeLibrary%': '3', # /MTd (debug DLL) - # See http://msdn.microsoft.com/en-us/library/aa652360(VS.71).aspx 'win_release_Optimization%': '2', # 2 = /Os 'win_debug_Optimization%': '0', # 0 = /Od @@ -94,8 +91,12 @@ 'dbghelp.lib', 'dwmapi.lib', 'gdi32.lib', + 'netapi32.lib', 'oleacc.lib', + 'powrprof.lib', 'user32.lib', + 'usp10.lib', + 'version.lib', 'winspool.lib', ], }, @@ -119,9 +120,6 @@ 'VCCLCompilerTool': { 'Optimization': '<(win_debug_Optimization)', 'BasicRuntimeChecks': '<(win_debug_RuntimeChecks)', - # We use Release to match the version of chromiumcontent.dll we - # link against. - 'RuntimeLibrary': '<(win_release_RuntimeLibrary)', 'conditions': [ # According to MSVS, InlineFunctionExpansion=0 means # "default inlining", not "/Ob0". @@ -158,7 +156,6 @@ 'msvs_settings': { 'VCCLCompilerTool': { 'Optimization': '<(win_release_Optimization)', - 'RuntimeLibrary': '<(win_release_RuntimeLibrary)', 'conditions': [ # According to MSVS, InlineFunctionExpansion=0 means # "default inlining", not "/Ob0". From 512deae254aa481f5d08be9adfc5806227312084 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Apr 2015 21:41:36 +0800 Subject: [PATCH 0500/1195] Fix generating configs on OS X and Linux --- brightray/brightray.gypi | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 7d03a5efe7e..7d38af35c8c 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -185,6 +185,15 @@ }, }, # Release_Base 'conditions': [ + ['libchromiumcontent_component', { + 'D': { + 'inherit_from': ['Common_Base', 'Debug_Base'], + }, # D (Debug) + }, { + 'R': { + 'inherit_from': ['Common_Base', 'Release_Base'], + }, # R (Release) + }], # libchromiumcontent_component ['OS=="win"', { 'x64_Base': { 'abstract': 1, @@ -202,23 +211,18 @@ 'TargetMachine': '17', # x64 }, }, - }, + }, # x64_Base }], # OS=="win" - ['libchromiumcontent_component', { - 'D': { - 'inherit_from': ['Common_Base', 'Debug_Base'], - }, + ['OS=="win" and libchromiumcontent_component==1', { 'D_x64': { 'inherit_from': ['Common_Base', 'x64_Base', 'Debug_Base'], - }, - }, { # libchromiumcontent_component==1 - 'R': { - 'inherit_from': ['Common_Base', 'Release_Base'], - }, + }, # D_x64 + }], # OS=="win" and libchromiumcontent_component==1 + ['OS=="win" and libchromiumcontent_component==0', { 'R_x64': { 'inherit_from': ['Common_Base', 'x64_Base', 'Release_Base'], - }, - }], # libchromiumcontent_component==0 + }, # R_x64 + }], # OS=="win" and libchromiumcontent_component==0 ], }, 'conditions': [ From 938182a3ebea2a01741119cab9b81676a94c8499 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 7 Apr 2015 11:28:56 +0800 Subject: [PATCH 0501/1195] mac: Fix linking with boringssl --- brightray/brightray.gyp | 9 +++------ brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 41db0f50443..0d0b330abf6 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -116,9 +116,6 @@ 'link_settings': { 'libraries': [ '$(SDKROOT)/System/Library/Frameworks/AppKit.framework', - # This library is built as shared library to avoid symbols - # conflict with Node. - '<(libchromiumcontent_dir)/libboringssl.dylib', ], }, }], @@ -154,17 +151,17 @@ ], }, }], - ['OS=="win" and libchromiumcontent_component', { + ['OS=="win" and libchromiumcontent_component==1', { 'link_settings': { 'libraries': [ '<(libchromiumcontent_dir)/base_static.lib', '<(libchromiumcontent_dir)/sandbox.lib', ], }, - }, { + }], + ['OS=="win" and libchromiumcontent_component==0', { 'link_settings': { 'libraries': [ - '<(libchromiumcontent_dir)/boringssl.dll', '<(libchromiumcontent_dir)/ffmpegsumo.lib', '<(libchromiumcontent_dir)/libyuv.lib', # content_browser.gypi: diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 301d2d617c6..b371f0a7b0c 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 301d2d617c64ed020bf787d541b9a7d5e10941a8 +Subproject commit b371f0a7b0c1dd47d68f6ea5bade36451a13e7e1 From 92ce000bb26ea39ce8c8122fcc23c55e2dae80d0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 7 Apr 2015 13:48:09 +0800 Subject: [PATCH 0502/1195] win: Link with DLL version of vcrt in component build --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 7d38af35c8c..8d77b60e24a 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -118,6 +118,7 @@ 'Debug_Base': { 'msvs_settings': { 'VCCLCompilerTool': { + 'RuntimeLibrary': '2', # /MD (nondebug DLL) 'Optimization': '<(win_debug_Optimization)', 'BasicRuntimeChecks': '<(win_debug_RuntimeChecks)', 'conditions': [ From b9ddf0eb316bf8233b8c8b2f52ac11eaa0ffeda4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 7 Apr 2015 16:28:38 +0800 Subject: [PATCH 0503/1195] Still link with shared_library of boringssl --- brightray/brightray.gyp | 4 ++++ brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 0d0b330abf6..9eded99d152 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -122,6 +122,9 @@ ['OS=="mac" and libchromiumcontent_component==0', { 'link_settings': { 'libraries': [ + # This library is built as shared library to avoid symbols + # conflict with Node. + '<(libchromiumcontent_dir)/libboringssl.dylib', # ui_base.gypi: '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', # net.gypi: @@ -162,6 +165,7 @@ ['OS=="win" and libchromiumcontent_component==0', { 'link_settings': { 'libraries': [ + '<(libchromiumcontent_dir)/boringssl.lib', '<(libchromiumcontent_dir)/ffmpegsumo.lib', '<(libchromiumcontent_dir)/libyuv.lib', # content_browser.gypi: diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index b371f0a7b0c..97917e79042 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit b371f0a7b0c1dd47d68f6ea5bade36451a13e7e1 +Subproject commit 97917e790421e8617ce685a1e32cf98a64052f7a From d1fb13b260f24ced8201787e29885cec56ae122c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 7 Apr 2015 20:18:09 +0800 Subject: [PATCH 0504/1195] Fix path to boringssl.dll --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 9eded99d152..00ef1723ee7 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -165,7 +165,7 @@ ['OS=="win" and libchromiumcontent_component==0', { 'link_settings': { 'libraries': [ - '<(libchromiumcontent_dir)/boringssl.lib', + '<(libchromiumcontent_dir)/boringssl.dll', '<(libchromiumcontent_dir)/ffmpegsumo.lib', '<(libchromiumcontent_dir)/libyuv.lib', # content_browser.gypi: From feeb1da5cabef234f7a4e58b9c8dff2aa3bd5d25 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 7 Apr 2015 23:39:08 +0800 Subject: [PATCH 0505/1195] Don't call download twice --- brightray/script/bootstrap | 8 ++++---- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index 23b33ca62df..b0754f7a1e4 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -31,7 +31,6 @@ def parse_args(): def update_submodules(): - return return (subprocess.call(['git', 'submodule', 'sync', '--quiet']) or subprocess.call(['git', 'submodule', 'update', '--init', '--recursive'])) @@ -42,9 +41,10 @@ def download_libchromiumcontent(is_dev, commit, url): download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', 'download') target = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') - subprocess.check_call([sys.executable, download, '-f', '-c', commit, url, - target]) - if not is_dev: + if is_dev: + subprocess.check_call([sys.executable, download, '-f', '-c', commit, url, + target]) + else: subprocess.check_call([sys.executable, download, '-s', '-f', '-c', commit, url, target]) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 97917e79042..d4f20e27753 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 97917e790421e8617ce685a1e32cf98a64052f7a +Subproject commit d4f20e2775350ec53506aba4244115dc5ca6d7b8 From a7f7834be957d26b7ed493bda19d3645529717d5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 8 Apr 2015 02:34:58 +0000 Subject: [PATCH 0506/1195] linux: Link with libboringssl.so --- brightray/brightray.gyp | 4 +++- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 00ef1723ee7..3b989acb569 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -106,12 +106,14 @@ ' Date: Wed, 8 Apr 2015 04:08:21 +0000 Subject: [PATCH 0507/1195] Link with static_library version of libgtk2ui --- brightray/brightray.gyp | 18 +++++++++++++++--- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 3b989acb569..d5316e05f92 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -110,9 +110,21 @@ ' Date: Wed, 8 Apr 2015 08:22:55 +0000 Subject: [PATCH 0508/1195] linux: Fix linking with system libraries --- brightray/brightray.gyp | 29 ++++++++++++++++++++++++++--- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index d5316e05f92..83b325d447d 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -92,10 +92,23 @@ 'common/main_delegate.h', 'common/main_delegate_mac.mm', ], - 'link_settings': { - 'libraries': [ '<@(libchromiumcontent_libraries)' ] - }, 'conditions': [ + ['OS=="linux" and libchromiumcontent_component==0', { + # On Linux we have to use "--whole-archive" to force executable + # to include all symbols, otherwise we will have plenty of + # unresolved symbols errors. + 'direct_dependent_settings': { + 'ldflags': [ + '-Wl,--whole-archive', + '<@(libchromiumcontent_libraries)', + '-Wl,--no-whole-archive', + ], + } + }, { + 'link_settings': { + 'libraries': [ '<@(libchromiumcontent_libraries)' ] + }, + }], ['OS=="linux"', { 'cflags_cc': [ '-Wno-deprecated-register', @@ -121,6 +134,16 @@ 'link_settings': { 'libraries': [ '<(libchromiumcontent_dir)/libboringssl.so', + '-lasound', + '-lcap', + '-lcups', + '-lrt', + '-ldl', + '-lresolv', + '-lfontconfig', + '-lfreetype', + '-lX11 -lXi -lXcursor -lXext -lXfixes -lXrender -lXcomposite -lXdamage -lXtst -lXrandr', + '-lexpat', ], }, }], diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index c94e623f595..09c2eb301ce 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit c94e623f5951db672958f10b098808fc2017ea40 +Subproject commit 09c2eb301ceb50f1ae01f9ba7af4a2adf77a4d87 From 2ef9e85f5e375e18e4e9d8c87639bf5b8507ef73 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 8 Apr 2015 19:20:51 +0800 Subject: [PATCH 0509/1195] Remove linux_clang option --- brightray/brightray.gypi | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 8d77b60e24a..e0336b0bbf5 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -19,9 +19,6 @@ 'mac_deployment_target%': '10.8', 'mac_sdkroot%': 'macosx', - # Build with clang under Linux. - 'linux_clang%': 1, - # See http://msdn.microsoft.com/en-us/library/aa652360(VS.71).aspx 'win_release_Optimization%': '2', # 2 = /Os 'win_debug_Optimization%': '0', # 0 = /Od @@ -271,16 +268,6 @@ ], }, }], - ['OS=="linux" and linux_clang==1', { - 'make_global_settings': [ - ['CC', '/usr/bin/clang'], - ['CXX', '/usr/bin/clang++'], - ['LINK', '$(CXX)'], - ['CC.host', '$(CC)'], - ['CXX.host', '$(CXX)'], - ['LINK.host', '$(LINK)'], - ], - }], ['OS=="win"', { 'target_defaults': { 'include_dirs': [ From 62d845f09eabd1129848d020900cc1eae3088eb6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 09:58:07 +0800 Subject: [PATCH 0510/1195] linux: Improve building flags for Release build --- brightray/brightray.gyp | 26 ++++++++++++++---- brightray/brightray.gypi | 59 +++++++++++++++++++++++++++------------- 2 files changed, 60 insertions(+), 25 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 83b325d447d..1a590987ab4 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -93,6 +93,7 @@ 'common/main_delegate_mac.mm', ], 'conditions': [ + # Link with libraries of libchromiumcontent. ['OS=="linux" and libchromiumcontent_component==0', { # On Linux we have to use "--whole-archive" to force executable # to include all symbols, otherwise we will have plenty of @@ -110,30 +111,43 @@ }, }], ['OS=="linux"', { - 'cflags_cc': [ - '-Wno-deprecated-register', - '-fno-rtti', - ], + 'variables': { + 'system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xrandr xext gconf-2.0', + }, 'link_settings': { 'ldflags': [ - ' Date: Thu, 9 Apr 2015 10:03:01 +0800 Subject: [PATCH 0511/1195] Move filename rules to another file --- brightray/brightray.gypi | 29 ++----------- brightray/filename_rules.gypi | 77 +++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 25 deletions(-) create mode 100644 brightray/filename_rules.gypi diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index c8d9d7ff150..c41b7c5e749 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -37,6 +37,10 @@ 'win_release_InlineFunctionExpansion%': '2', # 1 = only __inline, 2 = max }, 'target_defaults': { + 'includes': [ + # Rules for excluding e.g. foo_win.cc from the build on non-Windows. + 'filename_rules.gypi', + ], 'xcode_settings': { 'ALWAYS_SEARCH_USER_PATHS': 'NO', 'ARCHS': ['x86_64'], @@ -262,31 +266,6 @@ }], # OS=="win" and libchromiumcontent_component==0 ], }, - 'conditions': [ - ['OS!="mac"', { - 'sources/': [ - ['exclude', '/mac/'], - ['exclude', '_mac\.(mm|h)$'], - ], - }, { - 'sources/': [ - ['exclude', '/views/'], - ['exclude', '_views\.(cc|h)$'], - ], - }], - ['OS!="win"', { - 'sources/': [ - ['exclude', '/win/'], - ['exclude', '_win\.(cc|h)$'], - ], - }], - ['OS!="linux"', { - 'sources/': [ - ['exclude', '/linux/'], - ['exclude', '_linux\.(cc|h)$'], - ], - }], - ], }, 'conditions': [ ['OS=="win"', { diff --git a/brightray/filename_rules.gypi b/brightray/filename_rules.gypi new file mode 100644 index 00000000000..e1ee46dddee --- /dev/null +++ b/brightray/filename_rules.gypi @@ -0,0 +1,77 @@ +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# This gypi file defines the patterns used for determining whether a +# file is excluded from the build on a given platform. It is +# included by common.gypi for chromium_code. + +{ + 'target_conditions': [ + ['OS!="win"', { + 'sources/': [ ['exclude', '_win(_unittest)?\\.(h|cc)$'], + ['exclude', '(^|/)win/'], + ['exclude', '(^|/)win_[^/]*\\.(h|cc)$'] ], + }], + ['OS!="mac"', { + 'sources/': [ ['exclude', '_(cocoa|mac)(_unittest)?\\.(h|cc|mm?)$'], + ['exclude', '(^|/)(cocoa|mac)/'] ], + }], + ['OS!="ios"', { + 'sources/': [ ['exclude', '_ios(_unittest)?\\.(h|cc|mm?)$'], + ['exclude', '(^|/)ios/'] ], + }], + ['OS!="mac" and OS!="ios"', { + 'sources/': [ ['exclude', '\\.mm?$' ] ], + }], + # Do not exclude the linux files on *BSD since most of them can be + # shared at this point. + # In case a file is not needed, it is going to be excluded later on. + # TODO(evan): the above is not correct; we shouldn't build _linux + # files on non-linux. + ['OS!="linux" and OS!="openbsd" and OS!="freebsd"', { + 'sources/': [ + ['exclude', '(^|/)library_loaders/'], + ['exclude', '_linux(_unittest)?\\.(h|cc)$'], + ['exclude', '(^|/)linux_[^/]*\\.(h|cc)$'], + ['exclude', '(^|/)linux/'], + ['exclude', '_x11(_unittest)?\\.(h|cc)$'], + ['exclude', '(^|/)x11_[^/]*\\.(h|cc)$'], + ['exclude', '(^|/)x11/'], + ], + }], + ['OS!="android"', { + 'sources/': [ + ['exclude', '_android(_unittest)?\\.cc$'], + ['exclude', '(^|/)android/'], + ], + }], + ['OS=="win"', { + 'sources/': [ + ['exclude', '_posix(_unittest)?\\.(h|cc)$'], + ['exclude', '(^|/)posix/'], + ], + }], + ['OS!="linux" and OS!="openbsd" and OS!="freebsd"', { + 'sources/': [ + ['exclude', '_xdg(_unittest)?\\.(h|cc)$'], + ], + }], + ['OS!="linux" and OS!="openbsd" and OS!="freebsd"', { + 'sources/': [ + ['exclude', '_gtk(_browsertest|_unittest)?\\.(h|cc)$'], + ['exclude', '(^|/)gtk/'], + ['exclude', '(^|/)gtk_[^/]*\\.(h|cc)$'], + ['exclude', '(^|/)libgtk2ui/'], + ['exclude', '(^|/)x/'], + ], + }], + ['OS=="mac"', { + 'sources/': [ ['exclude', '_aura(_browsertest|_unittest)?\\.(h|cc)$'], + ['exclude', '(^|/)aura/'], + ['exclude', '_views\\.(h|cc)$'], + ['exclude', '(^|/)views/'], + ], + }], + ] +} From 845986750cd151963a2594964177c908e2aefe92 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 10:11:28 +0800 Subject: [PATCH 0512/1195] Move filenames to another file --- brightray/brightray.gyp | 69 ++------------------------------------- brightray/filenames.gypi | 70 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 67 deletions(-) create mode 100644 brightray/filenames.gypi diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 1a590987ab4..0497bf67e87 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -1,6 +1,6 @@ { 'includes': [ - 'brightray.gypi', + 'filenames.gypi', ], 'targets': [ { @@ -26,72 +26,7 @@ '<(libchromiumcontent_dir)/gen', ], }, - 'sources': [ - 'browser/brightray_paths.h', - 'browser/browser_client.cc', - 'browser/browser_client.h', - 'browser/browser_context.cc', - 'browser/browser_context.h', - 'browser/browser_main_parts.cc', - 'browser/browser_main_parts.h', - 'browser/browser_main_parts_mac.mm', - 'browser/default_web_contents_delegate.cc', - 'browser/default_web_contents_delegate.h', - 'browser/default_web_contents_delegate_mac.mm', - 'browser/devtools_contents_resizing_strategy.cc', - 'browser/devtools_contents_resizing_strategy.h', - 'browser/devtools_embedder_message_dispatcher.cc', - 'browser/devtools_embedder_message_dispatcher.h', - 'browser/devtools_manager_delegate.cc', - 'browser/devtools_manager_delegate.h', - 'browser/devtools_ui.cc', - 'browser/devtools_ui.h', - 'browser/inspectable_web_contents.cc', - 'browser/inspectable_web_contents.h', - 'browser/inspectable_web_contents_delegate.cc', - 'browser/inspectable_web_contents_delegate.h', - 'browser/inspectable_web_contents_impl.cc', - 'browser/inspectable_web_contents_impl.h', - 'browser/inspectable_web_contents_view.h', - 'browser/inspectable_web_contents_view_mac.h', - 'browser/inspectable_web_contents_view_mac.mm', - 'browser/mac/bry_application.h', - 'browser/mac/bry_application.mm', - 'browser/mac/bry_inspectable_web_contents_view.h', - 'browser/mac/bry_inspectable_web_contents_view.mm', - 'browser/media/media_capture_devices_dispatcher.cc', - 'browser/media/media_capture_devices_dispatcher.h', - 'browser/media/media_stream_devices_controller.cc', - 'browser/media/media_stream_devices_controller.h', - 'browser/network_delegate.cc', - 'browser/network_delegate.h', - 'browser/notification_presenter.h', - 'browser/notification_presenter_mac.h', - 'browser/notification_presenter_mac.mm', - 'browser/platform_notification_service_impl.cc', - 'browser/platform_notification_service_impl.h', - 'browser/linux/notification_presenter_linux.h', - 'browser/linux/notification_presenter_linux.cc', - 'browser/url_request_context_getter.cc', - 'browser/url_request_context_getter.h', - 'browser/views/inspectable_web_contents_view_views.h', - 'browser/views/inspectable_web_contents_view_views.cc', - 'browser/views/views_delegate.cc', - 'browser/views/views_delegate.h', - 'browser/web_ui_controller_factory.cc', - 'browser/web_ui_controller_factory.h', - 'common/application_info.h', - 'common/application_info_mac.mm', - 'common/application_info_win.cc', - 'common/content_client.cc', - 'common/content_client.h', - 'common/mac/foundation_util.h', - 'common/mac/main_application_bundle.h', - 'common/mac/main_application_bundle.mm', - 'common/main_delegate.cc', - 'common/main_delegate.h', - 'common/main_delegate_mac.mm', - ], + 'sources': [ '<@(brightray_sources)' ], 'conditions': [ # Link with libraries of libchromiumcontent. ['OS=="linux" and libchromiumcontent_component==0', { diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi new file mode 100644 index 00000000000..203e2037b43 --- /dev/null +++ b/brightray/filenames.gypi @@ -0,0 +1,70 @@ +{ + 'variables': { + 'brightray_sources': [ + 'browser/brightray_paths.h', + 'browser/browser_client.cc', + 'browser/browser_client.h', + 'browser/browser_context.cc', + 'browser/browser_context.h', + 'browser/browser_main_parts.cc', + 'browser/browser_main_parts.h', + 'browser/browser_main_parts_mac.mm', + 'browser/default_web_contents_delegate.cc', + 'browser/default_web_contents_delegate.h', + 'browser/default_web_contents_delegate_mac.mm', + 'browser/devtools_contents_resizing_strategy.cc', + 'browser/devtools_contents_resizing_strategy.h', + 'browser/devtools_embedder_message_dispatcher.cc', + 'browser/devtools_embedder_message_dispatcher.h', + 'browser/devtools_manager_delegate.cc', + 'browser/devtools_manager_delegate.h', + 'browser/devtools_ui.cc', + 'browser/devtools_ui.h', + 'browser/inspectable_web_contents.cc', + 'browser/inspectable_web_contents.h', + 'browser/inspectable_web_contents_delegate.cc', + 'browser/inspectable_web_contents_delegate.h', + 'browser/inspectable_web_contents_impl.cc', + 'browser/inspectable_web_contents_impl.h', + 'browser/inspectable_web_contents_view.h', + 'browser/inspectable_web_contents_view_mac.h', + 'browser/inspectable_web_contents_view_mac.mm', + 'browser/mac/bry_application.h', + 'browser/mac/bry_application.mm', + 'browser/mac/bry_inspectable_web_contents_view.h', + 'browser/mac/bry_inspectable_web_contents_view.mm', + 'browser/media/media_capture_devices_dispatcher.cc', + 'browser/media/media_capture_devices_dispatcher.h', + 'browser/media/media_stream_devices_controller.cc', + 'browser/media/media_stream_devices_controller.h', + 'browser/network_delegate.cc', + 'browser/network_delegate.h', + 'browser/notification_presenter.h', + 'browser/notification_presenter_mac.h', + 'browser/notification_presenter_mac.mm', + 'browser/platform_notification_service_impl.cc', + 'browser/platform_notification_service_impl.h', + 'browser/linux/notification_presenter_linux.h', + 'browser/linux/notification_presenter_linux.cc', + 'browser/url_request_context_getter.cc', + 'browser/url_request_context_getter.h', + 'browser/views/inspectable_web_contents_view_views.h', + 'browser/views/inspectable_web_contents_view_views.cc', + 'browser/views/views_delegate.cc', + 'browser/views/views_delegate.h', + 'browser/web_ui_controller_factory.cc', + 'browser/web_ui_controller_factory.h', + 'common/application_info.h', + 'common/application_info_mac.mm', + 'common/application_info_win.cc', + 'common/content_client.cc', + 'common/content_client.h', + 'common/mac/foundation_util.h', + 'common/mac/main_application_bundle.h', + 'common/mac/main_application_bundle.mm', + 'common/main_delegate.cc', + 'common/main_delegate.h', + 'common/main_delegate_mac.mm', + ], + }, +} From 9a691d1be8bd92d46afea1f028e8264e2fa519b6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 10:14:25 +0800 Subject: [PATCH 0513/1195] Add "linux_system_libraries" variable --- brightray/brightray.gyp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 0497bf67e87..5598d319b61 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -1,4 +1,8 @@ { + 'variables': { + # The libraries brightray will be compiled to. + 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xrandr xext gconf-2.0' + }, 'includes': [ 'filenames.gypi', ], @@ -46,26 +50,23 @@ }, }], ['OS=="linux"', { - 'variables': { - 'system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xrandr xext gconf-2.0', - }, 'link_settings': { 'ldflags': [ - ' Date: Thu, 9 Apr 2015 10:40:49 +0800 Subject: [PATCH 0514/1195] mac: Improve configs for Release build --- brightray/brightray.gypi | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index c41b7c5e749..9f869c3e472 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -16,9 +16,6 @@ }], ], - 'mac_deployment_target%': '10.8', - 'mac_sdkroot%': 'macosx', - # See http://msdn.microsoft.com/en-us/library/aa652360(VS.71).aspx 'win_release_Optimization%': '2', # 2 = /Os 'win_debug_Optimization%': '0', # 0 = /Od @@ -41,6 +38,7 @@ # Rules for excluding e.g. foo_win.cc from the build on non-Windows. 'filename_rules.gypi', ], + # Putting this in "configurations" will make overrides not working. 'xcode_settings': { 'ALWAYS_SEARCH_USER_PATHS': 'NO', 'ARCHS': ['x86_64'], @@ -50,9 +48,9 @@ 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', 'GCC_ENABLE_CPP_RTTI': 'NO', 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', - 'MACOSX_DEPLOYMENT_TARGET': '<(mac_deployment_target)', + 'MACOSX_DEPLOYMENT_TARGET': '10.8', 'RUN_CLANG_STATIC_ANALYZER': 'YES', - 'SDKROOT': '<(mac_sdkroot)', + 'SDKROOT': 'macosx', 'USE_HEADER_MAP': 'NO', 'WARNING_CFLAGS': [ '-Wall', @@ -202,6 +200,16 @@ }], ], }, + 'xcode_settings': { + 'DEAD_CODE_STRIPPING': 'YES', # -Wl,-dead_strip + 'GCC_OPTIMIZATION_LEVEL': '2', + 'OTHER_CFLAGS': [ + '-fno-inline', + '-fno-omit-frame-pointer', + '-fno-builtin', + '-fno-optimize-sibling-calls', + ], + }, }, 'conditions': [ ['OS=="linux"', { From 8a1a39b7b117f9646d60ffa7cbd656e2e4547a74 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 10:49:36 +0800 Subject: [PATCH 0515/1195] Add flag to build with clang --- brightray/brightray.gypi | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 9f869c3e472..0154806dec2 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -3,6 +3,9 @@ 'vendor/download/libchromiumcontent/filenames.gypi', ], 'variables': { + # Build with clang on Linux and Mac. + 'clang%': 1, + 'libchromiumcontent_src_dir': '<(libchromiumcontent_root_dir)/src', 'libchromiumcontent_component%': 1, 'conditions': [ @@ -274,8 +277,34 @@ }], # OS=="win" and libchromiumcontent_component==0 ], }, - }, + }, # target_defaults 'conditions': [ + ['clang', { + 'make_global_settings': [ + ['CC', '/usr/bin/clang'], + ['CXX', '/usr/bin/clang++'], + ['LINK', '$(CXX)'], + ['CC.host', '$(CC)'], + ['CXX.host', '$(CXX)'], + ['LINK.host', '$(LINK)'], + ], + 'target_defaults': { + 'cflags_cc': [ + '-std=c++11', + ], + 'xcode_settings': { + 'CC': '/usr/bin/clang', + 'LDPLUSPLUS': '/usr/bin/clang++', + 'OTHER_CFLAGS': [ + '-fcolor-diagnostics', + ], + + 'GCC_C_LANGUAGE_STANDARD': 'c99', # -std=c99 + 'CLANG_CXX_LIBRARY': 'libc++', # -stdlib=libc++ + 'CLANG_CXX_LANGUAGE_STANDARD': 'c++11', # -std=c++11 + }, + }, + }], # clang ['OS=="win"', { 'target_defaults': { 'include_dirs': [ From 6e3de02554b72dc611c534e8c801b44b63b8b9fd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 11:30:01 +0800 Subject: [PATCH 0516/1195] mac: "xcode_settings" doesn't work under "configurations" --- brightray/brightray.gypi | 55 +++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 0154806dec2..de001182a53 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -45,8 +45,6 @@ 'xcode_settings': { 'ALWAYS_SEARCH_USER_PATHS': 'NO', 'ARCHS': ['x86_64'], - 'CLANG_CXX_LANGUAGE_STANDARD': 'c++11', - 'CLANG_CXX_LIBRARY': 'libc++', 'COMBINE_HIDPI_IMAGES': 'YES', 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', 'GCC_ENABLE_CPP_RTTI': 'NO', @@ -168,10 +166,6 @@ ], }, }, - 'xcode_settings': { - 'COPY_PHASE_STRIP': 'NO', - 'GCC_OPTIMIZATION_LEVEL': '0', - }, }, # Debug_Base 'Release_Base': { 'msvs_settings': { @@ -203,16 +197,6 @@ }], ], }, - 'xcode_settings': { - 'DEAD_CODE_STRIPPING': 'YES', # -Wl,-dead_strip - 'GCC_OPTIMIZATION_LEVEL': '2', - 'OTHER_CFLAGS': [ - '-fno-inline', - '-fno-omit-frame-pointer', - '-fno-builtin', - '-fno-optimize-sibling-calls', - ], - }, }, 'conditions': [ ['OS=="linux"', { @@ -276,7 +260,35 @@ }, # R_x64 }], # OS=="win" and libchromiumcontent_component==0 ], - }, + }, # configurations + 'target_conditions': [ + # Putting this under "configurations" doesn't work. + ['libchromiumcontent_component', { + 'xcode_settings': { + 'GCC_OPTIMIZATION_LEVEL': '0', + }, + }, { # "Debug_Base" + 'xcode_settings': { + 'DEAD_CODE_STRIPPING': 'YES', # -Wl,-dead_strip + 'GCC_OPTIMIZATION_LEVEL': '2', + 'OTHER_CFLAGS': [ + '-fno-inline', + '-fno-omit-frame-pointer', + '-fno-builtin', + '-fno-optimize-sibling-calls', + ], + }, + }], # "Release_Base" + ['OS=="mac" and libchromiumcontent_component==0 and _type in ["executable", "shared_library"]', { + 'xcode_settings': { + # Generates symbols and strip the binary. + 'DEBUG_INFORMATION_FORMAT': 'dwarf-with-dsym', + 'DEPLOYMENT_POSTPROCESSING': 'YES', + 'STRIP_INSTALLED_PRODUCT': 'YES', + 'STRIPFLAGS': '-x', + }, + }], # OS=="mac" and libchromiumcontent_component==0 and _type in ["executable", "shared_library"] + ], # target_conditions }, # target_defaults 'conditions': [ ['clang', { @@ -303,6 +315,15 @@ 'CLANG_CXX_LIBRARY': 'libc++', # -stdlib=libc++ 'CLANG_CXX_LANGUAGE_STANDARD': 'c++11', # -std=c++11 }, + 'target_conditions': [ + ['_type in ["executable", "shared_library"]', { + 'xcode_settings': { + # On some machines setting CLANG_CXX_LIBRARY doesn't work for + # linker. + 'OTHER_LDFLAGS': [ '-stdlib=libc++' ], + }, + }], + ], }, }], # clang ['OS=="win"', { From 794b459ccd64edf64d8a4568b911a628ec7371ac Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 12:05:07 +0800 Subject: [PATCH 0517/1195] linux: Work around linker OOM on 32bit target --- brightray/brightray.gypi | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index de001182a53..d71e2f4ecb4 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -202,6 +202,8 @@ ['OS=="linux"', { 'cflags': [ '-O2', + # Generate symbols, will be stripped later. + '-g', # Don't emit the GCC version ident directives, they just end up # in the .comment section taking up binary size. '-fno-ident', @@ -288,6 +290,12 @@ 'STRIPFLAGS': '-x', }, }], # OS=="mac" and libchromiumcontent_component==0 and _type in ["executable", "shared_library"] + ['OS=="linux" and target_arch=="ia32" and _toolset=="target"', { + 'ldflags': [ + # Workaround for linker OOM. + '-Wl,--no-keep-memory', + ], + }], ], # target_conditions }, # target_defaults 'conditions': [ From 9d921afff0e0ba9a4e1bcc8b0c6e08c715e92aa8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 13:30:21 +0800 Subject: [PATCH 0518/1195] win: Remove unused config variables --- brightray/brightray.gypi | 85 +++++++--------------------------------- 1 file changed, 15 insertions(+), 70 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index d71e2f4ecb4..abea4809fc8 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -18,23 +18,6 @@ 'libchromiumcontent_libraries%': '<(libchromiumcontent_static_libraries)', }], ], - - # See http://msdn.microsoft.com/en-us/library/aa652360(VS.71).aspx - 'win_release_Optimization%': '2', # 2 = /Os - 'win_debug_Optimization%': '0', # 0 = /Od - - # See http://msdn.microsoft.com/en-us/library/2kxx5t2c(v=vs.80).aspx - # Tri-state: blank is default, 1 on, 0 off - 'win_release_OmitFramePointers%': '0', - # Tri-state: blank is default, 1 on, 0 off - 'win_debug_OmitFramePointers%': '', - - # See http://msdn.microsoft.com/en-us/library/8wtf2dfz(VS.71).aspx - 'win_debug_RuntimeChecks%': '3', # 3 = all checks enabled, 0 = off - - # See http://msdn.microsoft.com/en-us/library/47238hez(VS.71).aspx - 'win_debug_InlineFunctionExpansion%': '', # empty = default, 0 = off, - 'win_release_InlineFunctionExpansion%': '2', # 1 = only __inline, 2 = max }, 'target_defaults': { 'includes': [ @@ -137,65 +120,27 @@ 'msvs_settings': { 'VCCLCompilerTool': { 'RuntimeLibrary': '2', # /MD (nondebug DLL) - 'Optimization': '<(win_debug_Optimization)', - 'BasicRuntimeChecks': '<(win_debug_RuntimeChecks)', - 'conditions': [ - # According to MSVS, InlineFunctionExpansion=0 means - # "default inlining", not "/Ob0". - # Thus, we have to handle InlineFunctionExpansion==0 separately. - ['win_debug_InlineFunctionExpansion==0', { - 'AdditionalOptions': ['/Ob0'], - }], - ['win_debug_InlineFunctionExpansion!=""', { - 'InlineFunctionExpansion': - '<(win_debug_InlineFunctionExpansion)', - }], - # if win_debug_OmitFramePointers is blank, leave as default - ['win_debug_OmitFramePointers==1', { - 'OmitFramePointers': 'true', - }], - ['win_debug_OmitFramePointers==0', { - 'OmitFramePointers': 'false', - # The above is not sufficient (http://crbug.com/106711): it - # simply eliminates an explicit "/Oy", but both /O2 and /Ox - # perform FPO regardless, so we must explicitly disable. - # We still want the false setting above to avoid having - # "/Oy /Oy-" and warnings about overriding. - 'AdditionalOptions': ['/Oy-'], - }], - ], + 'Optimization': '0', # 0 = /Od + # See http://msdn.microsoft.com/en-us/library/8wtf2dfz(VS.71).aspx + 'BasicRuntimeChecks': '3', # 3 = all checks enabled, 0 = off }, }, }, # Debug_Base 'Release_Base': { 'msvs_settings': { 'VCCLCompilerTool': { - 'Optimization': '<(win_release_Optimization)', - 'conditions': [ - # According to MSVS, InlineFunctionExpansion=0 means - # "default inlining", not "/Ob0". - # Thus, we have to handle InlineFunctionExpansion==0 separately. - ['win_release_InlineFunctionExpansion==0', { - 'AdditionalOptions': ['/Ob0'], - }], - ['win_release_InlineFunctionExpansion!=""', { - 'InlineFunctionExpansion': - '<(win_release_InlineFunctionExpansion)', - }], - # if win_release_OmitFramePointers is blank, leave as default - ['win_release_OmitFramePointers==1', { - 'OmitFramePointers': 'true', - }], - ['win_release_OmitFramePointers==0', { - 'OmitFramePointers': 'false', - # The above is not sufficient (http://crbug.com/106711): it - # simply eliminates an explicit "/Oy", but both /O2 and /Ox - # perform FPO regardless, so we must explicitly disable. - # We still want the false setting above to avoid having - # "/Oy /Oy-" and warnings about overriding. - 'AdditionalOptions': ['/Oy-'], - }], - ], + # See http://msdn.microsoft.com/en-us/library/aa652360(VS.71).aspx + 'Optimization': '2', # 2 = /Os + # See http://msdn.microsoft.com/en-us/library/47238hez(VS.71).aspx + 'InlineFunctionExpansion': '2', # 2 = max + # See http://msdn.microsoft.com/en-us/library/2kxx5t2c(v=vs.80).aspx + 'OmitFramePointers': 'false', + # The above is not sufficient (http://crbug.com/106711): it + # simply eliminates an explicit "/Oy", but both /O2 and /Ox + # perform FPO regardless, so we must explicitly disable. + # We still want the false setting above to avoid having + # "/Oy /Oy-" and warnings about overriding. + 'AdditionalOptions': ['/Oy-'], }, }, 'conditions': [ From 02ee07c4a020848dc341e47872459493309c4845 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 13:38:54 +0800 Subject: [PATCH 0519/1195] win: No need to set default linked libraries --- brightray/brightray.gyp | 13 +++++++++++++ brightray/brightray.gypi | 17 ----------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 5598d319b61..10313d2ff06 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -170,6 +170,19 @@ ], 'msvs_settings': { 'VCLinkerTool': { + 'AdditionalDependencies': [ + 'advapi32.lib', + 'dbghelp.lib', + 'dwmapi.lib', + 'gdi32.lib', + 'netapi32.lib', + 'oleacc.lib', + 'powrprof.lib', + 'user32.lib', + 'usp10.lib', + 'version.lib', + 'winspool.lib', + ], 'DelayLoadDLLs': [ 'ffmpegsumo.dll', # content_common.gypi: diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index abea4809fc8..d90da93ddc9 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -67,23 +67,6 @@ 'IntermediateDirectory': '$(OutDir)\\obj\\$(ProjectName)', 'CharacterSet': '1', }, - 'msvs_settings': { - 'VCLinkerTool': { - 'AdditionalDependencies': [ - 'advapi32.lib', - 'dbghelp.lib', - 'dwmapi.lib', - 'gdi32.lib', - 'netapi32.lib', - 'oleacc.lib', - 'powrprof.lib', - 'user32.lib', - 'usp10.lib', - 'version.lib', - 'winspool.lib', - ], - }, - }, 'conditions': [ ['OS!="mac"', { 'defines': [ From a8eb750efa3abf58f9a343337682551ff43d883e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 14:03:42 +0800 Subject: [PATCH 0520/1195] win: Cleanup the compiler settings --- brightray/brightray.gypi | 169 ++++++++++++++++++++++----------------- 1 file changed, 96 insertions(+), 73 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index d90da93ddc9..bfee41eaac4 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -43,6 +43,71 @@ '-Wno-missing-field-initializers', ], }, + 'msvs_configuration_attributes': { + 'OutputDirectory': '<(DEPTH)\\build\\$(ConfigurationName)', + 'IntermediateDirectory': '$(OutDir)\\obj\\$(ProjectName)', + 'CharacterSet': '1', + }, + 'msvs_system_include_dirs': [ + '$(VSInstallDir)/VC/atlmfc/include', + ], + 'msvs_settings': { + 'VCCLCompilerTool': { + 'AdditionalOptions': ['/MP'], + 'MinimalRebuild': 'false', + 'BufferSecurityCheck': 'true', + 'EnableFunctionLevelLinking': 'true', + 'RuntimeTypeInfo': 'false', + 'WarningLevel': '4', + 'WarnAsError': 'true', + 'DebugInformationFormat': '3', + # Programs that use the Standard C++ library must be compiled with + # C++ + # exception handling enabled. + # http://support.microsoft.com/kb/154419 + 'ExceptionHandling': 1, + }, + 'VCLinkerTool': { + 'GenerateDebugInformation': 'true', + 'MapFileName': '$(OutDir)\\$(TargetName).map', + 'ImportLibrary': '$(OutDir)\\lib\\$(TargetName).lib', + 'LinkTimeCodeGeneration': 'true', # /LTCG + 'AdditionalOptions': [ + # ATL 8.0 included in WDK 7.1 makes the linker to generate + # following + # warnings: + # - warning LNK4254: section 'ATL' (50000040) merged into + # '.rdata' (40000040) with different attributes + # - warning LNK4078: multiple 'ATL' sections found with + # different attributes + '/ignore:4254', + '/ignore:4078', + # views_chromiumcontent.lib generates this warning because it's + # symobls are defined as dllexport but used as static library: + # - warning LNK4217: locally defined symbol imported in function + # - warning LNK4049: locally defined symbol imported + '/ignore:4217', + '/ignore:4049', + ], + }, + }, + 'msvs_disabled_warnings': [ + 4100, # unreferenced formal parameter + 4127, # conditional expression is constant + 4189, # local variable is initialized but not referenced + 4244, # 'initializing' : conversion from 'double' to 'size_t', possible loss of data + 4245, # 'initializing' : conversion from 'int' to 'const net::QuicVersionTag', signed/unsigned mismatch + 4251, # class 'std::xx' needs to have dll-interface. + 4310, # cast truncates constant value + 4355, # 'this' : used in base member initializer list + 4480, # nonstandard extension used: specifying underlying type for enum + 4481, # nonstandard extension used: override specifier 'override' + 4510, # default constructor could not be generated + 4512, # assignment operator could not be generated + 4610, # user defined constructor required + 4702, # unreachable code + 4819, # The file contains a character that cannot be represented in the current code page + ], 'configurations': { # The "Debug" and "Release" configurations are not actually used. 'Debug': {}, @@ -62,11 +127,6 @@ 'SK_IGNORE_ETC1_SUPPORT', 'SK_IGNORE_GPU_DITHER', ], - 'msvs_configuration_attributes': { - 'OutputDirectory': '<(DEPTH)\\build\\$(ConfigurationName)', - 'IntermediateDirectory': '$(OutDir)\\obj\\$(ProjectName)', - 'CharacterSet': '1', - }, 'conditions': [ ['OS!="mac"', { 'defines': [ @@ -86,6 +146,24 @@ '-fno-rtti', ], }], # OS=="linux" + ['OS=="win"', { + 'include_dirs': [ + '<(libchromiumcontent_src_dir)/third_party/wtl/include', + ], + 'defines': [ + '_WIN32_WINNT=0x0602', + 'WINVER=0x0602', + 'WIN32', + '_WINDOWS', + 'NOMINMAX', + 'PSAPI_VERSION=1', + '_CRT_RAND_S', + 'CERT_CHAIN_PARA_HAS_EXTRA_FIELDS', + 'WIN32_LEAN_AND_MEAN', + '_ATL_NO_OPENGL', + '_SECURE_ATL', + ], + }], # OS=="win" ], }, # Common_Base 'Debug_Base': { @@ -112,8 +190,9 @@ 'Release_Base': { 'msvs_settings': { 'VCCLCompilerTool': { - # See http://msdn.microsoft.com/en-us/library/aa652360(VS.71).aspx 'Optimization': '2', # 2 = /Os + 'FavorSizeOrSpeed': '1', # 1 = /Ot + 'WholeProgramOptimization': 'true', # See http://msdn.microsoft.com/en-us/library/47238hez(VS.71).aspx 'InlineFunctionExpansion': '2', # 2 = max # See http://msdn.microsoft.com/en-us/library/2kxx5t2c(v=vs.80).aspx @@ -178,17 +257,18 @@ }, }, }, # x64_Base + 'conditions': [ + ['libchromiumcontent_component', { + 'D_x64': { + 'inherit_from': ['Common_Base', 'x64_Base', 'Debug_Base'], + }, # D_x64 + }, { + 'R_x64': { + 'inherit_from': ['Common_Base', 'x64_Base', 'Release_Base'], + }, # R_x64 + }], # libchromiumcontent_component + ], }], # OS=="win" - ['OS=="win" and libchromiumcontent_component==1', { - 'D_x64': { - 'inherit_from': ['Common_Base', 'x64_Base', 'Debug_Base'], - }, # D_x64 - }], # OS=="win" and libchromiumcontent_component==1 - ['OS=="win" and libchromiumcontent_component==0', { - 'R_x64': { - 'inherit_from': ['Common_Base', 'x64_Base', 'Release_Base'], - }, # R_x64 - }], # OS=="win" and libchromiumcontent_component==0 ], }, # configurations 'target_conditions': [ @@ -262,62 +342,5 @@ ], }, }], # clang - ['OS=="win"', { - 'target_defaults': { - 'include_dirs': [ - '<(libchromiumcontent_src_dir)/third_party/wtl/include', - ], - 'defines': [ - '_WIN32_WINNT=0x0602', - 'WINVER=0x0602', - 'WIN32', - '_WINDOWS', - 'NOMINMAX', - 'PSAPI_VERSION=1', - '_CRT_RAND_S', - 'CERT_CHAIN_PARA_HAS_EXTRA_FIELDS', - 'WIN32_LEAN_AND_MEAN', - '_ATL_NO_OPENGL', - '_SECURE_ATL', - ], - 'msvs_system_include_dirs': [ - '$(VSInstallDir)/VC/atlmfc/include', - ], - 'msvs_settings': { - 'VCCLCompilerTool': { - 'AdditionalOptions': ['/MP'], - 'MinimalRebuild': 'false', - 'BufferSecurityCheck': 'true', - 'EnableFunctionLevelLinking': 'true', - 'RuntimeTypeInfo': 'false', - 'WarningLevel': '4', - 'WarnAsError': 'true', - 'DebugInformationFormat': '3', - }, - 'VCLinkerTool': { - 'GenerateDebugInformation': 'true', - 'MapFileName': '$(OutDir)\\$(TargetName).map', - 'ImportLibrary': '$(OutDir)\\lib\\$(TargetName).lib', - }, - }, - 'msvs_disabled_warnings': [ - 4100, # unreferenced formal parameter - 4127, # conditional expression is constant - 4189, # local variable is initialized but not referenced - 4244, # 'initializing' : conversion from 'double' to 'size_t', possible loss of data - 4245, # 'initializing' : conversion from 'int' to 'const net::QuicVersionTag', signed/unsigned mismatch - 4251, # class 'std::xx' needs to have dll-interface. - 4310, # cast truncates constant value - 4355, # 'this' : used in base member initializer list - 4480, # nonstandard extension used: specifying underlying type for enum - 4481, # nonstandard extension used: override specifier 'override' - 4510, # default constructor could not be generated - 4512, # assignment operator could not be generated - 4610, # user defined constructor required - 4702, # unreachable code - 4819, # The file contains a character that cannot be represented in the current code page - ], - }, - }], ], } From 62e945283123a3593aaf3c52f59617f3e09d35d9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 14:39:52 +0800 Subject: [PATCH 0521/1195] win: Do not use link time code generation It causes problems on Windows --- brightray/brightray.gypi | 2 -- 1 file changed, 2 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index bfee41eaac4..f643b5555ab 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -71,7 +71,6 @@ 'GenerateDebugInformation': 'true', 'MapFileName': '$(OutDir)\\$(TargetName).map', 'ImportLibrary': '$(OutDir)\\lib\\$(TargetName).lib', - 'LinkTimeCodeGeneration': 'true', # /LTCG 'AdditionalOptions': [ # ATL 8.0 included in WDK 7.1 makes the linker to generate # following @@ -192,7 +191,6 @@ 'VCCLCompilerTool': { 'Optimization': '2', # 2 = /Os 'FavorSizeOrSpeed': '1', # 1 = /Ot - 'WholeProgramOptimization': 'true', # See http://msdn.microsoft.com/en-us/library/47238hez(VS.71).aspx 'InlineFunctionExpansion': '2', # 2 = max # See http://msdn.microsoft.com/en-us/library/2kxx5t2c(v=vs.80).aspx From b85b08ef8c8fc10fd7ac92b64326df9baf7511b4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 9 Apr 2015 20:47:47 +0800 Subject: [PATCH 0522/1195] Separate V8 libraries from other libraries --- brightray/brightray.gypi | 2 ++ brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index f643b5555ab..d6263262166 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -13,9 +13,11 @@ ['libchromiumcontent_component', { 'libchromiumcontent_dir%': '<(libchromiumcontent_root_dir)/shared_library', 'libchromiumcontent_libraries%': '<(libchromiumcontent_shared_libraries)', + 'libchromiumcontent_v8_libraries%': '<(libchromiumcontent_shared_v8_libraries)', }, { 'libchromiumcontent_dir%': '<(libchromiumcontent_root_dir)/static_library', 'libchromiumcontent_libraries%': '<(libchromiumcontent_static_libraries)', + 'libchromiumcontent_v8_libraries%': '<(libchromiumcontent_static_v8_libraries)', }], ], }, diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 09c2eb301ce..fdfaa8d1e4f 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 09c2eb301ceb50f1ae01f9ba7af4a2adf77a4d87 +Subproject commit fdfaa8d1e4f1a9a54bf679bbfdb5bf0a3af49399 From 10122304edbe8a31c14cbd9bb2501204dd2b407e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 10 Apr 2015 12:06:55 +0800 Subject: [PATCH 0523/1195] Fix including icu libraries --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index fdfaa8d1e4f..44cb29a12cf 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit fdfaa8d1e4f1a9a54bf679bbfdb5bf0a3af49399 +Subproject commit 44cb29a12cf2b93064ce77a1be94528a535016f4 From 48c9f4a0a6a37140251d06af7bc9cd49fc000abc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 10 Apr 2015 18:49:19 +0800 Subject: [PATCH 0524/1195] No longer link with shared library of boringssl --- brightray/brightray.gyp | 6 ------ brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 10313d2ff06..42e087711fd 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -81,8 +81,6 @@ }, { 'link_settings': { 'libraries': [ - # libboringssl is always linked dynamically. - '<(libchromiumcontent_dir)/libboringssl.so', # Following libraries are required by libchromiumcontent: '-lasound', '-lcap', @@ -109,9 +107,6 @@ ['OS=="mac" and libchromiumcontent_component==0', { 'link_settings': { 'libraries': [ - # This library is built as shared library to avoid symbols - # conflict with Node. - '<(libchromiumcontent_dir)/libboringssl.dylib', # ui_base.gypi: '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', # net.gypi: @@ -152,7 +147,6 @@ ['OS=="win" and libchromiumcontent_component==0', { 'link_settings': { 'libraries': [ - '<(libchromiumcontent_dir)/boringssl.dll', '<(libchromiumcontent_dir)/ffmpegsumo.lib', '<(libchromiumcontent_dir)/libyuv.lib', # content_browser.gypi: diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 44cb29a12cf..a325ed7b30b 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 44cb29a12cf2b93064ce77a1be94528a535016f4 +Subproject commit a325ed7b30bf0680881783edd92ca235b5468e11 From a1b682cd50b42f70f4e9c72505487a2bf518cb77 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 11 Apr 2015 12:06:33 +0800 Subject: [PATCH 0525/1195] Debug_Base and Release_Base configs are abstract --- brightray/brightray.gypi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index d6263262166..db1ee869d45 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -168,6 +168,7 @@ ], }, # Common_Base 'Debug_Base': { + 'abstract': 1, 'defines': [ # Use this instead of "NDEBUG" to determine whether we are in # Debug build, because "NDEBUG" is already used by Chromium. @@ -189,6 +190,7 @@ }, }, # Debug_Base 'Release_Base': { + 'abstract': 1, 'msvs_settings': { 'VCCLCompilerTool': { 'Optimization': '2', # 2 = /Os From decf522f48e4d091eea8eeff4fe8e6f9f3c5a36a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 11 Apr 2015 13:26:29 +0800 Subject: [PATCH 0526/1195] Cleanup the brightray.gyp file --- brightray/brightray.gyp | 181 +++++++++++++++++++++------------------- 1 file changed, 95 insertions(+), 86 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 42e087711fd..55b597bdac8 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -44,11 +44,12 @@ '-Wl,--no-whole-archive', ], } - }, { + }, { # (Release build on Linux) 'link_settings': { 'libraries': [ '<@(libchromiumcontent_libraries)' ] }, - }], + }], # (Normal builds) + # Linux specific link settings. ['OS=="linux"', { 'link_settings': { 'ldflags': [ @@ -96,99 +97,107 @@ }, }], ], - }], + }], # OS=="linux" ['OS=="mac"', { 'link_settings': { 'libraries': [ '$(SDKROOT)/System/Library/Frameworks/AppKit.framework', ], }, - }], - ['OS=="mac" and libchromiumcontent_component==0', { - 'link_settings': { - 'libraries': [ - # ui_base.gypi: - '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', - # net.gypi: - '$(SDKROOT)/System/Library/Frameworks/Foundation.framework', - '$(SDKROOT)/System/Library/Frameworks/Security.framework', - '$(SDKROOT)/System/Library/Frameworks/SystemConfiguration.framework', - '$(SDKROOT)/usr/lib/libresolv.dylib', - # media.gyp: - '$(SDKROOT)/System/Library/Frameworks/AudioToolbox.framework', - '$(SDKROOT)/System/Library/Frameworks/AudioUnit.framework', - '$(SDKROOT)/System/Library/Frameworks/CoreAudio.framework', - '$(SDKROOT)/System/Library/Frameworks/CoreMIDI.framework', - '$(SDKROOT)/System/Library/Frameworks/CoreVideo.framework', - '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', - '$(SDKROOT)/System/Library/Frameworks/QTKit.framework', - # surface.gyp: - '$(SDKROOT)/System/Library/Frameworks/IOSurface.framework', - # content_common.gypi: - '$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework', - # base.gyp: - '$(SDKROOT)/System/Library/Frameworks/ApplicationServices.framework', - '$(SDKROOT)/System/Library/Frameworks/Carbon.framework', - '$(SDKROOT)/System/Library/Frameworks/CoreFoundation.framework', - '$(SDKROOT)/System/Library/Frameworks/IOKit.framework', - # content_browser.gypi: - '$(SDKROOT)/usr/lib/libbsm.dylib', - ], - }, - }], - ['OS=="win" and libchromiumcontent_component==1', { - 'link_settings': { - 'libraries': [ - '<(libchromiumcontent_dir)/base_static.lib', - '<(libchromiumcontent_dir)/sandbox.lib', - ], - }, - }], - ['OS=="win" and libchromiumcontent_component==0', { - 'link_settings': { - 'libraries': [ - '<(libchromiumcontent_dir)/ffmpegsumo.lib', - '<(libchromiumcontent_dir)/libyuv.lib', - # content_browser.gypi: - '-lsensorsapi.lib', - '-lportabledeviceguids.lib', - # content_common.gypi: - '-ld3d9.lib', - '-ldxva2.lib', - '-lstrmiids.lib', - '-lmf.lib', - '-lmfplat.lib', - '-lmfuuid.lib', - # media.gyp: - '-lmfreadwrite.lib', - ], - 'msvs_settings': { - 'VCLinkerTool': { - 'AdditionalDependencies': [ - 'advapi32.lib', - 'dbghelp.lib', - 'dwmapi.lib', - 'gdi32.lib', - 'netapi32.lib', - 'oleacc.lib', - 'powrprof.lib', - 'user32.lib', - 'usp10.lib', - 'version.lib', - 'winspool.lib', - ], - 'DelayLoadDLLs': [ - 'ffmpegsumo.dll', + 'conditions': [ + # Link with system frameworks. + ['libchromiumcontent_component==0', { + 'link_settings': { + 'libraries': [ + # ui_base.gypi: + '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', + # net.gypi: + '$(SDKROOT)/System/Library/Frameworks/Foundation.framework', + '$(SDKROOT)/System/Library/Frameworks/Security.framework', + '$(SDKROOT)/System/Library/Frameworks/SystemConfiguration.framework', + '$(SDKROOT)/usr/lib/libresolv.dylib', + # media.gyp: + '$(SDKROOT)/System/Library/Frameworks/AudioToolbox.framework', + '$(SDKROOT)/System/Library/Frameworks/AudioUnit.framework', + '$(SDKROOT)/System/Library/Frameworks/CoreAudio.framework', + '$(SDKROOT)/System/Library/Frameworks/CoreMIDI.framework', + '$(SDKROOT)/System/Library/Frameworks/CoreVideo.framework', + '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', + '$(SDKROOT)/System/Library/Frameworks/QTKit.framework', + # surface.gyp: + '$(SDKROOT)/System/Library/Frameworks/IOSurface.framework', # content_common.gypi: - 'd3d9.dll', - 'dxva2.dll', - 'mf.dll', - 'mfplat.dll', + '$(SDKROOT)/System/Library/Frameworks/QuartzCore.framework', + # base.gyp: + '$(SDKROOT)/System/Library/Frameworks/ApplicationServices.framework', + '$(SDKROOT)/System/Library/Frameworks/Carbon.framework', + '$(SDKROOT)/System/Library/Frameworks/CoreFoundation.framework', + '$(SDKROOT)/System/Library/Frameworks/IOKit.framework', + # content_browser.gypi: + '$(SDKROOT)/usr/lib/libbsm.dylib', ], }, - }, - }, - }], + }], + ] + }], # OS=="mac" + ['OS=="win"', { + 'conditions': [ + ['libchromiumcontent_component', { + # sandbox and base_static are always linked statically. + 'link_settings': { + 'libraries': [ + '<(libchromiumcontent_dir)/base_static.lib', + '<(libchromiumcontent_dir)/sandbox.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', + # content_common.gypi: + '-ld3d9.lib', + '-ldxva2.lib', + '-lstrmiids.lib', + '-lmf.lib', + '-lmfplat.lib', + '-lmfuuid.lib', + # media.gyp: + '-lmfreadwrite.lib', + ], + 'msvs_settings': { + 'VCLinkerTool': { + 'AdditionalDependencies': [ + 'advapi32.lib', + 'dbghelp.lib', + 'dwmapi.lib', + 'gdi32.lib', + 'netapi32.lib', + 'oleacc.lib', + 'powrprof.lib', + 'user32.lib', + 'usp10.lib', + 'version.lib', + 'winspool.lib', + ], + 'DelayLoadDLLs': [ + 'ffmpegsumo.dll', + # content_common.gypi: + 'd3d9.dll', + 'dxva2.dll', + 'mf.dll', + 'mfplat.dll', + ], + }, + }, + }, + }], # libchromiumcontent_component + ], + }], # OS=="win" ], }, ], From 59d99f7b607af0497944fb47ff5669fafeced25b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 11 Apr 2015 13:43:02 +0800 Subject: [PATCH 0527/1195] Set libchromiumcontent_component when bootstrapping --- brightray/script/build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/script/build b/brightray/script/build index 30ee528230a..6ee7da97a92 100755 --- a/brightray/script/build +++ b/brightray/script/build @@ -19,8 +19,9 @@ def run_gyp(): gyp_pylib = os.path.join(os.path.dirname(GYP), 'pylib') env['PYTHONPATH'] = os.path.pathsep.join([gyp_pylib, env.get('PYTHONPATH', '')]) + env['GYP_DEFINES'] = 'libchromiumcontent_component=static_library' return subprocess.call([sys.executable, GYP, '--depth', '.', - 'brightray.gyp'], env=env) + '-Ibrightray.gypi', 'brightray.gyp'], env=env) def build(): From 0deeae0214faaed9b8c3f7d578ac5a3ebd1b0c34 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 11 Apr 2015 14:44:01 +0800 Subject: [PATCH 0528/1195] Allow specifying the arch of libchromiumcontent to download --- brightray/script/bootstrap | 20 +++++++++++--------- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index b0754f7a1e4..579e0076b06 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -14,14 +14,17 @@ DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download') def main(): args = parse_args() - return (update_submodules() or - download_libchromiumcontent(args.dev, args.commit, args.url)) + + update_submodules() + download_libchromiumcontent(args.dev, args.commit, args.target_arch, args.url) def parse_args(): parser = argparse.ArgumentParser(description='Bootstrap this project') - parser.add_argument('-c', '--commit', nargs='?', default='HEAD', + parser.add_argument('-c', '--commit', required=True, help='The commit of libchromiumcontent to download.') + parser.add_argument('-t', '--target_arch', required=True, + help='The arch of libchromiumcontent to download.') parser.add_argument('-d', '--dev', action='store_true', help='Do not download static_library build') parser.add_argument('url', help='The base URL from which to download ' @@ -36,17 +39,16 @@ def update_submodules(): '--recursive'])) -def download_libchromiumcontent(is_dev, commit, url): +def download_libchromiumcontent(is_dev, commit, target_arch, url): mkdir_p(DOWNLOAD_DIR) download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', 'download') - target = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') + target_dir = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') + args = ['-f', '-c', commit, '-t', target_arch, url, target_dir] if is_dev: - subprocess.check_call([sys.executable, download, '-f', '-c', commit, url, - target]) + subprocess.check_call([sys.executable, download] + args) else: - subprocess.check_call([sys.executable, download, '-s', '-f', '-c', commit, - url, target]) + subprocess.check_call([sys.executable, download, '-s'] + args) def mkdir_p(path): diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index a325ed7b30b..185a9535aa8 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit a325ed7b30bf0680881783edd92ca235b5468e11 +Subproject commit 185a9535aa88ba19b03d3b76d172a9558ae37354 From a4a1812f173d7a3b65fe36f7252d135876a2984b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 11 Apr 2015 18:25:47 +0800 Subject: [PATCH 0529/1195] Require target_arch parameter --- brightray/script/bootstrap | 6 +++--- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index 579e0076b06..7cd1abffc06 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -23,10 +23,10 @@ def parse_args(): parser = argparse.ArgumentParser(description='Bootstrap this project') parser.add_argument('-c', '--commit', required=True, help='The commit of libchromiumcontent to download.') - parser.add_argument('-t', '--target_arch', required=True, - help='The arch of libchromiumcontent to download.') parser.add_argument('-d', '--dev', action='store_true', help='Do not download static_library build') + parser.add_argument('--target_arch', required=True, + help='The arch of libchromiumcontent to download.') parser.add_argument('url', help='The base URL from which to download ' 'libchromiumcontent (i.e., the URL you passed to ' 'libchromiumcontent\'s script/upload script') @@ -44,7 +44,7 @@ def download_libchromiumcontent(is_dev, commit, target_arch, url): download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', 'download') target_dir = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') - args = ['-f', '-c', commit, '-t', target_arch, url, target_dir] + args = ['-f', '-c', commit, '--target_arch', target_arch, url, target_dir] if is_dev: subprocess.check_call([sys.executable, download] + args) else: diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 185a9535aa8..6d2427e4f11 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 185a9535aa88ba19b03d3b76d172a9558ae37354 +Subproject commit 6d2427e4f1170aa56e9dc1c4fd8922dea7e233c0 From 5bb9c180f96084e7b022366d00a035dd52461a4d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 11 Apr 2015 18:58:46 +0800 Subject: [PATCH 0530/1195] win: Don't use _x64 targets --- brightray/brightray.gypi | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index db1ee869d45..03b14d2112a 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -164,6 +164,22 @@ '_ATL_NO_OPENGL', '_SECURE_ATL', ], + 'conditions': [ + ['target_arch=="x64"', { + 'msvs_configuration_platform': 'x64', + 'msvs_settings': { + 'VCLinkerTool': { + 'MinimumRequiredVersion': '5.02', # Server 2003. + 'TargetMachine': '17', # x86 - 64 + # Doesn't exist x64 SDK. Should use oleaut32 in any case. + 'IgnoreDefaultLibraryNames': [ 'olepro32.lib' ], + }, + 'VCLibrarianTool': { + 'TargetMachine': '17', # x64 + }, + }, + }], + ], }], # OS=="win" ], }, # Common_Base @@ -242,31 +258,15 @@ }, # R (Release) }], # libchromiumcontent_component ['OS=="win"', { - 'x64_Base': { - 'abstract': 1, - 'msvs_configuration_platform': 'x64', - 'msvs_settings': { - 'VCLinkerTool': { - # Make sure to understand http://crbug.com/361720 if you want to - # increase this. - 'MinimumRequiredVersion': '5.02', # Server 2003. - 'TargetMachine': '17', # x86 - 64 - # Doesn't exist x64 SDK. Should use oleaut32 in any case. - 'IgnoreDefaultLibraryNames': [ 'olepro32.lib' ], - }, - 'VCLibrarianTool': { - 'TargetMachine': '17', # x64 - }, - }, - }, # x64_Base 'conditions': [ + # gyp always assumes "_x64" targets on Windows. ['libchromiumcontent_component', { 'D_x64': { - 'inherit_from': ['Common_Base', 'x64_Base', 'Debug_Base'], + 'inherit_from': ['Common_Base', 'Debug_Base'], }, # D_x64 }, { 'R_x64': { - 'inherit_from': ['Common_Base', 'x64_Base', 'Release_Base'], + 'inherit_from': ['Common_Base', 'Release_Base'], }, # R_x64 }], # libchromiumcontent_component ], From 2e7b3f0d78d2b2d79a04d65a7d4252555a3b0a8b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 11 Apr 2015 23:27:41 +0800 Subject: [PATCH 0531/1195] win: Optimize for size --- brightray/brightray.gypi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 03b14d2112a..884f030a180 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -209,8 +209,10 @@ 'abstract': 1, 'msvs_settings': { 'VCCLCompilerTool': { - 'Optimization': '2', # 2 = /Os - 'FavorSizeOrSpeed': '1', # 1 = /Ot + # 1, optimizeMinSpace, Minimize Size (/O1) + 'Optimization': '1', + # 2, favorSize - Favor small code (/Os) + 'FavorSizeOrSpeed': '2', # See http://msdn.microsoft.com/en-us/library/47238hez(VS.71).aspx 'InlineFunctionExpansion': '2', # 2 = max # See http://msdn.microsoft.com/en-us/library/2kxx5t2c(v=vs.80).aspx From 36e6243085e3f6bb9101cc36e72698404cce9e7b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 12 Apr 2015 07:55:44 +0000 Subject: [PATCH 0532/1195] linux: Define _LARGEFILE_SOURCE --- brightray/brightray.gypi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 884f030a180..697c0c87b45 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -141,6 +141,10 @@ ], }], ['OS=="linux"', { + 'defines': [ + '_LARGEFILE_SOURCE', + '_LARGEFILE64_SOURCE', + ], 'cflags_cc': [ '-D__STRICT_ANSI__', '-std=gnu++11', From 4769e21e3dd7e65c12b10147ffc8561c7e2f116b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 12 Apr 2015 08:15:23 +0000 Subject: [PATCH 0533/1195] Add required defines under 32bit Linux --- brightray/brightray.gyp | 2 ++ brightray/brightray.gypi | 1 + 2 files changed, 3 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 55b597bdac8..7c9424e7935 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -64,11 +64,13 @@ ' Date: Mon, 20 Apr 2015 19:47:21 +0800 Subject: [PATCH 0534/1195] win: Delay load of MFReadWrite.dll Fixes atom/electron#1442. --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 7c9424e7935..17ed089afe3 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -191,8 +191,10 @@ # content_common.gypi: 'd3d9.dll', 'dxva2.dll', + # media.gyp: 'mf.dll', 'mfplat.dll', + 'mfreadwrite.dll', ], }, }, From b8689dc6cce86065120fcedc15d0d006d1a00120 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 20 Apr 2015 13:20:50 -0700 Subject: [PATCH 0535/1195] Add a parameter to ShowNotification for the icon --- brightray/browser/linux/notification_presenter_linux.cc | 1 + brightray/browser/linux/notification_presenter_linux.h | 1 + brightray/browser/notification_presenter.h | 3 +++ 3 files changed, 5 insertions(+) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index a3d72bc8faa..45c5c7d9f6b 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -52,6 +52,7 @@ NotificationPresenterLinux::~NotificationPresenterLinux() { void NotificationPresenterLinux::ShowNotification( const content::PlatformNotificationData& data, + const SkBitmap& icon, scoped_ptr delegate_ptr, base::Closure* cancel_callback) { std::string title = base::UTF16ToUTF8(data.title); diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index 384e2d2f8c7..ddd79e4c2e8 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -27,6 +27,7 @@ class NotificationPresenterLinux : public NotificationPresenter { // NotificationPresenter: void ShowNotification( const content::PlatformNotificationData&, + const SkBitmap& icon, scoped_ptr delegate, base::Closure* cancel_callback) override; diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index ad17cdb3c53..6c1a66fc593 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -4,6 +4,8 @@ #include "base/callback_forward.h" #include "base/memory/scoped_ptr.h" +class SkBitmap; + namespace content { class DesktopNotificationDelegate; struct PlatformNotificationData; @@ -19,6 +21,7 @@ class NotificationPresenter { virtual void ShowNotification( const content::PlatformNotificationData&, + const SkBitmap& icon, scoped_ptr delegate, base::Closure* cancel_callback) = 0; }; From a31ce8ce5020156b96f8207a3ec0650c603b2c98 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 20 Apr 2015 13:21:18 -0700 Subject: [PATCH 0536/1195] Make PlatformNotificationService pass along the icon --- brightray/browser/platform_notification_service_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service_impl.cc index f47d3851198..aaea4dcd610 100644 --- a/brightray/browser/platform_notification_service_impl.cc +++ b/brightray/browser/platform_notification_service_impl.cc @@ -44,7 +44,7 @@ void PlatformNotificationServiceImpl::DisplayNotification( base::Closure* cancel_callback) { auto presenter = notification_presenter(); if (presenter) - presenter->ShowNotification(notification_data, delegate.Pass(), cancel_callback); + presenter->ShowNotification(notification_data, icon, delegate.Pass(), cancel_callback); } void PlatformNotificationServiceImpl::DisplayPersistentNotification( From 3357dc0ef76435576cd94ca76bbc9fc95b8da548 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 20 Apr 2015 13:22:18 -0700 Subject: [PATCH 0537/1195] Set icon for notification, and disable action on Ubuntu --- .../linux/notification_presenter_linux.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 45c5c7d9f6b..88f0dcef9d5 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -8,10 +8,13 @@ #include "base/bind.h" #include "base/logging.h" #include "base/strings/utf_string_conversions.h" +#include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" #include "common/application_info.h" +#include + namespace brightray { namespace { @@ -63,8 +66,20 @@ void NotificationPresenterLinux::ShowNotification( g_object_set_data_full(G_OBJECT(notification), "delegate", delegate, operator delete); g_signal_connect(notification, "closed", G_CALLBACK(OnNotificationClosedThunk), this); - notify_notification_add_action(notification, "default", "View", OnNotificationViewThunk, this, - nullptr); + + // NB: On Unity, adding a notification action will cause the notification + // to display as a modal dialog box. Testing for distros that have "Unity + // Zen Nature" is difficult, we will test for the presence of libindicate, + // an Unity-only library. + struct stat dontcare; + if (stat("/usr/lib/libindicate.so", &dontcare)) { + notify_notification_add_action(notification, "default", "View", OnNotificationViewThunk, this, nullptr); + } + + GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon); + + notify_notification_set_image_from_pixbuf(notification, pixbuf); + notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT); GError* error = nullptr; notify_notification_show(notification, &error); From 7c52838ece13c80760a4e0e44ef6e044d6e1b40b Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 20 Apr 2015 13:29:10 -0700 Subject: [PATCH 0538/1195] Fix the build on OS X --- brightray/browser/notification_presenter_mac.h | 1 + brightray/browser/notification_presenter_mac.mm | 1 + 2 files changed, 2 insertions(+) diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index fd9dd737d9e..20cbee20e84 100644 --- a/brightray/browser/notification_presenter_mac.h +++ b/brightray/browser/notification_presenter_mac.h @@ -23,6 +23,7 @@ class NotificationPresenterMac : public NotificationPresenter { // NotificationPresenter: void ShowNotification( const content::PlatformNotificationData&, + const SkBitmap& icon, scoped_ptr delegate, base::Closure* cancel_callback) override; diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index f0a08d75974..cbe25c65a46 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -41,6 +41,7 @@ NotificationPresenterMac::~NotificationPresenterMac() { void NotificationPresenterMac::ShowNotification( const content::PlatformNotificationData& data, + const SkBitmap& icon, scoped_ptr delegate, base::Closure* cancel_callback) { auto notification = [[NSUserNotification alloc] init]; From 5d82bab10d8cbd81d8aa649ef18fae6887df243e Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 20 Apr 2015 15:31:24 -0700 Subject: [PATCH 0539/1195] Use DBus to detect indicator, not testing for files like an animal --- .../linux/notification_presenter_linux.cc | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 88f0dcef9d5..1995fce2f27 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -12,13 +12,44 @@ #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" #include "common/application_info.h" - -#include +#include "dbus/dbus.h" namespace brightray { namespace { +static bool unity_has_result = false; +static bool unity_result = false; + +static bool UnityIsRunning() { + if (unity_has_result) { + return unity_result; + } + + struct DBusError err; + struct DBusConnection* bus; + + dbus_error_init(&err); + + bus = dbus_bus_get(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) { + g_debug("Failed to get Session Bus reference"); + unity_result = false; + + goto out; + } + + unity_result = dbus_bus_name_has_owner(bus, "com.canonical.indicator.session", &err); + + if (dbus_error_is_set(&err)) { + unity_result = false; + } + +out: + unity_has_result = true; + return unity_result; +} + void log_and_clear_error(GError* error, const char* context) { LOG(ERROR) << context << ": domain=" << error->domain @@ -69,10 +100,9 @@ void NotificationPresenterLinux::ShowNotification( // NB: On Unity, adding a notification action will cause the notification // to display as a modal dialog box. Testing for distros that have "Unity - // Zen Nature" is difficult, we will test for the presence of libindicate, - // an Unity-only library. - struct stat dontcare; - if (stat("/usr/lib/libindicate.so", &dontcare)) { + // Zen Nature" is difficult, we will test for the presence of the indicate + // dbus service + if (!UnityIsRunning()) { notify_notification_add_action(notification, "default", "View", OnNotificationViewThunk, this, nullptr); } From 027a474fa24b27b802bfb008d86c6bc163627ff5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 21 Apr 2015 14:30:06 +0800 Subject: [PATCH 0540/1195] Include headers of mojo --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 17ed089afe3..26fa44ff57d 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -15,6 +15,7 @@ '<(libchromiumcontent_src_dir)', '<(libchromiumcontent_src_dir)/skia/config', '<(libchromiumcontent_src_dir)/third_party/skia/include/core', + '<(libchromiumcontent_src_dir)/third_party/mojo/src', '<(libchromiumcontent_src_dir)/third_party/WebKit', '<(libchromiumcontent_dir)/gen', ], @@ -26,6 +27,7 @@ '<(libchromiumcontent_src_dir)/skia/config', '<(libchromiumcontent_src_dir)/third_party/skia/include/core', '<(libchromiumcontent_src_dir)/third_party/icu/source/common', + '<(libchromiumcontent_src_dir)/third_party/mojo/src', '<(libchromiumcontent_src_dir)/third_party/WebKit', '<(libchromiumcontent_dir)/gen', ], From 80dd72b93c9946383f0ff74b9d836c0276b3886f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 21 Apr 2015 18:54:48 +0800 Subject: [PATCH 0541/1195] Upgrade to Chrome 42 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 6d2427e4f11..d5c126e2d8f 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 6d2427e4f1170aa56e9dc1c4fd8922dea7e233c0 +Subproject commit d5c126e2d8fd181a94720c64b18196505b937041 From 90b255f2cdd58e8082f4b39d3d2901b88fc27b85 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 21 Apr 2015 18:54:57 +0800 Subject: [PATCH 0542/1195] Fix API changes --- .../browser/devtools_manager_delegate.cc | 28 +++++++++---------- .../browser/inspectable_web_contents_impl.cc | 1 + .../browser/inspectable_web_contents_impl.h | 3 +- .../platform_notification_service_impl.cc | 15 ++++++---- .../platform_notification_service_impl.h | 18 ++++++------ .../browser/url_request_context_getter.cc | 6 ++-- 6 files changed, 40 insertions(+), 31 deletions(-) diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index 014a3d825c4..ec660d08ce0 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -50,17 +50,24 @@ const char kTargetTypeOther[] = "other"; class TCPServerSocketFactory : public content::DevToolsHttpHandler::ServerSocketFactory { public: - TCPServerSocketFactory(const std::string& address, int port, int backlog) - : content::DevToolsHttpHandler::ServerSocketFactory( - address, port, backlog) {} + TCPServerSocketFactory(const std::string& address, int port) + : address_(address), port_(port) { + } private: // content::DevToolsHttpHandler::ServerSocketFactory. - scoped_ptr Create() const override { - return scoped_ptr( - new net::TCPServerSocket(NULL, net::NetLog::Source())); + scoped_ptr CreateForHttpServer() override { + scoped_ptr socket( + new net::TCPServerSocket(nullptr, net::NetLog::Source())); + if (socket->ListenWithAddressAndPort(address_, port_, 10) != net::OK) + return scoped_ptr(); + + return socket; } + std::string address_; + uint16 port_; + DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); }; @@ -82,7 +89,7 @@ CreateSocketFactory() { } } return scoped_ptr( - new TCPServerSocketFactory("127.0.0.1", port, 1)); + new TCPServerSocketFactory("127.0.0.1", port)); } class Target : public content::DevToolsTarget { @@ -152,8 +159,6 @@ class DevToolsDelegate : public content::DevToolsHttpHandlerDelegate { std::string GetDiscoveryPageHTML() override; bool BundlesFrontendResources() override; base::FilePath GetDebugFrontendDir() override; - scoped_ptr CreateSocketForTethering( - std::string* name) override; private: DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); @@ -178,11 +183,6 @@ base::FilePath DevToolsDelegate::GetDebugFrontendDir() { return base::FilePath(); } -scoped_ptr DevToolsDelegate::CreateSocketForTethering( - std::string* name) { - return scoped_ptr(); -} - } // namespace // DevToolsManagerDelegate --------------------------------------------------- diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 9def5ad8630..dcd75cd76f2 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -324,6 +324,7 @@ void InspectableWebContentsImpl::AgentHostClosed( } void InspectableWebContentsImpl::AboutToNavigateRenderFrame( + content::RenderFrameHost* old_host, content::RenderFrameHost* new_host) { if (new_host->GetParent()) return; diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index a7e248d575d..6e6346ebb7c 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -104,7 +104,8 @@ class InspectableWebContentsImpl : bool replaced) override; // content::WebContentsObserver: - void AboutToNavigateRenderFrame(content::RenderFrameHost* new_host) override; + void AboutToNavigateRenderFrame(content::RenderFrameHost* old_host, + content::RenderFrameHost* new_host) override; void DidFinishLoad(content::RenderFrameHost* render_frame_host, const GURL& validated_url) override; void WebContentsDestroyed() override; diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service_impl.cc index f47d3851198..3a2153528a9 100644 --- a/brightray/browser/platform_notification_service_impl.cc +++ b/brightray/browser/platform_notification_service_impl.cc @@ -27,7 +27,14 @@ NotificationPresenter* PlatformNotificationServiceImpl::notification_presenter() return notification_presenter_.get(); } -blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermission( +blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermissionOnUIThread( + content::BrowserContext* browser_context, + const GURL& origin, + int render_process_id) { + return blink::WebNotificationPermissionAllowed; +} + +blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermissionOnIOThread( content::ResourceContext* resource_context, const GURL& origin, int render_process_id) { @@ -40,7 +47,6 @@ void PlatformNotificationServiceImpl::DisplayNotification( const SkBitmap& icon, const content::PlatformNotificationData& notification_data, scoped_ptr delegate, - int render_process_id, base::Closure* cancel_callback) { auto presenter = notification_presenter(); if (presenter) @@ -49,11 +55,10 @@ void PlatformNotificationServiceImpl::DisplayNotification( void PlatformNotificationServiceImpl::DisplayPersistentNotification( content::BrowserContext* browser_context, - int64 service_worker_registration_id, + int64_t service_worker_registration_id, const GURL& origin, const SkBitmap& icon, - const content::PlatformNotificationData& notification_data, - int render_process_id) { + const content::PlatformNotificationData& notification_data) { } void PlatformNotificationServiceImpl::ClosePersistentNotification( diff --git a/brightray/browser/platform_notification_service_impl.h b/brightray/browser/platform_notification_service_impl.h index 1a542bcc89b..4b0d4fa96c7 100644 --- a/brightray/browser/platform_notification_service_impl.h +++ b/brightray/browser/platform_notification_service_impl.h @@ -28,26 +28,28 @@ class PlatformNotificationServiceImpl ~PlatformNotificationServiceImpl() override; // content::PlatformNotificationService: - virtual blink::WebNotificationPermission CheckPermission( + blink::WebNotificationPermission CheckPermissionOnUIThread( + content::BrowserContext* browser_context, + const GURL& origin, + int render_process_id) override; + blink::WebNotificationPermission CheckPermissionOnIOThread( content::ResourceContext* resource_context, const GURL& origin, int render_process_id) override; - virtual void DisplayNotification( + void DisplayNotification( content::BrowserContext* browser_context, const GURL& origin, const SkBitmap& icon, const content::PlatformNotificationData& notification_data, scoped_ptr delegate, - int render_process_id, base::Closure* cancel_callback) override; - virtual void DisplayPersistentNotification( + void DisplayPersistentNotification( content::BrowserContext* browser_context, - int64 service_worker_registration_id, + int64_t service_worker_registration_id, const GURL& origin, const SkBitmap& icon, - const content::PlatformNotificationData& notification_data, - int render_process_id) override; - virtual void ClosePersistentNotification( + const content::PlatformNotificationData& notification_data) override; + void ClosePersistentNotification( content::BrowserContext* browser_context, const std::string& persistent_notification_id) override; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 8a142939818..6a92047266c 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -154,9 +154,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, NULL, NULL); storage_->set_cookie_store(content::CreateCookieStore(cookie_config)); - storage_->set_channel_id_service(new net::ChannelIDService( - new net::DefaultChannelIDStore(NULL), - base::WorkerPool::GetTaskRunner(true))); + storage_->set_channel_id_service(make_scoped_ptr( + new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), + base::WorkerPool::GetTaskRunner(true)))); storage_->set_http_user_agent_settings(new net::StaticHttpUserAgentSettings( "en-us,en", base::EmptyString())); From a5b6ffd93c02bb8e8ea7ce263eff8f56d393839e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 21 Apr 2015 19:05:39 +0800 Subject: [PATCH 0543/1195] mac: Link with IOBluetooth.framework --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 26fa44ff57d..4590c04ea36 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -139,6 +139,8 @@ '$(SDKROOT)/System/Library/Frameworks/IOKit.framework', # content_browser.gypi: '$(SDKROOT)/usr/lib/libbsm.dylib', + # bluetooth.gyp: + '$(SDKROOT)/System/Library/Frameworks/IOBluetooth.framework', ], }, }], From 7e88fe107ded6d92ac5d17f467b2a6f0fb81d14d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 21 Apr 2015 21:42:49 +0800 Subject: [PATCH 0544/1195] linux: Pass v8 snapshot's fd to child process --- brightray/brightray.gypi | 2 ++ brightray/browser/browser_client.cc | 36 ++++++++++++++++++++++++++++- brightray/browser/browser_client.h | 12 ++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 50f5a09b3bc..b1865de7851 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -119,6 +119,8 @@ 'defines': [ # We are using Release version libchromiumcontent: 'NDEBUG', + # Needed by gin: + 'V8_USE_EXTERNAL_STARTUP_DATA', # From skia_for_chromium_defines.gypi: 'SK_SUPPORT_LEGACY_GETTOPDEVICE', 'SK_SUPPORT_LEGACY_BITMAP_CONFIG', diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index b884cdcdbf1..887ad591d5c 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -12,7 +12,9 @@ #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 { @@ -27,9 +29,14 @@ BrowserClient* BrowserClient::Get() { } BrowserClient::BrowserClient() - : browser_main_parts_() { + : 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() { @@ -86,4 +93,31 @@ 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 fad326e10bc..cd3c0222310 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -46,8 +46,20 @@ 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 + DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; From a0e5d36305e1d8bd8176c78fac3fef10c30bf99e Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 21 Apr 2015 14:09:48 -0700 Subject: [PATCH 0545/1195] Free some stuff --- brightray/browser/linux/notification_presenter_linux.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 1995fce2f27..3ff75c51155 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -27,7 +27,7 @@ static bool UnityIsRunning() { } struct DBusError err; - struct DBusConnection* bus; + struct DBusConnection* bus = NULL; dbus_error_init(&err); @@ -35,6 +35,7 @@ static bool UnityIsRunning() { if (dbus_error_is_set(&err)) { g_debug("Failed to get Session Bus reference"); unity_result = false; + dbus_error_free(&err); goto out; } @@ -43,9 +44,12 @@ static bool UnityIsRunning() { if (dbus_error_is_set(&err)) { unity_result = false; + dbus_error_free(&err); } out: + if (bus) dbus_connection_unref(bus); + unity_has_result = true; return unity_result; } @@ -110,6 +114,7 @@ void NotificationPresenterLinux::ShowNotification( notify_notification_set_image_from_pixbuf(notification, pixbuf); notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT); + g_object_unref(pixbuf); GError* error = nullptr; notify_notification_show(notification, &error); From a99d29b8595fd67cdebd8c27b3b9f84a6114fc78 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 22 Apr 2015 05:50:27 +0000 Subject: [PATCH 0546/1195] linux: Fix compiler warning --- brightray/brightray.gyp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 4590c04ea36..904dc9056ca 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -68,6 +68,9 @@ '-Wno-deprecated-register', '-Wno-sentinel', ], + 'cflags_cc': [ + '-Wno-reserved-user-defined-literal', + ], 'direct_dependent_settings': { 'cflags': [ ' Date: Thu, 23 Apr 2015 13:26:34 +0800 Subject: [PATCH 0547/1195] win: Delay load of BluetoothApis.dll, fixes atom/electron#1462 --- brightray/brightray.gyp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 904dc9056ca..4b02f1b5539 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -202,6 +202,10 @@ 'mf.dll', 'mfplat.dll', 'mfreadwrite.dll', + # bluetooth.gyp: + 'BluetoothApis.dll', + 'Bthprops.cpl', + 'setupapi.dll', ], }, }, From 34a5e0865d191f0302e11fb253dbd220802a04e8 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 4 May 2015 18:49:30 +0800 Subject: [PATCH 0548/1195] Link pdf related libraries for component build. --- brightray/brightray.gyp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 4b02f1b5539..0e1d6ce2ce2 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -157,6 +157,26 @@ 'libraries': [ '<(libchromiumcontent_dir)/base_static.lib', '<(libchromiumcontent_dir)/sandbox.lib', + # pdf related libraries are linked statically. + '<(libchromiumcontent_dir)/bigint.lib', + '<(libchromiumcontent_dir)/fdrm.lib', + '<(libchromiumcontent_dir)/formfiller.lib', + '<(libchromiumcontent_dir)/fpdfapi.lib', + '<(libchromiumcontent_dir)/fpdfdoc.lib', + '<(libchromiumcontent_dir)/fpdftext.lib', + '<(libchromiumcontent_dir)/freetype.lib', + '<(libchromiumcontent_dir)/fxcodec.lib', + '<(libchromiumcontent_dir)/fxcrt.lib', + '<(libchromiumcontent_dir)/fxedit.lib', + '<(libchromiumcontent_dir)/fxge.lib', + '<(libchromiumcontent_dir)/javascript.lib', + '<(libchromiumcontent_dir)/jsapi.lib', + '<(libchromiumcontent_dir)/pdf.lib', + '<(libchromiumcontent_dir)/pdfium.lib', + '<(libchromiumcontent_dir)/pdfwindow.lib', + '<(libchromiumcontent_dir)/ppapi_cpp_objects.lib', + '<(libchromiumcontent_dir)/ppapi_internal_module.lib', + '<(libchromiumcontent_dir)/ui_zoom.lib', ], }, }, { From 9737ba3e3767bb130011403f9ad3dc8a4742febb Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 4 May 2015 15:35:25 -0700 Subject: [PATCH 0549/1195] Explicitly create HttpAuthHandlerFactory The CreateDefault method does not set a URLSecurityManager, so the code will fall-back to disabling all built-in authentication. Instead, use the default URLSecurityManager which will use IE Security Zones on Windows to determine whether a URL is part of the Local Intranet zone or on non-Windows, default proxy rules will be used (i.e. would a default proxy map vs. connect direct). --- .../browser/url_request_context_getter.cc | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 6a92047266c..75e18defc9a 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -21,6 +21,7 @@ #include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_server_properties_impl.h" +#include "net/http/url_security_manager.h" #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" #include "net/proxy/proxy_config_service.h" #include "net/proxy/proxy_script_fetcher_impl.h" @@ -188,11 +189,27 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { NULL, url_request_context_->network_delegate())); + auto url_sec_mgr = net::URLSecurityManager::Create(NULL, NULL); + + std::vector schemes; + schemes.push_back(std::string("basic")); + schemes.push_back(std::string("digest")); + schemes.push_back(std::string("ntlm")); + schemes.push_back(std::string("negotiate")); + + auto auth_handler_factory = + net::HttpAuthHandlerRegistryFactory::Create( + schemes, + url_sec_mgr, + host_resolver.get(), + std::string(), // gssapi_library_name + false, // negotiate_disable_cname_lookup + true); // negotiate_enable_port + storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); storage_->set_transport_security_state(new net::TransportSecurityState); storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); - storage_->set_http_auth_handler_factory( - net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); + storage_->set_http_auth_handler_factory(auth_handler_factory); scoped_ptr server_properties( new net::HttpServerPropertiesImpl); storage_->set_http_server_properties(server_properties.Pass()); From dbe969b5c53d12622e752adbd4ba8be17de36f71 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 5 May 2015 22:28:00 -0700 Subject: [PATCH 0550/1195] Fix indentation --- brightray/browser/url_request_context_getter.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 75e18defc9a..4eeb6f24dfb 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -198,13 +198,13 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { schemes.push_back(std::string("negotiate")); auto auth_handler_factory = - net::HttpAuthHandlerRegistryFactory::Create( - schemes, - url_sec_mgr, - host_resolver.get(), - std::string(), // gssapi_library_name - false, // negotiate_disable_cname_lookup - true); // negotiate_enable_port + net::HttpAuthHandlerRegistryFactory::Create( + schemes, + url_sec_mgr, + host_resolver.get(), + std::string(), // gssapi_library_name + false, // negotiate_disable_cname_lookup + true); // negotiate_enable_port storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); storage_->set_transport_security_state(new net::TransportSecurityState); From a18e5d7d5c1edb8e919fc876abce9d9cf3d742c4 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 5 May 2015 22:35:48 -0700 Subject: [PATCH 0551/1195] Come Correct with memory management --- brightray/browser/url_request_context_getter.cc | 5 ++--- brightray/browser/url_request_context_getter.h | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 4eeb6f24dfb..03a3fa156f7 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -21,7 +21,6 @@ #include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_server_properties_impl.h" -#include "net/http/url_security_manager.h" #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" #include "net/proxy/proxy_config_service.h" #include "net/proxy/proxy_script_fetcher_impl.h" @@ -120,6 +119,7 @@ URLRequestContextGetter::URLRequestContextGetter( base_path_(base_path), io_loop_(io_loop), file_loop_(file_loop), + url_sec_mgr_(net::URLSecurityManager::Create(NULL, NULL)), protocol_interceptors_(protocol_interceptors.Pass()) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -189,7 +189,6 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { NULL, url_request_context_->network_delegate())); - auto url_sec_mgr = net::URLSecurityManager::Create(NULL, NULL); std::vector schemes; schemes.push_back(std::string("basic")); @@ -200,7 +199,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { auto auth_handler_factory = net::HttpAuthHandlerRegistryFactory::Create( schemes, - url_sec_mgr, + url_sec_mgr_.get(), host_resolver.get(), std::string(), // gssapi_library_name false, // negotiate_disable_cname_lookup diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 85ed014422a..599bf6c4d22 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "content/public/browser/content_browser_client.h" #include "net/http/http_cache.h" +#include "net/http/url_security_manager.h" #include "net/url_request/url_request_context_getter.h" namespace base { @@ -68,6 +69,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr storage_; scoped_ptr url_request_context_; scoped_ptr host_mapping_rules_; + scoped_ptr url_sec_mgr_; content::ProtocolHandlerMap protocol_handlers_; content::URLRequestInterceptorScopedVector protocol_interceptors_; From d350e73dff4f4dcc78be63054856927eed4d9d22 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 12 May 2015 16:55:11 +0800 Subject: [PATCH 0552/1195] win: Link with msvcrt dll for Release build --- brightray/brightray.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index b1865de7851..2ca1765ddea 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -55,6 +55,7 @@ ], 'msvs_settings': { 'VCCLCompilerTool': { + 'RuntimeLibrary': '2', # /MD (nondebug DLL) 'AdditionalOptions': ['/MP'], 'MinimalRebuild': 'false', 'BufferSecurityCheck': 'true', @@ -205,7 +206,6 @@ ], 'msvs_settings': { 'VCCLCompilerTool': { - 'RuntimeLibrary': '2', # /MD (nondebug DLL) 'Optimization': '0', # 0 = /Od # See http://msdn.microsoft.com/en-us/library/8wtf2dfz(VS.71).aspx 'BasicRuntimeChecks': '3', # 3 = all checks enabled, 0 = off From e76b06b84c3bfdfad956598ad74fd91042184ccd Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Wed, 13 May 2015 09:54:56 +0800 Subject: [PATCH 0553/1195] No need to link pdf related libraries in component build. --- brightray/brightray.gyp | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 0e1d6ce2ce2..4b02f1b5539 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -157,26 +157,6 @@ 'libraries': [ '<(libchromiumcontent_dir)/base_static.lib', '<(libchromiumcontent_dir)/sandbox.lib', - # pdf related libraries are linked statically. - '<(libchromiumcontent_dir)/bigint.lib', - '<(libchromiumcontent_dir)/fdrm.lib', - '<(libchromiumcontent_dir)/formfiller.lib', - '<(libchromiumcontent_dir)/fpdfapi.lib', - '<(libchromiumcontent_dir)/fpdfdoc.lib', - '<(libchromiumcontent_dir)/fpdftext.lib', - '<(libchromiumcontent_dir)/freetype.lib', - '<(libchromiumcontent_dir)/fxcodec.lib', - '<(libchromiumcontent_dir)/fxcrt.lib', - '<(libchromiumcontent_dir)/fxedit.lib', - '<(libchromiumcontent_dir)/fxge.lib', - '<(libchromiumcontent_dir)/javascript.lib', - '<(libchromiumcontent_dir)/jsapi.lib', - '<(libchromiumcontent_dir)/pdf.lib', - '<(libchromiumcontent_dir)/pdfium.lib', - '<(libchromiumcontent_dir)/pdfwindow.lib', - '<(libchromiumcontent_dir)/ppapi_cpp_objects.lib', - '<(libchromiumcontent_dir)/ppapi_internal_module.lib', - '<(libchromiumcontent_dir)/ui_zoom.lib', ], }, }, { From 145c18f4c8c36c7e28bee014c4d8cc452e0ec050 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 18 May 2015 19:26:03 +0530 Subject: [PATCH 0554/1195] method to reset agent_host --- brightray/browser/inspectable_web_contents.h | 5 +++++ brightray/browser/inspectable_web_contents_impl.cc | 12 ++++++++++++ brightray/browser/inspectable_web_contents_impl.h | 3 +++ 3 files changed, 20 insertions(+) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index b0a05d48b38..7ac1366ea7c 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -3,6 +3,10 @@ #include "content/public/browser/web_contents.h" +namespace content { +class DevToolsAgentHost; +} + namespace brightray { class InspectableWebContentsDelegate; @@ -27,6 +31,7 @@ class InspectableWebContents { // Close the DevTools completely instead of just hide it. virtual void CloseDevTools() = 0; virtual bool IsDevToolsViewShowing() = 0; + virtual void AttachTo(const scoped_refptr&) = 0; // The delegate manages its own life. virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index dcd75cd76f2..bdc9f693187 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -188,6 +188,18 @@ bool InspectableWebContentsImpl::IsDevToolsViewShowing() { return devtools_web_contents_ && view_->IsDevToolsViewShowing(); } +void InspectableWebContentsImpl::AttachTo(const scoped_refptr& host) { + if (agent_host_.get()) + Detach(); + agent_host_ = host; + agent_host_->AttachClient(this); +} + +void InspectableWebContentsImpl::Detach() { + agent_host_->DetachClient(); + agent_host_ = nullptr; +} + gfx::Rect InspectableWebContentsImpl::GetDevToolsBounds() const { return devtools_bounds_; } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 6e6346ebb7c..7ef78105b8b 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -48,6 +48,9 @@ class InspectableWebContentsImpl : void ShowDevTools() override; void CloseDevTools() override; bool IsDevToolsViewShowing() override; + void AttachTo(const scoped_refptr&) override; + + void Detach(); // Return the last position and size of devtools window. gfx::Rect GetDevToolsBounds() const; From c60fcc4c9aeb98e48a9a5c01f1c40a3b6baba273 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 20 May 2015 13:52:24 +0800 Subject: [PATCH 0555/1195] Turn off incremental linking for Release build --- brightray/brightray.gypi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 2ca1765ddea..3554fd72734 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -231,6 +231,10 @@ # "/Oy /Oy-" and warnings about overriding. 'AdditionalOptions': ['/Oy-'], }, + 'VCLinkerTool': { + # Turn off incremental linking to save binary size. + 'LinkIncremental': '1', # /INCREMENTAL:NO + }, }, 'conditions': [ ['OS=="linux"', { From 0cbf8b6cd2168a6c79d12df6c5a341a22b86f7e2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 22 May 2015 14:50:41 +0800 Subject: [PATCH 0556/1195] Implement PermissionManager --- brightray/browser/browser_context.cc | 7 +++ brightray/browser/browser_context.h | 5 ++ brightray/browser/permission_manager.cc | 65 +++++++++++++++++++++++++ brightray/browser/permission_manager.h | 54 ++++++++++++++++++++ brightray/filenames.gypi | 2 + 5 files changed, 133 insertions(+) create mode 100644 brightray/browser/permission_manager.cc create mode 100644 brightray/browser/permission_manager.h diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 6d2a378be80..c4aa7d186d8 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -7,6 +7,7 @@ #include "browser/brightray_paths.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/network_delegate.h" +#include "browser/permission_manager.h" #include "common/application_info.h" #include "base/files/file_path.h" @@ -158,4 +159,10 @@ content::SSLHostStateDelegate* BrowserContext::GetSSLHostStateDelegate() { return nullptr; } +content::PermissionManager* BrowserContext::GetPermissionManager() { + if (!permission_manager_.get()) + permission_manager_.reset(new PermissionManager); + return permission_manager_.get(); +} + } // namespace brightray diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index ec1dd095b23..d7f957477f1 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -5,6 +5,7 @@ #ifndef BRIGHTRAY_BROWSER_BROWSER_CONTEXT_H_ #define BRIGHTRAY_BROWSER_BROWSER_CONTEXT_H_ +#include "browser/permission_manager.h" #include "browser/url_request_context_getter.h" #include "content/public/browser/browser_context.h" @@ -14,6 +15,8 @@ class PrefService; namespace brightray { +class PermissionManager; + class BrowserContext : public content::BrowserContext, public brightray::URLRequestContextGetter::Delegate { public: @@ -63,11 +66,13 @@ class BrowserContext : public content::BrowserContext, storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; content::PushMessagingService* GetPushMessagingService() override; content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; + content::PermissionManager* GetPermissionManager() override; base::FilePath path_; scoped_ptr resource_context_; scoped_refptr url_request_getter_; scoped_ptr prefs_; + scoped_ptr permission_manager_; DISALLOW_COPY_AND_ASSIGN(BrowserContext); }; diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc new file mode 100644 index 00000000000..5a2d4ee54c3 --- /dev/null +++ b/brightray/browser/permission_manager.cc @@ -0,0 +1,65 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/permission_manager.h" + +#include "base/callback.h" +#include "content/public/browser/permission_type.h" + +namespace brightray { + +PermissionManager::PermissionManager() { +} + +PermissionManager::~PermissionManager() { +} + +void PermissionManager::RequestPermission( + content::PermissionType permission, + content::WebContents* web_contents, + int request_id, + const GURL& requesting_origin, + bool user_gesture, + const base::Callback& callback) { + callback.Run(content::PERMISSION_STATUS_GRANTED); +} + +void PermissionManager::CancelPermissionRequest( + content::PermissionType permission, + content::WebContents* web_contents, + int request_id, + const GURL& requesting_origin) { +} + +void PermissionManager::ResetPermission( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) { +} + +content::PermissionStatus PermissionManager::GetPermissionStatus( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) { + return content::PERMISSION_STATUS_GRANTED; +} + +void PermissionManager::RegisterPermissionUsage( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) { +} + +int PermissionManager::SubscribePermissionStatusChange( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin, + const base::Callback& callback) { + return -1; +} + +void PermissionManager::UnsubscribePermissionStatusChange(int subscription_id) { +} + +} // namespace brightray diff --git a/brightray/browser/permission_manager.h b/brightray/browser/permission_manager.h new file mode 100644 index 00000000000..d40bcd95e1f --- /dev/null +++ b/brightray/browser/permission_manager.h @@ -0,0 +1,54 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BROWSER_PERMISSION_MANAGER_H_ +#define BROWSER_PERMISSION_MANAGER_H_ + +#include "base/callback_forward.h" +#include "base/macros.h" +#include "content/public/browser/permission_manager.h" + +namespace brightray { + +class PermissionManager : public content::PermissionManager { + public: + PermissionManager(); + ~PermissionManager() override; + + // content::PermissionManager: + void RequestPermission( + content::PermissionType permission, + content::WebContents* web_contents, + int request_id, + const GURL& requesting_origin, + bool user_gesture, + const base::Callback& callback) override; + void CancelPermissionRequest(content::PermissionType permission, + content::WebContents* web_contents, + int request_id, + const GURL& requesting_origin) override; + void ResetPermission(content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) override; + content::PermissionStatus GetPermissionStatus( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) override; + void RegisterPermissionUsage(content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin) override; + int SubscribePermissionStatusChange( + content::PermissionType permission, + const GURL& requesting_origin, + const GURL& embedding_origin, + const base::Callback& callback) override; + void UnsubscribePermissionStatusChange(int subscription_id) override; + + private: + DISALLOW_COPY_AND_ASSIGN(PermissionManager); +}; + +} // namespace brightray + +#endif // BROWSER_PERMISSION_MANAGER_H_ diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 203e2037b43..e1a152521bd 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -42,6 +42,8 @@ 'browser/notification_presenter.h', 'browser/notification_presenter_mac.h', 'browser/notification_presenter_mac.mm', + 'browser/permission_manager.cc', + 'browser/permission_manager.h', 'browser/platform_notification_service_impl.cc', 'browser/platform_notification_service_impl.h', 'browser/linux/notification_presenter_linux.h', From 37bd7fe3315c52b5e9f722c7e2315dd1059f978d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 22 May 2015 14:51:16 +0800 Subject: [PATCH 0557/1195] Remove parameter |by_user| in NotificationClosed --- brightray/browser/linux/notification_presenter_linux.cc | 4 ++-- brightray/browser/notification_presenter_mac.mm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 3ff75c51155..9baa4474e98 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -140,7 +140,7 @@ void NotificationPresenterLinux::CancelNotification(NotifyNotification* notifica if (error) log_and_clear_error(error, "notify_notification_close"); - GetDelegateFromNotification(notification)->NotificationClosed(false); + GetDelegateFromNotification(notification)->NotificationClosed(); DeleteNotification(notification); } @@ -150,7 +150,7 @@ void NotificationPresenterLinux::DeleteNotification(NotifyNotification* notifica } void NotificationPresenterLinux::OnNotificationClosed(NotifyNotification* notification) { - GetDelegateFromNotification(notification)->NotificationClosed(false); + GetDelegateFromNotification(notification)->NotificationClosed(); DeleteNotification(notification); } diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index cbe25c65a46..3b0c736daa3 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -85,7 +85,7 @@ void NotificationPresenterMac::CancelNotification(content::DesktopNotificationDe for (NSUserNotification* deliveredNotification in center.deliveredNotifications) if ([notification isEqual:deliveredNotification]) { [center removeDeliveredNotification:deliveredNotification]; - delegate->NotificationClosed(false); + delegate->NotificationClosed(); break; } From 66d49a5241c2bc445babf6e9bc724c87ee8b68df Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 22 May 2015 14:54:33 +0800 Subject: [PATCH 0558/1195] ProxyResolverV8::EnsureIsolateCreated is removed --- brightray/browser/browser_main_parts.cc | 6 ------ brightray/browser/browser_main_parts.h | 3 --- 2 files changed, 9 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index de938eacd99..21331707935 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -90,8 +90,6 @@ void BrowserMainParts::PreEarlyInitialization() { #if defined(OS_LINUX) OverrideLinuxAppDataPath(); #endif - - InitProxyResolverV8(); } void BrowserMainParts::ToolkitInitialized() { @@ -148,8 +146,4 @@ BrowserContext* BrowserMainParts::CreateBrowserContext() { return new BrowserContext; } -void BrowserMainParts::InitProxyResolverV8() { - net::ProxyResolverV8::EnsureIsolateCreated(); -} - } // namespace brightray diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 59674ef2e53..a5ba51508b4 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -50,9 +50,6 @@ class BrowserMainParts : public content::BrowserMainParts { // implementation. The caller takes ownership of the returned object. virtual BrowserContext* CreateBrowserContext(); - // Override this to change how ProxyResolverV8 is initialized. - virtual void InitProxyResolverV8(); - private: #if defined(OS_MACOSX) void IncreaseFileDescriptorLimit(); From 0f64da9dfc0fc40c9e21b262651d3e578c20006b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 22 May 2015 14:56:28 +0800 Subject: [PATCH 0559/1195] Implement NetworkDelegate::OnFirstPartyOnlyCookieExperimentEnabled --- brightray/browser/network_delegate.cc | 4 ++++ brightray/browser/network_delegate.h | 1 + 2 files changed, 5 insertions(+) diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index a065a6ebf06..9d586d72cf5 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -112,6 +112,10 @@ bool NetworkDelegate::OnCanEnablePrivacyMode( return false; } +bool NetworkDelegate::OnFirstPartyOnlyCookieExperimentEnabled() const { + return true; +} + bool NetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( const net::URLRequest& request, const GURL& target_url, diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index fcfbdbb8927..55835622ac2 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -62,6 +62,7 @@ class NetworkDelegate : public net::NetworkDelegate { bool OnCanEnablePrivacyMode( const GURL& url, const GURL& first_party_for_cookies) const override; + bool OnFirstPartyOnlyCookieExperimentEnabled() const override; bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( const net::URLRequest& request, const GURL& target_url, From 847dc32f7486d7adc200d0b66cee13292147f435 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 23 May 2015 11:10:40 +0800 Subject: [PATCH 0560/1195] Suppress compiler warning --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 3554fd72734..47be6215dc3 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -95,6 +95,7 @@ }, 'msvs_disabled_warnings': [ 4100, # unreferenced formal parameter + 4121, # alignment of a member was sensitive to packing 4127, # conditional expression is constant 4189, # local variable is initialized but not referenced 4244, # 'initializing' : conversion from 'double' to 'size_t', possible loss of data From ce266e86471dc7386c8739b1a11c6a12017ea8d7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 23 May 2015 11:25:37 +0800 Subject: [PATCH 0561/1195] Link with d3d11.lib --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 0e1d6ce2ce2..4c690f21a55 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -190,6 +190,7 @@ '-lportabledeviceguids.lib', # content_common.gypi: '-ld3d9.lib', + '-ld3d11.lib', '-ldxva2.lib', '-lstrmiids.lib', '-lmf.lib', From a9a5765544b3fd2430e4c7e2f1715dda3731dd2c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 27 May 2015 15:02:01 +0800 Subject: [PATCH 0562/1195] Remove trailing space --- brightray/browser/inspectable_web_contents_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 7ef78105b8b..655f77ad0a0 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -50,7 +50,7 @@ class InspectableWebContentsImpl : bool IsDevToolsViewShowing() override; void AttachTo(const scoped_refptr&) override; - void Detach(); + void Detach(); // Return the last position and size of devtools window. gfx::Rect GetDevToolsBounds() const; From eb2d94faf78f46877dd10a9b2049b435c8c9aa46 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 29 May 2015 15:50:12 +0800 Subject: [PATCH 0563/1195] Update to latest libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index d5c126e2d8f..e769ce0ef80 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit d5c126e2d8fd181a94720c64b18196505b937041 +Subproject commit e769ce0ef8007ecb780d8d25b729c454e11eaf3a From f494f90a3e6054a67288eb7619503f6a26cec204 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 29 May 2015 16:54:28 +0800 Subject: [PATCH 0564/1195] Link with ui_zoom in component build --- brightray/brightray.gyp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index f59e86c588e..4875710029d 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -82,6 +82,7 @@ ['libchromiumcontent_component', { 'link_settings': { 'libraries': [ + '<(libchromiumcontent_dir)/libui_zoom.a', # libgtk2ui is always linked statically. '<(libchromiumcontent_dir)/libgtk2ui.a', ], @@ -113,7 +114,13 @@ }, 'conditions': [ # Link with system frameworks. - ['libchromiumcontent_component==0', { + ['libchromiumcontent_component', { + 'link_settings': { + 'libraries': [ + '<(libchromiumcontent_dir)/libui_zoom.a', + ], + }, + }, { 'link_settings': { 'libraries': [ # ui_base.gypi: @@ -152,9 +159,10 @@ ['OS=="win"', { 'conditions': [ ['libchromiumcontent_component', { - # sandbox and base_static are always linked statically. 'link_settings': { 'libraries': [ + '<(libchromiumcontent_dir)/ui_zoom.lib', + # sandbox and base_static are always linked statically. '<(libchromiumcontent_dir)/base_static.lib', '<(libchromiumcontent_dir)/sandbox.lib', ], From 155a50d00ed0cd130c4baf4e47ab7efcf2d7e838 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 29 May 2015 17:51:22 +0800 Subject: [PATCH 0565/1195] Revert "Link with ui_zoom in component build" This reverts commit b48bc01c8f1fc11862f96db835a5f257aa6e53aa. --- brightray/brightray.gyp | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 4875710029d..f59e86c588e 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -82,7 +82,6 @@ ['libchromiumcontent_component', { 'link_settings': { 'libraries': [ - '<(libchromiumcontent_dir)/libui_zoom.a', # libgtk2ui is always linked statically. '<(libchromiumcontent_dir)/libgtk2ui.a', ], @@ -114,13 +113,7 @@ }, 'conditions': [ # Link with system frameworks. - ['libchromiumcontent_component', { - 'link_settings': { - 'libraries': [ - '<(libchromiumcontent_dir)/libui_zoom.a', - ], - }, - }, { + ['libchromiumcontent_component==0', { 'link_settings': { 'libraries': [ # ui_base.gypi: @@ -159,10 +152,9 @@ ['OS=="win"', { 'conditions': [ ['libchromiumcontent_component', { + # sandbox and base_static are always linked statically. 'link_settings': { 'libraries': [ - '<(libchromiumcontent_dir)/ui_zoom.lib', - # sandbox and base_static are always linked statically. '<(libchromiumcontent_dir)/base_static.lib', '<(libchromiumcontent_dir)/sandbox.lib', ], From 3a005fd52a106b54c5a6fa45767705c2fed8946c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 29 May 2015 17:51:50 +0800 Subject: [PATCH 0566/1195] Update libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index e769ce0ef80..534e0fbaaca 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit e769ce0ef8007ecb780d8d25b729c454e11eaf3a +Subproject commit 534e0fbaaca61a7b8d57578b2646d47cf4237d2a From 2025b60968090b14569f78c83ddf46de3c64546e Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Tue, 2 Jun 2015 16:54:15 -0400 Subject: [PATCH 0567/1195] Make devtools work when web security is enabled These changes bring our copy of devtools_ui.cc in line with https://chromium.googlesource.com/chromium/src.git/+/43.0.2357.92/chrome/browser/ui/webui/devtools_ui.cc Without these changes, opening the devtools prints errors like: [0602/165604:ERROR:CONSOLE(0)] "Refused to display 'chrome-devtools://devtools/inspector.html?can_dock=true&toolbarColor=rgba(223,223,223,1)&textColor=rgba(0,0,0,1)&experiments=true' in a frame because it set 'X-Frame-Options' to 'DENY'.", source: about:blank (0) [0602/165604:ERROR:CONSOLE(1514)] "Uncaught SecurityError: Sandbox access violation: Blocked a frame at "chrome-devtools://devtools" from accessing a frame at "null". The frame being accessed is sandboxed and lacks the "allow-same-origin" flag.", source: chrome-devtools://devtools/devtools.js (1514) --- brightray/browser/devtools_ui.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 42769b53c30..30a974fccfc 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -42,11 +42,12 @@ std::string GetMimeTypeForPath(const std::string& path) { return "image/png"; } else if (EndsWith(filename, ".gif", false)) { return "image/gif"; + } else if (EndsWith(filename, ".svg", false)) { + return "image/svg+xml"; } else if (EndsWith(filename, ".manifest", false)) { return "text/cache-manifest"; } - NOTREACHED(); - return "text/plain"; + return "text/html"; } class BundledDataSource : public content::URLDataSource { @@ -86,6 +87,14 @@ class BundledDataSource : public content::URLDataSource { return false; } + virtual bool ShouldDenyXFrameOptions() const override { + return false; + } + + virtual bool ShouldServeMimeTypeAsContentTypeHeader() const override { + return true; + } + private: virtual ~BundledDataSource() {} DISALLOW_COPY_AND_ASSIGN(BundledDataSource); From 894cc642766b0514ff49c6570429d8059d1f785a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 4 Jun 2015 14:41:16 +0800 Subject: [PATCH 0568/1195] Link with gmodule-2.0, fix atom/electron#1809 --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index f59e86c588e..7860d4813ad 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -1,7 +1,7 @@ { 'variables': { # The libraries brightray will be compiled to. - 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xrandr xext gconf-2.0' + 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xrandr xext gconf-2.0 gmodule-2.0' }, 'includes': [ 'filenames.gypi', From 62f860123dc4525c68953675b16a467cff45db5a Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 4 Jun 2015 22:21:23 +0530 Subject: [PATCH 0569/1195] delegate filesystem request calls --- brightray/browser/inspectable_web_contents_delegate.h | 3 +++ brightray/browser/inspectable_web_contents_impl.cc | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index d32b139ba94..531b96e1755 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -20,6 +20,9 @@ class InspectableWebContentsDelegate { virtual void DevToolsAppendToFile( const std::string& url, const std::string& content) {} virtual void DevToolsFocused() {} + virtual void DevToolsAddFileSystem() {} + virtual void DevToolsRemoveFileSystem( + const std::string& file_system_path) {} #if defined(USE_X11) // Called when creating devtools window. diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index bdc9f693187..27bf3dbac17 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -265,10 +265,14 @@ void InspectableWebContentsImpl::RequestFileSystems() { } void InspectableWebContentsImpl::AddFileSystem() { + if (delegate_) + delegate_->DevToolsAddFileSystem(); } void InspectableWebContentsImpl::RemoveFileSystem( const std::string& file_system_path) { + if (delegate_) + delegate_->DevToolsRemoveFileSystem(file_system_path); } void InspectableWebContentsImpl::UpgradeDraggedFileSystemPermissions( From d48a80bdfab44696ecf1b32732095648b36da8d9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 11:03:47 +0800 Subject: [PATCH 0570/1195] Update to new devtools messages --- .../devtools_embedder_message_dispatcher.cc | 329 ++++++++---------- .../devtools_embedder_message_dispatcher.h | 43 ++- .../browser/inspectable_web_contents_impl.cc | 156 ++++++--- .../browser/inspectable_web_contents_impl.h | 32 +- 4 files changed, 300 insertions(+), 260 deletions(-) diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index bb64846320b..c5b90fccef9 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -11,21 +11,23 @@ namespace brightray { namespace { -bool GetValue(const base::ListValue& list, int pos, std::string& value) { - return list.GetString(pos, &value); +using DispatchCallback = DevToolsEmbedderMessageDispatcher::DispatchCallback; + +bool GetValue(const base::Value* value, std::string* result) { + return value->GetAsString(result); } -bool GetValue(const base::ListValue& list, int pos, int& value) { - return list.GetInteger(pos, &value); +bool GetValue(const base::Value* value, int* result) { + return value->GetAsInteger(result); } -bool GetValue(const base::ListValue& list, int pos, bool& value) { - return list.GetBoolean(pos, &value); +bool GetValue(const base::Value* value, bool* result) { + return value->GetAsBoolean(result); } -bool GetValue(const base::ListValue& list, int pos, gfx::Rect& rect) { +bool GetValue(const base::Value* value, gfx::Rect* rect) { const base::DictionaryValue* dict; - if (!list.GetDictionary(pos, &dict)) + if (!value->GetAsDictionary(&dict)) return false; int x = 0; int y = 0; @@ -36,217 +38,164 @@ bool GetValue(const base::ListValue& list, int pos, gfx::Rect& rect) { !dict->GetInteger("width", &width) || !dict->GetInteger("height", &height)) return false; - rect.SetRect(x, y, width, height); + rect->SetRect(x, y, width, height); return true; } template struct StorageTraits { - typedef T StorageType; + using StorageType = T; }; template struct StorageTraits { - typedef T StorageType; + using StorageType = T; }; -template -class Argument { - public: - typedef typename StorageTraits::StorageType ValueType; - - Argument(const base::ListValue& list, int pos) { - valid_ = GetValue(list, pos, value_); +template +struct ParamTuple { + bool Parse(const base::ListValue& list, + const base::ListValue::const_iterator& it) { + return it == list.end(); } - ValueType value() const { return value_; } - bool valid() const { return valid_; } - - private: - ValueType value_; - bool valid_; + template + void Apply(const H& handler, As... args) { + handler.Run(args...); + } }; -bool ParseAndHandle0(const base::Callback& handler, - const base::ListValue& list) { - handler.Run(); +template +struct ParamTuple { + bool Parse(const base::ListValue& list, + const base::ListValue::const_iterator& it) { + return it != list.end() && GetValue(*it, &head) && tail.Parse(list, it + 1); + } + + template + void Apply(const H& handler, As... args) { + tail.template Apply(handler, args..., head); + } + + typename StorageTraits::StorageType head; + ParamTuple tail; +}; + +template +bool ParseAndHandle(const base::Callback& handler, + const DispatchCallback& callback, + const base::ListValue& list) { + ParamTuple tuple; + if (!tuple.Parse(list, list.begin())) + return false; + tuple.Apply(handler); return true; } -template -bool ParseAndHandle1(const base::Callback& handler, - const base::ListValue& list) { - if (list.GetSize() != 1) +template +bool ParseAndHandleWithCallback( + const base::Callback& handler, + const DispatchCallback& callback, + const base::ListValue& list) { + ParamTuple tuple; + if (!tuple.Parse(list, list.begin())) return false; - Argument arg1(list, 0); - if (!arg1.valid()) - return false; - handler.Run(arg1.value()); + tuple.Apply(handler, callback); return true; } -template -bool ParseAndHandle2(const base::Callback& handler, - const base::ListValue& list) { - if (list.GetSize() != 2) - return false; - Argument arg1(list, 0); - if (!arg1.valid()) - return false; - Argument arg2(list, 1); - if (!arg2.valid()) - return false; - handler.Run(arg1.value(), arg2.value()); - return true; -} +} // namespace -template -bool ParseAndHandle3(const base::Callback& handler, - const base::ListValue& list) { - if (list.GetSize() != 3) - return false; - Argument arg1(list, 0); - if (!arg1.valid()) - return false; - Argument arg2(list, 1); - if (!arg2.valid()) - return false; - Argument arg3(list, 2); - if (!arg3.valid()) - return false; - handler.Run(arg1.value(), arg2.value(), arg3.value()); - return true; -} +/** + * Dispatcher for messages sent from the frontend running in an + * isolated renderer (chrome-devtools:// or chrome://inspect) to the embedder + * in the browser. + * + * The messages are sent via InspectorFrontendHost.sendMessageToEmbedder or + * chrome.send method accordingly. + */ +class DispatcherImpl : public DevToolsEmbedderMessageDispatcher { + public: + ~DispatcherImpl() override {} -template -bool ParseAndHandle3(const base::Callback& handler, - const base::ListValue& list) { - if (list.GetSize() != 3) - return false; - Argument arg1(list, 0); - if (!arg1.valid()) - return false; - Argument arg2(list, 1); - if (!arg2.valid()) - return false; - Argument arg3(list, 2); - if (!arg3.valid()) - return false; - Argument arg4(list, 3); - if (!arg4.valid()) - return false; - handler.Run(arg1.value(), arg2.value(), arg3.value(), arg4.value()); - return true; -} + bool Dispatch(const DispatchCallback& callback, + const std::string& method, + const base::ListValue* params) override { + HandlerMap::iterator it = handlers_.find(method); + return it != handlers_.end() && it->second.Run(callback, *params); + } + + template + void RegisterHandler(const std::string& method, + void (Delegate::*handler)(As...), + Delegate* delegate) { + handlers_[method] = base::Bind(&ParseAndHandle, + base::Bind(handler, + base::Unretained(delegate))); + } + + template + void RegisterHandlerWithCallback( + const std::string& method, + void (Delegate::*handler)(const DispatchCallback&, As...), + Delegate* delegate) { + handlers_[method] = base::Bind(&ParseAndHandleWithCallback, + base::Bind(handler, + base::Unretained(delegate))); + } -typedef base::Callback ListValueParser; + private: + using Handler = base::Callback; + using HandlerMap = std::map; + HandlerMap handlers_; +}; -ListValueParser BindToListParser(const base::Callback& handler) { - return base::Bind(&ParseAndHandle0, handler); -} - -template -ListValueParser BindToListParser(const base::Callback& handler) { - return base::Bind(&ParseAndHandle1, handler); -} - -template -ListValueParser BindToListParser(const base::Callback& handler) { - return base::Bind(&ParseAndHandle2, handler); -} - -template -ListValueParser BindToListParser( - const base::Callback& handler) { - return base::Bind(&ParseAndHandle3, handler); -} - -template -ListValueParser BindToListParser( - const base::Callback& handler) { - return base::Bind(&ParseAndHandle3, handler); -} - -} // namespace - -DevToolsEmbedderMessageDispatcher::DevToolsEmbedderMessageDispatcher( +// static +DevToolsEmbedderMessageDispatcher* +DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend( Delegate* delegate) { - RegisterHandler("bringToFront", - BindToListParser(base::Bind(&Delegate::ActivateWindow, - base::Unretained(delegate)))); - RegisterHandler("closeWindow", - BindToListParser(base::Bind(&Delegate::CloseWindow, - base::Unretained(delegate)))); - RegisterHandler("setInspectedPageBounds", - BindToListParser(base::Bind(&Delegate::SetInspectedPageBounds, - base::Unretained(delegate)))); - RegisterHandler("inspectElementCompleted", - BindToListParser(base::Bind(&Delegate::InspectElementCompleted, - base::Unretained(delegate)))); - RegisterHandler("moveWindowBy", - BindToListParser(base::Bind(&Delegate::MoveWindow, - base::Unretained(delegate)))); - RegisterHandler("setIsDocked", - BindToListParser(base::Bind(&Delegate::SetIsDocked, - base::Unretained(delegate)))); - RegisterHandler("openInNewTab", - BindToListParser(base::Bind(&Delegate::OpenInNewTab, - base::Unretained(delegate)))); - RegisterHandler("save", - BindToListParser(base::Bind(&Delegate::SaveToFile, - base::Unretained(delegate)))); - RegisterHandler("append", - BindToListParser(base::Bind(&Delegate::AppendToFile, - base::Unretained(delegate)))); - RegisterHandler("requestFileSystems", - BindToListParser(base::Bind(&Delegate::RequestFileSystems, - base::Unretained(delegate)))); - RegisterHandler("addFileSystem", - BindToListParser(base::Bind(&Delegate::AddFileSystem, - base::Unretained(delegate)))); - RegisterHandler("removeFileSystem", - BindToListParser(base::Bind(&Delegate::RemoveFileSystem, - base::Unretained(delegate)))); - RegisterHandler("upgradeDraggedFileSystemPermissions", - BindToListParser(base::Bind(&Delegate::UpgradeDraggedFileSystemPermissions, - base::Unretained(delegate)))); - RegisterHandler("indexPath", - BindToListParser(base::Bind(&Delegate::IndexPath, - base::Unretained(delegate)))); - RegisterHandler("stopIndexing", - BindToListParser(base::Bind(&Delegate::StopIndexing, - base::Unretained(delegate)))); - RegisterHandler("searchInPath", - BindToListParser(base::Bind(&Delegate::SearchInPath, - base::Unretained(delegate)))); - RegisterHandler("zoomIn", - BindToListParser(base::Bind(&Delegate::ZoomIn, - base::Unretained(delegate)))); - RegisterHandler("zoomOut", - BindToListParser(base::Bind(&Delegate::ZoomOut, - base::Unretained(delegate)))); - RegisterHandler("resetZoom", - BindToListParser(base::Bind(&Delegate::ResetZoom, - base::Unretained(delegate)))); -} + DispatcherImpl* d = new DispatcherImpl(); -DevToolsEmbedderMessageDispatcher::~DevToolsEmbedderMessageDispatcher() {} - -std::string DevToolsEmbedderMessageDispatcher::Dispatch( - const std::string& method, base::ListValue* params) { - HandlerMap::iterator it = handlers_.find(method); - if (it == handlers_.end()) - return "Unsupported frontend host method: " + method; - - if (!it->second.Run(*params)) - return "Invalid frontend host message parameters: " + method; - return ""; -} - -void DevToolsEmbedderMessageDispatcher::RegisterHandler( - const std::string& method, const Handler& handler) { - handlers_[method] = handler; + d->RegisterHandler("bringToFront", &Delegate::ActivateWindow, delegate); + d->RegisterHandler("closeWindow", &Delegate::CloseWindow, delegate); + d->RegisterHandler("loadCompleted", &Delegate::LoadCompleted, delegate); + d->RegisterHandler("setInspectedPageBounds", + &Delegate::SetInspectedPageBounds, delegate); + d->RegisterHandler("inspectElementCompleted", + &Delegate::InspectElementCompleted, delegate); + d->RegisterHandler("inspectedURLChanged", + &Delegate::InspectedURLChanged, delegate); + d->RegisterHandlerWithCallback("setIsDocked", + &Delegate::SetIsDocked, delegate); + d->RegisterHandler("openInNewTab", &Delegate::OpenInNewTab, delegate); + d->RegisterHandler("save", &Delegate::SaveToFile, delegate); + d->RegisterHandler("append", &Delegate::AppendToFile, delegate); + d->RegisterHandler("requestFileSystems", + &Delegate::RequestFileSystems, delegate); + d->RegisterHandler("addFileSystem", &Delegate::AddFileSystem, delegate); + d->RegisterHandler("removeFileSystem", &Delegate::RemoveFileSystem, delegate); + d->RegisterHandler("upgradeDraggedFileSystemPermissions", + &Delegate::UpgradeDraggedFileSystemPermissions, delegate); + d->RegisterHandler("indexPath", &Delegate::IndexPath, delegate); + d->RegisterHandlerWithCallback("loadNetworkResource", + &Delegate::LoadNetworkResource, delegate); + d->RegisterHandler("stopIndexing", &Delegate::StopIndexing, delegate); + d->RegisterHandler("searchInPath", &Delegate::SearchInPath, delegate); + d->RegisterHandler("setWhitelistedShortcuts", + &Delegate::SetWhitelistedShortcuts, delegate); + d->RegisterHandler("zoomIn", &Delegate::ZoomIn, delegate); + d->RegisterHandler("zoomOut", &Delegate::ZoomOut, delegate); + d->RegisterHandler("resetZoom", &Delegate::ResetZoom, delegate); + d->RegisterHandler("setDevicesUpdatesEnabled", + &Delegate::SetDevicesUpdatesEnabled, delegate); + d->RegisterHandler("sendMessageToBrowser", + &Delegate::SendMessageToBrowser, delegate); + d->RegisterHandler("recordActionUMA", &Delegate::RecordActionUMA, delegate); + d->RegisterHandlerWithCallback("sendJsonRequest", + &Delegate::SendJsonRequest, delegate); + return d; } } // namespace brightray diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index defe16c1f43..851a2f49058 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -15,6 +15,7 @@ namespace base { class ListValue; +class Value; } namespace brightray { @@ -29,14 +30,18 @@ class DevToolsEmbedderMessageDispatcher { public: class Delegate { public: + using DispatchCallback = base::Callback; + virtual ~Delegate() {} virtual void ActivateWindow() = 0; virtual void CloseWindow() = 0; + virtual void LoadCompleted() = 0; virtual void SetInspectedPageBounds(const gfx::Rect& rect) = 0; virtual void InspectElementCompleted() = 0; - virtual void MoveWindow(int x, int y) = 0; - virtual void SetIsDocked(bool docked) = 0; + virtual void InspectedURLChanged(const std::string& url) = 0; + virtual void SetIsDocked(const DispatchCallback& callback, + bool is_docked) = 0; virtual void OpenInNewTab(const std::string& url) = 0; virtual void SaveToFile(const std::string& url, const std::string& content, @@ -48,29 +53,37 @@ class DevToolsEmbedderMessageDispatcher { virtual void RemoveFileSystem(const std::string& file_system_path) = 0; virtual void UpgradeDraggedFileSystemPermissions( const std::string& file_system_url) = 0; - virtual void IndexPath(int request_id, + virtual void IndexPath(int index_request_id, const std::string& file_system_path) = 0; - virtual void StopIndexing(int request_id) = 0; - virtual void SearchInPath(int request_id, + virtual void StopIndexing(int index_request_id) = 0; + virtual void LoadNetworkResource(const DispatchCallback& callback, + const std::string& url, + const std::string& headers, + int stream_id) = 0; + virtual void SearchInPath(int search_request_id, const std::string& file_system_path, const std::string& query) = 0; + virtual void SetWhitelistedShortcuts(const std::string& message) = 0; virtual void ZoomIn() = 0; virtual void ZoomOut() = 0; virtual void ResetZoom() = 0; + virtual void SetDevicesUpdatesEnabled(bool enabled) = 0; + virtual void SendMessageToBrowser(const std::string& message) = 0; + virtual void RecordActionUMA(const std::string& name, int action) = 0; + virtual void SendJsonRequest(const DispatchCallback& callback, + const std::string& browser_id, + const std::string& url) = 0; }; - explicit DevToolsEmbedderMessageDispatcher(Delegate* delegate); + using DispatchCallback = Delegate::DispatchCallback; - ~DevToolsEmbedderMessageDispatcher(); + virtual ~DevToolsEmbedderMessageDispatcher() {} + virtual bool Dispatch(const DispatchCallback& callback, + const std::string& method, + const base::ListValue* params) = 0; - std::string Dispatch(const std::string& method, base::ListValue* params); - - private: - typedef base::Callback Handler; - void RegisterHandler(const std::string& method, const Handler& handler); - - typedef std::map HandlerMap; - HandlerMap handlers_; + static DevToolsEmbedderMessageDispatcher* CreateForDevToolsFrontend( + Delegate* delegate); }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 27bf3dbac17..43fc7132db7 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -12,6 +12,8 @@ #include "browser/inspectable_web_contents_view.h" #include "base/json/json_reader.h" +#include "base/json/json_writer.h" +#include "base/metrics/histogram.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/strings/stringprintf.h" @@ -41,6 +43,11 @@ const char kFrontendHostId[] = "id"; const char kFrontendHostMethod[] = "method"; const char kFrontendHostParams[] = "params"; +const char kDevToolsActionTakenHistogram[] = "DevTools.ActionTaken"; +const int kDevToolsActionTakenBoundary = 100; +const char kDevToolsPanelShownHistogram[] = "DevTools.PanelShown"; +const int kDevToolsPanelShownBoundary = 20; + void RectToDictionary(const gfx::Rect& bounds, base::DictionaryValue* dict) { dict->SetInteger("x", bounds.x()); dict->SetInteger("y", bounds.y()); @@ -57,34 +64,6 @@ void DictionaryToRect(const base::DictionaryValue& dict, gfx::Rect* bounds) { *bounds = gfx::Rect(x, y, width, height); } -bool ParseMessage(const std::string& message, - std::string* method, - base::ListValue* params, - int* id) { - scoped_ptr parsed_message(base::JSONReader::Read(message)); - if (!parsed_message) - return false; - - base::DictionaryValue* dict = NULL; - if (!parsed_message->GetAsDictionary(&dict)) - return false; - if (!dict->GetString(kFrontendHostMethod, method)) - return false; - - // "params" is optional. - if (dict->HasKey(kFrontendHostParams)) { - base::ListValue* internal_params; - if (dict->GetList(kFrontendHostParams, &internal_params)) - params->Swap(internal_params); - else - return false; - } - - *id = 0; - dict->GetInteger(kFrontendHostId, id); - return true; -} - double GetZoomLevelForWebContents(content::WebContents* web_contents) { return content::HostZoomMap::GetZoomLevel(web_contents); } @@ -123,7 +102,8 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( content::WebContents* web_contents) : web_contents_(web_contents), can_dock_(true), - delegate_(nullptr) { + delegate_(nullptr), + weak_factory_(this) { auto context = static_cast(web_contents_->GetBrowserContext()); auto bounds_dict = context->prefs()->GetDictionary(kDevToolsBoundsPref); if (bounds_dict) @@ -152,7 +132,7 @@ void InspectableWebContentsImpl::ShowDevTools() { // SetIsDocked is called *BEFORE* ShowDevTools. if (!devtools_web_contents_) { embedder_message_dispatcher_.reset( - new DevToolsEmbedderMessageDispatcher(this)); + DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(this)); content::WebContents::CreateParams create_params(web_contents_->GetBrowserContext()); devtools_web_contents_.reset(content::WebContents::Create(create_params)); @@ -200,6 +180,29 @@ void InspectableWebContentsImpl::Detach() { agent_host_ = nullptr; } +void InspectableWebContentsImpl::CallClientFunction(const std::string& function_name, + const base::Value* arg1, + const base::Value* arg2, + const base::Value* arg3) { + std::string javascript = function_name + "("; + if (arg1) { + std::string json; + base::JSONWriter::Write(arg1, &json); + javascript.append(json); + if (arg2) { + base::JSONWriter::Write(arg2, &json); + javascript.append(", ").append(json); + if (arg3) { + base::JSONWriter::Write(arg3, &json); + javascript.append(", ").append(json); + } + } + } + javascript.append(");"); + devtools_web_contents_->GetMainFrame()->ExecuteJavaScript( + base::UTF8ToUTF16(javascript)); +} + gfx::Rect InspectableWebContentsImpl::GetDevToolsBounds() const { return devtools_bounds_; } @@ -219,6 +222,9 @@ void InspectableWebContentsImpl::CloseWindow() { devtools_web_contents()->DispatchBeforeUnload(false); } +void InspectableWebContentsImpl::LoadCompleted() { +} + void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { DevToolsContentsResizingStrategy strategy(rect); if (contents_resizing_strategy_.Equals(strategy)) @@ -231,11 +237,21 @@ void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { void InspectableWebContentsImpl::InspectElementCompleted() { } -void InspectableWebContentsImpl::MoveWindow(int x, int y) { +void InspectableWebContentsImpl::InspectedURLChanged(const std::string& url) { } -void InspectableWebContentsImpl::SetIsDocked(bool docked) { +void InspectableWebContentsImpl::LoadNetworkResource( + const DispatchCallback& callback, + const std::string& url, + const std::string& headers, + int stream_id) { +} + +void InspectableWebContentsImpl::SetIsDocked(const DispatchCallback& callback, + bool docked) { view_->SetIsDocked(docked); + if (!callback.is_null()) + callback.Run(nullptr); } void InspectableWebContentsImpl::OpenInNewTab(const std::string& url) { @@ -253,12 +269,6 @@ void InspectableWebContentsImpl::AppendToFile( delegate_->DevToolsAppendToFile(url, content); } -void InspectableWebContentsImpl::WebContentsFocused( - content::WebContents* contents) { - if (delegate_) - delegate_->DevToolsFocused(); -} - void InspectableWebContentsImpl::RequestFileSystems() { devtools_web_contents()->GetMainFrame()->ExecuteJavaScript( base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])")); @@ -292,6 +302,9 @@ void InspectableWebContentsImpl::SearchInPath( const std::string& query) { } +void InspectableWebContentsImpl::SetWhitelistedShortcuts(const std::string& message) { +} + void InspectableWebContentsImpl::ZoomIn() { double level = GetZoomLevelForWebContents(devtools_web_contents()); SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, false)); @@ -306,26 +319,56 @@ void InspectableWebContentsImpl::ResetZoom() { SetZoomLevelForWebContents(devtools_web_contents(), 0.); } +void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) { +} + +void InspectableWebContentsImpl::SendMessageToBrowser(const std::string& message) { + if (agent_host_.get()) + agent_host_->DispatchProtocolMessage(message); +} + +void InspectableWebContentsImpl::RecordActionUMA(const std::string& name, int action) { + if (name == kDevToolsActionTakenHistogram) + UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsActionTakenBoundary); + else if (name == kDevToolsPanelShownHistogram) + UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsPanelShownBoundary); +} + +void InspectableWebContentsImpl::SendJsonRequest(const DispatchCallback& callback, + const std::string& browser_id, + const std::string& url) { + callback.Run(nullptr); +} + void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::string& message) { std::string method; - base::ListValue params; - int id; - if (!ParseMessage(message, &method, ¶ms, &id)) { + base::ListValue empty_params; + base::ListValue* params = &empty_params; + + base::DictionaryValue* dict = NULL; + scoped_ptr parsed_message(base::JSONReader::Read(message)); + if (!parsed_message || + !parsed_message->GetAsDictionary(&dict) || + !dict->GetString(kFrontendHostMethod, &method) || + (dict->HasKey(kFrontendHostParams) && + !dict->GetList(kFrontendHostParams, ¶ms))) { LOG(ERROR) << "Invalid message was sent to embedder: " << message; return; } - - std::string error = embedder_message_dispatcher_->Dispatch(method, ¶ms); - if (id) { - std::string ack = base::StringPrintf( - "DevToolsAPI.embedderMessageAck(%d, \"%s\");", id, error.c_str()); - devtools_web_contents()->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(ack)); - } + int id = 0; + dict->GetInteger(kFrontendHostId, &id); + embedder_message_dispatcher_->Dispatch( + base::Bind(&InspectableWebContentsImpl::SendMessageAck, + weak_factory_.GetWeakPtr(), + id), + method, + params); } void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontendToBackend( const std::string& message) { - agent_host_->DispatchProtocolMessage(message); + if (agent_host_.get()) + agent_host_->DispatchProtocolMessage(message); } void InspectableWebContentsImpl::DispatchProtocolMessage( @@ -356,7 +399,7 @@ void InspectableWebContentsImpl::DidFinishLoad(content::RenderFrameHost* render_ // If the devtools can dock, "SetIsDocked" will be called by devtools itself. if (!can_dock_) - SetIsDocked(false); + SetIsDocked(DispatchCallback(), false); } void InspectableWebContentsImpl::WebContentsDestroyed() { @@ -400,4 +443,17 @@ void InspectableWebContentsImpl::CloseContents(content::WebContents* source) { CloseDevTools(); } +void InspectableWebContentsImpl::WebContentsFocused( + content::WebContents* contents) { + if (delegate_) + delegate_->DevToolsFocused(); +} + +void InspectableWebContentsImpl::SendMessageAck(int request_id, + const base::Value* arg) { + base::FundamentalValue id_value(request_id); + CallClientFunction("DevToolsAPI.embedderMessageAck", + &id_value, arg, nullptr); +} + } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 655f77ad0a0..bde6e1b4aac 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -11,6 +11,7 @@ #include "browser/devtools_contents_resizing_strategy.h" #include "browser/devtools_embedder_message_dispatcher.h" +#include "base/memory/weak_ptr.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/web_contents_delegate.h" @@ -51,6 +52,10 @@ class InspectableWebContentsImpl : void AttachTo(const scoped_refptr&) override; void Detach(); + void CallClientFunction(const std::string& function_name, + const base::Value* arg1, + const base::Value* arg2, + const base::Value* arg3); // Return the last position and size of devtools window. gfx::Rect GetDevToolsBounds() const; @@ -71,10 +76,15 @@ class InspectableWebContentsImpl : // DevToolsEmbedderMessageDispacher::Delegate void ActivateWindow() override; void CloseWindow() override; + void LoadCompleted() override; void SetInspectedPageBounds(const gfx::Rect& rect) override; void InspectElementCompleted() override; - void MoveWindow(int x, int y) override; - void SetIsDocked(bool docked) override; + void InspectedURLChanged(const std::string& url) override; + void LoadNetworkResource(const DispatchCallback& callback, + const std::string& url, + const std::string& headers, + int stream_id) override; + void SetIsDocked(const DispatchCallback& callback, bool is_docked) override; void OpenInNewTab(const std::string& url) override; void SaveToFile(const std::string& url, const std::string& content, @@ -86,15 +96,22 @@ class InspectableWebContentsImpl : void RemoveFileSystem(const std::string& file_system_path) override; void UpgradeDraggedFileSystemPermissions( const std::string& file_system_url) override; - void IndexPath(int request_id, + void IndexPath(int index_request_id, const std::string& file_system_path) override; - void StopIndexing(int request_id) override; - void SearchInPath(int request_id, + void StopIndexing(int index_request_id) override; + void SearchInPath(int search_request_id, const std::string& file_system_path, const std::string& query) override; + void SetWhitelistedShortcuts(const std::string& message) override; void ZoomIn() override; void ZoomOut() override; void ResetZoom() override; + void SetDevicesUpdatesEnabled(bool enabled) override; + void SendMessageToBrowser(const std::string& message) override; + void RecordActionUMA(const std::string& name, int action) override; + void SendJsonRequest(const DispatchCallback& callback, + const std::string& browser_id, + const std::string& url) override; // content::DevToolsFrontendHostDelegate: void HandleMessageFromDevToolsFrontend(const std::string& message) override; @@ -133,6 +150,9 @@ class InspectableWebContentsImpl : void CloseContents(content::WebContents* source) override; void WebContentsFocused(content::WebContents* contents) override; + void SendMessageAck(int request_id, + const base::Value* arg1); + scoped_ptr web_contents_; scoped_ptr devtools_web_contents_; scoped_ptr view_; @@ -147,6 +167,8 @@ class InspectableWebContentsImpl : InspectableWebContentsDelegate* delegate_; + base::WeakPtrFactory weak_factory_; + DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); }; From 9a9bc5530e13f1ba7ab1fafd857c94125fc1c26b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 11:20:20 +0800 Subject: [PATCH 0571/1195] Handle network requests from devtools --- .../browser/inspectable_web_contents_impl.cc | 100 ++++++++++++++++++ .../browser/inspectable_web_contents_impl.h | 11 +- 2 files changed, 109 insertions(+), 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 43fc7132db7..bc3a9aba54f 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -19,10 +19,14 @@ #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" +#include "net/http/http_response_headers.h" +#include "net/url_request/url_fetcher.h" +#include "net/url_request/url_fetcher_response_writer.h" namespace brightray { @@ -86,6 +90,59 @@ double GetNextZoomLevel(double level, bool out) { return level; } +// ResponseWriter ------------------------------------------------------------- + +class ResponseWriter : public net::URLFetcherResponseWriter { + public: + ResponseWriter(base::WeakPtr bindings, int stream_id); + ~ResponseWriter() override; + + // URLFetcherResponseWriter overrides: + int Initialize(const net::CompletionCallback& callback) override; + int Write(net::IOBuffer* buffer, + int num_bytes, + const net::CompletionCallback& callback) override; + int Finish(const net::CompletionCallback& callback) override; + + private: + base::WeakPtr bindings_; + int stream_id_; + + DISALLOW_COPY_AND_ASSIGN(ResponseWriter); +}; + +ResponseWriter::ResponseWriter(base::WeakPtr bindings, + int stream_id) + : bindings_(bindings), + stream_id_(stream_id) { +} + +ResponseWriter::~ResponseWriter() { +} + +int ResponseWriter::Initialize(const net::CompletionCallback& callback) { + return net::OK; +} + +int ResponseWriter::Write(net::IOBuffer* buffer, + int num_bytes, + const net::CompletionCallback& callback) { + base::FundamentalValue* id = new base::FundamentalValue(stream_id_); + base::StringValue* chunk = + new base::StringValue(std::string(buffer->data(), num_bytes)); + + content::BrowserThread::PostTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&InspectableWebContentsImpl::CallClientFunction, + bindings_, "DevToolsAPI.streamWrite", + base::Owned(id), base::Owned(chunk), nullptr)); + return num_bytes; +} + +int ResponseWriter::Finish(const net::CompletionCallback& callback) { + return net::OK; +} + } // namespace // Implemented separately on each platform. @@ -245,6 +302,24 @@ void InspectableWebContentsImpl::LoadNetworkResource( const std::string& url, const std::string& headers, int stream_id) { + GURL gurl(url); + if (!gurl.is_valid()) { + base::DictionaryValue response; + response.SetInteger("statusCode", 404); + callback.Run(&response); + return; + } + + auto browser_context = static_cast(devtools_web_contents_->GetBrowserContext()); + + net::URLFetcher* fetcher = + net::URLFetcher::Create(gurl, net::URLFetcher::GET, this); + pending_requests_[fetcher] = callback; + fetcher->SetRequestContext(browser_context->url_request_context_getter()); + fetcher->SetExtraRequestHeaders(headers); + fetcher->SaveResponseWithWriter(scoped_ptr( + new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id))); + fetcher->Start(); } void InspectableWebContentsImpl::SetIsDocked(const DispatchCallback& callback, @@ -406,6 +481,9 @@ void InspectableWebContentsImpl::WebContentsDestroyed() { agent_host_->DetachClient(); Observe(nullptr); agent_host_ = nullptr; + + for (const auto& pair : pending_requests_) + delete pair.first; } bool InspectableWebContentsImpl::AddMessageToConsole( @@ -449,6 +527,28 @@ void InspectableWebContentsImpl::WebContentsFocused( delegate_->DevToolsFocused(); } +void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) { + DCHECK(source); + PendingRequestsMap::iterator it = pending_requests_.find(source); + DCHECK(it != pending_requests_.end()); + + base::DictionaryValue response; + base::DictionaryValue* headers = new base::DictionaryValue(); + net::HttpResponseHeaders* rh = source->GetResponseHeaders(); + response.SetInteger("statusCode", rh ? rh->response_code() : 200); + response.Set("headers", headers); + + void* iterator = NULL; + std::string name; + std::string value; + while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) + headers->SetString(name, value); + + it->second.Run(&response); + pending_requests_.erase(it); + delete source; +} + void InspectableWebContentsImpl::SendMessageAck(int request_id, const base::Value* arg) { base::FundamentalValue id_value(request_id); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index bde6e1b4aac..932b0fd6a94 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -16,6 +16,7 @@ #include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_observer.h" +#include "net/url_request/url_fetcher_delegate.h" #include "ui/gfx/geometry/rect.h" class PrefRegistrySimple; @@ -35,7 +36,8 @@ class InspectableWebContentsImpl : public content::DevToolsAgentHostClient, public content::WebContentsObserver, public content::WebContentsDelegate, - public DevToolsEmbedderMessageDispatcher::Delegate { + public DevToolsEmbedderMessageDispatcher::Delegate, + public net::URLFetcherDelegate { public: static void RegisterPrefs(PrefRegistrySimple* pref_registry); @@ -130,7 +132,7 @@ class InspectableWebContentsImpl : const GURL& validated_url) override; void WebContentsDestroyed() override; - // content::WebContentsDelegate + // content::WebContentsDelegate: bool AddMessageToConsole(content::WebContents* source, int32 level, const base::string16& message, @@ -150,6 +152,9 @@ class InspectableWebContentsImpl : void CloseContents(content::WebContents* source) override; void WebContentsFocused(content::WebContents* contents) override; + // net::URLFetcherDelegate: + void OnURLFetchComplete(const net::URLFetcher* source) override; + void SendMessageAck(int request_id, const base::Value* arg1); @@ -167,6 +172,8 @@ class InspectableWebContentsImpl : InspectableWebContentsDelegate* delegate_; + using PendingRequestsMap = std::map; + PendingRequestsMap pending_requests_; base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); From 56747e975eb4f4053ab6b375712e32e1d7f590a9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 11:58:27 +0800 Subject: [PATCH 0572/1195] Avoid calling JavaScript of devtools WebContents too early It would craete a context that window.location is about:blank --- .../browser/inspectable_web_contents_impl.cc | 31 ++++++++++++++----- .../browser/inspectable_web_contents_impl.h | 1 + 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index bc3a9aba54f..3242316989f 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -52,6 +52,8 @@ const int kDevToolsActionTakenBoundary = 100; const char kDevToolsPanelShownHistogram[] = "DevTools.PanelShown"; const int kDevToolsPanelShownBoundary = 20; +const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; + void RectToDictionary(const gfx::Rect& bounds, base::DictionaryValue* dict) { dict->SetInteger("x", bounds.x()); dict->SetInteger("y", bounds.y()); @@ -159,6 +161,7 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( content::WebContents* web_contents) : web_contents_(web_contents), can_dock_(true), + frontend_loaded_(false), delegate_(nullptr), weak_factory_(this) { auto context = static_cast(web_contents_->GetBrowserContext()); @@ -280,6 +283,7 @@ void InspectableWebContentsImpl::CloseWindow() { } void InspectableWebContentsImpl::LoadCompleted() { + frontend_loaded_ = true; } void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { @@ -345,8 +349,8 @@ void InspectableWebContentsImpl::AppendToFile( } void InspectableWebContentsImpl::RequestFileSystems() { - devtools_web_contents()->GetMainFrame()->ExecuteJavaScript( - base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])")); + devtools_web_contents()->GetMainFrame()->ExecuteJavaScript( + base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])")); } void InspectableWebContentsImpl::AddFileSystem() { @@ -448,9 +452,22 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontendToBackend( void InspectableWebContentsImpl::DispatchProtocolMessage( content::DevToolsAgentHost* agent_host, const std::string& message) { - std::string code = "DevToolsAPI.dispatchMessage(" + message + ");"; - base::string16 javascript = base::UTF8ToUTF16(code); - web_contents()->GetMainFrame()->ExecuteJavaScript(javascript); + if (!frontend_loaded_) + return; + + if (message.length() < kMaxMessageChunkSize) { + base::string16 javascript = base::UTF8ToUTF16( + "DevToolsAPI.dispatchMessage(" + message + ");"); + devtools_web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); + return; + } + + base::FundamentalValue total_size(static_cast(message.length())); + for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { + base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); + CallClientFunction("DevToolsAPI.dispatchMessageChunk", + &message_value, pos ? NULL : &total_size, NULL); + } } void InspectableWebContentsImpl::AgentHostClosed( @@ -478,9 +495,9 @@ void InspectableWebContentsImpl::DidFinishLoad(content::RenderFrameHost* render_ } void InspectableWebContentsImpl::WebContentsDestroyed() { - agent_host_->DetachClient(); Observe(nullptr); - agent_host_ = nullptr; + Detach(); + frontend_loaded_ = false; for (const auto& pair : pending_requests_) delete pair.first; diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 932b0fd6a94..aec9548b98a 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -167,6 +167,7 @@ class InspectableWebContentsImpl : DevToolsContentsResizingStrategy contents_resizing_strategy_; gfx::Rect devtools_bounds_; bool can_dock_; + bool frontend_loaded_; scoped_ptr embedder_message_dispatcher_; From 95d28c398e2c510d53feef4474a43d86ec990885 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 12:07:27 +0800 Subject: [PATCH 0573/1195] Update cpplint --- brightray/browser/browser_context.cc | 4 +- brightray/browser/browser_context.h | 4 +- brightray/browser/browser_main_parts.h | 12 ++--- .../devtools_embedder_message_dispatcher.cc | 2 +- brightray/browser/devtools_ui.cc | 21 +++++---- .../inspectable_web_contents_view_mac.h | 12 ++--- .../linux/notification_presenter_linux.cc | 7 +-- .../media/media_capture_devices_dispatcher.h | 10 ++--- .../browser/url_request_context_getter.h | 4 +- .../inspectable_web_contents_view_views.h | 16 +++---- brightray/browser/views/views_delegate.h | 44 +++++++++---------- brightray/browser/web_ui_controller_factory.h | 10 ++--- brightray/common/main_delegate.h | 6 +-- brightray/vendor/google-styleguide | 2 +- 14 files changed, 77 insertions(+), 77 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index c4aa7d186d8..3e0e271164b 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -33,11 +33,11 @@ class BrowserContext::ResourceContext : public content::ResourceContext { } private: - virtual net::HostResolver* GetHostResolver() override { + net::HostResolver* GetHostResolver() override { return getter_->host_resolver(); } - virtual net::URLRequestContext* GetRequestContext() override { + net::URLRequestContext* GetRequestContext() override { return getter_->GetURLRequestContext(); } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index d7f957477f1..5cddd0a494e 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -40,9 +40,9 @@ class BrowserContext : public content::BrowserContext, virtual void RegisterPrefs(PrefRegistrySimple* pref_registry) {} // URLRequestContextGetter::Delegate: - virtual net::NetworkDelegate* CreateNetworkDelegate() override; + net::NetworkDelegate* CreateNetworkDelegate() override; - virtual base::FilePath GetPath() const override; + base::FilePath GetPath() const override; private: class ResourceContext; diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index a5ba51508b4..e8d7c323c78 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -39,12 +39,12 @@ class BrowserMainParts : public content::BrowserMainParts { protected: // content::BrowserMainParts: - virtual void PreEarlyInitialization() override; - virtual void ToolkitInitialized() override; - virtual void PreMainMessageLoopStart() override; - virtual void PreMainMessageLoopRun() override; - virtual void PostMainMessageLoopRun() override; - virtual int PreCreateThreads() override; + void PreEarlyInitialization() override; + void ToolkitInitialized() override; + void PreMainMessageLoopStart() override; + void PreMainMessageLoopRun() override; + void PostMainMessageLoopRun() override; + int PreCreateThreads() override; // Subclasses should override this to provide their own BrowserContxt // implementation. The caller takes ownership of the returned object. diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index c5b90fccef9..cb44ec16d86 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -104,7 +104,7 @@ bool ParseAndHandleWithCallback( return true; } -} // namespace +} // namespace /** * Dispatcher for messages sent from the frontend running in an diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 30a974fccfc..9b5eba7d6fc 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -52,18 +52,17 @@ std::string GetMimeTypeForPath(const std::string& path) { class BundledDataSource : public content::URLDataSource { public: - explicit BundledDataSource() { - } + BundledDataSource() {} // content::URLDataSource implementation. - virtual std::string GetSource() const override { + std::string GetSource() const override { return kChromeUIDevToolsBundledHost; } - virtual void StartDataRequest(const std::string& path, - int render_process_id, - int render_view_id, - const GotDataCallback& callback) override { + void StartDataRequest(const std::string& path, + int render_process_id, + int render_view_id, + const GotDataCallback& callback) override { std::string filename = PathWithoutParams(path); int resource_id = @@ -79,19 +78,19 @@ class BundledDataSource : public content::URLDataSource { callback.Run(bytes.get()); } - virtual std::string GetMimeType(const std::string& path) const override { + std::string GetMimeType(const std::string& path) const override { return GetMimeTypeForPath(path); } - virtual bool ShouldAddContentSecurityPolicy() const override { + bool ShouldAddContentSecurityPolicy() const override { return false; } - virtual bool ShouldDenyXFrameOptions() const override { + bool ShouldDenyXFrameOptions() const override { return false; } - virtual bool ShouldServeMimeTypeAsContentTypeHeader() const override { + bool ShouldServeMimeTypeAsContentTypeHeader() const override { return true; } diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 6a81d642c8d..fbe19adaebd 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -17,12 +17,12 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView { InspectableWebContentsImpl* inspectable_web_contents_impl); virtual ~InspectableWebContentsViewMac(); - virtual gfx::NativeView GetNativeView() const override; - virtual void ShowDevTools() override; - virtual void CloseDevTools() override; - virtual bool IsDevToolsViewShowing() override; - virtual void SetIsDocked(bool docked) override; - virtual void SetContentsResizingStrategy( + gfx::NativeView GetNativeView() const override; + void ShowDevTools() override; + void CloseDevTools() override; + bool IsDevToolsViewShowing() override; + void SetIsDocked(bool docked) override; + void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) override; InspectableWebContentsImpl* inspectable_web_contents() { diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 9baa4474e98..0c688906a7b 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -30,7 +30,7 @@ static bool UnityIsRunning() { struct DBusConnection* bus = NULL; dbus_error_init(&err); - + bus = dbus_bus_get(DBUS_BUS_SESSION, &err); if (dbus_error_is_set(&err)) { g_debug("Failed to get Session Bus reference"); @@ -39,7 +39,7 @@ static bool UnityIsRunning() { goto out; } - + unity_result = dbus_bus_name_has_owner(bus, "com.canonical.indicator.session", &err); if (dbus_error_is_set(&err)) { @@ -107,7 +107,8 @@ void NotificationPresenterLinux::ShowNotification( // Zen Nature" is difficult, we will test for the presence of the indicate // dbus service if (!UnityIsRunning()) { - notify_notification_add_action(notification, "default", "View", OnNotificationViewThunk, this, nullptr); + notify_notification_add_action( + notification, "default", "View", OnNotificationViewThunk, this, nullptr); } GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon); diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index f89f9b02203..be369a2ff61 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -51,17 +51,17 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { void DisableDeviceEnumerationForTesting(); // Overridden from content::MediaObserver: - virtual void OnAudioCaptureDevicesChanged() override; - virtual void OnVideoCaptureDevicesChanged() override; - virtual void OnMediaRequestStateChanged( + void OnAudioCaptureDevicesChanged() override; + void OnVideoCaptureDevicesChanged() override; + void OnMediaRequestStateChanged( int render_process_id, int render_view_id, int page_request_id, const GURL& security_origin, content::MediaStreamType stream_type, content::MediaRequestState state) override; - virtual void OnCreatingAudioStream(int render_process_id, - int render_view_id) override; + void OnCreatingAudioStream(int render_process_id, + int render_view_id) override; private: friend struct DefaultSingletonTraits; diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 599bf6c4d22..d1f847fc968 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -52,8 +52,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual ~URLRequestContextGetter(); // net::URLRequestContextGetter: - virtual net::URLRequestContext* GetURLRequestContext() override; - virtual scoped_refptr GetNetworkTaskRunner() const override; + net::URLRequestContext* GetURLRequestContext() override; + scoped_refptr GetNetworkTaskRunner() const override; net::HostResolver* host_resolver(); diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index 80934755692..4e250350463 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -24,13 +24,13 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, ~InspectableWebContentsViewViews(); // InspectableWebContentsView: - virtual views::View* GetView() override; - virtual views::View* GetWebView() override; - virtual void ShowDevTools() override; - virtual void CloseDevTools() override; - virtual bool IsDevToolsViewShowing() override; - virtual void SetIsDocked(bool docked) override; - virtual void SetContentsResizingStrategy( + views::View* GetView() override; + views::View* GetWebView() override; + void ShowDevTools() override; + void CloseDevTools() override; + bool IsDevToolsViewShowing() override; + void SetIsDocked(bool docked) override; + void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) override; InspectableWebContentsImpl* inspectable_web_contents() { @@ -39,7 +39,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, private: // views::View: - virtual void Layout() override; + void Layout() override; // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; diff --git a/brightray/browser/views/views_delegate.h b/brightray/browser/views/views_delegate.h index bd1e7bc2b6b..157660aa5d0 100644 --- a/brightray/browser/views/views_delegate.h +++ b/brightray/browser/views/views_delegate.h @@ -17,42 +17,42 @@ class ViewsDelegate : public views::ViewsDelegate { protected: // views::ViewsDelegate: - virtual void SaveWindowPlacement(const views::Widget* window, - const std::string& window_name, - const gfx::Rect& bounds, - ui::WindowShowState show_state) override; - virtual bool GetSavedWindowPlacement( + void SaveWindowPlacement(const views::Widget* window, + const std::string& window_name, + const gfx::Rect& bounds, + ui::WindowShowState show_state) override; + bool GetSavedWindowPlacement( const views::Widget* widget, const std::string& window_name, gfx::Rect* bounds, ui::WindowShowState* show_state) const override; - virtual void NotifyAccessibilityEvent( + void NotifyAccessibilityEvent( views::View* view, ui::AXEvent event_type) override; - virtual void NotifyMenuItemFocused(const base::string16& menu_name, - const base::string16& menu_item_name, - int item_index, - int item_count, - bool has_submenu) override; + void NotifyMenuItemFocused(const base::string16& menu_name, + const base::string16& menu_item_name, + int item_index, + int item_count, + bool has_submenu) override; #if defined(OS_WIN) - virtual HICON GetDefaultWindowIcon() const override; - virtual HICON GetSmallWindowIcon() const override; - virtual bool IsWindowInMetro(gfx::NativeWindow window) const override; + HICON GetDefaultWindowIcon() const override; + HICON GetSmallWindowIcon() const override; + bool IsWindowInMetro(gfx::NativeWindow window) const override; #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) - virtual gfx::ImageSkia* GetDefaultWindowIcon() const override; + gfx::ImageSkia* GetDefaultWindowIcon() const override; #endif - virtual views::NonClientFrameView* CreateDefaultNonClientFrameView( + views::NonClientFrameView* CreateDefaultNonClientFrameView( views::Widget* widget) override; - virtual void AddRef() override; - virtual void ReleaseRef() override; - virtual content::WebContents* CreateWebContents( + void AddRef() override; + void ReleaseRef() override; + content::WebContents* CreateWebContents( content::BrowserContext* browser_context, content::SiteInstance* site_instance) override; - virtual void OnBeforeWidgetInit( + void OnBeforeWidgetInit( views::Widget::InitParams* params, views::internal::NativeWidgetDelegate* delegate) override; - virtual base::TimeDelta GetDefaultTextfieldObscuredRevealDuration() override; - virtual bool WindowManagerProvidesTitleBar(bool maximized) override; + base::TimeDelta GetDefaultTextfieldObscuredRevealDuration() override; + bool WindowManagerProvidesTitleBar(bool maximized) override; private: DISALLOW_COPY_AND_ASSIGN(ViewsDelegate); diff --git a/brightray/browser/web_ui_controller_factory.h b/brightray/browser/web_ui_controller_factory.h index ed99e3247c5..6f860841aff 100644 --- a/brightray/browser/web_ui_controller_factory.h +++ b/brightray/browser/web_ui_controller_factory.h @@ -18,13 +18,13 @@ class WebUIControllerFactory : public content::WebUIControllerFactory { explicit WebUIControllerFactory(BrowserContext* browser_context); virtual ~WebUIControllerFactory(); - virtual content::WebUI::TypeID GetWebUIType( + content::WebUI::TypeID GetWebUIType( content::BrowserContext* browser_context, const GURL& url) const override; - virtual bool UseWebUIForURL(content::BrowserContext* browser_context, + bool UseWebUIForURL(content::BrowserContext* browser_context, + const GURL& url) const override; + bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, const GURL& url) const override; - virtual bool UseWebUIBindingsForURL(content::BrowserContext* browser_context, - const GURL& url) const override; - virtual content::WebUIController* CreateWebUIControllerForURL( + content::WebUIController* CreateWebUIControllerForURL( content::WebUI* web_ui, const GURL& url) const override; diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 153013b3c21..58349944746 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -49,11 +49,11 @@ class MainDelegate : public content::ContentMainDelegate { virtual void OverrideFrameworkBundlePath(); #endif - virtual bool BasicStartupComplete(int* exit_code) override; - virtual void PreSandboxStartup() override; + bool BasicStartupComplete(int* exit_code) override; + void PreSandboxStartup() override; private: - virtual content::ContentBrowserClient* CreateContentBrowserClient() override; + content::ContentBrowserClient* CreateContentBrowserClient() override; void InitializeResourceBundle(); diff --git a/brightray/vendor/google-styleguide b/brightray/vendor/google-styleguide index 8025f5495c0..ba88c8a53f1 160000 --- a/brightray/vendor/google-styleguide +++ b/brightray/vendor/google-styleguide @@ -1 +1 @@ -Subproject commit 8025f5495c04f1cf9e0d65a0aaa97b58c304faf7 +Subproject commit ba88c8a53f1b563c43fc063cc048e5efdc238c18 From aa926680a2aef5ba87f99169efa87464c9bbf9c3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 12:10:01 +0800 Subject: [PATCH 0574/1195] No more need to override DidFinishLoad --- .../browser/inspectable_web_contents_impl.cc | 17 +++++------------ .../browser/inspectable_web_contents_impl.h | 2 -- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 3242316989f..5d109e123e0 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -284,6 +284,11 @@ void InspectableWebContentsImpl::CloseWindow() { void InspectableWebContentsImpl::LoadCompleted() { frontend_loaded_ = true; + view_->ShowDevTools(); + + // If the devtools can dock, "SetIsDocked" will be called by devtools itself. + if (!can_dock_) + SetIsDocked(DispatchCallback(), false); } void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { @@ -482,18 +487,6 @@ void InspectableWebContentsImpl::AboutToNavigateRenderFrame( frontend_host_.reset(content::DevToolsFrontendHost::Create(new_host, this)); } -void InspectableWebContentsImpl::DidFinishLoad(content::RenderFrameHost* render_frame_host, - const GURL& validated_url) { - if (render_frame_host->GetParent()) - return; - - view_->ShowDevTools(); - - // If the devtools can dock, "SetIsDocked" will be called by devtools itself. - if (!can_dock_) - SetIsDocked(DispatchCallback(), false); -} - void InspectableWebContentsImpl::WebContentsDestroyed() { Observe(nullptr); Detach(); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index aec9548b98a..249d0867daa 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -128,8 +128,6 @@ class InspectableWebContentsImpl : // content::WebContentsObserver: void AboutToNavigateRenderFrame(content::RenderFrameHost* old_host, content::RenderFrameHost* new_host) override; - void DidFinishLoad(content::RenderFrameHost* render_frame_host, - const GURL& validated_url) override; void WebContentsDestroyed() override; // content::WebContentsDelegate: From 05f182f650810082a1fbae187f467f598ac24b2b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 12:24:48 +0800 Subject: [PATCH 0575/1195] Clean up code --- brightray/browser/inspectable_web_contents.h | 25 ++++++++++++------- .../browser/inspectable_web_contents_impl.cc | 20 +++++++++++---- .../browser/inspectable_web_contents_impl.h | 22 ++++++---------- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 7ac1366ea7c..dc22a37cada 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -3,6 +3,10 @@ #include "content/public/browser/web_contents.h" +namespace base { +class Value; +} + namespace content { class DevToolsAgentHost; } @@ -14,8 +18,7 @@ class InspectableWebContentsView; class InspectableWebContents { public: - static InspectableWebContents* Create( - const content::WebContents::CreateParams&); + static InspectableWebContents* Create(const content::WebContents::CreateParams&); // The returned InspectableWebContents takes ownership of the passed-in // WebContents. @@ -26,16 +29,20 @@ class InspectableWebContents { virtual InspectableWebContentsView* GetView() const = 0; virtual content::WebContents* GetWebContents() const = 0; - virtual void SetCanDock(bool can_dock) = 0; - virtual void ShowDevTools() = 0; - // Close the DevTools completely instead of just hide it. - virtual void CloseDevTools() = 0; - virtual bool IsDevToolsViewShowing() = 0; - virtual void AttachTo(const scoped_refptr&) = 0; - // The delegate manages its own life. virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0; virtual InspectableWebContentsDelegate* GetDelegate() const = 0; + + virtual void SetCanDock(bool can_dock) = 0; + virtual void ShowDevTools() = 0; + virtual void CloseDevTools() = 0; + virtual bool IsDevToolsViewShowing() = 0; + virtual void AttachTo(const scoped_refptr&) = 0; + virtual void Detach() = 0; + virtual void CallClientFunction(const std::string& function_name, + const base::Value* arg1, + const base::Value* arg2, + const base::Value* arg3) = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 5d109e123e0..01f750ea02c 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -160,8 +160,8 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { InspectableWebContentsImpl::InspectableWebContentsImpl( content::WebContents* web_contents) : web_contents_(web_contents), - can_dock_(true), frontend_loaded_(false), + can_dock_(true), delegate_(nullptr), weak_factory_(this) { auto context = static_cast(web_contents_->GetBrowserContext()); @@ -183,6 +183,14 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const { return web_contents_.get(); } +void InspectableWebContentsImpl::SetDelegate(InspectableWebContentsDelegate* delegate) { + delegate_ = delegate; +} + +InspectableWebContentsDelegate* InspectableWebContentsImpl::GetDelegate() const { + return delegate_; +} + void InspectableWebContentsImpl::SetCanDock(bool can_dock) { can_dock_ = can_dock; } @@ -429,7 +437,7 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::st base::ListValue empty_params; base::ListValue* params = &empty_params; - base::DictionaryValue* dict = NULL; + base::DictionaryValue* dict = nullptr; scoped_ptr parsed_message(base::JSONReader::Read(message)); if (!parsed_message || !parsed_message->GetAsDictionary(&dict) || @@ -471,7 +479,7 @@ void InspectableWebContentsImpl::DispatchProtocolMessage( for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); CallClientFunction("DevToolsAPI.dispatchMessageChunk", - &message_value, pos ? NULL : &total_size, NULL); + &message_value, pos ? nullptr : &total_size, nullptr); } } @@ -488,9 +496,11 @@ void InspectableWebContentsImpl::AboutToNavigateRenderFrame( } void InspectableWebContentsImpl::WebContentsDestroyed() { + frontend_loaded_ = false; Observe(nullptr); Detach(); - frontend_loaded_ = false; + agent_host_ = nullptr; + embedder_message_dispatcher_ = nullptr; for (const auto& pair : pending_requests_) delete pair.first; @@ -548,7 +558,7 @@ void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* sourc response.SetInteger("statusCode", rh ? rh->response_code() : 200); response.Set("headers", headers); - void* iterator = NULL; + void* iterator = nullptr; std::string name; std::string value; while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 249d0867daa..cb7738a72b9 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -47,29 +47,23 @@ class InspectableWebContentsImpl : InspectableWebContentsView* GetView() const override; content::WebContents* GetWebContents() const override; + void SetDelegate(InspectableWebContentsDelegate* delegate) override; + InspectableWebContentsDelegate* GetDelegate() const override; void SetCanDock(bool can_dock) override; void ShowDevTools() override; void CloseDevTools() override; bool IsDevToolsViewShowing() override; void AttachTo(const scoped_refptr&) override; - - void Detach(); + void Detach() override; void CallClientFunction(const std::string& function_name, const base::Value* arg1, const base::Value* arg2, - const base::Value* arg3); + const base::Value* arg3) override; // Return the last position and size of devtools window. gfx::Rect GetDevToolsBounds() const; void SaveDevToolsBounds(const gfx::Rect& bounds); - virtual void SetDelegate(InspectableWebContentsDelegate* delegate) { - delegate_ = delegate; - } - virtual InspectableWebContentsDelegate* GetDelegate() const { - return delegate_; - } - content::WebContents* devtools_web_contents() { return devtools_web_contents_.get(); } @@ -159,17 +153,17 @@ class InspectableWebContentsImpl : scoped_ptr web_contents_; scoped_ptr devtools_web_contents_; scoped_ptr view_; + + bool frontend_loaded_; scoped_refptr agent_host_; scoped_ptr frontend_host_; + scoped_ptr embedder_message_dispatcher_; DevToolsContentsResizingStrategy contents_resizing_strategy_; gfx::Rect devtools_bounds_; bool can_dock_; - bool frontend_loaded_; - scoped_ptr embedder_message_dispatcher_; - - InspectableWebContentsDelegate* delegate_; + InspectableWebContentsDelegate* delegate_; // weak references. using PendingRequestsMap = std::map; PendingRequestsMap pending_requests_; From 9ab9b392d6ce22fcba7fbf2f0bcf4418ef08080a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 12:34:54 +0800 Subject: [PATCH 0576/1195] Fix crash when quitting --- brightray/browser/inspectable_web_contents_impl.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 01f750ea02c..3dfffccbfb1 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -499,8 +499,6 @@ void InspectableWebContentsImpl::WebContentsDestroyed() { frontend_loaded_ = false; Observe(nullptr); Detach(); - agent_host_ = nullptr; - embedder_message_dispatcher_ = nullptr; for (const auto& pair : pending_requests_) delete pair.first; From d1e70e78269987a6b4d930d998e472850783f416 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 14:33:37 +0800 Subject: [PATCH 0577/1195] Add InspectableWebContents::GetDevToolsWebContents --- brightray/browser/inspectable_web_contents.h | 7 ++++--- .../browser/inspectable_web_contents_impl.cc | 18 +++++++++++------- .../browser/inspectable_web_contents_impl.h | 5 +---- .../mac/bry_inspectable_web_contents_view.mm | 12 +++++++----- .../inspectable_web_contents_view_views.cc | 6 ++++-- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index dc22a37cada..edf26ed117d 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -28,6 +28,7 @@ class InspectableWebContents { virtual InspectableWebContentsView* GetView() const = 0; virtual content::WebContents* GetWebContents() const = 0; + virtual content::WebContents* GetDevToolsWebContents() const = 0; // The delegate manages its own life. virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0; @@ -40,9 +41,9 @@ class InspectableWebContents { virtual void AttachTo(const scoped_refptr&) = 0; virtual void Detach() = 0; virtual void CallClientFunction(const std::string& function_name, - const base::Value* arg1, - const base::Value* arg2, - const base::Value* arg3) = 0; + const base::Value* arg1 = nullptr, + const base::Value* arg2 = nullptr, + const base::Value* arg3 = nullptr) = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 3dfffccbfb1..832768a8967 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -183,6 +183,10 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const { return web_contents_.get(); } +content::WebContents* InspectableWebContentsImpl::GetDevToolsWebContents() const { + return devtools_web_contents_.get(); +} + void InspectableWebContentsImpl::SetDelegate(InspectableWebContentsDelegate* delegate) { delegate_ = delegate; } @@ -287,7 +291,7 @@ void InspectableWebContentsImpl::ActivateWindow() { } void InspectableWebContentsImpl::CloseWindow() { - devtools_web_contents()->DispatchBeforeUnload(false); + GetDevToolsWebContents()->DispatchBeforeUnload(false); } void InspectableWebContentsImpl::LoadCompleted() { @@ -362,7 +366,7 @@ void InspectableWebContentsImpl::AppendToFile( } void InspectableWebContentsImpl::RequestFileSystems() { - devtools_web_contents()->GetMainFrame()->ExecuteJavaScript( + GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript( base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])")); } @@ -398,17 +402,17 @@ void InspectableWebContentsImpl::SetWhitelistedShortcuts(const std::string& mess } void InspectableWebContentsImpl::ZoomIn() { - double level = GetZoomLevelForWebContents(devtools_web_contents()); - SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, false)); + double level = GetZoomLevelForWebContents(GetDevToolsWebContents()); + SetZoomLevelForWebContents(GetDevToolsWebContents(), GetNextZoomLevel(level, false)); } void InspectableWebContentsImpl::ZoomOut() { - double level = GetZoomLevelForWebContents(devtools_web_contents()); - SetZoomLevelForWebContents(devtools_web_contents(), GetNextZoomLevel(level, true)); + double level = GetZoomLevelForWebContents(GetDevToolsWebContents()); + SetZoomLevelForWebContents(GetDevToolsWebContents(), GetNextZoomLevel(level, true)); } void InspectableWebContentsImpl::ResetZoom() { - SetZoomLevelForWebContents(devtools_web_contents(), 0.); + SetZoomLevelForWebContents(GetDevToolsWebContents(), 0.); } void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index cb7738a72b9..d9af6cf1230 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -46,6 +46,7 @@ class InspectableWebContentsImpl : InspectableWebContentsView* GetView() const override; content::WebContents* GetWebContents() const override; + content::WebContents* GetDevToolsWebContents() const override; void SetDelegate(InspectableWebContentsDelegate* delegate) override; InspectableWebContentsDelegate* GetDelegate() const override; @@ -64,10 +65,6 @@ class InspectableWebContentsImpl : gfx::Rect GetDevToolsBounds() const; void SaveDevToolsBounds(const gfx::Rect& bounds); - content::WebContents* devtools_web_contents() { - return devtools_web_contents_.get(); - } - private: // DevToolsEmbedderMessageDispacher::Delegate void ActivateWindow() override; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index bb2e065d337..7fb76539fc0 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -43,8 +43,9 @@ using namespace brightray; if (visible == devtools_visible_) return; - auto webContents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); - auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + auto inspectable_web_contents = inspectableWebContentsView_->inspectable_web_contents(); + auto webContents = inspectable_web_contents->GetWebContents(); + auto devToolsWebContents = inspectable_web_contents->GetDevToolsWebContents(); auto devToolsView = devToolsWebContents->GetNativeView(); if (visible && devtools_docked_) { @@ -92,7 +93,8 @@ using namespace brightray; // Switch to new state. devtools_docked_ = docked; if (!docked) { - auto devToolsWebContents = inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + auto inspectable_web_contents = inspectableWebContentsView_->inspectable_web_contents(); + auto devToolsWebContents = inspectable_web_contents->GetDevToolsWebContents(); auto devToolsView = devToolsWebContents->GetNativeView(); auto styleMask = NSTitledWindowMask | NSClosableWindowMask | @@ -158,7 +160,7 @@ using namespace brightray; - (void)windowDidBecomeMain:(NSNotification*)notification { content::WebContents* web_contents = - inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + inspectableWebContentsView_->inspectable_web_contents()->GetDevToolsWebContents(); if (!web_contents) return; @@ -171,7 +173,7 @@ using namespace brightray; - (void)windowDidResignMain:(NSNotification*)notification { content::WebContents* web_contents = - inspectableWebContentsView_->inspectable_web_contents()->devtools_web_contents(); + inspectableWebContentsView_->inspectable_web_contents()->GetDevToolsWebContents(); if (!web_contents) return; diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 05344daf550..b6079fb9ef6 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -104,12 +104,14 @@ void InspectableWebContentsViewViews::ShowDevTools() { devtools_visible_ = true; if (devtools_window_) { - devtools_window_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents()); + devtools_window_web_view_->SetWebContents( + inspectable_web_contents_->GetDevToolsWebContents()); devtools_window_->SetBounds(inspectable_web_contents()->GetDevToolsBounds()); devtools_window_->Show(); } else { devtools_web_view_->SetVisible(true); - devtools_web_view_->SetWebContents(inspectable_web_contents_->devtools_web_contents()); + devtools_web_view_->SetWebContents( + inspectable_web_contents_->GetDevToolsWebContents()); devtools_web_view_->RequestFocus(); Layout(); } From 51bb3574055653ec43d0970c81729a7bcdb8212d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Jun 2015 16:57:17 +0800 Subject: [PATCH 0578/1195] Add DevToolsOpened and DevToolsClosed events --- brightray/browser/inspectable_web_contents_delegate.h | 2 ++ brightray/browser/inspectable_web_contents_impl.cc | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index 531b96e1755..b193bd459dd 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -23,6 +23,8 @@ class InspectableWebContentsDelegate { virtual void DevToolsAddFileSystem() {} virtual void DevToolsRemoveFileSystem( const std::string& file_system_path) {} + virtual void DevToolsOpened() {} + virtual void DevToolsClosed() {} #if defined(USE_X11) // Called when creating devtools window. diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 832768a8967..e383bc545c0 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -301,6 +301,9 @@ void InspectableWebContentsImpl::LoadCompleted() { // If the devtools can dock, "SetIsDocked" will be called by devtools itself. if (!can_dock_) SetIsDocked(DispatchCallback(), false); + + if (delegate_) + delegate_->DevToolsOpened(); } void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { @@ -506,6 +509,9 @@ void InspectableWebContentsImpl::WebContentsDestroyed() { for (const auto& pair : pending_requests_) delete pair.first; + + if (delegate_) + delegate_->DevToolsClosed(); } bool InspectableWebContentsImpl::AddMessageToConsole( From ee6b14d1d84f76d31e8e6e44b1bf994ee655cbf5 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Fri, 5 Jun 2015 20:24:38 +0530 Subject: [PATCH 0579/1195] adding support for kLogNetLog switch --- brightray/browser/net_log.cc | 66 +++++++++++++++++++ brightray/browser/net_log.h | 36 ++++++++++ .../browser/url_request_context_getter.cc | 5 +- brightray/filenames.gypi | 2 + 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 brightray/browser/net_log.cc create mode 100644 brightray/browser/net_log.h diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc new file mode 100644 index 00000000000..4090b9c1080 --- /dev/null +++ b/brightray/browser/net_log.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#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 "content/public/common/content_switches.h" +#include "net/log/net_log_util.h" +#include "net/url_request/url_request_context.h" + +namespace brightray { + +NetLog::NetLog(net::URLRequestContext* context) + : added_events_(false), + context_(context) { + auto command_line = base::CommandLine::ForCurrentProcess(); + + if (command_line->HasSwitch(switches::kLogNetLog)) { + 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"; + + fprintf(log_file_.get(), "{\"events\": [\n"); + + if (context_.get()) { + DCHECK(context_->CalledOnValidThread()); + + std::set contexts; + contexts.insert(context_.get()); + + net::CreateNetLogEntriesForActiveObjects(contexts, this); + } + + DeprecatedAddObserver(this, net::NetLog::LogLevel::LOG_STRIP_PRIVATE_DATA); + } +} + +NetLog::~NetLog() { + DeprecatedRemoveObserver(this); + fprintf(log_file_.get(), "]}"); + log_file_.reset(); +} + +void NetLog::OnAddEntry(const net::NetLog::Entry& entry) { + std::string json; + base::JSONWriter::Write(entry.ToValue(), &json); + + fprintf(log_file_.get(), "%s%s", (added_events_ ? ",\n" : ""), json.c_str()); + added_events_ = true; +} + +} // namespace brightray diff --git a/brightray/browser/net_log.h b/brightray/browser/net_log.h new file mode 100644 index 00000000000..37a992a2f16 --- /dev/null +++ b/brightray/browser/net_log.h @@ -0,0 +1,36 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#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; +} + +namespace brightray { + +class NetLog : public net::NetLog, + public net::NetLog::ThreadSafeObserver { + public: + explicit NetLog(net::URLRequestContext* context); + virtual ~NetLog(); + + void OnAddEntry(const net::NetLog::Entry& entry) override; + + private: + bool added_events_; + scoped_ptr context_; + base::ScopedFILE log_file_; + + DISALLOW_COPY_AND_ASSIGN(NetLog); +}; + +} // namespace brightray + +#endif // BROWSER_NET_LOG_H_ diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 03a3fa156f7..0fda6500150 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -6,6 +6,7 @@ #include +#include "browser/net_log.h" #include "browser/network_delegate.h" #include "base/command_line.h" @@ -146,6 +147,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { auto& command_line = *base::CommandLine::ForCurrentProcess(); if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext); + url_request_context_->set_net_log(new NetLog(url_request_context_.get())); network_delegate_.reset(delegate_->CreateNetworkDelegate()); url_request_context_->set_network_delegate(network_delegate_.get()); @@ -161,7 +163,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_http_user_agent_settings(new net::StaticHttpUserAgentSettings( "en-us,en", base::EmptyString())); - scoped_ptr host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); + scoped_ptr host_resolver(net::HostResolver::CreateDefaultResolver(nullptr)); // --host-resolver-rules if (command_line.HasSwitch(switches::kHostResolverRules)) { @@ -226,6 +228,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { url_request_context_->channel_id_service(); network_session_params.http_auth_handler_factory = url_request_context_->http_auth_handler_factory(); + network_session_params.net_log = url_request_context_->net_log(); // --ignore-certificate-errors if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index e1a152521bd..fda1bb8d1ef 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -37,6 +37,8 @@ 'browser/media/media_capture_devices_dispatcher.h', 'browser/media/media_stream_devices_controller.cc', 'browser/media/media_stream_devices_controller.h', + 'browser/net_log.cc', + 'browser/net_log.h', 'browser/network_delegate.cc', 'browser/network_delegate.h', 'browser/notification_presenter.h', From 10223577008510eececdc30b6b9f8f025a7b5c36 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sat, 6 Jun 2015 00:13:10 +0530 Subject: [PATCH 0580/1195] adding netconstants to log --- brightray/browser/net_log.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index 4090b9c1080..d0aa4abd216 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -34,7 +34,11 @@ NetLog::NetLog(net::URLRequestContext* context) LOG(ERROR) << "Could not open file: " << log_path.value() << "for net logging"; - fprintf(log_file_.get(), "{\"events\": [\n"); + std::string json; + scoped_ptr constants = net::GetNetConstants(); + base::JSONWriter::Write(constants.release(), &json); + fprintf(log_file_.get(), "{\"constants\": %s, \n", json.c_str()); + fprintf(log_file_.get(), "\"events\": [\n"); if (context_.get()) { DCHECK(context_->CalledOnValidThread()); From 33f65ba98152c9ec8366f4a324f5f2f740de068f Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sat, 6 Jun 2015 14:33:07 +0530 Subject: [PATCH 0581/1195] fix crash on quit --- brightray/browser/net_log.cc | 28 ++++++++++++++++--- brightray/browser/net_log.h | 5 ++-- .../browser/url_request_context_getter.cc | 4 ++- .../browser/url_request_context_getter.h | 2 ++ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index d0aa4abd216..e4be6c70035 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -13,6 +13,25 @@ #include "net/log/net_log_util.h" #include "net/url_request/url_request_context.h" +namespace { + +base::Value* GetConstants() { + scoped_ptr constants = net::GetNetConstants(); + + // Adding client information to constants dictionary. + base::DictionaryValue* client_info = new base::DictionaryValue(); + + client_info->SetString("name", "Electron"); + client_info->SetString("command_line", + base::CommandLine::ForCurrentProcess()->GetCommandLineString()); + + constants->Set("clientInfo", client_info); + + return constants.release(); +} + +} // namespace + namespace brightray { NetLog::NetLog(net::URLRequestContext* context) @@ -35,16 +54,15 @@ NetLog::NetLog(net::URLRequestContext* context) << "for net logging"; std::string json; - scoped_ptr constants = net::GetNetConstants(); - base::JSONWriter::Write(constants.release(), &json); + base::JSONWriter::Write(GetConstants(), &json); fprintf(log_file_.get(), "{\"constants\": %s, \n", json.c_str()); fprintf(log_file_.get(), "\"events\": [\n"); - if (context_.get()) { + if (context_) { DCHECK(context_->CalledOnValidThread()); std::set contexts; - contexts.insert(context_.get()); + contexts.insert(context_); net::CreateNetLogEntriesForActiveObjects(contexts, this); } @@ -55,6 +73,8 @@ NetLog::NetLog(net::URLRequestContext* context) NetLog::~NetLog() { DeprecatedRemoveObserver(this); + + // Ending events array. fprintf(log_file_.get(), "]}"); log_file_.reset(); } diff --git a/brightray/browser/net_log.h b/brightray/browser/net_log.h index 37a992a2f16..4aade754f35 100644 --- a/brightray/browser/net_log.h +++ b/brightray/browser/net_log.h @@ -19,13 +19,14 @@ class NetLog : public net::NetLog, public net::NetLog::ThreadSafeObserver { public: explicit NetLog(net::URLRequestContext* context); - virtual ~NetLog(); + ~NetLog() override; void OnAddEntry(const net::NetLog::Entry& entry) override; private: bool added_events_; - scoped_ptr context_; + // We use raw pointer to prevent reference cycle. + net::URLRequestContext* const context_; base::ScopedFILE log_file_; DISALLOW_COPY_AND_ASSIGN(NetLog); diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 0fda6500150..0ab19af5217 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -22,6 +22,7 @@ #include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_server_properties_impl.h" +#include "net/log/net_log.h" #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" #include "net/proxy/proxy_config_service.h" #include "net/proxy/proxy_script_fetcher_impl.h" @@ -147,7 +148,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { auto& command_line = *base::CommandLine::ForCurrentProcess(); if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext); - url_request_context_->set_net_log(new NetLog(url_request_context_.get())); + net_log_.reset(new NetLog(url_request_context_.get())); + url_request_context_->set_net_log(net_log_.get()); 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 d1f847fc968..45906bbb720 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -17,6 +17,7 @@ class MessageLoop; } namespace net { +class NetLog; class HostMappingRules; class HostResolver; class NetworkDelegate; @@ -65,6 +66,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { 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_; From 15255944b634c32127992af2bb445d9f6ae41c7e Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 8 Jun 2015 19:19:44 +0530 Subject: [PATCH 0582/1195] create net log instance only when needed --- brightray/browser/net_log.cc | 25 ++++++++----------- .../browser/url_request_context_getter.cc | 9 +++++-- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index e4be6c70035..7861a96ecf0 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -21,7 +21,6 @@ base::Value* GetConstants() { // Adding client information to constants dictionary. base::DictionaryValue* client_info = new base::DictionaryValue(); - client_info->SetString("name", "Electron"); client_info->SetString("command_line", base::CommandLine::ForCurrentProcess()->GetCommandLineString()); @@ -38,21 +37,19 @@ NetLog::NetLog(net::URLRequestContext* context) : added_events_(false), context_(context) { auto command_line = base::CommandLine::ForCurrentProcess(); + base::FilePath log_path = + command_line->GetSwitchValuePath(switches::kLogNetLog); - if (command_line->HasSwitch(switches::kLogNetLog)) { - 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"; + #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; base::JSONWriter::Write(GetConstants(), &json); fprintf(log_file_.get(), "{\"constants\": %s, \n", json.c_str()); diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 0ab19af5217..256ec4005d1 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -148,8 +148,13 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { auto& command_line = *base::CommandLine::ForCurrentProcess(); if (!url_request_context_.get()) { url_request_context_.reset(new net::URLRequestContext); - net_log_.reset(new NetLog(url_request_context_.get())); - url_request_context_->set_net_log(net_log_.get()); + + // --log-net-log + if (command_line.HasSwitch(switches::kLogNetLog)) { + net_log_.reset(new NetLog(url_request_context_.get())); + url_request_context_->set_net_log(net_log_.get()); + } + network_delegate_.reset(delegate_->CreateNetworkDelegate()); url_request_context_->set_network_delegate(network_delegate_.get()); From 2ba119f3958cdf61fc8774121c530f922dd9daeb Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 8 Jun 2015 19:56:48 +0530 Subject: [PATCH 0583/1195] fix memory leak --- brightray/browser/net_log.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index 7861a96ecf0..6959ffbbe64 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -51,7 +51,8 @@ NetLog::NetLog(net::URLRequestContext* context) << "for net logging"; } else { std::string json; - base::JSONWriter::Write(GetConstants(), &json); + scoped_ptr constants(GetConstants()); + base::JSONWriter::Write(constants.get(), &json); fprintf(log_file_.get(), "{\"constants\": %s, \n", json.c_str()); fprintf(log_file_.get(), "\"events\": [\n"); From 8adb65fa29e4619b4e8e87064e6d3e0cc09684b4 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 8 Jun 2015 20:31:07 +0530 Subject: [PATCH 0584/1195] fix dereferencing null pointer --- brightray/browser/inspectable_web_contents_impl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index e383bc545c0..c30c6f1becb 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -248,7 +248,8 @@ void InspectableWebContentsImpl::AttachTo(const scoped_refptrDetachClient(); + if (agent_host_.get()) + agent_host_->DetachClient(); agent_host_ = nullptr; } From b2eb23aa019b4713ae5cf453a570060ccb68a411 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Jun 2015 09:51:38 +0800 Subject: [PATCH 0585/1195] Clean up code --- brightray/browser/net_log.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index 6959ffbbe64..f8c54342dfb 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -15,18 +15,17 @@ namespace { -base::Value* GetConstants() { +scoped_ptr GetConstants() { scoped_ptr constants = net::GetNetConstants(); // Adding client information to constants dictionary. base::DictionaryValue* client_info = new base::DictionaryValue(); - - client_info->SetString("command_line", + client_info->SetString( + "command_line", base::CommandLine::ForCurrentProcess()->GetCommandLineString()); constants->Set("clientInfo", client_info); - - return constants.release(); + return constants; } } // namespace @@ -51,7 +50,7 @@ NetLog::NetLog(net::URLRequestContext* context) << "for net logging"; } else { std::string json; - scoped_ptr constants(GetConstants()); + 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"); From 64c4a3450762c9986c1604f62f52f92cf2b29ed7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Jun 2015 10:41:25 +0800 Subject: [PATCH 0586/1195] Make devtools_web_contents_ is destroyed before everything The WebContentsDestroyed still access the other members, so if they are destroyed before the devtools_web_contents_ in the destructor, we will crash there. --- brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- brightray/browser/inspectable_web_contents_impl.h | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c30c6f1becb..f196efa0248 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -159,10 +159,10 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { InspectableWebContentsImpl::InspectableWebContentsImpl( content::WebContents* web_contents) - : web_contents_(web_contents), - frontend_loaded_(false), + : frontend_loaded_(false), can_dock_(true), delegate_(nullptr), + web_contents_(web_contents), weak_factory_(this) { auto context = static_cast(web_contents_->GetBrowserContext()); auto bounds_dict = context->prefs()->GetDictionary(kDevToolsBoundsPref); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index d9af6cf1230..5df435b15e7 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -147,10 +147,6 @@ class InspectableWebContentsImpl : void SendMessageAck(int request_id, const base::Value* arg1); - scoped_ptr web_contents_; - scoped_ptr devtools_web_contents_; - scoped_ptr view_; - bool frontend_loaded_; scoped_refptr agent_host_; scoped_ptr frontend_host_; @@ -160,10 +156,14 @@ class InspectableWebContentsImpl : gfx::Rect devtools_bounds_; bool can_dock_; - InspectableWebContentsDelegate* delegate_; // weak references. - using PendingRequestsMap = std::map; PendingRequestsMap pending_requests_; + InspectableWebContentsDelegate* delegate_; // weak references. + + scoped_ptr view_; + scoped_ptr web_contents_; + scoped_ptr devtools_web_contents_; + base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsImpl); From 5e943e1456fd01e7348610233e16793a703df7db Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 Jun 2015 11:09:16 +0800 Subject: [PATCH 0587/1195] view_ needs to be destroyed after web_contents_ --- brightray/browser/inspectable_web_contents_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 5df435b15e7..6a28346040a 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -160,9 +160,9 @@ class InspectableWebContentsImpl : PendingRequestsMap pending_requests_; InspectableWebContentsDelegate* delegate_; // weak references. - scoped_ptr view_; scoped_ptr web_contents_; scoped_ptr devtools_web_contents_; + scoped_ptr view_; base::WeakPtrFactory weak_factory_; From 3ac3a2f115b432cc7334e229c045d1e809c3454b Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 8 Jun 2015 21:37:48 +0530 Subject: [PATCH 0588/1195] intiailse platform clientcertstore --- brightray/brightray.gypi | 1 + brightray/browser/browser_context.cc | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 47be6215dc3..97f4f4a3a2f 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -149,6 +149,7 @@ '_LARGEFILE_SOURCE', '_LARGEFILE64_SOURCE', '_FILE_OFFSET_BITS=64', + 'USE_OPENSSL', ], 'cflags_cc': [ '-D__STRICT_ANSI__', diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 3e0e271164b..40f187b6404 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -19,6 +19,15 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" +#include "net/ssl/client_cert_store.h" + +#if defined(USE_NSS_CERTS) +#include "net/ssl/client_cert_store_nss.h" +#elif defined(OS_WIN) +#include "net/ssl/client_cert_store_win.h" +#elif defined(OS_MACOSX) +#include "net/ssl/client_cert_store_mac.h" +#endif using content::BrowserThread; @@ -41,6 +50,19 @@ class BrowserContext::ResourceContext : public content::ResourceContext { return getter_->GetURLRequestContext(); } + scoped_ptr CreateClientCertStore() override { + #if defined(USE_NSS_CERTS) + return scoped_ptr(new net::ClientCertStoreNSS( + net::ClientCertStoreNSS::PasswordDelegateFactory())); + #elif defined(OS_WIN) + return scoped_ptr(new net:ClientCertStoreWin()); + #elif defined(OS_MACOSX) + return scoped_ptr(new net::ClientCertStoreMac()); + #elif defined(USE_OPENSSL) + return scoped_ptr(); + #endif + } + URLRequestContextGetter* getter_; }; From 9868d46d630625f92c0ece066e5d84b20ecdbb0e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 10 Jun 2015 19:15:45 +0800 Subject: [PATCH 0589/1195] OpenSSL is actually used by all platforms --- brightray/brightray.gypi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 97f4f4a3a2f..0f6c15f81b9 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -121,6 +121,8 @@ 'defines': [ # We are using Release version libchromiumcontent: 'NDEBUG', + # We are using OpenSSL on all platforms: + 'USE_OPENSSL', # Needed by gin: 'V8_USE_EXTERNAL_STARTUP_DATA', # From skia_for_chromium_defines.gypi: @@ -149,7 +151,6 @@ '_LARGEFILE_SOURCE', '_LARGEFILE64_SOURCE', '_FILE_OFFSET_BITS=64', - 'USE_OPENSSL', ], 'cflags_cc': [ '-D__STRICT_ANSI__', From 3cea64b0f60df3ca4cc0c00f36f9ca88ec1e0dd3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 10 Jun 2015 19:30:35 +0800 Subject: [PATCH 0590/1195] Fix typo --- brightray/browser/browser_context.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 40f187b6404..1c61e286b1b 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -55,7 +55,7 @@ class BrowserContext::ResourceContext : public content::ResourceContext { return scoped_ptr(new net::ClientCertStoreNSS( net::ClientCertStoreNSS::PasswordDelegateFactory())); #elif defined(OS_WIN) - return scoped_ptr(new net:ClientCertStoreWin()); + return scoped_ptr(new net::ClientCertStoreWin()); #elif defined(OS_MACOSX) return scoped_ptr(new net::ClientCertStoreMac()); #elif defined(USE_OPENSSL) From 27fbdf3cf2f57f6c991f57a48828a1407b350998 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 11 Jun 2015 23:18:47 +0530 Subject: [PATCH 0591/1195] define openssl_certs on linux --- brightray/brightray.gypi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 0f6c15f81b9..a14cc134319 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -151,6 +151,8 @@ '_LARGEFILE_SOURCE', '_LARGEFILE64_SOURCE', '_FILE_OFFSET_BITS=64', + # Relying on openssl cert store until crbug.com/462040 + 'USE_OPENSSL_CERTS', ], 'cflags_cc': [ '-D__STRICT_ANSI__', From ca021d030f81ffef979125ecc6657458c9ee2537 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 16 Jun 2015 16:03:43 +0800 Subject: [PATCH 0592/1195] Add --ignore-connections-limit switch --- brightray/browser/network_delegate.cc | 28 +++++++++++++++++++++++++++ brightray/browser/network_delegate.h | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index 9d586d72cf5..373b5819a71 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -4,11 +4,30 @@ #include "browser/network_delegate.h" +#include +#include + +#include "base/command_line.h" +#include "base/strings/string_split.h" +#include "net/base/load_flags.h" #include "net/base/net_errors.h" +#include "net/url_request/url_request.h" namespace brightray { +namespace { + +// Ignore the limit of 6 connections per host. +const char kIgnoreConnectionsLimit[] = "ignore-connections-limit"; + +} // namespace + NetworkDelegate::NetworkDelegate() { + auto command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(kIgnoreConnectionsLimit)) { + std::string value = command_line->GetSwitchValueASCII(kIgnoreConnectionsLimit); + base::SplitString(value, ',', &ignore_connections_limit_domains_); + } } NetworkDelegate::~NetworkDelegate() { @@ -18,6 +37,15 @@ int NetworkDelegate::OnBeforeURLRequest( net::URLRequest* request, const net::CompletionCallback& callback, GURL* new_url) { + for (const auto& domain : ignore_connections_limit_domains_) { + if (request->url().DomainIs(domain.c_str(), domain.size())) { + // Allow unlimited concurrent connections. + request->SetPriority(net::MAXIMUM_PRIORITY); + request->SetLoadFlags(request->load_flags() | net::LOAD_IGNORE_LIMITS); + break; + } + } + return net::OK; } diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 55835622ac2..642b0b4cac5 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -5,6 +5,9 @@ #ifndef BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_ #define BRIGHTRAY_BROWSER_NETWORK_DELEGATE_H_ +#include +#include + #include "net/base/network_delegate.h" namespace brightray { @@ -69,6 +72,8 @@ class NetworkDelegate : public net::NetworkDelegate { const GURL& referrer_url) const override; private: + std::vector ignore_connections_limit_domains_; + DISALLOW_COPY_AND_ASSIGN(NetworkDelegate); }; From 0e98519d3b4a313160ee990ad5a2fcd074e6456e Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Tue, 16 Jun 2015 17:59:58 -0700 Subject: [PATCH 0593/1195] Set contentImage based on the passed-in image --- brightray/browser/notification_presenter_mac.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 3b0c736daa3..198c8350874 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -7,9 +7,11 @@ #include "base/bind.h" #include "base/stl_util.h" +#include "base/mac/mac_util.h" #include "base/strings/sys_string_conversions.h" #include "content/public/common/platform_notification_data.h" #include "content/public/browser/desktop_notification_delegate.h" +#include "skia/ext/skia_utils_mac.h" #import @@ -47,6 +49,7 @@ void NotificationPresenterMac::ShowNotification( auto notification = [[NSUserNotification alloc] init]; notification.title = base::SysUTF16ToNSString(data.title); notification.informativeText = base::SysUTF16ToNSString(data.body); + notification.contentImage = gfx::SkBitmapToNSImageWithColorSpace(icon, base::mac::GetGenericRGBColorSpace()); notifications_map_[delegate.get()].reset(notification); [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; From c3de789fd78a751bbcdd4e76d4d947c6033db7ce Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 17 Jun 2015 13:01:48 -0700 Subject: [PATCH 0594/1195] Ensure we don't try to set contentImage on 10.7/10.8. That would be rude! --- brightray/browser/notification_presenter_mac.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 198c8350874..02e2cb4f916 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/stl_util.h" #include "base/mac/mac_util.h" +#include "base/mac/sdk_forward_declarations.h" #include "base/strings/sys_string_conversions.h" #include "content/public/common/platform_notification_data.h" #include "content/public/browser/desktop_notification_delegate.h" @@ -49,7 +50,9 @@ void NotificationPresenterMac::ShowNotification( auto notification = [[NSUserNotification alloc] init]; notification.title = base::SysUTF16ToNSString(data.title); notification.informativeText = base::SysUTF16ToNSString(data.body); - notification.contentImage = gfx::SkBitmapToNSImageWithColorSpace(icon, base::mac::GetGenericRGBColorSpace()); + + if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_9) + notification.contentImage = gfx::SkBitmapToNSImageWithColorSpace(icon, base::mac::GetGenericRGBColorSpace()); notifications_map_[delegate.get()].reset(notification); [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; From 9fb30b702a7f72b7553f6252c4d5364bd1eeeaed Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 18 Jun 2015 12:41:36 +0800 Subject: [PATCH 0595/1195] Check if image is empty. --- brightray/browser/notification_presenter_mac.mm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 02e2cb4f916..60abc6af76d 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -8,7 +8,6 @@ #include "base/bind.h" #include "base/stl_util.h" #include "base/mac/mac_util.h" -#include "base/mac/sdk_forward_declarations.h" #include "base/strings/sys_string_conversions.h" #include "content/public/common/platform_notification_data.h" #include "content/public/browser/desktop_notification_delegate.h" @@ -51,7 +50,7 @@ void NotificationPresenterMac::ShowNotification( notification.title = base::SysUTF16ToNSString(data.title); notification.informativeText = base::SysUTF16ToNSString(data.body); - if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_9) + if (base::mac::IsOSYosemiteOrLater() && !icon.drawsNothing()) notification.contentImage = gfx::SkBitmapToNSImageWithColorSpace(icon, base::mac::GetGenericRGBColorSpace()); notifications_map_[delegate.get()].reset(notification); From f9dc87ba973acc9e665f597706fc3ee61b1033c3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 25 Jun 2015 12:29:34 +0800 Subject: [PATCH 0596/1195] Add InspectableWebContentsViewDelegate --- .../inspectable_web_contents_delegate.cc | 9 ------ .../inspectable_web_contents_delegate.h | 14 ---------- .../browser/inspectable_web_contents_impl.cc | 11 ++------ .../browser/inspectable_web_contents_view.h | 14 ++++++++++ .../inspectable_web_contents_view_delegate.cc | 10 +++++++ .../inspectable_web_contents_view_delegate.h | 28 +++++++++++++++++++ .../inspectable_web_contents_view_mac.mm | 5 ++++ .../inspectable_web_contents_view_views.cc | 15 ++++++---- brightray/filenames.gypi | 3 +- 9 files changed, 71 insertions(+), 38 deletions(-) delete mode 100644 brightray/browser/inspectable_web_contents_delegate.cc create mode 100644 brightray/browser/inspectable_web_contents_view_delegate.cc create mode 100644 brightray/browser/inspectable_web_contents_view_delegate.h diff --git a/brightray/browser/inspectable_web_contents_delegate.cc b/brightray/browser/inspectable_web_contents_delegate.cc deleted file mode 100644 index 81d395b5db3..00000000000 --- a/brightray/browser/inspectable_web_contents_delegate.cc +++ /dev/null @@ -1,9 +0,0 @@ -#include "browser/inspectable_web_contents_delegate.h" - -namespace brightray { - -gfx::ImageSkia InspectableWebContentsDelegate::GetDevToolsWindowIcon() { - return gfx::ImageSkia(); -} - -} // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index b193bd459dd..606bfa9a4ea 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -3,34 +3,20 @@ #include -#include "ui/gfx/image/image_skia.h" - namespace brightray { class InspectableWebContentsDelegate { public: virtual ~InspectableWebContentsDelegate() {} - // Returns the icon of devtools window. - virtual gfx::ImageSkia GetDevToolsWindowIcon(); - // Requested by WebContents of devtools. virtual void DevToolsSaveToFile( const std::string& url, const std::string& content, bool save_as) {} virtual void DevToolsAppendToFile( const std::string& url, const std::string& content) {} - virtual void DevToolsFocused() {} virtual void DevToolsAddFileSystem() {} virtual void DevToolsRemoveFileSystem( const std::string& file_system_path) {} - virtual void DevToolsOpened() {} - virtual void DevToolsClosed() {} - -#if defined(USE_X11) - // Called when creating devtools window. - virtual void GetDevToolsWindowWMClass( - std::string* name, std::string* class_name) {} -#endif }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index f196efa0248..fa62d3d202a 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -10,6 +10,7 @@ #include "browser/browser_main_parts.h" #include "browser/inspectable_web_contents_delegate.h" #include "browser/inspectable_web_contents_view.h" +#include "browser/inspectable_web_contents_view_delegate.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" @@ -302,9 +303,6 @@ void InspectableWebContentsImpl::LoadCompleted() { // If the devtools can dock, "SetIsDocked" will be called by devtools itself. if (!can_dock_) SetIsDocked(DispatchCallback(), false); - - if (delegate_) - delegate_->DevToolsOpened(); } void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { @@ -510,9 +508,6 @@ void InspectableWebContentsImpl::WebContentsDestroyed() { for (const auto& pair : pending_requests_) delete pair.first; - - if (delegate_) - delegate_->DevToolsClosed(); } bool InspectableWebContentsImpl::AddMessageToConsole( @@ -552,8 +547,8 @@ void InspectableWebContentsImpl::CloseContents(content::WebContents* source) { void InspectableWebContentsImpl::WebContentsFocused( content::WebContents* contents) { - if (delegate_) - delegate_->DevToolsFocused(); + if (view_->GetDelegate()) + view_->GetDelegate()->DevToolsFocused(); } void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) { diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 1675ec73688..31c30e1f328 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -13,10 +13,21 @@ class View; namespace brightray { +class InspectableWebContentsViewDelegate; + class InspectableWebContentsView { public: + InspectableWebContentsView() : delegate_(nullptr) {} virtual ~InspectableWebContentsView() {} + // The delegate manages its own life. + void SetDelegate(InspectableWebContentsViewDelegate* delegate) { + delegate_ = delegate; + } + InspectableWebContentsViewDelegate* GetDelegate() const { + return delegate_; + } + #if defined(TOOLKIT_VIEWS) // Returns the container control, which has devtools view attached. virtual views::View* GetView() = 0; @@ -35,6 +46,9 @@ class InspectableWebContentsView { virtual void SetIsDocked(bool docked) = 0; virtual void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) = 0; + + private: + InspectableWebContentsViewDelegate* delegate_; // weak references. }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_view_delegate.cc b/brightray/browser/inspectable_web_contents_view_delegate.cc new file mode 100644 index 00000000000..5906499da8c --- /dev/null +++ b/brightray/browser/inspectable_web_contents_view_delegate.cc @@ -0,0 +1,10 @@ +#include "browser/inspectable_web_contents_view_delegate.h" + +namespace brightray { + +gfx::ImageSkia InspectableWebContentsViewDelegate::GetDevToolsWindowIcon() { + return gfx::ImageSkia(); +} + +} // namespace brightray + diff --git a/brightray/browser/inspectable_web_contents_view_delegate.h b/brightray/browser/inspectable_web_contents_view_delegate.h new file mode 100644 index 00000000000..900857c7a10 --- /dev/null +++ b/brightray/browser/inspectable_web_contents_view_delegate.h @@ -0,0 +1,28 @@ +#ifndef BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_DELEGATE_H_ +#define BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_DELEGATE_H_ + +#include "ui/gfx/image/image_skia.h" + +namespace brightray { + +class InspectableWebContentsViewDelegate { + public: + virtual ~InspectableWebContentsViewDelegate() {} + + virtual void DevToolsFocused() {} + virtual void DevToolsOpened() {} + virtual void DevToolsClosed() {} + + // Returns the icon of devtools window. + virtual gfx::ImageSkia GetDevToolsWindowIcon(); + +#if defined(USE_X11) + // Called when creating devtools window. + virtual void GetDevToolsWindowWMClass( + std::string* name, std::string* class_name) {} +#endif +}; + +} // namespace brightray + +#endif // BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_DELEGATE_H_ diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index aeca189b796..6cd08da2f6a 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -3,6 +3,7 @@ #import #include "browser/inspectable_web_contents.h" +#include "browser/inspectable_web_contents_view_delegate.h" #import "browser/mac/bry_inspectable_web_contents_view.h" namespace brightray { @@ -26,10 +27,14 @@ gfx::NativeView InspectableWebContentsViewMac::GetNativeView() const { void InspectableWebContentsViewMac::ShowDevTools() { [view_ setDevToolsVisible:YES]; + if (GetDelegate()) + GetDelegate()->DevToolsOpened(); } void InspectableWebContentsViewMac::CloseDevTools() { [view_ setDevToolsVisible:NO]; + if (GetDelegate()) + GetDelegate()->DevToolsClosed(); } bool InspectableWebContentsViewMac::IsDevToolsViewShowing() { diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index b6079fb9ef6..52528efba7f 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -2,6 +2,7 @@ #include "browser/inspectable_web_contents_delegate.h" #include "browser/inspectable_web_contents_impl.h" +#include "browser/inspectable_web_contents_view_delegate.h" #include "base/strings/utf_string_conversions.h" #include "ui/views/controls/webview/webview.h" @@ -27,9 +28,8 @@ class DevToolsWindowDelegate : public views::ClientView, // A WidgetDelegate should be deleted on DeleteDelegate. set_owned_by_client(); - InspectableWebContentsDelegate* delegate = shell->inspectable_web_contents()->GetDelegate(); - if (delegate) - icon_ = delegate->GetDevToolsWindowIcon(); + if (shell->GetDelegate()) + icon_ = shell->GetDelegate()->GetDevToolsWindowIcon(); } virtual ~DevToolsWindowDelegate() {} @@ -115,6 +115,8 @@ void InspectableWebContentsViewViews::ShowDevTools() { devtools_web_view_->RequestFocus(); Layout(); } + if (GetDelegate()) + GetDelegate()->DevToolsOpened(); } void InspectableWebContentsViewViews::CloseDevTools() { @@ -131,6 +133,8 @@ void InspectableWebContentsViewViews::CloseDevTools() { devtools_web_view_->SetWebContents(NULL); Layout(); } + if (GetDelegate()) + GetDelegate()->DevToolsClosed(); } bool InspectableWebContentsViewViews::IsDevToolsViewShowing() { @@ -153,9 +157,8 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { #if defined(USE_X11) params.wm_role_name = "devtools"; - InspectableWebContentsDelegate* delegate = inspectable_web_contents()->GetDelegate(); - if (delegate) - delegate->GetDevToolsWindowWMClass(¶ms.wm_class_name, ¶ms.wm_class_class); + if (GetDelegate()) + GetDelegate()->GetDevToolsWindowWMClass(¶ms.wm_class_name, ¶ms.wm_class_class); #endif devtools_window_->Init(params); diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index fda1bb8d1ef..8334e44cd5e 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -22,8 +22,9 @@ 'browser/devtools_ui.h', 'browser/inspectable_web_contents.cc', 'browser/inspectable_web_contents.h', - 'browser/inspectable_web_contents_delegate.cc', 'browser/inspectable_web_contents_delegate.h', + 'browser/inspectable_web_contents_view_delegate.cc', + 'browser/inspectable_web_contents_view_delegate.h', 'browser/inspectable_web_contents_impl.cc', 'browser/inspectable_web_contents_impl.h', 'browser/inspectable_web_contents_view.h', From f477e6ca6aae0fb6f39868487a0d3a0ccf627669 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 26 Jun 2015 10:58:06 +0800 Subject: [PATCH 0597/1195] Don't hide methods of content::BrowserContext --- brightray/browser/browser_context.h | 39 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 5cddd0a494e..0fb42303a32 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -25,6 +25,26 @@ class BrowserContext : public content::BrowserContext, virtual void Initialize(); + // content::BrowserContext: + scoped_ptr CreateZoomLevelDelegate( + const base::FilePath& partition_path) override; + bool IsOffTheRecord() const override; + net::URLRequestContextGetter* GetRequestContext() override; + net::URLRequestContextGetter* GetRequestContextForRenderProcess( + int renderer_child_id); + net::URLRequestContextGetter* GetMediaRequestContext() override; + net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( + int renderer_child_id) override; + net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( + const base::FilePath& partition_path, bool in_memory) override; + content::ResourceContext* GetResourceContext() override; + content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; + content::BrowserPluginGuestManager* GetGuestManager() override; + storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; + content::PushMessagingService* GetPushMessagingService() override; + content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; + content::PermissionManager* GetPermissionManager() override; + net::URLRequestContextGetter* CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors); @@ -49,25 +69,6 @@ class BrowserContext : public content::BrowserContext, void RegisterInternalPrefs(PrefRegistrySimple* pref_registry); - scoped_ptr CreateZoomLevelDelegate( - const base::FilePath& partition_path) override; - bool IsOffTheRecord() const override; - net::URLRequestContextGetter* GetRequestContext() override; - net::URLRequestContextGetter* GetRequestContextForRenderProcess( - int renderer_child_id); - net::URLRequestContextGetter* GetMediaRequestContext() override; - net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( - int renderer_child_id) override; - net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( - const base::FilePath& partition_path, bool in_memory) override; - content::ResourceContext* GetResourceContext() override; - content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; - content::BrowserPluginGuestManager* GetGuestManager() override; - storage::SpecialStoragePolicy* GetSpecialStoragePolicy() override; - content::PushMessagingService* GetPushMessagingService() override; - content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; - content::PermissionManager* GetPermissionManager() override; - base::FilePath path_; scoped_ptr resource_context_; scoped_refptr url_request_getter_; From 899c730ece9ff7f11860126f6502af30d7e8b0be Mon Sep 17 00:00:00 2001 From: Antonin Hildebrand Date: Fri, 26 Jun 2015 11:39:41 +0200 Subject: [PATCH 0598/1195] Missing overrides ninja compilation failed for me under OS X 10.11 --- brightray/browser/browser_context.h | 2 +- brightray/common/content_client.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 0fb42303a32..0a7a4c314ac 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -31,7 +31,7 @@ class BrowserContext : public content::BrowserContext, bool IsOffTheRecord() const override; net::URLRequestContextGetter* GetRequestContext() override; net::URLRequestContextGetter* GetRequestContextForRenderProcess( - int renderer_child_id); + int renderer_child_id) override; net::URLRequestContextGetter* GetMediaRequestContext() override; net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( int renderer_child_id) override; diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index 5d22e55ab9d..f0e4449e251 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -18,7 +18,7 @@ class ContentClient : public content::ContentClient { private: std::string GetProduct() const override; std::string GetUserAgent() const override; - base::string16 GetLocalizedString(int message_id) const; + base::string16 GetLocalizedString(int message_id) const override; base::StringPiece GetDataResource(int resource_id, ui::ScaleFactor) const override; gfx::Image& GetNativeImageNamed(int resource_id) const override; From d440a3c21d25aa9f2a003523a3909bf7fd5bb543 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 1 Jul 2015 14:32:04 +0800 Subject: [PATCH 0599/1195] Do not force using clang --- brightray/brightray.gypi | 40 ---------------------------------------- 1 file changed, 40 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index a14cc134319..ec599c475dd 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -3,9 +3,6 @@ 'vendor/download/libchromiumcontent/filenames.gypi', ], 'variables': { - # Build with clang on Linux and Mac. - 'clang%': 1, - 'libchromiumcontent_src_dir': '<(libchromiumcontent_root_dir)/src', 'libchromiumcontent_component%': 1, 'conditions': [ @@ -326,41 +323,4 @@ }], ], # target_conditions }, # target_defaults - 'conditions': [ - ['clang', { - 'make_global_settings': [ - ['CC', '/usr/bin/clang'], - ['CXX', '/usr/bin/clang++'], - ['LINK', '$(CXX)'], - ['CC.host', '$(CC)'], - ['CXX.host', '$(CXX)'], - ['LINK.host', '$(LINK)'], - ], - 'target_defaults': { - 'cflags_cc': [ - '-std=c++11', - ], - 'xcode_settings': { - 'CC': '/usr/bin/clang', - 'LDPLUSPLUS': '/usr/bin/clang++', - 'OTHER_CFLAGS': [ - '-fcolor-diagnostics', - ], - - 'GCC_C_LANGUAGE_STANDARD': 'c99', # -std=c99 - 'CLANG_CXX_LIBRARY': 'libc++', # -stdlib=libc++ - 'CLANG_CXX_LANGUAGE_STANDARD': 'c++11', # -std=c++11 - }, - 'target_conditions': [ - ['_type in ["executable", "shared_library"]', { - 'xcode_settings': { - # On some machines setting CLANG_CXX_LIBRARY doesn't work for - # linker. - 'OTHER_LDFLAGS': [ '-stdlib=libc++' ], - }, - }], - ], - }, - }], # clang - ], } From 3826e8864a2a5f4bb535d2d775e013756ce1024e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 1 Jul 2015 06:49:43 +0000 Subject: [PATCH 0600/1195] Fix a compiler warning --- brightray/browser/views/inspectable_web_contents_view_views.cc | 2 +- 1 file changed, 1 insertion(+), 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 52528efba7f..8cae49db41e 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -45,7 +45,7 @@ class DevToolsWindowDelegate : public views::ClientView, views::Widget* GetWidget() override { return widget_; } const views::Widget* GetWidget() const override { return widget_; } views::View* GetContentsView() override { return view_; } - views::ClientView* CreateClientView(views::Widget* widget) { return this; } + views::ClientView* CreateClientView(views::Widget* widget) override { return this; } // views::ClientView: bool CanClose() override { From c210c68beea86e8051cec8c381fcdda8be2b2a30 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 1 Jul 2015 07:48:29 +0000 Subject: [PATCH 0601/1195] Remove -std=gnu++11 flag --- brightray/brightray.gypi | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index ec599c475dd..65f93297c23 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -153,7 +153,6 @@ ], 'cflags_cc': [ '-D__STRICT_ANSI__', - '-std=gnu++11', '-fno-rtti', ], }], # OS=="linux" From 36447f661379f98a8c0d51733f4ac73ff1547799 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Jul 2015 10:52:20 +0800 Subject: [PATCH 0602/1195] Use NSS instead of OpenSSL --- brightray/brightray.gypi | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 65f93297c23..cc8469417b6 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -118,8 +118,6 @@ 'defines': [ # We are using Release version libchromiumcontent: 'NDEBUG', - # We are using OpenSSL on all platforms: - 'USE_OPENSSL', # Needed by gin: 'V8_USE_EXTERNAL_STARTUP_DATA', # From skia_for_chromium_defines.gypi: @@ -148,8 +146,8 @@ '_LARGEFILE_SOURCE', '_LARGEFILE64_SOURCE', '_FILE_OFFSET_BITS=64', - # Relying on openssl cert store until crbug.com/462040 - 'USE_OPENSSL_CERTS', + # "use_nss_certs" is set to 1 in libchromiumcontent. + 'USE_NSS_CERTS', ], 'cflags_cc': [ '-D__STRICT_ANSI__', From 31b88f737059e406d57c46d2f6630404e5a89079 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Jul 2015 11:49:49 +0800 Subject: [PATCH 0603/1195] USE_NSS is used before Chrome 45 --- brightray/brightray.gypi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index cc8469417b6..ed4fce523b9 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -148,6 +148,8 @@ '_FILE_OFFSET_BITS=64', # "use_nss_certs" is set to 1 in libchromiumcontent. 'USE_NSS_CERTS', + # USE_NSS is set to be compatible with Chrome < 45. + 'USE_NSS', ], 'cflags_cc': [ '-D__STRICT_ANSI__', From e67d0db4483a6d0e339d293edd83bac17c05fe27 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Jul 2015 12:03:33 +0800 Subject: [PATCH 0604/1195] OpenSSL is still used on Windows and Mac --- brightray/brightray.gypi | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index ed4fce523b9..d03703ba4a3 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -136,9 +136,16 @@ 'USE_AURA', ], }], - ['OS not in ["mac", "win"]', { + ['OS in ["mac", "win"]', { + 'defines': [ + 'USE_OPENSSL', + ], + }, { 'defines': [ 'USE_X11', + # "use_nss_certs" is set to 1 in libchromiumcontent. + 'USE_NSS_CERTS', + 'USE_NSS', # deprecated after Chrome 45. ], }], ['OS=="linux"', { @@ -146,10 +153,6 @@ '_LARGEFILE_SOURCE', '_LARGEFILE64_SOURCE', '_FILE_OFFSET_BITS=64', - # "use_nss_certs" is set to 1 in libchromiumcontent. - 'USE_NSS_CERTS', - # USE_NSS is set to be compatible with Chrome < 45. - 'USE_NSS', ], 'cflags_cc': [ '-D__STRICT_ANSI__', From 08b851dd0f01c8d72413d81c08a6bee04892cd21 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Jul 2015 13:48:31 +0800 Subject: [PATCH 0605/1195] Load cursor from current module --- brightray/browser/browser_main_parts.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 21331707935..807e5022497 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -37,6 +37,7 @@ #endif #if defined(OS_WIN) +#include "ui/base/cursor/cursor_loader_win.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" #include "ui/gfx/platform_font_win.h" @@ -105,6 +106,10 @@ void BrowserMainParts::ToolkitInitialized() { #if defined(OS_WIN) gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; + + wchar_t module_name[MAX_PATH] = { 0 }; + if (GetModuleFileName(NULL, module_name, MAX_PATH)) + ui::CursorLoaderWin::SetCursorResourceModule(module_name); #endif } From 681e868a5b15031eb8a29795b45880cfef3eb8dc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 7 Jul 2015 14:15:27 +0800 Subject: [PATCH 0606/1195] Link with nss --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 7860d4813ad..fce7dfc1ad3 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -1,7 +1,7 @@ { 'variables': { # The libraries brightray will be compiled to. - 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xrandr xext gconf-2.0 gmodule-2.0' + 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xrandr xext gconf-2.0 gmodule-2.0 nss' }, 'includes': [ 'filenames.gypi', From ca09f32548d0146a9a020860e0b56d6fcd708d75 Mon Sep 17 00:00:00 2001 From: Robo Date: Fri, 10 Jul 2015 13:52:02 +0530 Subject: [PATCH 0607/1195] adding support for kProxyPacUrl --- brightray/browser/url_request_context_getter.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 256ec4005d1..15d49fac05e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -72,6 +72,9 @@ const char kNoProxyServer[] = "no-proxy-server"; // affects HTTP and HTTPS requests. const char kProxyServer[] = "proxy-server"; +// Uses the pac script at the given URL. +const char kProxyPacUrl[] = "proxy-pac-url"; + } // namespace net::URLRequestJobFactory* URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( @@ -183,12 +186,18 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { // --proxy-server net::DhcpProxyScriptFetcherFactory dhcp_factory; - if (command_line.HasSwitch(kNoProxyServer)) + if (command_line.HasSwitch(kNoProxyServer)) { storage_->set_proxy_service(net::ProxyService::CreateDirect()); - else if (command_line.HasSwitch(kProxyServer)) + } else if (command_line.HasSwitch(kProxyServer)) { storage_->set_proxy_service(net::ProxyService::CreateFixed( command_line.GetSwitchValueASCII(kProxyServer))); - else + } else if (command_line.HasSwitch(kProxyPacUrl)) { + auto proxy_config = net::ProxyConfig::CreateFromCustomPacURL( + GURL(command_line.GetSwitchValueASCII(kProxyPacUrl))); + proxy_config.set_pac_mandatory(true); + storage_->set_proxy_service(net::ProxyService::CreateFixed( + proxy_config)); + } else { storage_->set_proxy_service( net::CreateProxyServiceUsingV8ProxyResolver( proxy_config_service_.release(), @@ -197,7 +206,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { host_resolver.get(), NULL, url_request_context_->network_delegate())); - + } std::vector schemes; schemes.push_back(std::string("basic")); From 8bb0ea438daace2adc93fabedac3a4fba3e3f622 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 14 Jul 2015 10:04:34 -0700 Subject: [PATCH 0608/1195] Enable override user agent in URLRequestContextGetter --- brightray/browser/url_request_context_getter.cc | 4 ++++ brightray/browser/url_request_context_getter.h | 1 + 2 files changed, 5 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 15d49fac05e..ad134394b7c 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -77,6 +77,10 @@ const char kProxyPacUrl[] = "proxy-pac-url"; } // namespace +std::string URLRequestContextGetter::Delegate::GetUserAgent() { + return base::EmptyString(); +} + net::URLRequestJobFactory* URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector* protocol_interceptors) { diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 45906bbb720..4546ce91062 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -36,6 +36,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual ~Delegate() {} virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; } + virtual std::string GetUserAgent(); virtual net::URLRequestJobFactory* CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector* protocol_interceptors); From 6b1e4cc91a4d337eb62c071daec79cdee1c5a262 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 14 Jul 2015 11:37:57 -0700 Subject: [PATCH 0609/1195] Set user agent from the delegate --- brightray/browser/url_request_context_getter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index ad134394b7c..81cc3268e51 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -175,7 +175,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), base::WorkerPool::GetTaskRunner(true)))); storage_->set_http_user_agent_settings(new net::StaticHttpUserAgentSettings( - "en-us,en", base::EmptyString())); + "en-us,en", delegate_->GetUserAgent())); scoped_ptr host_resolver(net::HostResolver::CreateDefaultResolver(nullptr)); From 7496cb29fee3dfc8c0ab1a256ad78b27bf21a1d2 Mon Sep 17 00:00:00 2001 From: Robo Date: Tue, 14 Jul 2015 23:12:52 +0530 Subject: [PATCH 0610/1195] create netlog for devtoolsnetlogobserver --- brightray/browser/browser_client.cc | 4 ++ brightray/browser/browser_client.h | 1 + brightray/browser/browser_context.cc | 4 ++ brightray/browser/browser_context.h | 1 + brightray/browser/net_log.cc | 58 ++++++++++--------- .../browser/url_request_context_getter.cc | 6 +- .../browser/url_request_context_getter.h | 1 + 7 files changed, 44 insertions(+), 31 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 887ad591d5c..493e896366f 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -80,6 +80,10 @@ void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( additional_schemes->push_back(content::kChromeUIScheme); } +net::NetLog* BrowserClient::GetNetLog() { + return browser_context()->GetNetLog(); +} + base::FilePath BrowserClient::GetDefaultDownloadDirectory() { // ~/Downloads base::FilePath path; diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index cd3c0222310..f9b0f0d0585 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -43,6 +43,7 @@ class BrowserClient : public content::ContentBrowserClient { content::PlatformNotificationService* GetPlatformNotificationService() override; void GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) override; + net::NetLog* GetNetLog() override; base::FilePath GetDefaultDownloadDirectory() override; content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override; diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 1c61e286b1b..ec41caed255 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -114,6 +114,10 @@ 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 0a7a4c314ac..9244ac40c2f 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -48,6 +48,7 @@ class BrowserContext : public content::BrowserContext, net::URLRequestContextGetter* CreateRequestContext( 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/net_log.cc b/brightray/browser/net_log.cc index f8c54342dfb..6a2b9c3d76f 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -36,44 +36,48 @@ NetLog::NetLog(net::URLRequestContext* context) : added_events_(false), context_(context) { auto command_line = base::CommandLine::ForCurrentProcess(); - base::FilePath log_path = - command_line->GetSwitchValuePath(switches::kLogNetLog); + if (command_line->HasSwitch(switches::kLogNetLog)) { + 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 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 (!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()); + if (context_) { + DCHECK(context_->CalledOnValidThread()); - std::set contexts; - contexts.insert(context_); + std::set contexts; + contexts.insert(context_); - net::CreateNetLogEntriesForActiveObjects(contexts, this); + net::CreateNetLogEntriesForActiveObjects(contexts, this); + } + + DeprecatedAddObserver(this, net::NetLog::LogLevel::LOG_STRIP_PRIVATE_DATA); } - - DeprecatedAddObserver(this, net::NetLog::LogLevel::LOG_STRIP_PRIVATE_DATA); } } NetLog::~NetLog() { - DeprecatedRemoveObserver(this); + if (log_file_) { + DeprecatedRemoveObserver(this); - // Ending events array. - fprintf(log_file_.get(), "]}"); - log_file_.reset(); + // Ending events array. + fprintf(log_file_.get(), "]}"); + log_file_.reset(); + } } void NetLog::OnAddEntry(const net::NetLog::Entry& entry) { diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 256ec4005d1..12e4f348fe2 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -150,10 +150,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { url_request_context_.reset(new net::URLRequestContext); // --log-net-log - if (command_line.HasSwitch(switches::kLogNetLog)) { - net_log_.reset(new NetLog(url_request_context_.get())); - url_request_context_->set_net_log(net_log_.get()); - } + net_log_.reset(new NetLog(url_request_context_.get())); + url_request_context_->set_net_log(net_log_.get()); 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 45906bbb720..a901139da12 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -57,6 +57,7 @@ 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_; From 935d1e142f25e848910c2ea2732acb70797409a6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 20 Jul 2015 18:24:24 +0800 Subject: [PATCH 0611/1195] Make bottom corner more round --- .../mac/bry_inspectable_web_contents_view.h | 5 ++ .../mac/bry_inspectable_web_contents_view.mm | 76 ++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 8cf7540b60f..ea6e3f9a811 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -5,6 +5,8 @@ #include "base/mac/scoped_nsobject.h" #include "ui/base/cocoa/base_view.h" +@class CAShapeLayer; + namespace brightray { class InspectableWebContentsViewMac; } @@ -19,6 +21,9 @@ using brightray::InspectableWebContentsViewMac; BOOL devtools_visible_; BOOL devtools_docked_; + // Weak reference to the mask of the hosted layer. + CAShapeLayer* layerMask_; + DevToolsContentsResizingStrategy strategy_; } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 7fb76539fc0..a7f4134b4fa 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -1,14 +1,24 @@ #include "browser/mac/bry_inspectable_web_contents_view.h" +#import + #include "browser/inspectable_web_contents_impl.h" #include "browser/inspectable_web_contents_view_mac.h" #include "content/public/browser/render_widget_host_view.h" -#import "ui/base/cocoa/underlay_opengl_hosting_window.h" +#include "ui/base/cocoa/animation_utils.h" +#include "ui/base/cocoa/underlay_opengl_hosting_window.h" #include "ui/gfx/mac/scoped_ns_disable_screen_updates.h" using namespace brightray; +namespace { + +// The radius of the rounded corners. +const CGFloat kRoundedCornerRadius = 4; + +} // namespace + @implementation BRYInspectableWebContentsView - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view { @@ -26,8 +36,14 @@ using namespace brightray; [self addSubview:contentsView]; // See https://code.google.com/p/chromium/issues/detail?id=348490. + ScopedCAActionDisabler disabler; + base::scoped_nsobject layer([[CALayer alloc] init]); + [self setLayer:layer]; [self setWantsLayer:YES]; + // See https://code.google.com/p/chromium/issues/detail?id=396264. + [self updateLayerMask]; + return self; } @@ -35,6 +51,12 @@ using namespace brightray; [self adjustSubviews]; } +// Every time the frame's size changes, the layer mask needs to be updated. +- (void)setFrameSize:(NSSize)newSize { + [super setFrameSize:newSize]; + [self updateLayerMask]; +} + - (IBAction)showDevTools:(id)sender { inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools(); } @@ -152,6 +174,58 @@ using namespace brightray; [contentsView setFrame:[self flipRectToNSRect:new_contents_bounds]]; } +// Creates a path whose bottom two corners are rounded. +// Caller takes ownership of the path. +- (CGPathRef)createRoundedBottomCornersPath:(NSSize)size { + CGMutablePathRef path = CGPathCreateMutable(); + CGFloat width = size.width; + CGFloat height = size.height; + CGFloat cornerRadius = kRoundedCornerRadius; + + // Top left corner. + CGPathMoveToPoint(path, NULL, 0, height); + + // Top right corner. + CGPathAddLineToPoint(path, NULL, width, height); + + // Bottom right corner. + CGPathAddArc(path, + NULL, + width - cornerRadius, + cornerRadius, + cornerRadius, + 0, + -M_PI_2, + true); + + // Bottom left corner. + CGPathAddArc(path, + NULL, + cornerRadius, + cornerRadius, + cornerRadius, + -M_PI_2, + -M_PI, + true); + + // Draw line back to top-left corner. + CGPathAddLineToPoint(path, NULL, 0, height); + CGPathCloseSubpath(path); + return path; +} + +// Updates the path of the layer mask to have make window have round corner. +- (void)updateLayerMask { + if (![self layer].mask) { + layerMask_ = [CAShapeLayer layer]; + [self layer].mask = layerMask_; + } + + CGPathRef path = [self createRoundedBottomCornersPath:self.bounds.size]; + layerMask_.path = path; + CGPathRelease(path); +} + #pragma mark - NSWindowDelegate - (void)windowWillClose:(NSNotification*)notification { From e9da74e58a504c6682d340a5207a7d98069bff16 Mon Sep 17 00:00:00 2001 From: Robo Date: Fri, 24 Jul 2015 15:13:36 +0530 Subject: [PATCH 0612/1195] fix devtools workspace api to accept file path --- brightray/browser/inspectable_web_contents_delegate.h | 5 +++-- brightray/browser/inspectable_web_contents_impl.cc | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index 606bfa9a4ea..9c4ee722c2a 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -14,9 +14,10 @@ class InspectableWebContentsDelegate { const std::string& url, const std::string& content, bool save_as) {} virtual void DevToolsAppendToFile( const std::string& url, const std::string& content) {} - virtual void DevToolsAddFileSystem() {} + virtual void DevToolsAddFileSystem( + const base::FilePath& file_system_path) {} virtual void DevToolsRemoveFileSystem( - const std::string& file_system_path) {} + const base::FilePath& file_system_path) {} }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index fa62d3d202a..ba566f2339f 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -374,13 +374,14 @@ void InspectableWebContentsImpl::RequestFileSystems() { void InspectableWebContentsImpl::AddFileSystem() { if (delegate_) - delegate_->DevToolsAddFileSystem(); + delegate_->DevToolsAddFileSystem(base::FilePath()); } void InspectableWebContentsImpl::RemoveFileSystem( const std::string& file_system_path) { if (delegate_) - delegate_->DevToolsRemoveFileSystem(file_system_path); + delegate_->DevToolsRemoveFileSystem( + base::FilePath::FromUTF8Unsafe(file_system_path)); } void InspectableWebContentsImpl::UpgradeDraggedFileSystemPermissions( From a56a0505fa48288b7e2a7dac82fd33030a1fa50f Mon Sep 17 00:00:00 2001 From: Robo Date: Mon, 27 Jul 2015 20:04:21 +0530 Subject: [PATCH 0613/1195] save devtools zoom level preference --- .../browser/inspectable_web_contents_impl.cc | 37 +++++++++++++------ .../browser/inspectable_web_contents_impl.h | 7 ++++ 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index fa62d3d202a..0efb2b759cb 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -43,6 +43,7 @@ const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?" "textColor=rgba(0,0,0,1)&" "experiments=true"; const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; +const char kDevToolsZoomPref[] = "brightray.devtools.zoom"; const char kFrontendHostId[] = "id"; const char kFrontendHostMethod[] = "method"; @@ -71,11 +72,8 @@ void DictionaryToRect(const base::DictionaryValue& dict, gfx::Rect* bounds) { *bounds = gfx::Rect(x, y, width, height); } -double GetZoomLevelForWebContents(content::WebContents* web_contents) { - return content::HostZoomMap::GetZoomLevel(web_contents); -} - -void SetZoomLevelForWebContents(content::WebContents* web_contents, double level) { +void SetZoomLevelForWebContents(content::WebContents* web_contents, + double level) { content::HostZoomMap::SetZoomLevel(web_contents, level); } @@ -156,6 +154,7 @@ void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { auto bounds_dict = make_scoped_ptr(new base::DictionaryValue); RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get()); registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release()); + registry->RegisterDoublePref(kDevToolsZoomPref, 0.); } InspectableWebContentsImpl::InspectableWebContentsImpl( @@ -166,7 +165,8 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( web_contents_(web_contents), weak_factory_(this) { auto context = static_cast(web_contents_->GetBrowserContext()); - auto bounds_dict = context->prefs()->GetDictionary(kDevToolsBoundsPref); + pref_service_ = context->prefs(); + auto bounds_dict = pref_service_->GetDictionary(kDevToolsBoundsPref); if (bounds_dict) DictionaryToRect(*bounds_dict, &devtools_bounds_); @@ -282,14 +282,24 @@ gfx::Rect InspectableWebContentsImpl::GetDevToolsBounds() const { } void InspectableWebContentsImpl::SaveDevToolsBounds(const gfx::Rect& bounds) { - auto context = static_cast(web_contents_->GetBrowserContext()); base::DictionaryValue bounds_dict; RectToDictionary(bounds, &bounds_dict); - context->prefs()->Set(kDevToolsBoundsPref, bounds_dict); + pref_service_->Set(kDevToolsBoundsPref, bounds_dict); devtools_bounds_ = bounds; } +double InspectableWebContentsImpl::GetDevToolsZoomLevel() const { + return pref_service_->GetDouble(kDevToolsZoomPref); +} + +void InspectableWebContentsImpl::UpdateDevToolsZoomLevel(double level) { + pref_service_->SetDouble(kDevToolsZoomPref, level); +} + void InspectableWebContentsImpl::ActivateWindow() { + // Set the zoom level. + SetZoomLevelForWebContents(GetDevToolsWebContents(), + GetDevToolsZoomLevel()); } void InspectableWebContentsImpl::CloseWindow() { @@ -404,17 +414,20 @@ void InspectableWebContentsImpl::SetWhitelistedShortcuts(const std::string& mess } void InspectableWebContentsImpl::ZoomIn() { - double level = GetZoomLevelForWebContents(GetDevToolsWebContents()); - SetZoomLevelForWebContents(GetDevToolsWebContents(), GetNextZoomLevel(level, false)); + double new_level = GetNextZoomLevel(GetDevToolsZoomLevel(), false); + SetZoomLevelForWebContents(GetDevToolsWebContents(), new_level); + UpdateDevToolsZoomLevel(new_level); } void InspectableWebContentsImpl::ZoomOut() { - double level = GetZoomLevelForWebContents(GetDevToolsWebContents()); - SetZoomLevelForWebContents(GetDevToolsWebContents(), GetNextZoomLevel(level, true)); + double new_level = GetNextZoomLevel(GetDevToolsZoomLevel(), true); + SetZoomLevelForWebContents(GetDevToolsWebContents(), new_level); + UpdateDevToolsZoomLevel(new_level); } void InspectableWebContentsImpl::ResetZoom() { SetZoomLevelForWebContents(GetDevToolsWebContents(), 0.); + UpdateDevToolsZoomLevel(0.); } void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 6a28346040a..2b3ce59ff9d 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -19,6 +19,7 @@ #include "net/url_request/url_fetcher_delegate.h" #include "ui/gfx/geometry/rect.h" +class PrefService; class PrefRegistrySimple; namespace content { @@ -65,6 +66,10 @@ class InspectableWebContentsImpl : gfx::Rect GetDevToolsBounds() const; void SaveDevToolsBounds(const gfx::Rect& bounds); + // Return the last set zoom level of devtools window. + double GetDevToolsZoomLevel() const; + void UpdateDevToolsZoomLevel(double level); + private: // DevToolsEmbedderMessageDispacher::Delegate void ActivateWindow() override; @@ -160,6 +165,8 @@ class InspectableWebContentsImpl : PendingRequestsMap pending_requests_; InspectableWebContentsDelegate* delegate_; // weak references. + PrefService* pref_service_; // weak reference. + scoped_ptr web_contents_; scoped_ptr devtools_web_contents_; scoped_ptr view_; From 81ba4e3a3e2ed00e6069364dcf5b421b05f2aa43 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Aug 2015 16:43:26 +0800 Subject: [PATCH 0614/1195] Guard against empty image --- .../browser/linux/notification_presenter_linux.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 0c688906a7b..db9c67d3c89 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -13,6 +13,7 @@ #include "content/public/common/platform_notification_data.h" #include "common/application_info.h" #include "dbus/dbus.h" +#include "third_party/skia/include/core/SkBitmap.h" namespace brightray { @@ -111,11 +112,12 @@ void NotificationPresenterLinux::ShowNotification( notification, "default", "View", OnNotificationViewThunk, this, nullptr); } - GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon); - - notify_notification_set_image_from_pixbuf(notification, pixbuf); - notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT); - g_object_unref(pixbuf); + if (!icon.drawsNothing()) { + GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon); + notify_notification_set_image_from_pixbuf(notification, pixbuf); + notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT); + g_object_unref(pixbuf); + } GError* error = nullptr; notify_notification_show(notification, &error); From bb7cd8f26128fb2207df4fd888885279e0a95c5a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Aug 2015 16:44:32 +0800 Subject: [PATCH 0615/1195] Guard agains empty notification --- brightray/browser/linux/notification_presenter_linux.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index db9c67d3c89..557e527047d 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -153,12 +153,16 @@ void NotificationPresenterLinux::DeleteNotification(NotifyNotification* notifica } void NotificationPresenterLinux::OnNotificationClosed(NotifyNotification* notification) { + if (!notification) + return; GetDelegateFromNotification(notification)->NotificationClosed(); DeleteNotification(notification); } void NotificationPresenterLinux::OnNotificationView( NotifyNotification* notification, char* action) { + if (!notification) + return; GetDelegateFromNotification(notification)->NotificationClick(); DeleteNotification(notification); } From 0ef2857534209c7b88b8cf3a2229dba58d409a9c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Aug 2015 22:43:59 +0800 Subject: [PATCH 0616/1195] Don't show devtools window in too small size or out of screen --- .../browser/inspectable_web_contents_impl.cc | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index d5ac488efea..006986af610 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -28,6 +28,7 @@ #include "net/http/http_response_headers.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher_response_writer.h" +#include "ui/gfx/screen.h" namespace brightray { @@ -72,6 +73,11 @@ void DictionaryToRect(const base::DictionaryValue& dict, gfx::Rect* bounds) { *bounds = gfx::Rect(x, y, width, height); } +bool IsPointInRect(const gfx::Point& point, const gfx::Rect& rect) { + return point.x() > rect.x() && point.x() < (rect.width() + rect.x()) && + point.y() > rect.y() && point.y() < (rect.height() + rect.y()); +} + void SetZoomLevelForWebContents(content::WebContents* web_contents, double level) { content::HostZoomMap::SetZoomLevel(web_contents, level); @@ -167,8 +173,20 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( auto context = static_cast(web_contents_->GetBrowserContext()); pref_service_ = context->prefs(); auto bounds_dict = pref_service_->GetDictionary(kDevToolsBoundsPref); - if (bounds_dict) + if (bounds_dict) { DictionaryToRect(*bounds_dict, &devtools_bounds_); + // Sometimes the devtools window is out of screen or has too small size. + if (devtools_bounds_.height() < 100 || devtools_bounds_.width() < 100) { + devtools_bounds_.set_height(600); + devtools_bounds_.set_width(800); + } + gfx::Rect display = gfx::Screen::GetNativeScreen() + ->GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); + if (!IsPointInRect(devtools_bounds_.origin(), display)) { + devtools_bounds_.set_x(0); + devtools_bounds_.set_y(0); + } + } view_.reset(CreateInspectableContentsView(this)); } From 5b4a42f7e9539fa66dad132dc3965ea024046efa Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Aug 2015 22:50:30 +0800 Subject: [PATCH 0617/1195] Show devtools window in the middle of display --- brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 006986af610..c3df837943e 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -183,8 +183,8 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( gfx::Rect display = gfx::Screen::GetNativeScreen() ->GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); if (!IsPointInRect(devtools_bounds_.origin(), display)) { - devtools_bounds_.set_x(0); - devtools_bounds_.set_y(0); + 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 1f65b47e8e0ca737fec59b995449419da23f34a0 Mon Sep 17 00:00:00 2001 From: Robo Date: Fri, 7 Aug 2015 14:30:49 +0530 Subject: [PATCH 0618/1195] allow updating devtools title in undocked mode --- .../browser/inspectable_web_contents_impl.cc | 4 +++ .../browser/inspectable_web_contents_view.h | 2 ++ .../inspectable_web_contents_view_views.cc | 28 +++++++++++++------ .../inspectable_web_contents_view_views.h | 10 +++++++ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c3df837943e..f66c23b81f3 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -23,6 +23,7 @@ #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/navigation_entry.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" #include "net/http/http_response_headers.h" @@ -49,6 +50,7 @@ const char kDevToolsZoomPref[] = "brightray.devtools.zoom"; const char kFrontendHostId[] = "id"; const char kFrontendHostMethod[] = "method"; const char kFrontendHostParams[] = "params"; +const char kTitleFormat[] = "Developer Tools - %s"; const char kDevToolsActionTakenHistogram[] = "DevTools.ActionTaken"; const int kDevToolsActionTakenBoundary = 100; @@ -346,6 +348,8 @@ void InspectableWebContentsImpl::InspectElementCompleted() { } void InspectableWebContentsImpl::InspectedURLChanged(const std::string& url) { + view_->SetTitle(base::UTF8ToUTF16(base::StringPrintf(kTitleFormat, + url.c_str()))); } void InspectableWebContentsImpl::LoadNetworkResource( diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 31c30e1f328..469677a1ae6 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -1,6 +1,7 @@ #ifndef BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_H_ #define BRIGHTRAY_BROWSER_INSPECTABLE_WEB_CONTENTS_VIEW_H_ +#include "base/strings/string16.h" #include "ui/gfx/native_widget_types.h" class DevToolsContentsResizingStrategy; @@ -46,6 +47,7 @@ class InspectableWebContentsView { virtual void SetIsDocked(bool docked) = 0; virtual void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) = 0; + virtual void SetTitle(const base::string16& title) = 0; private: InspectableWebContentsViewDelegate* delegate_; // weak references. diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 8cae49db41e..6a7dd75aa6f 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -33,6 +33,8 @@ class DevToolsWindowDelegate : public views::ClientView, } virtual ~DevToolsWindowDelegate() {} + void SetWindowTitle(const base::string16& title) { title_ = title; } + // views::WidgetDelegate: void DeleteDelegate() override { delete this; } views::View* GetInitiallyFocusedView() override { return view_; } @@ -73,10 +75,11 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsViewViews::InspectableWebContentsViewViews( InspectableWebContentsImpl* inspectable_web_contents) : inspectable_web_contents_(inspectable_web_contents), - devtools_window_web_view_(NULL), - contents_web_view_(new views::WebView(NULL)), - devtools_web_view_(new views::WebView(NULL)), - devtools_visible_(false) { + devtools_window_web_view_(nullptr), + contents_web_view_(new views::WebView(nullptr)), + devtools_web_view_(new views::WebView(nullptr)), + devtools_visible_(false), + devtools_window_delegate_(nullptr) { set_owned_by_client(); devtools_web_view_->SetVisible(false); @@ -127,7 +130,8 @@ void InspectableWebContentsViewViews::CloseDevTools() { if (devtools_window_) { inspectable_web_contents()->SaveDevToolsBounds(devtools_window_->GetWindowBoundsInScreen()); devtools_window_.reset(); - devtools_window_web_view_ = NULL; + devtools_window_web_view_ = nullptr; + devtools_window_delegate_ = nullptr; } else { devtools_web_view_->SetVisible(false); devtools_web_view_->SetWebContents(NULL); @@ -147,12 +151,13 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { if (!docked) { devtools_window_.reset(new views::Widget); devtools_window_web_view_ = new views::WebView(NULL); + devtools_window_delegate_ = new DevToolsWindowDelegate(this, + devtools_window_web_view_, + devtools_window_.get()); views::Widget::InitParams params; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.delegate = new DevToolsWindowDelegate(this, - devtools_window_web_view_, - devtools_window_.get()); + params.delegate = GetDevToolsWindowDelegate(); params.bounds = inspectable_web_contents()->GetDevToolsBounds(); #if defined(USE_X11) @@ -174,6 +179,13 @@ void InspectableWebContentsViewViews::SetContentsResizingStrategy( Layout(); } +void InspectableWebContentsViewViews::SetTitle(const base::string16& title) { + if (devtools_window_) { + GetDevToolsWindowDelegate()->SetWindowTitle(title); + devtools_window_->UpdateWindowTitle(); + } +} + void InspectableWebContentsViewViews::Layout() { if (!devtools_web_view_->visible()) { contents_web_view_->SetBoundsRect(GetContentsBounds()); diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index 4e250350463..a6c3ae62f8c 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -14,6 +14,10 @@ class Widget; namespace brightray { +namespace { +class DevToolsWindowDelegate; +} + class InspectableWebContentsImpl; class InspectableWebContentsViewViews : public InspectableWebContentsView, @@ -23,6 +27,10 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, InspectableWebContentsImpl* inspectable_web_contents_impl); ~InspectableWebContentsViewViews(); + DevToolsWindowDelegate* GetDevToolsWindowDelegate() const { + return devtools_window_delegate_; + } + // InspectableWebContentsView: views::View* GetView() override; views::View* GetWebView() override; @@ -32,6 +40,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, void SetIsDocked(bool docked) override; void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) override; + void SetTitle(const base::string16& title) override; InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; @@ -51,6 +60,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, DevToolsContentsResizingStrategy strategy_; bool devtools_visible_; + DevToolsWindowDelegate* devtools_window_delegate_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewViews); }; From 26f4d09b2c3bf31067c43c26fddfcb20552343cd Mon Sep 17 00:00:00 2001 From: Robo Date: Fri, 7 Aug 2015 14:55:58 +0530 Subject: [PATCH 0619/1195] implement for osx --- brightray/browser/inspectable_web_contents_impl.cc | 1 - brightray/browser/inspectable_web_contents_view_mac.h | 1 + brightray/browser/inspectable_web_contents_view_mac.mm | 4 ++++ brightray/browser/mac/bry_inspectable_web_contents_view.h | 1 + .../browser/mac/bry_inspectable_web_contents_view.mm | 8 ++++++++ 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index f66c23b81f3..d2d5c196936 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -23,7 +23,6 @@ #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/navigation_entry.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" #include "net/http/http_response_headers.h" diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index fbe19adaebd..0dbb7beb82c 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -24,6 +24,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView { void SetIsDocked(bool docked) override; void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) override; + void SetTitle(const base::string16& title) override; InspectableWebContentsImpl* inspectable_web_contents() { return inspectable_web_contents_; diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index 6cd08da2f6a..e676653953e 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -50,4 +50,8 @@ void InspectableWebContentsViewMac::SetContentsResizingStrategy( [view_ setContentsResizingStrategy:strategy]; } +void InspectableWebContentsViewMac::SetTitle(const base::string16& title) { + [view_ setTitle:title]; +} + } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index ea6e3f9a811..c3c5a1ada0f 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -32,5 +32,6 @@ using brightray::InspectableWebContentsViewMac; - (BOOL)isDevToolsVisible; - (void)setIsDocked:(BOOL)docked; - (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy; +- (void)setTitle:(const base::string16&)title; @end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index a7f4134b4fa..f2dac929739 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -2,6 +2,7 @@ #import +#include "base/strings/sys_string_conversions.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/inspectable_web_contents_view_mac.h" @@ -174,6 +175,13 @@ const CGFloat kRoundedCornerRadius = 4; [contentsView setFrame:[self flipRectToNSRect:new_contents_bounds]]; } +- (void)setTitle:(const base::string16&)title { + if (devtools_window_) { + NSString* title_string = base::SysUTF16ToNSString(title); + [devtools_window_ setTitle:title_string]; + } +} + // Creates a path whose bottom two corners are rounded. // Caller takes ownership of the path. - (CGPathRef)createRoundedBottomCornersPath:(NSSize)size { From ef91261aa5dd013b99cfd5c832b2ed72012bbc50 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 23 Jul 2015 14:49:13 +0800 Subject: [PATCH 0620/1195] No NetLog anymore, use NetLogCaptureMode. --- brightray/browser/net_log.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index 6a2b9c3d76f..fae651515e3 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "content/public/common/content_switches.h" #include "net/log/net_log_util.h" +#include "net/log/net_log_capture_mode.h" #include "net/url_request/url_request_context.h" namespace { @@ -65,7 +66,7 @@ NetLog::NetLog(net::URLRequestContext* context) net::CreateNetLogEntriesForActiveObjects(contexts, this); } - DeprecatedAddObserver(this, net::NetLog::LogLevel::LOG_STRIP_PRIVATE_DATA); + DeprecatedAddObserver(this, net::NetLogCaptureMode::Default()); } } } From ce6172b829062696f077c77b22255439e7e902f0 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 23 Jul 2015 14:53:42 +0800 Subject: [PATCH 0621/1195] Update PlatformNotificationServiceImpl Interfaces. --- brightray/browser/platform_notification_service_impl.cc | 8 +++++++- brightray/browser/platform_notification_service_impl.h | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service_impl.cc index b613dc2ad22..d2b0f679a6c 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 4b0d4fa96c7..da1e2ad81eb 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_; From c5ae2926e1f96704ec582b9a1cd8ee03a9b892f4 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 23 Jul 2015 15:00:14 +0800 Subject: [PATCH 0622/1195] WebContentsFocused is removed. Use OnWebContentsFocused instead. --- brightray/browser/inspectable_web_contents_impl.cc | 6 ++---- brightray/browser/inspectable_web_contents_impl.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c3df837943e..80b142c4ad6 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -21,7 +21,6 @@ #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" @@ -364,7 +363,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); @@ -577,8 +576,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 2b3ce59ff9d..0c185df79ea 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -125,6 +125,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 +145,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; From dd11ad8db3000c4dc24e6b1a8e6b07c0c763e9a8 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 23 Jul 2015 15:03:55 +0800 Subject: [PATCH 0623/1195] DevToolsHttpHandler::GetFrontendResourceId is removed. --- brightray/browser/devtools_ui.cc | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 9b5eba7d6fc..c5df7e02764 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()); } From 2703f186a6022d92608d9527f2d327f2615726a5 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 23 Jul 2015 15:04:47 +0800 Subject: [PATCH 0624/1195] DevToolsHttpHandler is moved from content to devtools_http_handler namespace. --- brightray/browser/browser_main_parts.cc | 2 +- brightray/browser/browser_main_parts.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 807e5022497..fe6a42b9369 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 e8d7c323c78..d5ae8f1b7f2 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_; From 2dd8bc0c78de33d9f61aa2ee54b5ba6ad3fdaa77 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 23 Jul 2015 18:17:06 +0800 Subject: [PATCH 0625/1195] ffmpegsumo.dll => ffmpeg.dll --- brightray/brightray.gyp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index fce7dfc1ad3..218f4afbfe6 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -163,8 +163,8 @@ # Link with system libraries. 'link_settings': { 'libraries': [ - # ffmpegsumo.lib is required for linking with ffmpegsumo.dll - '<(libchromiumcontent_dir)/ffmpegsumo.lib', + # ffmpeg.dll.lib is required for linking with ffmpeg.dll + '<(libchromiumcontent_dir)/ffmpeg.dll.lib', # content_browser.gypi: '-lsensorsapi.lib', '-lportabledeviceguids.lib', @@ -195,7 +195,7 @@ 'winspool.lib', ], 'DelayLoadDLLs': [ - 'ffmpegsumo.dll', + 'ffmpeg.dll', # content_common.gypi: 'd3d9.dll', 'dxva2.dll', From 7d22da516941ea821c7c428fd12eebadb138110f Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 23 Jul 2015 18:18:03 +0800 Subject: [PATCH 0626/1195] Fix API changes in DevToolsManagerDelegate. --- .../browser/devtools_manager_delegate.cc | 135 ++++-------------- brightray/browser/devtools_manager_delegate.h | 9 +- brightray/common/content_client.cc | 18 ++- brightray/common/content_client.h | 2 + 4 files changed, 48 insertions(+), 116 deletions(-) diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index ec660d08ce0..0491d8aa859 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -12,27 +12,21 @@ #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_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 +37,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 +61,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 +78,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 +112,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,12 +127,16 @@ 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() { @@ -208,22 +151,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 529f1ff7b89..154ea9ccbf7 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/common/content_client.cc b/brightray/common/content_client.cc index 3867ed6fe3f..b13fc73ef90 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 f0e4449e251..d54cf5df730 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(); From 68a45aa29aab099a223c08389d9b1467a38ce2df Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 24 Jul 2015 10:10:25 +0800 Subject: [PATCH 0627/1195] [Win] Link devtools_discovery.lib and devtools_http_handler.lib in component builds. --- brightray/brightray.gyp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 218f4afbfe6..f0b048dbdbe 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -152,11 +152,14 @@ ['OS=="win"', { 'conditions': [ ['libchromiumcontent_component', { - # sandbox and base_static are always linked statically. + # sandbox, base_static, devtools_discovery, devtools_http_handler + # 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', ], }, }, { From 6171ab8f6bffb55d1cde16f4b71a455e4b28ac50 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Tue, 4 Aug 2015 16:02:44 +0800 Subject: [PATCH 0628/1195] [Win] Link http_server.lib. --- brightray/brightray.gyp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index f0b048dbdbe..f134eb2721f 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -152,14 +152,15 @@ ['OS=="win"', { 'conditions': [ ['libchromiumcontent_component', { - # sandbox, base_static, devtools_discovery, devtools_http_handler - # 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', ], }, }, { From f82ab5f1937ba3dd66f14910f9a7b4b569063b87 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 6 Aug 2015 13:39:23 +0800 Subject: [PATCH 0629/1195] Implement devtools preference interfaces. --- .../devtools_embedder_message_dispatcher.cc | 5 ++++ .../devtools_embedder_message_dispatcher.h | 5 ++++ .../browser/inspectable_web_contents_impl.cc | 26 +++++++++++++++++++ .../browser/inspectable_web_contents_impl.h | 5 ++++ 4 files changed, 41 insertions(+) diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index cb44ec16d86..2a4b3817659 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 851a2f49058..46f54dfbf2c 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/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 80b142c4ad6..6d2f24fae4c 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -17,6 +17,7 @@ #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" @@ -44,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"; @@ -160,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( @@ -469,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; diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 0c185df79ea..62cfffec4f6 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; From 089a4cf08f17b8f97d55909b874bb62d5f29d908 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Aug 2015 10:04:07 +0800 Subject: [PATCH 0630/1195] Disable -Wunneeded-internal-declaration warning --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index d03703ba4a3..32189ab93a8 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': { From 1cd7434a66ac07eb318e66bea5f4f73de6aa4ac3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Aug 2015 10:05:27 +0800 Subject: [PATCH 0631/1195] Include Foundation.h at right place --- brightray/browser/notification_presenter_mac.h | 9 ++++++--- brightray/browser/notification_presenter_mac.mm | 2 -- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h index 20cbee20e84..768bf2b6f1a 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 60abc6af76d..81527772ffb 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_; From 3deb8297e1b16448d4428e710c693f058fb7f0d0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Aug 2015 10:24:53 +0800 Subject: [PATCH 0632/1195] Update to Chrome 44 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 534e0fbaaca..cf133b8ebfe 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 534e0fbaaca61a7b8d57578b2646d47cf4237d2a +Subproject commit cf133b8ebfeb3579032d3092351c801a3112aa7c From edda9d04880e9956e57120e5ba84b7eaa58dccfd Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Aug 2015 10:39:40 +0800 Subject: [PATCH 0633/1195] Link with a few more static libraries on Linux and OS X --- brightray/brightray.gyp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index f134eb2721f..143d9f47178 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: From 8a92ef34a72003d0e24fb5664d9ab49ced3ea833 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Aug 2015 18:29:55 +0800 Subject: [PATCH 0634/1195] Store NetLog in BrowserClient --- brightray/browser/browser_client.cc | 6 +- brightray/browser/browser_client.h | 7 +- brightray/browser/browser_context.cc | 6 +- brightray/browser/browser_context.h | 2 +- brightray/browser/net_log.cc | 74 ++++++------------- brightray/browser/net_log.h | 17 ++--- .../browser/url_request_context_getter.cc | 6 +- .../browser/url_request_context_getter.h | 7 +- 8 files changed, 46 insertions(+), 79 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 493e896366f..4bbf371aeaa 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -63,7 +63,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 +83,7 @@ void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( } net::NetLog* BrowserClient::GetNetLog() { - return browser_context()->GetNetLog(); + return &net_log_; } base::FilePath BrowserClient::GetDefaultDownloadDirectory() { diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index f9b0f0d0585..1c8d256ce3d 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; @@ -46,7 +46,6 @@ class BrowserClient : public content::ContentBrowserClient { net::NetLog* GetNetLog() override; base::FilePath GetDefaultDownloadDirectory() override; content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override; - #if defined(OS_POSIX) && !defined(OS_MACOSX) void GetAdditionalMappedFilesForChildProcess( const base::CommandLine& command_line, @@ -61,6 +60,8 @@ class BrowserClient : public content::ContentBrowserClient { 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 ec41caed255..c490de4fe27 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 9244ac40c2f..6b0ca300b2a 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/net_log.cc b/brightray/browser/net_log.cc index fae651515e3..59447436356 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -4,15 +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/log/net_log_capture_mode.h" -#include "net/url_request/url_request_context.h" + +namespace brightray { namespace { @@ -31,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::NetLogCaptureMode::Default()); - } + 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 4aade754f35..e62c335350c 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/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 9f796a7a9f0..2896c49ae46 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 afab504c3f2..376f69c9a2f 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_; From c4d192b9a4f43da0cafd3c5bedff68adcfce5a76 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 21 Aug 2015 16:14:19 +0800 Subject: [PATCH 0635/1195] linux: Fix building --- brightray/browser/browser_client.cc | 35 ------------------- brightray/browser/browser_client.h | 12 ------- .../browser/devtools_manager_delegate.cc | 7 ++++ 3 files changed, 7 insertions(+), 47 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 4bbf371aeaa..18b5fd855e2 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() { @@ -99,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 1c8d256ce3d..f69b017e5e1 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -46,20 +46,8 @@ class BrowserClient : public content::ContentBrowserClient { net::NetLog* GetNetLog() override; 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/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index 0491d8aa859..89c3469fc0d 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -14,6 +14,7 @@ #include "base/strings/utf_string_conversions.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_frontend_host.h" @@ -140,6 +141,12 @@ DevToolsManagerDelegate::CreateHttpHandler() { } 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() { From c9557f2b395316f53a51bceae74763702d42baa8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 21 Aug 2015 16:19:57 +0800 Subject: [PATCH 0636/1195] win: Fix Release build --- brightray/brightray.gyp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 143d9f47178..b3c4e92e6fd 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -179,8 +179,6 @@ # Link with system libraries. 'link_settings': { 'libraries': [ - # ffmpeg.dll.lib is required for linking with ffmpeg.dll - '<(libchromiumcontent_dir)/ffmpeg.dll.lib', # content_browser.gypi: '-lsensorsapi.lib', '-lportabledeviceguids.lib', @@ -200,6 +198,7 @@ 'AdditionalDependencies': [ 'advapi32.lib', 'dbghelp.lib', + 'delayimp.lib', 'dwmapi.lib', 'gdi32.lib', 'netapi32.lib', @@ -211,7 +210,6 @@ 'winspool.lib', ], 'DelayLoadDLLs': [ - 'ffmpeg.dll', # content_common.gypi: 'd3d9.dll', 'dxva2.dll', From eb709a9a8f60797ee163fdba4ec9e20cf34fceb2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 25 Aug 2015 20:55:07 +0800 Subject: [PATCH 0637/1195] Fix building on OS X --- brightray/browser/inspectable_web_contents_view_mac.mm | 3 ++- brightray/browser/mac/bry_inspectable_web_contents_view.h | 2 +- .../browser/mac/bry_inspectable_web_contents_view.mm | 8 ++------ 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index e676653953e..42ca3c6f3a1 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -2,6 +2,7 @@ #import +#include "base/strings/sys_string_conversions.h" #include "browser/inspectable_web_contents.h" #include "browser/inspectable_web_contents_view_delegate.h" #import "browser/mac/bry_inspectable_web_contents_view.h" @@ -51,7 +52,7 @@ void InspectableWebContentsViewMac::SetContentsResizingStrategy( } void InspectableWebContentsViewMac::SetTitle(const base::string16& title) { - [view_ setTitle:title]; + [view_ setTitle:base::SysUTF16ToNSString(title)]; } } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index c3c5a1ada0f..b5dbb415e5b 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -32,6 +32,6 @@ using brightray::InspectableWebContentsViewMac; - (BOOL)isDevToolsVisible; - (void)setIsDocked:(BOOL)docked; - (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy; -- (void)setTitle:(const base::string16&)title; +- (void)setTitle:(NSString*)title; @end diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index f2dac929739..20267769e28 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -2,7 +2,6 @@ #import -#include "base/strings/sys_string_conversions.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/inspectable_web_contents_view_mac.h" @@ -175,11 +174,8 @@ const CGFloat kRoundedCornerRadius = 4; [contentsView setFrame:[self flipRectToNSRect:new_contents_bounds]]; } -- (void)setTitle:(const base::string16&)title { - if (devtools_window_) { - NSString* title_string = base::SysUTF16ToNSString(title); - [devtools_window_ setTitle:title_string]; - } +- (void)setTitle:(NSString*)title { + [devtools_window_ setTitle:title]; } // Creates a path whose bottom two corners are rounded. From c0b9fd415df91dc5763ab2ad26d4306141001fe7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 26 Aug 2015 15:56:39 +0800 Subject: [PATCH 0638/1195] Revert "Make bottom corner more round" This reverts commit f9a64dde5da537f615cd7080a335c6304c6a814e. --- .../mac/bry_inspectable_web_contents_view.h | 5 -- .../mac/bry_inspectable_web_contents_view.mm | 76 +------------------ 2 files changed, 1 insertion(+), 80 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index b5dbb415e5b..3b72aba08cc 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -5,8 +5,6 @@ #include "base/mac/scoped_nsobject.h" #include "ui/base/cocoa/base_view.h" -@class CAShapeLayer; - namespace brightray { class InspectableWebContentsViewMac; } @@ -21,9 +19,6 @@ using brightray::InspectableWebContentsViewMac; BOOL devtools_visible_; BOOL devtools_docked_; - // Weak reference to the mask of the hosted layer. - CAShapeLayer* layerMask_; - DevToolsContentsResizingStrategy strategy_; } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 20267769e28..1bb84e5abb5 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -1,24 +1,14 @@ #include "browser/mac/bry_inspectable_web_contents_view.h" -#import - #include "browser/inspectable_web_contents_impl.h" #include "browser/inspectable_web_contents_view_mac.h" #include "content/public/browser/render_widget_host_view.h" -#include "ui/base/cocoa/animation_utils.h" -#include "ui/base/cocoa/underlay_opengl_hosting_window.h" +#import "ui/base/cocoa/underlay_opengl_hosting_window.h" #include "ui/gfx/mac/scoped_ns_disable_screen_updates.h" using namespace brightray; -namespace { - -// The radius of the rounded corners. -const CGFloat kRoundedCornerRadius = 4; - -} // namespace - @implementation BRYInspectableWebContentsView - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view { @@ -36,14 +26,8 @@ const CGFloat kRoundedCornerRadius = 4; [self addSubview:contentsView]; // See https://code.google.com/p/chromium/issues/detail?id=348490. - ScopedCAActionDisabler disabler; - base::scoped_nsobject layer([[CALayer alloc] init]); - [self setLayer:layer]; [self setWantsLayer:YES]; - // See https://code.google.com/p/chromium/issues/detail?id=396264. - [self updateLayerMask]; - return self; } @@ -51,12 +35,6 @@ const CGFloat kRoundedCornerRadius = 4; [self adjustSubviews]; } -// Every time the frame's size changes, the layer mask needs to be updated. -- (void)setFrameSize:(NSSize)newSize { - [super setFrameSize:newSize]; - [self updateLayerMask]; -} - - (IBAction)showDevTools:(id)sender { inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools(); } @@ -178,58 +156,6 @@ const CGFloat kRoundedCornerRadius = 4; [devtools_window_ setTitle:title]; } -// Creates a path whose bottom two corners are rounded. -// Caller takes ownership of the path. -- (CGPathRef)createRoundedBottomCornersPath:(NSSize)size { - CGMutablePathRef path = CGPathCreateMutable(); - CGFloat width = size.width; - CGFloat height = size.height; - CGFloat cornerRadius = kRoundedCornerRadius; - - // Top left corner. - CGPathMoveToPoint(path, NULL, 0, height); - - // Top right corner. - CGPathAddLineToPoint(path, NULL, width, height); - - // Bottom right corner. - CGPathAddArc(path, - NULL, - width - cornerRadius, - cornerRadius, - cornerRadius, - 0, - -M_PI_2, - true); - - // Bottom left corner. - CGPathAddArc(path, - NULL, - cornerRadius, - cornerRadius, - cornerRadius, - -M_PI_2, - -M_PI, - true); - - // Draw line back to top-left corner. - CGPathAddLineToPoint(path, NULL, 0, height); - CGPathCloseSubpath(path); - return path; -} - -// Updates the path of the layer mask to have make window have round corner. -- (void)updateLayerMask { - if (![self layer].mask) { - layerMask_ = [CAShapeLayer layer]; - [self layer].mask = layerMask_; - } - - CGPathRef path = [self createRoundedBottomCornersPath:self.bounds.size]; - layerMask_.path = path; - CGPathRelease(path); -} - #pragma mark - NSWindowDelegate - (void)windowWillClose:(NSNotification*)notification { From 89e66f15c3f7b41006b890f3674fe6b185f7247a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 26 Aug 2015 15:34:57 +0800 Subject: [PATCH 0639/1195] Link with 10.9 SDK --- brightray/brightray.gypi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 32189ab93a8..82f4cdf55ad 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -31,7 +31,7 @@ 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', 'GCC_ENABLE_CPP_RTTI': 'NO', 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', - 'MACOSX_DEPLOYMENT_TARGET': '10.8', + 'MACOSX_DEPLOYMENT_TARGET': '10.9', 'RUN_CLANG_STATIC_ANALYZER': 'YES', 'SDKROOT': 'macosx', 'USE_HEADER_MAP': 'NO', @@ -40,6 +40,7 @@ '-Wextra', '-Wno-unused-parameter', '-Wno-missing-field-initializers', + '-Wno-deprecated-declarations', '-Wno-unneeded-internal-declaration', ], }, From fa5c8fc943be3ef993cab5712e8746f5e987426c Mon Sep 17 00:00:00 2001 From: Robo Date: Thu, 27 Aug 2015 03:10:02 +0530 Subject: [PATCH 0640/1195] handle partition config in browser context --- brightray/browser/browser_context.cc | 9 ++++-- brightray/browser/browser_context.h | 4 ++- brightray/browser/browser_main_parts.cc | 2 +- .../browser/url_request_context_getter.cc | 28 ++++++++++++++----- .../browser/url_request_context_getter.h | 2 ++ 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index c490de4fe27..34701a4d9c2 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -69,13 +69,17 @@ class BrowserContext::ResourceContext : public content::ResourceContext { BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { } -void BrowserContext::Initialize() { +void BrowserContext::Initialize(const base::FilePath& partition_path, bool in_memory) { if (!PathService::Get(DIR_USER_DATA, &path_)) { PathService::Get(DIR_APP_DATA, &path_); path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); PathService::Override(DIR_USER_DATA, path_); } + if (!partition_path.empty()) + path_ = path_.Append(partition_path); + in_memory_ = in_memory; + auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); base::PrefServiceFactory prefs_factory; prefs_factory.SetUserPrefsFile(prefs_path, @@ -108,6 +112,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( this, net_log, GetPath(), + in_memory_, BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), protocol_handlers, @@ -130,7 +135,7 @@ scoped_ptr BrowserContext::CreateZoomLevelDelegate( } bool BrowserContext::IsOffTheRecord() const { - return false; + return in_memory_; } net::URLRequestContextGetter* BrowserContext::GetRequestContext() { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 6b0ca300b2a..a59d21c49a1 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -23,7 +23,8 @@ class BrowserContext : public content::BrowserContext, BrowserContext(); ~BrowserContext(); - virtual void Initialize(); + virtual void Initialize(const base::FilePath& partition_path, + bool in_memory = false); // content::BrowserContext: scoped_ptr CreateZoomLevelDelegate( @@ -71,6 +72,7 @@ class BrowserContext : public content::BrowserContext, void RegisterInternalPrefs(PrefRegistrySimple* pref_registry); base::FilePath path_; + bool in_memory_; scoped_ptr resource_context_; scoped_refptr url_request_getter_; scoped_ptr prefs_; diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index fe6a42b9369..537d1c1f295 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -121,7 +121,7 @@ void BrowserMainParts::PreMainMessageLoopStart() { void BrowserMainParts::PreMainMessageLoopRun() { browser_context_.reset(CreateBrowserContext()); - browser_context_->Initialize(); + browser_context_->Initialize(base::FilePath()); web_ui_controller_factory_.reset( new WebUIControllerFactory(browser_context_.get())); diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 2896c49ae46..e390f1c2afe 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -121,6 +121,7 @@ URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, NetLog* net_log, const base::FilePath& base_path, + bool in_memory, base::MessageLoop* io_loop, base::MessageLoop* file_loop, content::ProtocolHandlerMap* protocol_handlers, @@ -128,6 +129,7 @@ URLRequestContextGetter::URLRequestContextGetter( : delegate_(delegate), net_log_(net_log), base_path_(base_path), + in_memory_(in_memory), io_loop_(io_loop), file_loop_(file_loop), url_sec_mgr_(net::URLSecurityManager::Create(NULL, NULL)), @@ -154,8 +156,8 @@ net::HostResolver* URLRequestContextGetter::host_resolver() { net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - auto& command_line = *base::CommandLine::ForCurrentProcess(); if (!url_request_context_.get()) { + auto& command_line = *base::CommandLine::ForCurrentProcess(); url_request_context_.reset(new net::URLRequestContext); // --log-net-log @@ -166,11 +168,18 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { url_request_context_->set_network_delegate(network_delegate_.get()); storage_.reset(new net::URLRequestContextStorage(url_request_context_.get())); - auto cookie_config = content::CookieStoreConfig( - base_path_.Append(FILE_PATH_LITERAL("Cookies")), - content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, - NULL, NULL); - storage_->set_cookie_store(content::CreateCookieStore(cookie_config)); + + scoped_refptr cookie_store = nullptr; + if (in_memory_) { + cookie_store = content::CreateCookieStore(content::CookieStoreConfig()); + } else { + auto cookie_config = content::CookieStoreConfig( + base_path_.Append(FILE_PATH_LITERAL("Cookies")), + content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, + NULL, NULL); + cookie_store = content::CreateCookieStore(cookie_config); + } + storage_->set_cookie_store(cookie_store.get()); storage_->set_channel_id_service(make_scoped_ptr( new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), base::WorkerPool::GetTaskRunner(true)))); @@ -265,7 +274,12 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_host_resolver(host_resolver.Pass()); network_session_params.host_resolver = url_request_context_->host_resolver(); - net::HttpCache::BackendFactory* backend = delegate_->CreateHttpCacheBackendFactory(base_path_); + net::HttpCache::BackendFactory* backend = nullptr; + if (in_memory_) { + backend = net::HttpCache::DefaultBackend::InMemory(0); + } else { + backend = delegate_->CreateHttpCacheBackendFactory(base_path_); + } storage_->set_http_transaction_factory(new net::HttpCache(network_session_params, backend)); storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 376f69c9a2f..ab773b29a40 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -49,6 +49,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { Delegate* delegate, NetLog* net_log, const base::FilePath& base_path, + bool in_memory, base::MessageLoop* io_loop, base::MessageLoop* file_loop, content::ProtocolHandlerMap* protocol_handlers, @@ -66,6 +67,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { NetLog* net_log_; base::FilePath base_path_; + bool in_memory_; base::MessageLoop* io_loop_; base::MessageLoop* file_loop_; From 0e956c497dcd26290216f07e03c178b5f07eb210 Mon Sep 17 00:00:00 2001 From: Robo Date: Fri, 28 Aug 2015 01:24:05 +0530 Subject: [PATCH 0641/1195] use browser context from webcontents for registering datasource --- brightray/browser/browser_context.cc | 4 ++-- brightray/browser/browser_context.h | 2 +- brightray/browser/browser_main_parts.cc | 6 ++---- brightray/browser/browser_main_parts.h | 2 -- brightray/browser/devtools_ui.cc | 5 ++--- brightray/browser/devtools_ui.h | 4 +++- .../browser/web_ui_controller_factory.cc | 21 ++++++++++--------- brightray/browser/web_ui_controller_factory.h | 11 +++++----- 8 files changed, 27 insertions(+), 28 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 34701a4d9c2..756f27e0f95 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -69,7 +69,7 @@ class BrowserContext::ResourceContext : public content::ResourceContext { BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { } -void BrowserContext::Initialize(const base::FilePath& partition_path, bool in_memory) { +void BrowserContext::Initialize(const std::string& partition_path, bool in_memory) { if (!PathService::Get(DIR_USER_DATA, &path_)) { PathService::Get(DIR_APP_DATA, &path_); path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); @@ -77,7 +77,7 @@ void BrowserContext::Initialize(const base::FilePath& partition_path, bool in_me } if (!partition_path.empty()) - path_ = path_.Append(partition_path); + path_ = path_.Append(base::FilePath::FromUTF8Unsafe(partition_path)); in_memory_ = in_memory; auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index a59d21c49a1..ebf16a32b73 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -23,7 +23,7 @@ class BrowserContext : public content::BrowserContext, BrowserContext(); ~BrowserContext(); - virtual void Initialize(const base::FilePath& partition_path, + virtual void Initialize(const std::string& partition_path, bool in_memory = false); // content::BrowserContext: diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 537d1c1f295..fd283f72ed0 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -121,12 +121,10 @@ void BrowserMainParts::PreMainMessageLoopStart() { void BrowserMainParts::PreMainMessageLoopRun() { browser_context_.reset(CreateBrowserContext()); - browser_context_->Initialize(base::FilePath()); + browser_context_->Initialize(std::string()); - web_ui_controller_factory_.reset( - new WebUIControllerFactory(browser_context_.get())); content::WebUIControllerFactory::RegisterFactory( - web_ui_controller_factory_.get()); + WebUIControllerFactory::GetInstance()); // --remote-debugging-port auto command_line = base::CommandLine::ForCurrentProcess(); diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index d5ae8f1b7f2..8822cb7c09d 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -28,7 +28,6 @@ class WMState; namespace brightray { class BrowserContext; -class WebUIControllerFactory; class BrowserMainParts : public content::BrowserMainParts { public: @@ -57,7 +56,6 @@ class BrowserMainParts : public content::BrowserMainParts { #endif scoped_ptr browser_context_; - scoped_ptr web_ui_controller_factory_; scoped_ptr devtools_http_handler_; #if defined(TOOLKIT_VIEWS) diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index c5df7e02764..8f8ded3b76d 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -6,8 +6,6 @@ #include -#include "browser/browser_context.h" - #include "base/memory/ref_counted_memory.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" @@ -93,7 +91,8 @@ class BundledDataSource : public content::URLDataSource { } // namespace -DevToolsUI::DevToolsUI(BrowserContext* browser_context, content::WebUI* web_ui) +DevToolsUI::DevToolsUI(content::BrowserContext* browser_context, + content::WebUI* web_ui) : WebUIController(web_ui) { web_ui->SetBindings(0); content::URLDataSource::Add(browser_context, new BundledDataSource()); diff --git a/brightray/browser/devtools_ui.h b/brightray/browser/devtools_ui.h index 1f5ff4f7217..176de9b71ba 100644 --- a/brightray/browser/devtools_ui.h +++ b/brightray/browser/devtools_ui.h @@ -6,6 +6,7 @@ #define BRIGHTRAY_BROWSER_DEVTOOLS_UI_H_ #include "base/compiler_specific.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/web_ui_controller.h" namespace brightray { @@ -14,7 +15,8 @@ class BrowserContext; class DevToolsUI : public content::WebUIController { public: - explicit DevToolsUI(BrowserContext* browser_context, content::WebUI* web_ui); + explicit DevToolsUI(content::BrowserContext* browser_context, + content::WebUI* web_ui); private: DISALLOW_COPY_AND_ASSIGN(DevToolsUI); diff --git a/brightray/browser/web_ui_controller_factory.cc b/brightray/browser/web_ui_controller_factory.cc index 9a9694de083..cacc2f8dc28 100644 --- a/brightray/browser/web_ui_controller_factory.cc +++ b/brightray/browser/web_ui_controller_factory.cc @@ -4,9 +4,8 @@ #include "browser/web_ui_controller_factory.h" -#include "browser/browser_context.h" #include "browser/devtools_ui.h" - +#include "base/memory/singleton.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" #include "content/public/common/url_constants.h" @@ -19,9 +18,12 @@ const char kChromeUIDevToolsBundledHost[] = "devtools"; } -WebUIControllerFactory::WebUIControllerFactory(BrowserContext* browser_context) - : browser_context_(browser_context) { - DCHECK(browser_context_); +// static +WebUIControllerFactory* WebUIControllerFactory::GetInstance() { + return Singleton::get(); +} + +WebUIControllerFactory::WebUIControllerFactory() { } WebUIControllerFactory::~WebUIControllerFactory() { @@ -48,11 +50,10 @@ bool WebUIControllerFactory::UseWebUIBindingsForURL( content::WebUIController* WebUIControllerFactory::CreateWebUIControllerForURL( content::WebUI* web_ui, const GURL& url) const { - DCHECK(browser_context_); - - if (url.host() == kChromeUIDevToolsBundledHost) - return new DevToolsUI(browser_context_, web_ui); - + if (url.host() == kChromeUIDevToolsBundledHost) { + auto browser_context = web_ui->GetWebContents()->GetBrowserContext(); + return new DevToolsUI(browser_context, web_ui); + } return NULL; } diff --git a/brightray/browser/web_ui_controller_factory.h b/brightray/browser/web_ui_controller_factory.h index 6f860841aff..3367255bba3 100644 --- a/brightray/browser/web_ui_controller_factory.h +++ b/brightray/browser/web_ui_controller_factory.h @@ -9,13 +9,17 @@ #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_controller_factory.h" +template struct DefaultSingletonTraits; + namespace brightray { class BrowserContext; class WebUIControllerFactory : public content::WebUIControllerFactory { public: - explicit WebUIControllerFactory(BrowserContext* browser_context); + static WebUIControllerFactory* GetInstance(); + + WebUIControllerFactory(); virtual ~WebUIControllerFactory(); content::WebUI::TypeID GetWebUIType( @@ -28,11 +32,8 @@ class WebUIControllerFactory : public content::WebUIControllerFactory { content::WebUI* web_ui, const GURL& url) const override; - static WebUIControllerFactory* GetInstance(); - private: - // Weak reference to the browser context. - BrowserContext* browser_context_; + friend struct DefaultSingletonTraits; DISALLOW_COPY_AND_ASSIGN(WebUIControllerFactory); }; From 5e004b4c24f080e2b65f2192980b22452c10068e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Sep 2015 14:22:50 +0800 Subject: [PATCH 0642/1195] Upgrade to Chrome 45 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index cf133b8ebfe..10d2bfe6830 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit cf133b8ebfeb3579032d3092351c801a3112aa7c +Subproject commit 10d2bfe683038c79d76d5facd3771da535c9329b From 38a211db2eadbd79e3c831742d7b76afa4831d79 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Sep 2015 15:16:34 +0800 Subject: [PATCH 0643/1195] Fix API changes --- brightray/browser/devtools_ui.cc | 14 +++++++------- brightray/browser/inspectable_web_contents_impl.cc | 8 ++++---- brightray/browser/inspectable_web_contents_impl.h | 2 +- brightray/browser/network_delegate.cc | 5 ----- brightray/browser/network_delegate.h | 1 - brightray/browser/permission_manager.cc | 4 ++-- brightray/browser/permission_manager.h | 4 ++-- brightray/browser/url_request_context_getter.cc | 5 +++-- 8 files changed, 19 insertions(+), 24 deletions(-) diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 8f8ded3b76d..2e08a32d8fb 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -29,19 +29,19 @@ std::string PathWithoutParams(const std::string& path) { std::string GetMimeTypeForPath(const std::string& path) { std::string filename = PathWithoutParams(path); - if (EndsWith(filename, ".html", false)) { + if (base::EndsWith(filename, ".html", false)) { return "text/html"; - } else if (EndsWith(filename, ".css", false)) { + } else if (base::EndsWith(filename, ".css", false)) { return "text/css"; - } else if (EndsWith(filename, ".js", false)) { + } else if (base::EndsWith(filename, ".js", false)) { return "application/javascript"; - } else if (EndsWith(filename, ".png", false)) { + } else if (base::EndsWith(filename, ".png", false)) { return "image/png"; - } else if (EndsWith(filename, ".gif", false)) { + } else if (base::EndsWith(filename, ".gif", false)) { return "image/gif"; - } else if (EndsWith(filename, ".svg", false)) { + } else if (base::EndsWith(filename, ".svg", false)) { return "image/svg+xml"; - } else if (EndsWith(filename, ".manifest", false)) { + } else if (base::EndsWith(filename, ".manifest", false)) { return "text/cache-manifest"; } return "text/html"; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 1aa442f09d0..59647b9a7f0 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -282,13 +282,13 @@ void InspectableWebContentsImpl::CallClientFunction(const std::string& function_ std::string javascript = function_name + "("; if (arg1) { std::string json; - base::JSONWriter::Write(arg1, &json); + base::JSONWriter::Write(*arg1, &json); javascript.append(json); if (arg2) { - base::JSONWriter::Write(arg2, &json); + base::JSONWriter::Write(*arg2, &json); javascript.append(", ").append(json); if (arg3) { - base::JSONWriter::Write(arg3, &json); + base::JSONWriter::Write(*arg3, &json); javascript.append(", ").append(json); } } @@ -586,7 +586,7 @@ bool InspectableWebContentsImpl::ShouldCreateWebContents( int route_id, int main_frame_route_id, WindowContainerType window_container_type, - const base::string16& frame_name, + const std::string& frame_name, const GURL& target_url, const std::string& partition_id, content::SessionStorageNamespace* session_storage_namespace) { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 62cfffec4f6..9b985bbc6c9 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -143,7 +143,7 @@ class InspectableWebContentsImpl : int route_id, int main_frame_route_id, WindowContainerType window_container_type, - const base::string16& frame_name, + const std::string& frame_name, const GURL& target_url, const std::string& partition_id, content::SessionStorageNamespace* session_storage_namespace) override; diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index 373b5819a71..dbaeeeed3e2 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -129,11 +129,6 @@ bool NetworkDelegate::OnCanAccessFile(const net::URLRequest& request, return true; } -bool NetworkDelegate::OnCanThrottleRequest( - const net::URLRequest& request) const { - return false; -} - bool NetworkDelegate::OnCanEnablePrivacyMode( const GURL& url, const GURL& first_party_for_cookies) const { diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 642b0b4cac5..f281f663ffa 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -61,7 +61,6 @@ class NetworkDelegate : public net::NetworkDelegate { net::CookieOptions* options) override; bool OnCanAccessFile(const net::URLRequest& request, const base::FilePath& path) const override; - bool OnCanThrottleRequest(const net::URLRequest& request) const override; bool OnCanEnablePrivacyMode( const GURL& url, const GURL& first_party_for_cookies) const override; diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc index 5a2d4ee54c3..1290739c360 100644 --- a/brightray/browser/permission_manager.cc +++ b/brightray/browser/permission_manager.cc @@ -17,7 +17,7 @@ PermissionManager::~PermissionManager() { void PermissionManager::RequestPermission( content::PermissionType permission, - content::WebContents* web_contents, + content::RenderFrameHost* render_frame_host, int request_id, const GURL& requesting_origin, bool user_gesture, @@ -27,7 +27,7 @@ void PermissionManager::RequestPermission( void PermissionManager::CancelPermissionRequest( content::PermissionType permission, - content::WebContents* web_contents, + content::RenderFrameHost* render_frame_host, int request_id, const GURL& requesting_origin) { } diff --git a/brightray/browser/permission_manager.h b/brightray/browser/permission_manager.h index d40bcd95e1f..a0860dd39bd 100644 --- a/brightray/browser/permission_manager.h +++ b/brightray/browser/permission_manager.h @@ -19,13 +19,13 @@ class PermissionManager : public content::PermissionManager { // content::PermissionManager: void RequestPermission( content::PermissionType permission, - content::WebContents* web_contents, + content::RenderFrameHost* render_frame_host, int request_id, const GURL& requesting_origin, bool user_gesture, const base::Callback& callback) override; void CancelPermissionRequest(content::PermissionType permission, - content::WebContents* web_contents, + content::RenderFrameHost* render_frame_host, int request_id, const GURL& requesting_origin) override; void ResetPermission(content::PermissionType permission, diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index e390f1c2afe..b27a94cb3a7 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -143,7 +143,7 @@ URLRequestContextGetter::URLRequestContextGetter( // must synchronously run on the glib message loop. This will be passed to // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( - io_loop_->message_loop_proxy(), file_loop_->message_loop_proxy())); + io_loop_->task_runner(), file_loop_->task_runner())); } URLRequestContextGetter::~URLRequestContextGetter() { @@ -233,7 +233,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { url_sec_mgr_.get(), host_resolver.get(), std::string(), // gssapi_library_name - false, // negotiate_disable_cname_lookup + std::string(), // gssapi_library_nam + false, // auth_android_negotiate_account_type true); // negotiate_enable_port storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); From 90125c44e39b561a26f87a57f7a7a1e5a966e599 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Sep 2015 17:29:30 +0800 Subject: [PATCH 0644/1195] Fix API changes on Linux --- brightray/browser/views/views_delegate.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc index 0d28ddcc321..0dbdf37dc68 100644 --- a/brightray/browser/views/views_delegate.cc +++ b/brightray/browser/views/views_delegate.cc @@ -13,13 +13,9 @@ namespace brightray { ViewsDelegate::ViewsDelegate() { - DCHECK(!views::ViewsDelegate::views_delegate); - views::ViewsDelegate::views_delegate = this; } ViewsDelegate::~ViewsDelegate() { - DCHECK_EQ(views::ViewsDelegate::views_delegate, this); - views::ViewsDelegate::views_delegate = NULL; } void ViewsDelegate::SaveWindowPlacement(const views::Widget* window, From f077a514596fb2fe39dd0cb2f2ae5784603857a9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Sep 2015 17:49:51 +0800 Subject: [PATCH 0645/1195] Define ENABLE_WEBRTC --- brightray/brightray.gypi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 82f4cdf55ad..12c5049e890 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -118,6 +118,8 @@ 'Common_Base': { 'abstract': 1, 'defines': [ + # Used by content_browser_client.h: + 'ENABLE_WEBRTC', # We are using Release version libchromiumcontent: 'NDEBUG', # Needed by gin: From dca5c763e9b99c4eab374bf5628f380decb916f6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 2 Sep 2015 18:25:59 +0800 Subject: [PATCH 0646/1195] Use the new devtools URL --- brightray/browser/devtools_ui.cc | 41 +++++++++++++++---- .../browser/inspectable_web_contents_impl.cc | 12 +++--- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 2e08a32d8fb..390a2dbf216 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -20,7 +20,8 @@ namespace brightray { namespace { -const char kChromeUIDevToolsBundledHost[] = "devtools"; +const char kChromeUIDevToolsHost[] = "devtools"; +const char kChromeUIDevToolsBundledPath[] = "bundled"; std::string PathWithoutParams(const std::string& path) { return GURL(std::string("chrome-devtools://devtools/") + path) @@ -53,19 +54,23 @@ class BundledDataSource : public content::URLDataSource { // content::URLDataSource implementation. std::string GetSource() const override { - return kChromeUIDevToolsBundledHost; + return kChromeUIDevToolsHost; } void StartDataRequest(const std::string& path, int render_process_id, - int render_view_id, + int render_frame_id, const GotDataCallback& callback) override { - std::string filename = PathWithoutParams(path); - base::StringPiece resource = - content::DevToolsFrontendHost::GetFrontendResource(filename); - scoped_refptr bytes( - new base::RefCountedStaticMemory(resource.data(), resource.length())); - callback.Run(bytes.get()); + // Serve request from local bundle. + std::string bundled_path_prefix(kChromeUIDevToolsBundledPath); + bundled_path_prefix += "/"; + if (base::StartsWith(path, bundled_path_prefix, + base::CompareCase::INSENSITIVE_ASCII)) { + StartBundledDataRequest(path.substr(bundled_path_prefix.length()), + render_process_id, render_frame_id, callback); + return; + } + callback.Run(nullptr); } std::string GetMimeType(const std::string& path) const override { @@ -84,6 +89,24 @@ class BundledDataSource : public content::URLDataSource { return true; } + void StartBundledDataRequest( + const std::string& path, + int render_process_id, + int render_frame_id, + const content::URLDataSource::GotDataCallback& callback) { + std::string filename = PathWithoutParams(path); + base::StringPiece resource = + content::DevToolsFrontendHost::GetFrontendResource(filename); + + DLOG_IF(WARNING, resource.empty()) + << "Unable to find dev tool resource: " << filename + << ". If you compiled with debug_devtools=1, try running with " + "--debug-devtools."; + scoped_refptr bytes( + new base::RefCountedStaticMemory(resource.data(), resource.length())); + callback.Run(bytes.get()); + } + private: virtual ~BundledDataSource() {} DISALLOW_COPY_AND_ASSIGN(BundledDataSource); diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 59647b9a7f0..c7d93a7aca0 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -38,11 +38,13 @@ const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0, 1.1, 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 5.0 }; -const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/devtools.html?" - "can_dock=%s&" - "toolbarColor=rgba(223,223,223,1)&" - "textColor=rgba(0,0,0,1)&" - "experiments=true"; +const char kChromeUIDevToolsURL[] = + "chrome-devtools://devtools/bundled/inspector.html?" + "can_dock=%s&" + "toolbarColor=rgba(223,223,223,1)&" + "textColor=rgba(0,0,0,1)&" + "experiments=true"; + const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; const char kDevToolsZoomPref[] = "brightray.devtools.zoom"; const char kDevToolsPreferences[] = "brightray.devtools.preferences"; From af505db9082a1300e349ac1621ee1ca6929cf221 Mon Sep 17 00:00:00 2001 From: Takashi Toyoshima Date: Sat, 5 Sep 2015 14:50:47 +0900 Subject: [PATCH 0647/1195] Grant ChildProcessSecurityPolicy for MIDI from PermissionManager PermissionManager should set ChildProcessSecurityPolicy for MIDI SysEx permission. Otherwise, the browser kills unauthorized renderers that are going to send MIDI SysEx messages. Fixes #138. --- brightray/browser/permission_manager.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc index 1290739c360..24795ac279e 100644 --- a/brightray/browser/permission_manager.cc +++ b/brightray/browser/permission_manager.cc @@ -5,7 +5,10 @@ #include "browser/permission_manager.h" #include "base/callback.h" +#include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/permission_type.h" +#include "content/public/browser/render_frame_host.h" +#include "content/public/browser/render_process_host.h" namespace brightray { @@ -22,6 +25,10 @@ void PermissionManager::RequestPermission( const GURL& requesting_origin, bool user_gesture, const base::Callback& callback) { + if (permission == content::PermissionType::MIDI_SYSEX) { + content::ChildProcessSecurityPolicy::GetInstance()-> + GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID()); + } callback.Run(content::PERMISSION_STATUS_GRANTED); } From 58fb166b0b3803d3f5a38eaf5f190bd440057e8d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 5 Sep 2015 19:46:55 +0800 Subject: [PATCH 0648/1195] Pass partition name instead of path to BrowserContext --- brightray/browser/browser_context.cc | 22 ++++++++++++++++++---- brightray/browser/browser_context.h | 3 +-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 756f27e0f95..207925c0aeb 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -16,9 +16,11 @@ #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/prefs/pref_service_factory.h" +#include "base/strings/string_util.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" +#include "net/base/escape.h" #include "net/ssl/client_cert_store.h" #if defined(USE_NSS_CERTS) @@ -33,6 +35,15 @@ using content::BrowserThread; namespace brightray { +namespace { + +// Convert string to lower case and escape it. +std::string MakePartitionName(const std::string& input) { + return net::EscapePath(base::StringToLowerASCII(input)); +} + +} // namespace + class BrowserContext::ResourceContext : public content::ResourceContext { public: ResourceContext() : getter_(nullptr) {} @@ -66,19 +77,22 @@ class BrowserContext::ResourceContext : public content::ResourceContext { URLRequestContextGetter* getter_; }; -BrowserContext::BrowserContext() : resource_context_(new ResourceContext) { +BrowserContext::BrowserContext() + : in_memory_(false), + resource_context_(new ResourceContext) { } -void BrowserContext::Initialize(const std::string& partition_path, bool in_memory) { +void BrowserContext::Initialize(const std::string& partition, bool in_memory) { if (!PathService::Get(DIR_USER_DATA, &path_)) { PathService::Get(DIR_APP_DATA, &path_); path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); PathService::Override(DIR_USER_DATA, path_); } - if (!partition_path.empty()) - path_ = path_.Append(base::FilePath::FromUTF8Unsafe(partition_path)); in_memory_ = in_memory; + if (!in_memory && !partition.empty()) + path_ = path_.Append(FILE_PATH_LITERAL("Partitions")) + .Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition))); auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); base::PrefServiceFactory prefs_factory; diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index ebf16a32b73..68328c0fae8 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -23,8 +23,7 @@ class BrowserContext : public content::BrowserContext, BrowserContext(); ~BrowserContext(); - virtual void Initialize(const std::string& partition_path, - bool in_memory = false); + void Initialize(const std::string& partition, bool in_memory = false); // content::BrowserContext: scoped_ptr CreateZoomLevelDelegate( From dc1e50c62e0e13935684ec22e9a6cfa1712c2c0a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 5 Sep 2015 20:03:18 +0800 Subject: [PATCH 0649/1195] Store BrowserContext in ref-counted ptr --- brightray/browser/browser_context.h | 5 ++++- brightray/browser/browser_main_parts.cc | 4 ++-- brightray/browser/browser_main_parts.h | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 68328c0fae8..68ed6aafd25 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -8,6 +8,7 @@ #include "browser/permission_manager.h" #include "browser/url_request_context_getter.h" +#include "base/memory/ref_counted.h" #include "content/public/browser/browser_context.h" class PrefRegistrySimple; @@ -17,7 +18,8 @@ namespace brightray { class PermissionManager; -class BrowserContext : public content::BrowserContext, +class BrowserContext : public base::RefCounted, + public content::BrowserContext, public brightray::URLRequestContextGetter::Delegate { public: BrowserContext(); @@ -66,6 +68,7 @@ class BrowserContext : public content::BrowserContext, base::FilePath GetPath() const override; private: + friend class base::RefCounted; class ResourceContext; void RegisterInternalPrefs(PrefRegistrySimple* pref_registry); diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index fd283f72ed0..1e35eca97dd 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -120,7 +120,7 @@ void BrowserMainParts::PreMainMessageLoopStart() { } void BrowserMainParts::PreMainMessageLoopRun() { - browser_context_.reset(CreateBrowserContext()); + browser_context_ = CreateBrowserContext(); browser_context_->Initialize(std::string()); content::WebUIControllerFactory::RegisterFactory( @@ -133,7 +133,7 @@ void BrowserMainParts::PreMainMessageLoopRun() { } void BrowserMainParts::PostMainMessageLoopRun() { - browser_context_.reset(); + browser_context_ = nullptr; } int BrowserMainParts::PreCreateThreads() { diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 8822cb7c09d..0e151d8dd48 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -6,6 +6,7 @@ #define BRIGHTRAY_BROWSER_BROWSER_MAIN_PARTS_H_ #include "base/compiler_specific.h" +#include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" @@ -55,7 +56,7 @@ class BrowserMainParts : public content::BrowserMainParts { void InitializeMainNib(); #endif - scoped_ptr browser_context_; + scoped_refptr browser_context_; scoped_ptr devtools_http_handler_; #if defined(TOOLKIT_VIEWS) From 1a8dc779514ffb3a5e8dcefc45899510f0b23e0c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 5 Sep 2015 20:52:50 +0800 Subject: [PATCH 0650/1195] Move management of browser context to BrowserContext --- brightray/browser/browser_context.cc | 24 ++++++++++++----- brightray/browser/browser_context.h | 34 ++++++++++++++++++++++--- brightray/browser/browser_main_parts.cc | 3 +-- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 207925c0aeb..ec9f681e428 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -44,6 +44,20 @@ std::string MakePartitionName(const std::string& input) { } // namespace +// static +BrowserContext::BrowserContextMap BrowserContext::browser_context_map_; + +// static +BrowserContext* BrowserContext::From(const std::string& partition, + bool in_memory) { + PartitionKey key(partition, in_memory); + if (!ContainsKey(browser_context_map_, key)) { + auto browser_context = BrowserContext::Create(partition, in_memory); + browser_context_map_[key] = make_scoped_refptr(browser_context); + } + return browser_context_map_[key].get(); +} + class BrowserContext::ResourceContext : public content::ResourceContext { public: ResourceContext() : getter_(nullptr) {} @@ -77,20 +91,16 @@ class BrowserContext::ResourceContext : public content::ResourceContext { URLRequestContextGetter* getter_; }; -BrowserContext::BrowserContext() - : in_memory_(false), +BrowserContext::BrowserContext(const std::string& partition, bool in_memory) + : in_memory_(in_memory), resource_context_(new ResourceContext) { -} - -void BrowserContext::Initialize(const std::string& partition, bool in_memory) { if (!PathService::Get(DIR_USER_DATA, &path_)) { PathService::Get(DIR_APP_DATA, &path_); path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); PathService::Override(DIR_USER_DATA, path_); } - in_memory_ = in_memory; - if (!in_memory && !partition.empty()) + if (!in_memory_ && !partition.empty()) path_ = path_.Append(FILE_PATH_LITERAL("Partitions")) .Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition))); diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 68ed6aafd25..b7cf340a1aa 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -5,6 +5,8 @@ #ifndef BRIGHTRAY_BROWSER_BROWSER_CONTEXT_H_ #define BRIGHTRAY_BROWSER_BROWSER_CONTEXT_H_ +#include + #include "browser/permission_manager.h" #include "browser/url_request_context_getter.h" @@ -22,10 +24,11 @@ class BrowserContext : public base::RefCounted, public content::BrowserContext, public brightray::URLRequestContextGetter::Delegate { public: - BrowserContext(); - ~BrowserContext(); + // Get or Create the BrowserContext according to its |partition| and |in_memory|. + static BrowserContext* From(const std::string& partition, bool in_memory); - void Initialize(const std::string& partition, bool in_memory = false); + // Create a new BrowserContext, embedders should implement it on their own. + static BrowserContext* Create(const std::string& partition, bool in_memory); // content::BrowserContext: scoped_ptr CreateZoomLevelDelegate( @@ -59,6 +62,9 @@ class BrowserContext : public base::RefCounted, PrefService* prefs() { return prefs_.get(); } protected: + BrowserContext(const std::string& partition, bool in_memory); + ~BrowserContext() override; + // Subclasses should override this to register custom preferences. virtual void RegisterPrefs(PrefRegistrySimple* pref_registry) {} @@ -73,6 +79,28 @@ class BrowserContext : public base::RefCounted, void RegisterInternalPrefs(PrefRegistrySimple* pref_registry); + // partition_id => browser_context + struct PartitionKey { + std::string partition; + bool in_memory; + + PartitionKey(const std::string& partition, bool in_memory) + : partition(partition), in_memory(in_memory) {} + + bool operator<(const PartitionKey& other) const { + if (partition != other.partition) + return in_memory < other.in_memory; + return partition < other.partition; + } + + bool operator==(const PartitionKey& other) const { + return (partition == other.partition) && (in_memory == other.in_memory); + } + }; + using BrowserContextMap = + std::map>; + static BrowserContextMap browser_context_map_; + base::FilePath path_; bool in_memory_; scoped_ptr resource_context_; diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 1e35eca97dd..01dae70fe69 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -121,7 +121,6 @@ void BrowserMainParts::PreMainMessageLoopStart() { void BrowserMainParts::PreMainMessageLoopRun() { browser_context_ = CreateBrowserContext(); - browser_context_->Initialize(std::string()); content::WebUIControllerFactory::RegisterFactory( WebUIControllerFactory::GetInstance()); @@ -146,7 +145,7 @@ int BrowserMainParts::PreCreateThreads() { } BrowserContext* BrowserMainParts::CreateBrowserContext() { - return new BrowserContext; + return BrowserContext::From("", false); } } // namespace brightray From d2ea3b496dec0a37ef69c6bba9374a040c58e1d7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 5 Sep 2015 22:34:42 +0800 Subject: [PATCH 0651/1195] Only store weak ref to BrowserContext --- brightray/browser/browser_context.cc | 32 +++++++++++++------------ brightray/browser/browser_context.h | 11 ++++++--- brightray/browser/browser_main_parts.cc | 6 +---- brightray/browser/browser_main_parts.h | 4 ---- 4 files changed, 26 insertions(+), 27 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index ec9f681e428..f5d6effdeba 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -44,20 +44,6 @@ std::string MakePartitionName(const std::string& input) { } // namespace -// static -BrowserContext::BrowserContextMap BrowserContext::browser_context_map_; - -// static -BrowserContext* BrowserContext::From(const std::string& partition, - bool in_memory) { - PartitionKey key(partition, in_memory); - if (!ContainsKey(browser_context_map_, key)) { - auto browser_context = BrowserContext::Create(partition, in_memory); - browser_context_map_[key] = make_scoped_refptr(browser_context); - } - return browser_context_map_[key].get(); -} - class BrowserContext::ResourceContext : public content::ResourceContext { public: ResourceContext() : getter_(nullptr) {} @@ -91,9 +77,25 @@ class BrowserContext::ResourceContext : public content::ResourceContext { URLRequestContextGetter* getter_; }; +// static +BrowserContext::BrowserContextMap BrowserContext::browser_context_map_; + +// static +scoped_refptr BrowserContext::From( + 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_map_[key] = browser_context->weak_factory_.GetWeakPtr(); + return browser_context; +} + BrowserContext::BrowserContext(const std::string& partition, bool in_memory) : in_memory_(in_memory), - resource_context_(new ResourceContext) { + resource_context_(new ResourceContext), + weak_factory_(this) { if (!PathService::Get(DIR_USER_DATA, &path_)) { PathService::Get(DIR_APP_DATA, &path_); path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index b7cf340a1aa..0ae89f3e48c 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -11,6 +11,7 @@ #include "browser/url_request_context_getter.h" #include "base/memory/ref_counted.h" +#include "base/memory/weak_ptr.h" #include "content/public/browser/browser_context.h" class PrefRegistrySimple; @@ -25,10 +26,12 @@ class BrowserContext : public base::RefCounted, public brightray::URLRequestContextGetter::Delegate { public: // Get or Create the BrowserContext according to its |partition| and |in_memory|. - static BrowserContext* From(const std::string& partition, bool in_memory); + static scoped_refptr From( + const std::string& partition, bool in_memory); // Create a new BrowserContext, embedders should implement it on their own. - static BrowserContext* Create(const std::string& partition, bool in_memory); + static scoped_refptr Create( + const std::string& partition, bool in_memory); // content::BrowserContext: scoped_ptr CreateZoomLevelDelegate( @@ -98,7 +101,7 @@ class BrowserContext : public base::RefCounted, } }; using BrowserContextMap = - std::map>; + std::map>; static BrowserContextMap browser_context_map_; base::FilePath path_; @@ -108,6 +111,8 @@ class BrowserContext : public base::RefCounted, scoped_ptr prefs_; scoped_ptr permission_manager_; + base::WeakPtrFactory weak_factory_; + DISALLOW_COPY_AND_ASSIGN(BrowserContext); }; diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 01dae70fe69..b69c90f88a5 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -120,7 +120,7 @@ void BrowserMainParts::PreMainMessageLoopStart() { } void BrowserMainParts::PreMainMessageLoopRun() { - browser_context_ = CreateBrowserContext(); + browser_context_ = BrowserContext::From("", false); content::WebUIControllerFactory::RegisterFactory( WebUIControllerFactory::GetInstance()); @@ -144,8 +144,4 @@ int BrowserMainParts::PreCreateThreads() { return 0; } -BrowserContext* BrowserMainParts::CreateBrowserContext() { - return BrowserContext::From("", false); -} - } // namespace brightray diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 0e151d8dd48..5ed3e1eb1f6 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -46,10 +46,6 @@ class BrowserMainParts : public content::BrowserMainParts { void PostMainMessageLoopRun() override; int PreCreateThreads() override; - // Subclasses should override this to provide their own BrowserContxt - // implementation. The caller takes ownership of the returned object. - virtual BrowserContext* CreateBrowserContext(); - private: #if defined(OS_MACOSX) void IncreaseFileDescriptorLimit(); From 87a1b68c477cad2303a3ac33a080d1995f8a259f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 6 Sep 2015 10:29:59 +0800 Subject: [PATCH 0652/1195] Fix typo --- brightray/browser/browser_context.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 0ae89f3e48c..836d17c84bf 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -91,7 +91,7 @@ class BrowserContext : public base::RefCounted, : partition(partition), in_memory(in_memory) {} bool operator<(const PartitionKey& other) const { - if (partition != other.partition) + if (partition == other.partition) return in_memory < other.in_memory; return partition < other.partition; } From 451dd038660176b76f2198c956f8988a0b22ccda Mon Sep 17 00:00:00 2001 From: Robo Date: Mon, 7 Sep 2015 22:44:13 +0530 Subject: [PATCH 0653/1195] create net log file after context is created --- brightray/browser/net_log.cc | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index 59447436356..7d781a22e7b 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -30,6 +30,12 @@ scoped_ptr GetConstants() { } // namespace NetLog::NetLog() { +} + +NetLog::~NetLog() { +} + +void NetLog::StartLogging(net::URLRequestContext* url_request_context) { auto command_line = base::CommandLine::ForCurrentProcess(); if (!command_line->HasSwitch(switches::kLogNetLog)) return; @@ -46,17 +52,12 @@ NetLog::NetLog() { << "for net logging"; return; } -} - -NetLog::~NetLog() { -} - -void NetLog::StartLogging(net::URLRequestContext* url_request_context) { - if (!log_file_) - return; scoped_ptr constants(GetConstants()); - write_to_file_observer_.StartObserving(this, log_file_.Pass(), constants.get(), url_request_context); + write_to_file_observer_.StartObserving(this, + log_file_.Pass(), + constants.get(), + url_request_context); } } // namespace brightray From c30f458d4fb17655a86a8177d78b84c33dc6aa32 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Sep 2015 11:04:46 +0800 Subject: [PATCH 0654/1195] Add IsDevToolsViewFocused method --- .../browser/inspectable_web_contents_view.h | 1 + .../inspectable_web_contents_view_mac.h | 1 + .../inspectable_web_contents_view_mac.mm | 4 ++ .../mac/bry_inspectable_web_contents_view.h | 2 + .../mac/bry_inspectable_web_contents_view.mm | 38 +++++++++++++++++++ .../inspectable_web_contents_view_views.cc | 7 ++++ .../inspectable_web_contents_view_views.h | 1 + 7 files changed, 54 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_view.h b/brightray/browser/inspectable_web_contents_view.h index 469677a1ae6..2fabf5d2ba3 100644 --- a/brightray/browser/inspectable_web_contents_view.h +++ b/brightray/browser/inspectable_web_contents_view.h @@ -44,6 +44,7 @@ class InspectableWebContentsView { // Hide the DevTools view. virtual void CloseDevTools() = 0; virtual bool IsDevToolsViewShowing() = 0; + virtual bool IsDevToolsViewFocused() = 0; virtual void SetIsDocked(bool docked) = 0; virtual void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) = 0; diff --git a/brightray/browser/inspectable_web_contents_view_mac.h b/brightray/browser/inspectable_web_contents_view_mac.h index 0dbb7beb82c..e7ad57fbee8 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.h +++ b/brightray/browser/inspectable_web_contents_view_mac.h @@ -21,6 +21,7 @@ class InspectableWebContentsViewMac : public InspectableWebContentsView { void ShowDevTools() override; void CloseDevTools() override; bool IsDevToolsViewShowing() override; + bool IsDevToolsViewFocused() override; void SetIsDocked(bool docked) override; void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) override; diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index 42ca3c6f3a1..7d61fb0b7a8 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -42,6 +42,10 @@ bool InspectableWebContentsViewMac::IsDevToolsViewShowing() { return [view_ isDevToolsVisible]; } +bool InspectableWebContentsViewMac::IsDevToolsViewFocused() { + return [view_ isDevToolsFocused]; +} + void InspectableWebContentsViewMac::SetIsDocked(bool docked) { [view_ setIsDocked:docked]; } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 3b72aba08cc..7d8556973ab 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -18,6 +18,7 @@ using brightray::InspectableWebContentsViewMac; base::scoped_nsobject devtools_window_; BOOL devtools_visible_; BOOL devtools_docked_; + BOOL devtools_is_first_responder_; DevToolsContentsResizingStrategy strategy_; } @@ -25,6 +26,7 @@ using brightray::InspectableWebContentsViewMac; - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view; - (void)setDevToolsVisible:(BOOL)visible; - (BOOL)isDevToolsVisible; +- (BOOL)isDevToolsFocused; - (void)setIsDocked:(BOOL)docked; - (void)setContentsResizingStrategy:(const DevToolsContentsResizingStrategy&)strategy; - (void)setTitle:(NSString*)title; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 1bb84e5abb5..dd40f1e259d 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -19,6 +19,13 @@ using namespace brightray; inspectableWebContentsView_ = view; devtools_visible_ = NO; devtools_docked_ = NO; + devtools_is_first_responder_ = NO; + + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(viewDidBecomeFirstResponder:) + name:kViewDidBecomeFirstResponder + object:nil]; auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); auto contentsView = contents->GetNativeView(); @@ -86,6 +93,14 @@ using namespace brightray; return devtools_visible_; } +- (BOOL)isDevToolsFocused { + if (devtools_docked_) { + return [[self window] isKeyWindow] && devtools_is_first_responder_; + } else { + return [devtools_window_ isKeyWindow]; + } +} + - (void)setIsDocked:(BOOL)docked { // Revert to no-devtools state. [self setDevToolsVisible:NO]; @@ -156,6 +171,29 @@ using namespace brightray; [devtools_window_ setTitle:title]; } +- (void)viewDidBecomeFirstResponder:(NSNotification*)notification { + auto inspectable_web_contents = inspectableWebContentsView_->inspectable_web_contents(); + if (!inspectable_web_contents) + return; + auto webContents = inspectable_web_contents->GetWebContents(); + auto webContentsView = webContents->GetNativeView(); + + NSView* view = [notification object]; + if ([[webContentsView subviews] containsObject:view]) { + devtools_is_first_responder_ = NO; + return; + } + + auto devToolsWebContents = inspectable_web_contents->GetDevToolsWebContents(); + if (!devToolsWebContents) + return; + auto devToolsView = devToolsWebContents->GetNativeView(); + + if ([[devToolsView subviews] containsObject:view]) { + devtools_is_first_responder_ = YES; + } +} + #pragma mark - NSWindowDelegate - (void)windowWillClose:(NSNotification*)notification { diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 6a7dd75aa6f..79fcc103796 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -145,6 +145,13 @@ bool InspectableWebContentsViewViews::IsDevToolsViewShowing() { return devtools_visible_; } +bool InspectableWebContentsViewViews::IsDevToolsViewFocused() { + if (devtools_web_view_) + return devtools_web_view_->HasFocus(); + else + return false; +} + void InspectableWebContentsViewViews::SetIsDocked(bool docked) { CloseDevTools(); diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index a6c3ae62f8c..bcdbdb9518b 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -37,6 +37,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, void ShowDevTools() override; void CloseDevTools() override; bool IsDevToolsViewShowing() override; + bool IsDevToolsViewFocused() override; void SetIsDocked(bool docked) override; void SetContentsResizingStrategy( const DevToolsContentsResizingStrategy& strategy) override; From 352f758cd1ceeddb50298930a378b3092a154bc8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Sep 2015 11:24:35 +0800 Subject: [PATCH 0655/1195] Make DevToolsFocused in OS X --- .../browser/inspectable_web_contents_impl.cc | 2 ++ .../mac/bry_inspectable_web_contents_view.h | 1 + .../mac/bry_inspectable_web_contents_view.mm | 26 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index c7d93a7aca0..f6532e4ed0f 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -608,8 +608,10 @@ void InspectableWebContentsImpl::CloseContents(content::WebContents* source) { } void InspectableWebContentsImpl::OnWebContentsFocused() { +#if defined(TOOLKIT_VIEWS) if (view_->GetDelegate()) view_->GetDelegate()->DevToolsFocused(); +#endif } void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) { diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index 7d8556973ab..b67baa63857 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -24,6 +24,7 @@ using brightray::InspectableWebContentsViewMac; } - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view; +- (void)notifyDevToolsFocused; - (void)setDevToolsVisible:(BOOL)visible; - (BOOL)isDevToolsVisible; - (BOOL)isDevToolsFocused; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index dd40f1e259d..1123f7e0cd5 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -1,6 +1,7 @@ #include "browser/mac/bry_inspectable_web_contents_view.h" #include "browser/inspectable_web_contents_impl.h" +#include "browser/inspectable_web_contents_view_delegate.h" #include "browser/inspectable_web_contents_view_mac.h" #include "content/public/browser/render_widget_host_view.h" @@ -27,6 +28,12 @@ using namespace brightray; name:kViewDidBecomeFirstResponder object:nil]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(parentWindowBecameMain:) + name:NSWindowDidBecomeMainNotification + object:nil]; + auto contents = inspectableWebContentsView_->inspectable_web_contents()->GetWebContents(); auto contentsView = contents->GetNativeView(); [contentsView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; @@ -38,6 +45,11 @@ using namespace brightray; return self; } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { [self adjustSubviews]; } @@ -46,6 +58,11 @@ using namespace brightray; inspectableWebContentsView_->inspectable_web_contents()->ShowDevTools(); } +- (void)notifyDevToolsFocused { + if (inspectableWebContentsView_->GetDelegate()) + inspectableWebContentsView_->GetDelegate()->DevToolsFocused(); +} + - (void)setDevToolsVisible:(BOOL)visible { if (visible == devtools_visible_) return; @@ -191,9 +208,16 @@ using namespace brightray; if ([[devToolsView subviews] containsObject:view]) { devtools_is_first_responder_ = YES; + [self notifyDevToolsFocused]; } } +- (void)parentWindowBecameMain:(NSNotification*)notification { + NSWindow* parentWindow = [notification object]; + if ([self window] == parentWindow && devtools_docked_ && devtools_is_first_responder_) + [self notifyDevToolsFocused]; +} + #pragma mark - NSWindowDelegate - (void)windowWillClose:(NSNotification*)notification { @@ -211,6 +235,8 @@ using namespace brightray; content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView(); if (rwhv) rwhv->SetActive(true); + + [self notifyDevToolsFocused]; } - (void)windowDidResignMain:(NSNotification*)notification { From 34e1a38d188a803fb266461c0a87fb01247f7a83 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Sep 2015 11:59:57 +0800 Subject: [PATCH 0656/1195] Use 10.10 SDK --- brightray/brightray.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 12c5049e890..db67597b6d0 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -31,7 +31,7 @@ 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', 'GCC_ENABLE_CPP_RTTI': 'NO', 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', - 'MACOSX_DEPLOYMENT_TARGET': '10.9', + 'MACOSX_DEPLOYMENT_TARGET': '10.10', 'RUN_CLANG_STATIC_ANALYZER': 'YES', 'SDKROOT': 'macosx', 'USE_HEADER_MAP': 'NO', From 3f53564a4fefaed16b32a5833ec3bd102a262817 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Sep 2015 12:14:46 +0800 Subject: [PATCH 0657/1195] Use the SDKROOT under 10.10 --- brightray/brightray.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index db67597b6d0..4d014bb5c1f 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -33,7 +33,7 @@ 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', 'MACOSX_DEPLOYMENT_TARGET': '10.10', 'RUN_CLANG_STATIC_ANALYZER': 'YES', - 'SDKROOT': 'macosx', + 'SDKROOT': 'macosx10.10', 'USE_HEADER_MAP': 'NO', 'WARNING_CFLAGS': [ '-Wall', From fa588f104cf207dd1f625063ff19f93f98946fd2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 16 Sep 2015 19:54:52 +0800 Subject: [PATCH 0658/1195] Set MACOSX_DEPLOYMENT_TARGET to 10.8 Fixes atom/electron#2790. --- brightray/brightray.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 4d014bb5c1f..fa442967671 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -31,7 +31,7 @@ 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', 'GCC_ENABLE_CPP_RTTI': 'NO', 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', - 'MACOSX_DEPLOYMENT_TARGET': '10.10', + 'MACOSX_DEPLOYMENT_TARGET': '10.8', 'RUN_CLANG_STATIC_ANALYZER': 'YES', 'SDKROOT': 'macosx10.10', 'USE_HEADER_MAP': 'NO', From fc33eb99f79fe5377b98d2b3463d2c3f5d4b4b28 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 17 Sep 2015 11:19:08 +0800 Subject: [PATCH 0659/1195] Unsubscribe from NSNotificationCenter when WebContents is destroyed Due to ref-counted references the NSView is not destroyed immediately when WebContents is destroyed, so it is not reliable to do this in the destructor. --- brightray/browser/inspectable_web_contents_view_mac.mm | 1 + brightray/browser/mac/bry_inspectable_web_contents_view.h | 1 + brightray/browser/mac/bry_inspectable_web_contents_view.mm | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index 7d61fb0b7a8..f4c1cd5cb8b 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -19,6 +19,7 @@ InspectableWebContentsViewMac::InspectableWebContentsViewMac(InspectableWebConte } InspectableWebContentsViewMac::~InspectableWebContentsViewMac() { + [view_ removeObservers]; CloseDevTools(); } diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.h b/brightray/browser/mac/bry_inspectable_web_contents_view.h index b67baa63857..9819f2d767e 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.h +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.h @@ -24,6 +24,7 @@ using brightray::InspectableWebContentsViewMac; } - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view; +- (void)removeObservers; - (void)notifyDevToolsFocused; - (void)setDevToolsVisible:(BOOL)visible; - (BOOL)isDevToolsVisible; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 1123f7e0cd5..53afef7b6e5 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -45,9 +45,8 @@ using namespace brightray; return self; } -- (void)dealloc { +- (void)removeObservers { [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; } - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { From ca9a54a41eb70390a9ac18b3c695c07a933e0cde Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 17 Sep 2015 15:00:14 +0800 Subject: [PATCH 0660/1195] Check whether devtools is opened when executing js code Fixes atom/electron#2808. --- brightray/browser/inspectable_web_contents_impl.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index f6532e4ed0f..82ba5970ed6 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -281,6 +281,9 @@ void InspectableWebContentsImpl::CallClientFunction(const std::string& function_ const base::Value* arg1, const base::Value* arg2, const base::Value* arg3) { + if (!devtools_web_contents_) + return; + std::string javascript = function_name + "("; if (arg1) { std::string json; From 5d9c41c416505c11127ee3690486e049a9cb088b Mon Sep 17 00:00:00 2001 From: Robo Date: Mon, 21 Sep 2015 22:14:32 +0530 Subject: [PATCH 0661/1195] allowing delegates to provide their sslconfigservice --- brightray/browser/url_request_context_getter.cc | 6 +++++- brightray/browser/url_request_context_getter.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index b27a94cb3a7..4150b777f7a 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -117,6 +117,10 @@ URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(const base::Fil BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); } +net::SSLConfigService* URLRequestContextGetter::Delegate::CreateSSLConfigService() { + return new net::SSLConfigServiceDefaults; +} + URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, NetLog* net_log, @@ -239,7 +243,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); storage_->set_transport_security_state(new net::TransportSecurityState); - storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); + storage_->set_ssl_config_service(delegate_->CreateSSLConfigService()); storage_->set_http_auth_handler_factory(auth_handler_factory); scoped_ptr server_properties( new net::HttpServerPropertiesImpl); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index ab773b29a40..830171a52c2 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -43,6 +43,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { content::URLRequestInterceptorScopedVector* protocol_interceptors); virtual net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory( const base::FilePath& base_path); + virtual net::SSLConfigService* CreateSSLConfigService(); }; URLRequestContextGetter( From a1e646f1b346f030374227a20a8b7b5015c4438a Mon Sep 17 00:00:00 2001 From: Robo Date: Sat, 26 Sep 2015 23:49:27 +0530 Subject: [PATCH 0662/1195] enabling network emulation in devtools --- brightray/browser/browser_context.cc | 7 + brightray/browser/browser_context.h | 3 + .../browser/devtools_manager_delegate.cc | 7 +- brightray/browser/devtools_manager_delegate.h | 4 + .../net/devtools_network_conditions.cc | 35 +++ .../browser/net/devtools_network_conditions.h | 43 +++ .../net/devtools_network_controller.cc | 74 +++++ .../browser/net/devtools_network_controller.h | 40 +++ .../net/devtools_network_interceptor.cc | 255 ++++++++++++++++ .../net/devtools_network_interceptor.h | 84 ++++++ .../net/devtools_network_protocol_handler.cc | 173 +++++++++++ .../net/devtools_network_protocol_handler.h | 47 +++ .../net/devtools_network_transaction.cc | 283 ++++++++++++++++++ .../net/devtools_network_transaction.h | 131 ++++++++ .../devtools_network_transaction_factory.cc | 45 +++ .../devtools_network_transaction_factory.h | 39 +++ .../browser/url_request_context_getter.cc | 10 +- .../browser/url_request_context_getter.h | 3 + brightray/filenames.gypi | 12 + 19 files changed, 1292 insertions(+), 3 deletions(-) create mode 100644 brightray/browser/net/devtools_network_conditions.cc create mode 100644 brightray/browser/net/devtools_network_conditions.h create mode 100644 brightray/browser/net/devtools_network_controller.cc create mode 100644 brightray/browser/net/devtools_network_controller.h create mode 100644 brightray/browser/net/devtools_network_interceptor.cc create mode 100644 brightray/browser/net/devtools_network_interceptor.h create mode 100644 brightray/browser/net/devtools_network_protocol_handler.cc create mode 100644 brightray/browser/net/devtools_network_protocol_handler.h create mode 100644 brightray/browser/net/devtools_network_transaction.cc create mode 100644 brightray/browser/net/devtools_network_transaction.h create mode 100644 brightray/browser/net/devtools_network_transaction_factory.cc create mode 100644 brightray/browser/net/devtools_network_transaction_factory.h diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index f5d6effdeba..96e21ae854d 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -136,6 +136,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( DCHECK(!url_request_getter_.get()); url_request_getter_ = new URLRequestContextGetter( this, + GetDevToolsNetworkController(), net_log, GetPath(), in_memory_, @@ -147,6 +148,12 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( return url_request_getter_.get(); } +DevToolsNetworkController* BrowserContext::GetDevToolsNetworkController() { + if (!controller_) + controller_.reset(new DevToolsNetworkController); + return controller_.get(); +} + net::NetworkDelegate* BrowserContext::CreateNetworkDelegate() { return new NetworkDelegate; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 836d17c84bf..e6c339d8eef 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -7,6 +7,7 @@ #include +#include "browser/net/devtools_network_controller.h" #include "browser/permission_manager.h" #include "browser/url_request_context_getter.h" @@ -57,6 +58,7 @@ class BrowserContext : public base::RefCounted, NetLog* net_log, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors); + DevToolsNetworkController* GetDevToolsNetworkController(); net::URLRequestContextGetter* url_request_context_getter() const { return url_request_getter_.get(); @@ -107,6 +109,7 @@ class BrowserContext : public base::RefCounted, base::FilePath path_; bool in_memory_; scoped_ptr resource_context_; + scoped_ptr controller_; scoped_refptr url_request_getter_; scoped_ptr prefs_; scoped_ptr permission_manager_; diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index 89c3469fc0d..95b6fb3b5b2 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -6,6 +6,8 @@ #include +#include "browser/net/devtools_network_protocol_handler.h" + #include "base/bind.h" #include "base/command_line.h" #include "base/files/file_path.h" @@ -140,7 +142,8 @@ DevToolsManagerDelegate::CreateHttpHandler() { GetBrightrayUserAgent()); } -DevToolsManagerDelegate::DevToolsManagerDelegate() { +DevToolsManagerDelegate::DevToolsManagerDelegate() + : handler_(new DevToolsNetworkProtocolHandler) { // 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 @@ -155,7 +158,7 @@ DevToolsManagerDelegate::~DevToolsManagerDelegate() { base::DictionaryValue* DevToolsManagerDelegate::HandleCommand( content::DevToolsAgentHost* agent_host, base::DictionaryValue* command) { - return NULL; + return handler_->HandleCommand(agent_host, command); } } // namespace brightray diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h index 154ea9ccbf7..ed8e357482b 100644 --- a/brightray/browser/devtools_manager_delegate.h +++ b/brightray/browser/devtools_manager_delegate.h @@ -16,6 +16,8 @@ class DevToolsHttpHandler; namespace brightray { +class DevToolsNetworkProtocolHandler; + class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { public: static devtools_http_handler::DevToolsHttpHandler* CreateHttpHandler(); @@ -32,6 +34,8 @@ class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { base::DictionaryValue* command) override; private: + scoped_ptr handler_; + DISALLOW_COPY_AND_ASSIGN(DevToolsManagerDelegate); }; diff --git a/brightray/browser/net/devtools_network_conditions.cc b/brightray/browser/net/devtools_network_conditions.cc new file mode 100644 index 00000000000..0005c7f56c7 --- /dev/null +++ b/brightray/browser/net/devtools_network_conditions.cc @@ -0,0 +1,35 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "browser/net/devtools_network_conditions.h" + +namespace brightray { + +DevToolsNetworkConditions::DevToolsNetworkConditions(bool offline) + : offline_(offline), + latency_(0), + download_throughput_(0), + upload_throughput_(0) { +} + +DevToolsNetworkConditions::DevToolsNetworkConditions( + bool offline, + double latency, + double download_throughput, + double upload_throughput) + : offline_(offline), + latency_(latency), + download_throughput_(download_throughput), + upload_throughput_(upload_throughput) { +} + +DevToolsNetworkConditions::~DevToolsNetworkConditions() { +} + +bool DevToolsNetworkConditions::IsThrottling() const { + return !offline_ && ((latency_ != 0.0) || (download_throughput_ != 0.0) || + (upload_throughput_ != 0.0)); +} + +} // namespace brightray diff --git a/brightray/browser/net/devtools_network_conditions.h b/brightray/browser/net/devtools_network_conditions.h new file mode 100644 index 00000000000..81aae86f8d4 --- /dev/null +++ b/brightray/browser/net/devtools_network_conditions.h @@ -0,0 +1,43 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BROWSER_DEVTOOLS_NETWORK_CONDITIONS_H_ +#define BROWSER_DEVTOOLS_NETWORK_CONDITIONS_H_ + +#include +#include + +#include "base/macros.h" +#include "url/gurl.h" + +namespace brightray { + +class DevToolsNetworkConditions { + public: + explicit DevToolsNetworkConditions(bool offline); + DevToolsNetworkConditions(bool offline, + double latency, + double download_throughput, + double upload_throughput); + ~DevToolsNetworkConditions(); + + bool IsThrottling() const; + + bool offline() const { return offline_; } + double latency() const { return latency_; } + double download_throughput() const { return download_throughput_; } + double upload_throughput() const { return upload_throughput_; } + + private: + const bool offline_; + const double latency_; + const double download_throughput_; + const double upload_throughput_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkConditions); +}; + +} // namespace brightray + +#endif // BROWSER_DEVTOOLS_NETWORK_CONDITIONS_H_ diff --git a/brightray/browser/net/devtools_network_controller.cc b/brightray/browser/net/devtools_network_controller.cc new file mode 100644 index 00000000000..42ebf06471f --- /dev/null +++ b/brightray/browser/net/devtools_network_controller.cc @@ -0,0 +1,74 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/net/devtools_network_controller.h" + +#include "browser/net/devtools_network_conditions.h" +#include "browser/net/devtools_network_interceptor.h" +#include "browser/net/devtools_network_transaction.h" + +#include "base/bind.h" +#include "content/public/browser/browser_thread.h" + +using content::BrowserThread; + +namespace brightray { + +DevToolsNetworkController::DevToolsNetworkController() + : default_interceptor_(new DevToolsNetworkInterceptor) { +} + +DevToolsNetworkController::~DevToolsNetworkController() { +} + +void DevToolsNetworkController::SetNetworkState( + const std::string& client_id, + scoped_ptr conditions) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + + if (client_id.empty()) { + if (!conditions) + return; + default_interceptor_->UpdateConditions(conditions.Pass()); + return; + } + + auto interceptor = interceptors_.get(client_id); + if (!interceptor) { + if (!conditions) + return; + scoped_ptr new_interceptor( + new DevToolsNetworkInterceptor); + new_interceptor->UpdateConditions(conditions.Pass()); + interceptors_.set(client_id, new_interceptor.Pass()); + } else { + if (!conditions) { + scoped_ptr online_conditions( + new DevToolsNetworkConditions(false)); + interceptor->UpdateConditions(online_conditions.Pass()); + interceptors_.erase(client_id); + } else { + interceptor->UpdateConditions(conditions.Pass()); + } + } +} + +base::WeakPtr +DevToolsNetworkController::GetInterceptor(DevToolsNetworkTransaction* transaction) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + DCHECK(transaction->request()); + + if (!interceptors_.size()) + return default_interceptor_->GetWeakPtr(); + + transaction->ProcessRequest(); + auto& client_id = transaction->client_id(); + auto interceptor = interceptors_.get(client_id); + if (!interceptor) + return default_interceptor_->GetWeakPtr(); + + return interceptor->GetWeakPtr(); +} + +} // namespace brightray diff --git a/brightray/browser/net/devtools_network_controller.h b/brightray/browser/net/devtools_network_controller.h new file mode 100644 index 00000000000..a73268f798f --- /dev/null +++ b/brightray/browser/net/devtools_network_controller.h @@ -0,0 +1,40 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BROWSER_DEVTOOLS_NETWORK_CONTROLLER_H_ +#define BROWSER_DEVTOOLS_NETWORK_CONTROLLER_H_ + +#include "base/containers/scoped_ptr_hash_map.h" +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" + +namespace brightray { + +class DevToolsNetworkConditions; +class DevToolsNetworkInterceptor; +class DevToolsNetworkTransaction; + +class DevToolsNetworkController { + public: + DevToolsNetworkController(); + virtual ~DevToolsNetworkController(); + + void SetNetworkState(const std::string& client_id, + scoped_ptr conditions); + base::WeakPtr GetInterceptor( + DevToolsNetworkTransaction* transaction); + + private: + using InterceptorMap = base::ScopedPtrHashMap>; + scoped_ptr default_interceptor_; + InterceptorMap interceptors_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController); +}; + +} // namespace brightray + +#endif // BROWSER_DEVTOOLS_NETWORK_CONTROLLER_H_ diff --git a/brightray/browser/net/devtools_network_interceptor.cc b/brightray/browser/net/devtools_network_interceptor.cc new file mode 100644 index 00000000000..78afb00a09a --- /dev/null +++ b/brightray/browser/net/devtools_network_interceptor.cc @@ -0,0 +1,255 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "browser/net/devtools_network_interceptor.h" + +#include + +#include "browser/net/devtools_network_conditions.h" +#include "browser/net/devtools_network_transaction.h" + +#include "base/time/time.h" +#include "net/base/load_timing_info.h" + +namespace brightray { + +namespace { + +int64_t kPacketSize = 1500; + +} // namespace + +DevToolsNetworkInterceptor::DevToolsNetworkInterceptor() + : conditions_(new DevToolsNetworkConditions(false)), + weak_ptr_factory_(this) { +} + +DevToolsNetworkInterceptor::~DevToolsNetworkInterceptor() { +} + +base::WeakPtr +DevToolsNetworkInterceptor::GetWeakPtr() { + return weak_ptr_factory_.GetWeakPtr(); +} + +void DevToolsNetworkInterceptor::UpdateConditions( + scoped_ptr conditions) { + DCHECK(conditions); + base::TimeTicks now = base::TimeTicks::Now(); + if (conditions_->IsThrottling()) + UpdateThrottledTransactions(now); + + conditions_ = conditions.Pass(); + + if (conditions_->offline()) { + timer_.Stop(); + throttled_transactions_.clear(); + suspended_transactions_.clear(); + Transactions old_transactions(transactions_); + Transactions::iterator it = old_transactions.begin(); + for (; it != old_transactions.end(); ++it) { + if (transactions_.find(*it) == transactions_.end()) + continue; + if (!(*it)->request() || (*it)->failed()) + continue; + if (ShouldFail(*it)) + (*it)->Fail(); + } + return; + } + + if (conditions_->IsThrottling()) { + DCHECK_NE(conditions_->download_throughput(), 0); + offset_ = now; + last_tick_ = 0; + int64_t us_tick_length = + (1000000L * kPacketSize) / conditions_->download_throughput(); + DCHECK_NE(us_tick_length, 0); + if (us_tick_length == 0) + us_tick_length = 1; + tick_length_ = base::TimeDelta::FromMicroseconds(us_tick_length); + latency_length_ = base::TimeDelta(); + double latency = conditions_->latency(); + if (latency > 0) + latency_length_ = base::TimeDelta::FromMillisecondsD(latency); + ArmTimer(now); + } else { + timer_.Stop(); + + std::vector throttled_transactions; + throttled_transactions.swap(throttled_transactions_); + for (auto& throttled_transaction : throttled_transactions) + FireThrottledCallback(throttled_transaction); + + SuspendedTransactions suspended_transactions; + suspended_transactions.swap(suspended_transactions_); + for (auto& suspended_transaction : suspended_transactions) + FireThrottledCallback(suspended_transaction.first); + } +} + +void DevToolsNetworkInterceptor::AddTransaction( + DevToolsNetworkTransaction* transaction) { + DCHECK(transactions_.find(transaction) == transactions_.end()); + transactions_.insert(transaction); +} + +void DevToolsNetworkInterceptor::RemoveTransaction( + DevToolsNetworkTransaction* transaction) { + DCHECK(transactions_.find(transaction) != transactions_.end()); + transactions_.erase(transaction); + + if (!conditions_->IsThrottling()) + return; + + base::TimeTicks now = base::TimeTicks::Now(); + UpdateThrottledTransactions(now); + throttled_transactions_.erase(std::remove(throttled_transactions_.begin(), + throttled_transactions_.end(), transaction), + throttled_transactions_.end()); + + SuspendedTransactions::iterator it = suspended_transactions_.begin(); + for (; it != suspended_transactions_.end(); ++it) { + if (it->first == transaction) { + suspended_transactions_.erase(it); + break; + } + } + + ArmTimer(now); +} + +bool DevToolsNetworkInterceptor::ShouldFail( + const DevToolsNetworkTransaction* transaction) { + return conditions_->offline(); +} + +bool DevToolsNetworkInterceptor::ShouldThrottle( + const DevToolsNetworkTransaction* transaction) { + return conditions_->IsThrottling(); +} + +void DevToolsNetworkInterceptor::ThrottleTransaction( + DevToolsNetworkTransaction* transaction, bool start) { + base::TimeTicks now = base::TimeTicks::Now(); + UpdateThrottledTransactions(now); + if (start && latency_length_ != base::TimeDelta()) { + net::LoadTimingInfo load_timing_info; + base::TimeTicks send_end; + if (transaction->GetLoadTimingInfo(&load_timing_info)) + send_end = load_timing_info.send_end; + if (send_end.is_null()) + send_end = now; + int64_t us_send_end = (send_end - base::TimeTicks()).InMicroseconds(); + suspended_transactions_.push_back( + SuspendedTransaction(transaction, us_send_end)); + UpdateSuspendedTransactions(now); + } else { + throttled_transactions_.push_back(transaction); + } + ArmTimer(now); +} + +void DevToolsNetworkInterceptor::UpdateThrottledTransactions( + base::TimeTicks now) { + int64_t last_tick = (now - offset_) / tick_length_; + int64_t ticks = last_tick - last_tick_; + last_tick_ = last_tick; + + int64_t length = throttled_transactions_.size(); + if (!length) { + UpdateSuspendedTransactions(now); + return; + } + + int64_t shift = ticks % length; + for (int64_t i = 0; i < length; ++i) { + throttled_transactions_[i]->DecreaseThrottledByteCount( + (ticks / length) * kPacketSize + (i < shift ? kPacketSize : 0)); + } + std::rotate(throttled_transactions_.begin(), + throttled_transactions_.begin() + shift, throttled_transactions_.end()); + + UpdateSuspendedTransactions(now); +} + +void DevToolsNetworkInterceptor::UpdateSuspendedTransactions( + base::TimeTicks now) { + int64_t activation_baseline = + (now - latency_length_ - base::TimeTicks()).InMicroseconds(); + SuspendedTransactions suspended_transactions; + SuspendedTransactions::iterator it = suspended_transactions_.begin(); + for (; it != suspended_transactions_.end(); ++it) { + if (it->second <= activation_baseline) + throttled_transactions_.push_back(it->first); + else + suspended_transactions.push_back(*it); + } + suspended_transactions_.swap(suspended_transactions); +} + +void DevToolsNetworkInterceptor::ArmTimer(base::TimeTicks now) { + size_t throttle_count = throttled_transactions_.size(); + size_t suspend_count = suspended_transactions_.size(); + if (!throttle_count && !suspend_count) + return; + + int64_t min_ticks_left = 0x10000L; + for (size_t i = 0; i < throttle_count; ++i) { + int64_t packets_left = (throttled_transactions_[i]->throttled_byte_count() + + kPacketSize - 1) / kPacketSize; + int64_t ticks_left = (i + 1) + throttle_count * (packets_left - 1); + if (i == 0 || ticks_left < min_ticks_left) + min_ticks_left = ticks_left; + } + + base::TimeTicks desired_time = + offset_ + tick_length_ * (last_tick_ + min_ticks_left); + + int64_t min_baseline = std::numeric_limits::max(); + for (size_t i = 0; i < suspend_count; ++i) { + if (suspended_transactions_[i].second < min_baseline) + min_baseline = suspended_transactions_[i].second; + } + + if (suspend_count) { + base::TimeTicks activation_time = base::TimeTicks() + + base::TimeDelta::FromMicroseconds(min_baseline) + latency_length_; + if (activation_time < desired_time) + desired_time = activation_time; + } + + timer_.Start(FROM_HERE, desired_time - now, + base::Bind(&DevToolsNetworkInterceptor::OnTimer, + base::Unretained(this))); +} + +void DevToolsNetworkInterceptor::OnTimer() { + base::TimeTicks now = base::TimeTicks::Now(); + UpdateThrottledTransactions(now); + + std::vector active_transactions; + std::vector finished_transactions; + size_t length = throttled_transactions_.size(); + for (size_t i = 0; i < length; ++i) { + if (throttled_transactions_[i]->throttled_byte_count() < 0) + finished_transactions.push_back(throttled_transactions_[i]); + else + active_transactions.push_back(throttled_transactions_[i]); + } + throttled_transactions_.swap(active_transactions); + + for (auto& transaction : finished_transactions) + FireThrottledCallback(transaction); + + ArmTimer(now); +} + +void DevToolsNetworkInterceptor::FireThrottledCallback( + DevToolsNetworkTransaction* transaction) { + if (transactions_.find(transaction) != transactions_.end()) + transaction->FireThrottledCallback(); +} + +} // namespace brightray diff --git a/brightray/browser/net/devtools_network_interceptor.h b/brightray/browser/net/devtools_network_interceptor.h new file mode 100644 index 00000000000..330a7340bd5 --- /dev/null +++ b/brightray/browser/net/devtools_network_interceptor.h @@ -0,0 +1,84 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BROWSER_DEVTOOLS_NETWORK_INTERCEPTOR_H_ +#define BROWSER_DEVTOOLS_NETWORK_INTERCEPTOR_H_ + +#include +#include +#include +#include + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "base/timer/timer.h" + +namespace base { +class TimeDelta; +class TimeTicks; +} + +namespace brightray { + +class DevToolsNetworkConditions; +class DevToolsNetworkTransaction; + +class DevToolsNetworkInterceptor { + public: + DevToolsNetworkInterceptor(); + virtual ~DevToolsNetworkInterceptor(); + + base::WeakPtr GetWeakPtr(); + + // Applies network emulation configuration. + void UpdateConditions(scoped_ptr conditions); + + void AddTransaction(DevToolsNetworkTransaction* transaction); + void RemoveTransaction(DevToolsNetworkTransaction* transaction); + + // Returns whether transaction should fail with |net::ERR_INTERNET_DISCONNECTED| + bool ShouldFail(const DevToolsNetworkTransaction* transaction); + // Returns whether transaction should be throttled. + bool ShouldThrottle(const DevToolsNetworkTransaction* transaction); + + void ThrottleTransaction(DevToolsNetworkTransaction* transaction, bool start); + + const DevToolsNetworkConditions* conditions() const { + return conditions_.get(); + } + + private: + void UpdateThrottledTransactions(base::TimeTicks now); + void UpdateSuspendedTransactions(base::TimeTicks now); + void ArmTimer(base::TimeTicks now); + void OnTimer(); + void FireThrottledCallback(DevToolsNetworkTransaction* transaction); + + scoped_ptr conditions_; + + using Transactions = std::set; + Transactions transactions_; + + // Transactions suspended for a latency period. + using SuspendedTransaction = std::pair; + using SuspendedTransactions = std::vector; + SuspendedTransactions suspended_transactions_; + + // Transactions waiting certain amount of transfer to be accounted. + std::vector throttled_transactions_; + + base::OneShotTimer timer_; + base::TimeTicks offset_; + base::TimeDelta tick_length_; + base::TimeDelta latency_length_; + uint64_t last_tick_; + + base::WeakPtrFactory weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkInterceptor); +}; + +} // namespace brightray + +#endif // BROWSER_DEVTOOLS_NETWORK_INTERCEPTOR_H_ diff --git a/brightray/browser/net/devtools_network_protocol_handler.cc b/brightray/browser/net/devtools_network_protocol_handler.cc new file mode 100644 index 00000000000..b94a0413289 --- /dev/null +++ b/brightray/browser/net/devtools_network_protocol_handler.cc @@ -0,0 +1,173 @@ +// Copyright (c) 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/net/devtools_network_protocol_handler.h" + +#include "browser/browser_context.h" +#include "browser/net/devtools_network_conditions.h" +#include "browser/net/devtools_network_controller.h" + +#include "base/strings/stringprintf.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/devtools_agent_host.h" + +using content::BrowserThread; + +namespace brightray { + +namespace { + +namespace params { + +const char kDownloadThroughput[] = "downloadThroughput"; +const char kLatency[] = "latency"; +const char kOffline[] = "offline"; +const char kUploadThroughput[] = "uploadThroughput"; +const char kResult[] = "result"; +const char kErrorCode[] = "code"; +const char kErrorMessage[] = "message"; + +} // namespace params + +const char kEmulateNetworkConditions[] = "Network.emulateNetworkConditions"; +const char kCanEmulateNetworkConditions[] = "Network.canEmulateNetworkConditions"; +const char kId[] = "id"; +const char kMethod[] = "method"; +const char kParams[] = "params"; +const char kError[] = "error"; +// JSON RPC 2.0 spec: http://www.jsonrpc.org/specification#error_object +const int kErrorInvalidParams = -32602; + + +bool ParseCommand(const base::DictionaryValue* command, + int* id, + std::string* method, + const base::DictionaryValue** params) { + if (!command) + return false; + + if (!command->GetInteger(kId, id) || *id < 0) + return false; + + if (!command->GetString(kMethod, method)) + return false; + + if (!command->GetDictionary(kParams, params)) + *params = nullptr; + + return true; +} + +scoped_ptr +CreateSuccessResponse(int id, scoped_ptr result) { + scoped_ptr response(new base::DictionaryValue); + response->SetInteger(kId, id); + response->Set(params::kResult, result.release()); + return response.Pass(); +} + +scoped_ptr +CreateFailureResponse(int id, const std::string& param) { + scoped_ptr response(new base::DictionaryValue); + auto error_object = new base::DictionaryValue; + response->Set(kError, error_object); + error_object->SetInteger(params::kErrorCode, kErrorInvalidParams); + error_object->SetString(params::kErrorMessage, + base::StringPrintf("Missing or Invalid '%s' parameter", param.c_str())); + return response.Pass(); +} + +void UpdateNetworkStateInIO(brightray::DevToolsNetworkController* controller, + const std::string& client_id, + scoped_ptr conditions) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + controller->SetNetworkState(client_id, conditions.Pass()); +} + +} // namespace + +DevToolsNetworkProtocolHandler::DevToolsNetworkProtocolHandler() { +} + +DevToolsNetworkProtocolHandler::~DevToolsNetworkProtocolHandler() { +} + +base::DictionaryValue* DevToolsNetworkProtocolHandler::HandleCommand( + content::DevToolsAgentHost* agent_host, + base::DictionaryValue* command) { + int id = 0; + std::string method; + const base::DictionaryValue* params = nullptr; + + if (!ParseCommand(command, &id, &method, ¶ms)) + return nullptr; + + if (method == kEmulateNetworkConditions) + return EmulateNetworkConditions(agent_host, id, params).release(); + + if (method == kCanEmulateNetworkConditions) + return CanEmulateNetworkConditions(agent_host, id, params).release(); + + return nullptr; +} + +scoped_ptr +DevToolsNetworkProtocolHandler::CanEmulateNetworkConditions( + content::DevToolsAgentHost* agent_host, + int id, + const base::DictionaryValue* params) { + scoped_ptr result(new base::DictionaryValue); + result->SetBoolean(params::kResult, true); + return CreateSuccessResponse(id, result.Pass()); +} + +scoped_ptr +DevToolsNetworkProtocolHandler::EmulateNetworkConditions( + content::DevToolsAgentHost* agent_host, + int id, + const base::DictionaryValue* params) { + bool offline = false; + if (!params || !params->GetBoolean(params::kOffline, &offline)) + return CreateFailureResponse(id, params::kOffline); + + double latency = 0.0; + if (!params->GetDouble(params::kLatency, &latency)) + return CreateFailureResponse(id, params::kLatency); + if (latency < 0.0) + latency = 0.0; + + double download_throughput = 0.0; + if (!params->GetDouble(params::kDownloadThroughput, &download_throughput)) + return CreateFailureResponse(id, params::kDownloadThroughput); + if (download_throughput < 0.0) + download_throughput = 0.0; + + double upload_throughput = 0.0; + if (!params->GetDouble(params::kUploadThroughput, &upload_throughput)) + return CreateFailureResponse(id, params::kUploadThroughput); + if (upload_throughput < 0.0) + upload_throughput = 0.0; + + scoped_ptr conditions( + new DevToolsNetworkConditions(offline, + latency, + download_throughput, + upload_throughput)); + UpdateNetworkState(agent_host, conditions.Pass()); + return scoped_ptr(); +} + +void DevToolsNetworkProtocolHandler::UpdateNetworkState( + content::DevToolsAgentHost* agent_host, + scoped_ptr conditions) { + auto browser_context = + static_cast(agent_host->GetBrowserContext()); + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, + base::Bind(&UpdateNetworkStateInIO, + browser_context->GetDevToolsNetworkController(), + agent_host->GetId(), + base::Passed(&conditions))); +} + +} // namespace brightray diff --git a/brightray/browser/net/devtools_network_protocol_handler.h b/brightray/browser/net/devtools_network_protocol_handler.h new file mode 100644 index 00000000000..4fba01b74d3 --- /dev/null +++ b/brightray/browser/net/devtools_network_protocol_handler.h @@ -0,0 +1,47 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BROWSER_DEVTOOLS_NETWORK_PROTOCOL_HANDLER_H_ +#define BROWSER_DEVTOOLS_NETWORK_PROTOCOL_HANDLER_H_ + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "base/values.h" + +namespace content { +class DevToolsAgentHost; +} + +namespace brightray { + +class DevToolsNetworkConditions; + +class DevToolsNetworkProtocolHandler { + public: + DevToolsNetworkProtocolHandler(); + ~DevToolsNetworkProtocolHandler(); + + base::DictionaryValue* HandleCommand( + content::DevToolsAgentHost* agent_host, + base::DictionaryValue* command); + + private: + scoped_ptr CanEmulateNetworkConditions( + content::DevToolsAgentHost* agent_host, + int command_id, + const base::DictionaryValue* params); + scoped_ptr EmulateNetworkConditions( + content::DevToolsAgentHost* agent_host, + int command_id, + const base::DictionaryValue* params); + void UpdateNetworkState( + content::DevToolsAgentHost* agent_host, + scoped_ptr conditions); + + DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkProtocolHandler); +}; + +} // namespace brightray + +#endif // BROWSER_DEVTOOLS_NETWORK_PROTOCOL_HANDLER_H_ diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc new file mode 100644 index 00000000000..c8c74a67999 --- /dev/null +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -0,0 +1,283 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/net/devtools_network_transaction.h" + +#include "browser/net/devtools_network_controller.h" +#include "browser/net/devtools_network_interceptor.h" + +#include "net/base/net_errors.h" +#include "net/base/upload_progress.h" +#include "net/http/http_network_transaction.h" +#include "net/http/http_request_info.h" +#include "net/socket/connection_attempts.h" + +namespace brightray { + +namespace { + +const char kDevToolsEmulateNetworkConditionsClientId[] = + "X-DevTools-Emulate-Network-Conditions-Client-Id"; + +} // namespace + +DevToolsNetworkTransaction::DevToolsNetworkTransaction( + DevToolsNetworkController* controller, + scoped_ptr transaction) + : controller_(controller), + transaction_(transaction.Pass()), + request_(nullptr), + failed_(false), + throttled_byte_count_(0), + callback_type_(NONE) { + proxy_callback_ = base::Bind(&DevToolsNetworkTransaction::OnCallback, + base::Unretained(this)); +} + +DevToolsNetworkTransaction::~DevToolsNetworkTransaction() { + if (interceptor_) + interceptor_->RemoveTransaction(this); +} + +void DevToolsNetworkTransaction::ProcessRequest() { + DCHECK(request_); + + bool has_devtools_client_id = request_->extra_headers.HasHeader( + kDevToolsEmulateNetworkConditionsClientId); + if (!has_devtools_client_id) + return; + + custom_request_.reset(new net::HttpRequestInfo(*request_)); + custom_request_->extra_headers.GetHeader( + kDevToolsEmulateNetworkConditionsClientId, &client_id_); + custom_request_->extra_headers.RemoveHeader( + kDevToolsEmulateNetworkConditionsClientId); + + request_ = custom_request_.get(); +} + +void DevToolsNetworkTransaction::Fail() { + DCHECK(request_); + DCHECK(!failed_); + + failed_ = true; + transaction_->SetBeforeNetworkStartCallback( + BeforeNetworkStartCallback()); + + if (callback_.is_null()) + return; + + net::CompletionCallback original_callback = callback_; + callback_.Reset(); + callback_type_ = NONE; + original_callback.Run(net::ERR_INTERNET_DISCONNECTED); +} + +void DevToolsNetworkTransaction::DecreaseThrottledByteCount( + int64_t delta) { + throttled_byte_count_ -= delta; +} + +int DevToolsNetworkTransaction::Start( + const net::HttpRequestInfo* request, + const net::CompletionCallback& callback, + const net::BoundNetLog& net_log) { + DCHECK(request); + + request_ = request; + interceptor_ = controller_->GetInterceptor(this); + interceptor_->AddTransaction(this); + + if (interceptor_->ShouldFail(this)) { + failed_ = true; + transaction_->SetBeforeNetworkStartCallback(BeforeNetworkStartCallback()); + return net::ERR_INTERNET_DISCONNECTED; + } + int rv = transaction_->Start(request_, proxy_callback_, net_log); + return SetupCallback(callback, rv, START); +} + +int DevToolsNetworkTransaction::RestartIgnoringLastError( + const net::CompletionCallback& callback) { + if (failed_) + return net::ERR_INTERNET_DISCONNECTED; + int rv = transaction_->RestartIgnoringLastError(proxy_callback_); + return SetupCallback(callback, rv, RESTART_IGNORING_LAST_ERROR); +} + +int DevToolsNetworkTransaction::RestartWithCertificate( + net::X509Certificate* client_certificate, + const net::CompletionCallback& callback) { + if (failed_) + return net::ERR_INTERNET_DISCONNECTED; + int rv = transaction_->RestartWithCertificate(client_certificate, proxy_callback_); + return SetupCallback(callback, rv, RESTART_WITH_CERTIFICATE); +} + +int DevToolsNetworkTransaction::RestartWithAuth( + const net::AuthCredentials& credentials, + const net::CompletionCallback& callback) { + if (failed_) + return net::ERR_INTERNET_DISCONNECTED; + int rv = transaction_->RestartWithAuth(credentials, proxy_callback_); + return SetupCallback(callback, rv, RESTART_WITH_AUTH); +} + +bool DevToolsNetworkTransaction::IsReadyToRestartForAuth() { + return transaction_->IsReadyToRestartForAuth(); +} + +int DevToolsNetworkTransaction::Read( + net::IOBuffer* buffer, + int length, + const net::CompletionCallback& callback) { + if (failed_) + return net::ERR_INTERNET_DISCONNECTED; + int rv = transaction_->Read(buffer, length, proxy_callback_); + return SetupCallback(callback, rv, READ); +} + +void DevToolsNetworkTransaction::StopCaching() { + transaction_->StopCaching(); +} + +bool DevToolsNetworkTransaction::GetFullRequestHeaders( + net::HttpRequestHeaders* headers) const { + return transaction_->GetFullRequestHeaders(headers); +} + +int64_t DevToolsNetworkTransaction::GetTotalReceivedBytes() const { + return transaction_->GetTotalReceivedBytes(); +} + +void DevToolsNetworkTransaction::DoneReading() { + transaction_->DoneReading(); +} + +const net::HttpResponseInfo* +DevToolsNetworkTransaction::GetResponseInfo() const { + return transaction_->GetResponseInfo(); +} + +net::LoadState DevToolsNetworkTransaction::GetLoadState() const { + return transaction_->GetLoadState(); +} + +net::UploadProgress DevToolsNetworkTransaction::GetUploadProgress() const { + return transaction_->GetUploadProgress(); +} + +void DevToolsNetworkTransaction::SetQuicServerInfo( + net::QuicServerInfo* info) { + transaction_->SetQuicServerInfo(info); +} + +bool DevToolsNetworkTransaction::GetLoadTimingInfo( + net::LoadTimingInfo* info) const { + return transaction_->GetLoadTimingInfo(info); +} + +void DevToolsNetworkTransaction::SetPriority(net::RequestPriority priority) { + transaction_->SetPriority(priority); +} + +void DevToolsNetworkTransaction::SetWebSocketHandshakeStreamCreateHelper( + net::WebSocketHandshakeStreamBase::CreateHelper* helper) { + transaction_->SetWebSocketHandshakeStreamCreateHelper(helper); +} + +void DevToolsNetworkTransaction::SetBeforeNetworkStartCallback( + const BeforeNetworkStartCallback& callback) { + transaction_->SetBeforeNetworkStartCallback(callback); +} + +void DevToolsNetworkTransaction::SetBeforeProxyHeadersSentCallback( + const BeforeProxyHeadersSentCallback& callback) { + transaction_->SetBeforeProxyHeadersSentCallback(callback); +} + +int DevToolsNetworkTransaction::ResumeNetworkStart() { + if (failed_) + return net::ERR_INTERNET_DISCONNECTED; + return transaction_->ResumeNetworkStart(); +} + +void DevToolsNetworkTransaction::GetConnectionAttempts( + net::ConnectionAttempts* out) const { + transaction_->GetConnectionAttempts(out); +} + +void DevToolsNetworkTransaction::OnCallback(int rv) { + if (failed_ || callback_.is_null()) + return; + + if (callback_type_ == START || callback_type_ == READ) { + if (interceptor_ && interceptor_->ShouldThrottle(this)) { + Throttle(rv); + return; + } + } + + net::CompletionCallback original_callback = callback_; + callback_.Reset(); + callback_type_ = NONE; + original_callback.Run(rv); +} + +int DevToolsNetworkTransaction::SetupCallback( + net::CompletionCallback callback, + int result, + CallbackType callback_type) { + DCHECK(callback_type_ == NONE); + + if (result == net::ERR_IO_PENDING) { + callback_type_ = callback_type; + callback_ = callback; + return result; + } + + if (!interceptor_ || !interceptor_->ShouldThrottle(this)) + return result; + + // Only START and READ operation throttling is supported. + if (callback_type != START && callback_type != READ) + return result; + + // In case of error |throttled_byte_count_| is unknown. + if (result < 0) + return result; + + // URLRequestJob relies on synchronous end-of-stream notification. + if (callback_type == READ && result == 0) + return result; + + callback_type_ = callback_type; + callback_ = callback; + Throttle(result); + return net::ERR_IO_PENDING; +} + +void DevToolsNetworkTransaction::Throttle(int result) { + throttled_result_ = result; + + if (callback_type_ == START) + throttled_byte_count_ += transaction_->GetTotalReceivedBytes(); + if (result > 0) + throttled_byte_count_ += result; + + if (interceptor_) + interceptor_->ThrottleTransaction(this, callback_type_ == START); +} + +void DevToolsNetworkTransaction::FireThrottledCallback() { + DCHECK(!callback_.is_null()); + DCHECK(callback_type_ == READ || callback_type_ == START); + + net::CompletionCallback original_callback = callback_; + callback_.Reset(); + callback_type_ = NONE; + original_callback.Run(throttled_result_); +} + +} // namespace brightray diff --git a/brightray/browser/net/devtools_network_transaction.h b/brightray/browser/net/devtools_network_transaction.h new file mode 100644 index 00000000000..19295bf0dc7 --- /dev/null +++ b/brightray/browser/net/devtools_network_transaction.h @@ -0,0 +1,131 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BROWSER_DEVTOOLS_NETWORK_TRANSACTION_H_ +#define BROWSER_DEVTOOLS_NETWORK_TRANSACTION_H_ + +#include + +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "net/base/completion_callback.h" +#include "net/base/load_states.h" +#include "net/base/request_priority.h" +#include "net/http/http_transaction.h" +#include "net/websockets/websocket_handshake_stream_base.h" + +namespace brightray { + +class DevToolsNetworkController; +class DevToolsNetworkInterceptor; + +class DevToolsNetworkTransaction : public net::HttpTransaction { + public: + DevToolsNetworkTransaction( + DevToolsNetworkController* controller, + scoped_ptr network_transaction); + ~DevToolsNetworkTransaction() override; + + // Checks if request contains DevTools specific headers. Found values are + // remembered and corresponding keys are removed from headers. + void ProcessRequest(); + + // Runs callback with net::ERR_INTERNET_DISCONNECTED result. + void Fail(); + + void DecreaseThrottledByteCount(int64_t delta); + void FireThrottledCallback(); + + // HttpTransaction methods: + int Start(const net::HttpRequestInfo* request, + const net::CompletionCallback& callback, + const net::BoundNetLog& net_log) override; + int RestartIgnoringLastError( + const net::CompletionCallback& callback) override; + int RestartWithCertificate(net::X509Certificate* client_cert, + const net::CompletionCallback& callback) override; + int RestartWithAuth(const net::AuthCredentials& credentials, + const net::CompletionCallback& callback) override; + bool IsReadyToRestartForAuth() override; + + int Read(net::IOBuffer* buf, + int buf_len, + const net::CompletionCallback& callback) override; + void StopCaching() override; + bool GetFullRequestHeaders(net::HttpRequestHeaders* headers) const override; + int64_t GetTotalReceivedBytes() const override; + void DoneReading() override; + const net::HttpResponseInfo* GetResponseInfo() const override; + net::LoadState GetLoadState() const override; + net::UploadProgress GetUploadProgress() const override; + void SetQuicServerInfo(net::QuicServerInfo* quic_server_info) override; + bool GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override; + void SetPriority(net::RequestPriority priority) override; + void SetWebSocketHandshakeStreamCreateHelper( + net::WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; + void SetBeforeNetworkStartCallback( + const BeforeNetworkStartCallback& callback) override; + void SetBeforeProxyHeadersSentCallback( + const BeforeProxyHeadersSentCallback& callback) override; + int ResumeNetworkStart() override; + void GetConnectionAttempts(net::ConnectionAttempts* out) const override; + + bool failed() const { return failed_; } + + const net::HttpRequestInfo* request() const { return request_; } + + int64_t throttled_byte_count() const { return throttled_byte_count_; } + + const std::string& client_id() const { + return client_id_; + } + + private: + enum CallbackType { + NONE, + READ, + RESTART_IGNORING_LAST_ERROR, + RESTART_WITH_AUTH, + RESTART_WITH_CERTIFICATE, + START + }; + + // Proxy callback handler. Runs saved callback. + void OnCallback(int result); + + int SetupCallback( + net::CompletionCallback callback, + int result, + CallbackType callback_type); + void Throttle(int result); + + DevToolsNetworkController* controller_; + base::WeakPtr interceptor_; + + // Modified request. Should be destructed after |transaction_| + scoped_ptr custom_request_; + + // Original network transaction. + scoped_ptr transaction_; + + const net::HttpRequestInfo* request_; + + // True if Fail was already invoked. + bool failed_; + + // Value of "X-DevTools-Emulate-Network-Conditions-Client-Id" request header. + std::string client_id_; + + int throttled_result_; + int64_t throttled_byte_count_; + CallbackType callback_type_; + net::CompletionCallback proxy_callback_; + net::CompletionCallback callback_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkTransaction); +}; + +} // namespace brightray + +#endif // BROWSER_DEVTOOLS_NETWORK_TRANSACTION_H_ diff --git a/brightray/browser/net/devtools_network_transaction_factory.cc b/brightray/browser/net/devtools_network_transaction_factory.cc new file mode 100644 index 00000000000..72367112f8f --- /dev/null +++ b/brightray/browser/net/devtools_network_transaction_factory.cc @@ -0,0 +1,45 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/net/devtools_network_transaction_factory.h" + +#include "browser/net/devtools_network_controller.h" +#include "browser/net/devtools_network_transaction.h" + +#include "net/base/net_errors.h" +#include "net/http/http_network_layer.h" +#include "net/http/http_network_transaction.h" + +namespace brightray { + +DevToolsNetworkTransactionFactory::DevToolsNetworkTransactionFactory( + DevToolsNetworkController* controller, + net::HttpNetworkSession* session) + : controller_(controller), + network_layer_(new net::HttpNetworkLayer(session)) { +} + +DevToolsNetworkTransactionFactory::~DevToolsNetworkTransactionFactory() { +} + +int DevToolsNetworkTransactionFactory::CreateTransaction( + net::RequestPriority priority, + scoped_ptr* transaction) { + scoped_ptr new_transaction; + int rv = network_layer_->CreateTransaction(priority, &new_transaction); + if (rv != net::OK) + return rv; + transaction->reset(new DevToolsNetworkTransaction(controller_, new_transaction.Pass())); + return net::OK; +} + +net::HttpCache* DevToolsNetworkTransactionFactory::GetCache() { + return network_layer_->GetCache(); +} + +net::HttpNetworkSession* DevToolsNetworkTransactionFactory::GetSession() { + return network_layer_->GetSession(); +} + +} // namespace brightray diff --git a/brightray/browser/net/devtools_network_transaction_factory.h b/brightray/browser/net/devtools_network_transaction_factory.h new file mode 100644 index 00000000000..a14d97c1d13 --- /dev/null +++ b/brightray/browser/net/devtools_network_transaction_factory.h @@ -0,0 +1,39 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BROWSER_DEVTOOLS_NETWORK_TRANSACTION_FACTORY_H_ +#define BROWSER_DEVTOOLS_NETWORK_TRANSACTION_FACTORY_H_ + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "net/base/request_priority.h" +#include "net/http/http_transaction_factory.h" + +namespace brightray { + +class DevToolsNetworkController; + +class DevToolsNetworkTransactionFactory : public net::HttpTransactionFactory { + public: + explicit DevToolsNetworkTransactionFactory( + DevToolsNetworkController* controller, + net::HttpNetworkSession* session); + ~DevToolsNetworkTransactionFactory() override; + + // net::HttpTransactionFactory: + int CreateTransaction(net::RequestPriority priority, + scoped_ptr* transaction) override; + net::HttpCache* GetCache() override; + net::HttpNetworkSession* GetSession() override; + + private: + DevToolsNetworkController* controller_; + scoped_ptr network_layer_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkTransactionFactory); +}; + +} // namespace brightray + +#endif // BROWSER_DEVTOOLS_NETWORK_TRANSACTION_FACTORY_H_ diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 4150b777f7a..840e86ce9c0 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -6,6 +6,8 @@ #include +#include "browser/net/devtools_network_controller.h" +#include "browser/net/devtools_network_transaction_factory.h" #include "browser/net_log.h" #include "browser/network_delegate.h" @@ -123,6 +125,7 @@ net::SSLConfigService* URLRequestContextGetter::Delegate::CreateSSLConfigService URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, + DevToolsNetworkController* controller, NetLog* net_log, const base::FilePath& base_path, bool in_memory, @@ -131,6 +134,7 @@ URLRequestContextGetter::URLRequestContextGetter( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors) : delegate_(delegate), + controller_(controller), net_log_(net_log), base_path_(base_path), in_memory_(in_memory), @@ -279,13 +283,17 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_host_resolver(host_resolver.Pass()); network_session_params.host_resolver = url_request_context_->host_resolver(); + net::HttpNetworkSession* session = new net::HttpNetworkSession(network_session_params); net::HttpCache::BackendFactory* backend = nullptr; if (in_memory_) { backend = net::HttpCache::DefaultBackend::InMemory(0); } else { backend = delegate_->CreateHttpCacheBackendFactory(base_path_); } - storage_->set_http_transaction_factory(new net::HttpCache(network_session_params, backend)); + storage_->set_http_transaction_factory(new net::HttpCache( + new DevToolsNetworkTransactionFactory(controller_, session), + url_request_context_->net_log(), + backend)); storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( &protocol_handlers_, &protocol_interceptors_)); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 830171a52c2..4794f1bf6e5 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -27,6 +27,7 @@ class URLRequestJobFactory; namespace brightray { +class DevToolsNetworkController; class NetLog; class URLRequestContextGetter : public net::URLRequestContextGetter { @@ -48,6 +49,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { URLRequestContextGetter( Delegate* delegate, + DevToolsNetworkController* controller, NetLog* net_log, const base::FilePath& base_path, bool in_memory, @@ -66,6 +68,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { private: Delegate* delegate_; + DevToolsNetworkController* controller_; NetLog* net_log_; base::FilePath base_path_; bool in_memory_; diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 8334e44cd5e..b614b6538f2 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -38,6 +38,18 @@ 'browser/media/media_capture_devices_dispatcher.h', 'browser/media/media_stream_devices_controller.cc', 'browser/media/media_stream_devices_controller.h', + 'browser/net/devtools_network_conditions.cc', + 'browser/net/devtools_network_conditions.h', + 'browser/net/devtools_network_controller.cc', + 'browser/net/devtools_network_controller.h', + 'browser/net/devtools_network_interceptor.cc', + 'browser/net/devtools_network_interceptor.h', + 'browser/net/devtools_network_protocol_handler.cc', + 'browser/net/devtools_network_protocol_handler.h', + 'browser/net/devtools_network_transaction_factory.cc', + 'browser/net/devtools_network_transaction_factory.h', + 'browser/net/devtools_network_transaction.cc', + 'browser/net/devtools_network_transaction.h', 'browser/net_log.cc', 'browser/net_log.h', 'browser/network_delegate.cc', From 9122922133c41d273eab05e2d9ed81ea1c810aa5 Mon Sep 17 00:00:00 2001 From: Robo Date: Wed, 30 Sep 2015 16:28:46 +0530 Subject: [PATCH 0663/1195] provide remoteBase to load remote devtools modules --- .../browser/inspectable_web_contents_impl.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 82ba5970ed6..1ff21b694a0 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -25,6 +25,7 @@ #include "content/public/browser/host_zoom_map.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" +#include "content/public/common/user_agent.h" #include "net/http/http_response_headers.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher_response_writer.h" @@ -40,10 +41,14 @@ const double kPresetZoomFactors[] = { 0.25, 0.333, 0.5, 0.666, 0.75, 0.9, 1.0, const char kChromeUIDevToolsURL[] = "chrome-devtools://devtools/bundled/inspector.html?" + "remoteBase=%s&" "can_dock=%s&" "toolbarColor=rgba(223,223,223,1)&" "textColor=rgba(0,0,0,1)&" "experiments=true"; +const char kChromeUIDevToolsRemoteFrontendBase[] = + "https://chrome-devtools-frontend.appspot.com/"; +const char kChromeUIDevToolsRemoteFrontendPath[] = "serve_file"; const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; const char kDevToolsZoomPref[] = "brightray.devtools.zoom"; @@ -101,6 +106,14 @@ double GetNextZoomLevel(double level, bool out) { return level; } +GURL GetRemoteBaseURL() { + return GURL(base::StringPrintf( + "%s%s/%s/", + kChromeUIDevToolsRemoteFrontendBase, + kChromeUIDevToolsRemoteFrontendPath, + content::GetWebKitRevision().c_str())); +} + // ResponseWriter ------------------------------------------------------------- class ResponseWriter : public net::URLFetcherResponseWriter { @@ -241,7 +254,9 @@ void InspectableWebContentsImpl::ShowDevTools() { web_contents_->GetMainFrame(), this)); agent_host_->AttachClient(this); - GURL devtools_url(base::StringPrintf(kChromeUIDevToolsURL, can_dock_ ? "true" : "")); + GURL devtools_url(base::StringPrintf(kChromeUIDevToolsURL, + GetRemoteBaseURL().spec().c_str(), + can_dock_ ? "true" : "")); devtools_web_contents_->GetController().LoadURL( devtools_url, content::Referrer(), From 50a95792a174e1ecb4acc5e1e979046410540dae Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 28 Sep 2015 11:09:19 -0700 Subject: [PATCH 0664/1195] Rewrite unity check to look for libunity SOs --- .../linux/notification_presenter_linux.cc | 46 +++++++++---------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 557e527047d..e77075470d1 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -7,14 +7,17 @@ #include "base/bind.h" #include "base/logging.h" +#include "base/files/file_enumerator.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" #include "common/application_info.h" -#include "dbus/dbus.h" #include "third_party/skia/include/core/SkBitmap.h" +using namespace base; +using namespace std; + namespace brightray { namespace { @@ -23,34 +26,29 @@ static bool unity_has_result = false; static bool unity_result = false; static bool UnityIsRunning() { + FileEnumerator* enumerator = NULL; + if (unity_has_result) { return unity_result; } + + // Look for the presence of libunity as our hint that we're under Ubuntu + FilePath haystack; + string needle("/usr/lib/libunity-"); - struct DBusError err; - struct DBusConnection* bus = NULL; - - dbus_error_init(&err); - - bus = dbus_bus_get(DBUS_BUS_SESSION, &err); - if (dbus_error_is_set(&err)) { - g_debug("Failed to get Session Bus reference"); - unity_result = false; - dbus_error_free(&err); - - goto out; + enumerator = new FileEnumerator(FilePath("/usr/lib"), false, FileEnumerator::FILES); + + while (!((haystack = enumerator->Next()).empty())) { + if (haystack.value().compare(0, needle.length(), needle) == 0) { + unity_result = true; + goto out; + } } - - unity_result = dbus_bus_name_has_owner(bus, "com.canonical.indicator.session", &err); - - if (dbus_error_is_set(&err)) { - unity_result = false; - dbus_error_free(&err); - } - -out: - if (bus) dbus_connection_unref(bus); - + + unity_result = false; + +out: + if (enumerator) delete enumerator; unity_has_result = true; return unity_result; } From 1a8377b198add8a6e005003d2f6d9c76c405ab2e Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Wed, 30 Sep 2015 09:14:31 -0700 Subject: [PATCH 0665/1195] Add environment variable as escape hatch --- brightray/browser/linux/notification_presenter_linux.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index e77075470d1..0e92eb5104f 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -13,6 +13,7 @@ #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" #include "common/application_info.h" +#include #include "third_party/skia/include/core/SkBitmap.h" using namespace base; @@ -31,6 +32,11 @@ static bool UnityIsRunning() { if (unity_has_result) { return unity_result; } + + if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER")) { + unity_result = true; + goto out; + } // Look for the presence of libunity as our hint that we're under Ubuntu FilePath haystack; From 5a97cfaa64236fdcb23c8c4e164ab11d60d4d0f6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 1 Oct 2015 17:30:59 +0800 Subject: [PATCH 0666/1195] Code cleanup --- .../linux/notification_presenter_linux.cc | 44 +++++++------------ 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 0e92eb5104f..10e8dec765f 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/logging.h" #include "base/files/file_enumerator.h" +#include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" #include "content/public/browser/desktop_notification_delegate.h" @@ -16,46 +17,33 @@ #include #include "third_party/skia/include/core/SkBitmap.h" -using namespace base; -using namespace std; - namespace brightray { namespace { -static bool unity_has_result = false; -static bool unity_result = false; +bool unity_has_result = false; +bool unity_result = false; -static bool UnityIsRunning() { - FileEnumerator* enumerator = NULL; +bool UnityIsRunning() { + if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER")) + return true; - if (unity_has_result) { + if (unity_has_result) return unity_result; - } - if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER")) { - unity_result = true; - goto out; - } - - // Look for the presence of libunity as our hint that we're under Ubuntu - FilePath haystack; - string needle("/usr/lib/libunity-"); + unity_has_result = true; - enumerator = new FileEnumerator(FilePath("/usr/lib"), false, FileEnumerator::FILES); - - while (!((haystack = enumerator->Next()).empty())) { - if (haystack.value().compare(0, needle.length(), needle) == 0) { + // Look for the presence of libunity as our hint that we're under Ubuntu. + base::FileEnumerator enumerator(base::FilePath("/usr/lib"), + false, base::FileEnumerator::FILES); + base::FilePath haystack; + while (!((haystack = enumerator.Next()).empty())) { + if (base::StartsWith(haystack.value(), "/usr/lib/libunity-", base::CompareCase::SENSITIVE)) { unity_result = true; - goto out; + break; } } - - unity_result = false; - -out: - if (enumerator) delete enumerator; - unity_has_result = true; + return unity_result; } From 64b03339646ba771869e56e4d33a66994203f8ea Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 2 Oct 2015 17:27:48 +0800 Subject: [PATCH 0667/1195] [OS X] Link dependent libraries for desktop capture API. --- brightray/brightray.gyp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b3c4e92e6fd..fce3e3573cf 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -112,6 +112,7 @@ 'link_settings': { 'libraries': [ '$(SDKROOT)/System/Library/Frameworks/AppKit.framework', + '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', ], }, 'conditions': [ @@ -122,6 +123,12 @@ '<(libchromiumcontent_dir)/libdevtools_discovery.a', '<(libchromiumcontent_dir)/libdevtools_http_handler.a', '<(libchromiumcontent_dir)/libhttp_server.a', + '<(libchromiumcontent_dir)/libdesktop_capture.a', + '<(libchromiumcontent_dir)/librtc_base.a', + '<(libchromiumcontent_dir)/librtc_base_approved.a', + '<(libchromiumcontent_dir)/libsystem_wrappers.a', + '<(libchromiumcontent_dir)/libwebrtc_common.a', + '<(libchromiumcontent_dir)/libyuv.a', ], }, }, { From 59cbd0a00defd67df7107f57ed6579ec3ea49a9d Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sat, 3 Oct 2015 10:49:42 +0800 Subject: [PATCH 0668/1195] [Windows] Link libraries for desktop capture API. --- brightray/brightray.gyp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index fce3e3573cf..cdc6e60907b 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -180,6 +180,13 @@ '<(libchromiumcontent_dir)/devtools_discovery.lib', '<(libchromiumcontent_dir)/devtools_http_handler.lib', '<(libchromiumcontent_dir)/http_server.lib', + '<(libchromiumcontent_dir)/desktop_capture.lib', + '<(libchromiumcontent_dir)/desktop_capture_differ_sse2.lib', + '<(libchromiumcontent_dir)/rtc_base.lib', + '<(libchromiumcontent_dir)/rtc_base_approved.lib', + '<(libchromiumcontent_dir)/system_wrappers.lib', + '<(libchromiumcontent_dir)/webrtc_common.lib', + '<(libchromiumcontent_dir)/libyuv.lib', ], }, }, { From 63085fb0b0d02b565967201a30af947e6d37baa5 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sat, 3 Oct 2015 13:43:20 +0800 Subject: [PATCH 0669/1195] [Linux] Link libraries for desktop capture API. --- brightray/brightray.gyp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index cdc6e60907b..f84ed74cda6 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -87,6 +87,13 @@ '<(libchromiumcontent_dir)/libdevtools_discovery.a', '<(libchromiumcontent_dir)/libdevtools_http_handler.a', '<(libchromiumcontent_dir)/libhttp_server.a', + '<(libchromiumcontent_dir)/libdesktop_capture.a', + '<(libchromiumcontent_dir)/libdesktop_capture_differ_sse2.a', + '<(libchromiumcontent_dir)/libsystem_wrappers.a', + '<(libchromiumcontent_dir)/librtc_base.a', + '<(libchromiumcontent_dir)/librtc_base_approved.a', + '<(libchromiumcontent_dir)/libwebrtc_common.a', + '<(libchromiumcontent_dir)/libyuv.a', ], }, }, { From 6044ab05f3e17c487105908556bf78641ab3a2df Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 4 Oct 2015 15:40:51 +0800 Subject: [PATCH 0670/1195] Ignore X Window System errors --- brightray/browser/browser_main_parts.cc | 99 ++++++++++++++++++++++--- brightray/browser/browser_main_parts.h | 1 + 2 files changed, 88 insertions(+), 12 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index b69c90f88a5..b87be5a8ee3 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -11,6 +11,7 @@ #include "base/command_line.h" #include "base/strings/string_number_conversions.h" #include "components/devtools_http_handler/devtools_http_handler.h" +#include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" #include "net/proxy/proxy_resolver_v8.h" @@ -19,21 +20,21 @@ #include "ui/views/widget/desktop_aura/desktop_screen.h" #endif -#if defined(USE_AURA) && defined(USE_X11) -#include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" -#include "ui/views/linux_ui/linux_ui.h" -#include "ui/wm/core/wm_state.h" -#endif - #if defined(TOOLKIT_VIEWS) #include "browser/views/views_delegate.h" #endif -#if defined(OS_LINUX) +#if defined(USE_X11) #include "base/environment.h" #include "base/path_service.h" #include "base/nix/xdg_util.h" +#include "base/thread_task_runner_handle.h" #include "browser/brightray_paths.h" +#include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" +#include "ui/base/x/x11_util.h" +#include "ui/base/x/x11_util_internal.h" +#include "ui/views/linux_ui/linux_ui.h" +#include "ui/wm/core/wm_state.h" #endif #if defined(OS_WIN) @@ -43,6 +44,8 @@ #include "ui/gfx/platform_font_win.h" #endif +using content::BrowserThread; + namespace brightray { namespace { @@ -58,7 +61,14 @@ int GetMinimumFontSize() { } #endif -#if defined(OS_LINUX) +#if defined(USE_X11) +// Indicates that we're currently responding to an IO error (by shutting down). +bool g_in_x11_io_error_handler = false; + +// Number of seconds to wait for UI thread to get an IO error if we get it on +// the background thread. +const int kWaitForUIThreadSeconds = 10; + void OverrideLinuxAppDataPath() { base::FilePath path; if (PathService::Get(DIR_APP_DATA, &path)) @@ -69,6 +79,53 @@ void OverrideLinuxAppDataPath() { base::nix::kDotConfigDir); PathService::Override(DIR_APP_DATA, path); } + +int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { + if (!g_in_x11_io_error_handler) { + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(&ui::LogErrorEventDescription, d, *error)); + } + return 0; +} + +// This function is used to help us diagnose crash dumps that happen +// during the shutdown process. +NOINLINE void WaitingForUIThreadToHandleIOError() { + // Ensure function isn't optimized away. + asm(""); + sleep(kWaitForUIThreadSeconds); +} + +int BrowserX11IOErrorHandler(Display* d) { + if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { + // Wait for the UI thread (which has a different connection to the X server) + // to get the error. We can't call shutdown from this thread without + // tripping an error. Doing it through a function so that we'll be able + // to see it in any crash dumps. + WaitingForUIThreadToHandleIOError(); + return 0; + } + + // If there's an IO error it likely means the X server has gone away. + // If this CHECK fails, then that means SessionEnding() below triggered some + // code that tried to talk to the X server, resulting in yet another error. + CHECK(!g_in_x11_io_error_handler); + + g_in_x11_io_error_handler = true; + LOG(ERROR) << "X IO error received (X server probably went away)"; + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); + + return 0; +} + +int X11EmptyErrorHandler(Display* d, XErrorEvent* error) { + return 0; +} + +int X11EmptyIOErrorHandler(Display* d) { + return 0; +} #endif } // namespace @@ -84,12 +141,14 @@ void BrowserMainParts::PreEarlyInitialization() { IncreaseFileDescriptorLimit(); #endif -#if defined(USE_AURA) && defined(USE_X11) +#if defined(USE_X11) views::LinuxUI::SetInstance(BuildGtk2UI()); -#endif - -#if defined(OS_LINUX) OverrideLinuxAppDataPath(); + + // Installs the X11 error handlers for the browser process used during + // startup. They simply print error messages and exit because + // we can't shutdown properly while creating and initializing services. + ui::SetX11ErrorHandlers(nullptr, nullptr); #endif } @@ -131,8 +190,24 @@ void BrowserMainParts::PreMainMessageLoopRun() { devtools_http_handler_.reset(DevToolsManagerDelegate::CreateHttpHandler()); } +void BrowserMainParts::PostMainMessageLoopStart() { +#if defined(USE_X11) + // Installs the X11 error handlers for the browser process after the + // main message loop has started. This will allow us to exit cleanly + // if X exits before us. + ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler); +#endif +} + void BrowserMainParts::PostMainMessageLoopRun() { browser_context_ = nullptr; + +#if defined(USE_X11) + // Unset the X11 error handlers. The X11 error handlers log the errors using a + // |PostTask()| on the message-loop. But since the message-loop is in the + // process of terminating, this can cause errors. + ui::SetX11ErrorHandlers(X11EmptyErrorHandler, X11EmptyIOErrorHandler); +#endif } int BrowserMainParts::PreCreateThreads() { diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 5ed3e1eb1f6..da35d78c229 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -43,6 +43,7 @@ class BrowserMainParts : public content::BrowserMainParts { void ToolkitInitialized() override; void PreMainMessageLoopStart() override; void PreMainMessageLoopRun() override; + void PostMainMessageLoopStart() override; void PostMainMessageLoopRun() override; int PreCreateThreads() override; From 6ca7767f09e375710cdb5229d7b08781e101e274 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 4 Oct 2015 16:52:14 +0800 Subject: [PATCH 0671/1195] linux: Set device scaling factor --- brightray/browser/browser_main_parts.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index b87be5a8ee3..6fc464fe7f2 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -212,10 +212,13 @@ void BrowserMainParts::PostMainMessageLoopRun() { int BrowserMainParts::PreCreateThreads() { #if defined(USE_AURA) - gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, - views::CreateDesktopScreen()); + gfx::Screen* screen = views::CreateDesktopScreen(); + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen); +#if defined(USE_X11) + views::LinuxUI::instance()->UpdateDeviceScaleFactor( + screen->GetPrimaryDisplay().device_scale_factor()); +#endif #endif - return 0; } From c205ab0944936532f34f407abb2108d45a1930c4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 4 Oct 2015 22:15:01 +0800 Subject: [PATCH 0672/1195] Fix tooltip can not show outside window --- brightray/browser/views/views_delegate.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc index 0dbdf37dc68..a18d52a6ae2 100644 --- a/brightray/browser/views/views_delegate.cc +++ b/brightray/browser/views/views_delegate.cc @@ -5,6 +5,7 @@ #include "browser/views/views_delegate.h" #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" +#include "ui/views/widget/native_widget_aura.h" #if defined(OS_LINUX) #include "ui/views/linux_ui/linux_ui.h" @@ -89,10 +90,13 @@ void ViewsDelegate::OnBeforeWidgetInit( if (params->native_widget) return; - // The native_widget is required when using aura. - if (params->type == views::Widget::InitParams::TYPE_MENU || - (params->parent == NULL && params->context == NULL && !params->child)) + if (params->parent && + params->type != views::Widget::InitParams::TYPE_MENU && + params->type != views::Widget::InitParams::TYPE_TOOLTIP) { + params->native_widget = new views::NativeWidgetAura(delegate); + } else { params->native_widget = new views::DesktopNativeWidgetAura(delegate); + } } From ef9f6eb8c3f2bda1dfb0de3aeca3f407d699b2d0 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 5 Oct 2015 12:50:18 +0800 Subject: [PATCH 0673/1195] Define related marcos for webrtc on Windows and OS X. --- brightray/brightray.gypi | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index fa442967671..cd567485a83 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -163,6 +163,13 @@ '-fno-rtti', ], }], # OS=="linux" + ['OS=="mac"', { + 'defines': [ + # The usage of "webrtc/modules/desktop_capture/desktop_capture_options.h" + # is required to see this macro. + 'WEBRTC_MAC', + ], + }], # OS=="mac" ['OS=="win"', { 'include_dirs': [ '<(libchromiumcontent_src_dir)/third_party/wtl/include', @@ -179,6 +186,9 @@ 'WIN32_LEAN_AND_MEAN', '_ATL_NO_OPENGL', '_SECURE_ATL', + # The usage of "webrtc/modules/desktop_capture/desktop_capture_options.h" + # is required to see this macro. + 'WEBRTC_WIN', ], 'conditions': [ ['target_arch=="x64"', { From 7f0b8f01e1779dbb5065a07445ffa7b01b81e103 Mon Sep 17 00:00:00 2001 From: joshaber Date: Mon, 5 Oct 2015 10:15:34 -0400 Subject: [PATCH 0674/1195] mac: Don't define an SDKROOT. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This way Xcode will use the latest SDK, whatever it is, and we don’t have to bump this every time Apple releases an OS update. --- brightray/brightray.gypi | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index fa442967671..e7006435c78 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -33,7 +33,6 @@ 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', 'MACOSX_DEPLOYMENT_TARGET': '10.8', 'RUN_CLANG_STATIC_ANALYZER': 'YES', - 'SDKROOT': 'macosx10.10', 'USE_HEADER_MAP': 'NO', 'WARNING_CFLAGS': [ '-Wall', From 3d0ab70aa128ceae37a47802a49eacbe4e674d8a Mon Sep 17 00:00:00 2001 From: joshaber Date: Mon, 5 Oct 2015 10:15:54 -0400 Subject: [PATCH 0675/1195] mac: Force Xcode to use C++11. For whatever reason, this is necessary in Xcode 7. --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index e7006435c78..4931cfc29c1 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -31,6 +31,7 @@ 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO', 'GCC_ENABLE_CPP_RTTI': 'NO', 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', + 'CLANG_CXX_LANGUAGE_STANDARD': 'c++11', 'MACOSX_DEPLOYMENT_TARGET': '10.8', 'RUN_CLANG_STATIC_ANALYZER': 'YES', 'USE_HEADER_MAP': 'NO', From 73632d4189744ac05f658b75e32e6dd6262a992a Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Tue, 6 Oct 2015 15:19:38 +0800 Subject: [PATCH 0676/1195] Fix RegisterPrefs not working in subclass. Don't call virtual function in subclass's constructor. --- brightray/browser/browser_context.cc | 3 +++ brightray/browser/browser_context.h | 1 + 2 files changed, 4 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index f5d6effdeba..a0349809f77 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -88,6 +88,7 @@ scoped_refptr BrowserContext::From( 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; } @@ -105,7 +106,9 @@ BrowserContext::BrowserContext(const std::string& partition, bool in_memory) if (!in_memory_ && !partition.empty()) path_ = path_.Append(FILE_PATH_LITERAL("Partitions")) .Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition))); +} +void BrowserContext::InitPrefs() { auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); base::PrefServiceFactory prefs_factory; prefs_factory.SetUserPrefsFile(prefs_path, diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 836d17c84bf..abfa860003c 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -62,6 +62,7 @@ class BrowserContext : public base::RefCounted, return url_request_getter_.get(); } + void InitPrefs(); PrefService* prefs() { return prefs_.get(); } protected: From 407b406f349fe0b9660d56d52ba42df7f9985d16 Mon Sep 17 00:00:00 2001 From: joshaber Date: Tue, 6 Oct 2015 16:07:54 -0400 Subject: [PATCH 0677/1195] Don't reference the dylib directly. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://forums.developer.apple.com/thread/4572 is the best reference I could find for this. Apple replaced (some?) dylibs with “text-based stub libraries” (.tbd’s). So we shouldn’t try to reference the dylib directly anymore. --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b3c4e92e6fd..b0ff498dcc1 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -153,7 +153,7 @@ '$(SDKROOT)/System/Library/Frameworks/CoreFoundation.framework', '$(SDKROOT)/System/Library/Frameworks/IOKit.framework', # content_browser.gypi: - '$(SDKROOT)/usr/lib/libbsm.dylib', + '-lbsm', # bluetooth.gyp: '$(SDKROOT)/System/Library/Frameworks/IOBluetooth.framework', ], From b7296d8a4eb70b7703c2d9030d8172316d2926b1 Mon Sep 17 00:00:00 2001 From: Robo Date: Fri, 9 Oct 2015 13:21:53 +0530 Subject: [PATCH 0678/1195] set accept-language header from system locale --- brightray/browser/url_request_context_getter.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 840e86ce9c0..6edd4b150eb 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -40,6 +40,7 @@ #include "net/url_request/url_request_context_storage.h" #include "net/url_request/url_request_intercepting_job_factory.h" #include "net/url_request/url_request_job_factory_impl.h" +#include "ui/base/l10n/l10n_util.h" #include "url/url_constants.h" #include "storage/browser/quota/special_storage_policy.h" @@ -191,8 +192,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_channel_id_service(make_scoped_ptr( new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), base::WorkerPool::GetTaskRunner(true)))); + + std::string accept_lang = l10n_util::GetApplicationLocale(""); storage_->set_http_user_agent_settings(new net::StaticHttpUserAgentSettings( - "en-us,en", delegate_->GetUserAgent())); + net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang), delegate_->GetUserAgent())); scoped_ptr host_resolver(net::HostResolver::CreateDefaultResolver(nullptr)); From 0659be44bcf3df722a49d9a63d28548c099d5860 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 28 Sep 2015 15:10:53 +0800 Subject: [PATCH 0679/1195] Update to mas branch of libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 10d2bfe6830..27ccc74468a 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 10d2bfe683038c79d76d5facd3771da535c9329b +Subproject commit 27ccc74468a444323f32dbe79219f049c9de9be6 From 7caaad2c7acaf976a99ce1f2e906d8f469849bfa Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 9 Oct 2015 21:29:51 +0800 Subject: [PATCH 0680/1195] Control linking of QTKit in electron --- brightray/brightray.gyp | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b0ff498dcc1..a93e83c3c77 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -142,7 +142,6 @@ '$(SDKROOT)/System/Library/Frameworks/CoreMIDI.framework', '$(SDKROOT)/System/Library/Frameworks/CoreVideo.framework', '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', - '$(SDKROOT)/System/Library/Frameworks/QTKit.framework', # surface.gyp: '$(SDKROOT)/System/Library/Frameworks/IOSurface.framework', # content_common.gypi: From 2981a7e25689ce3072938486b0c62ddd086501da Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 12 Oct 2015 21:09:39 +0800 Subject: [PATCH 0681/1195] Remove storage limitation of WebSQL. --- brightray/browser/browser_context.cc | 4 ++- brightray/browser/browser_context.h | 5 +++ brightray/browser/special_storage_policy.cc | 39 +++++++++++++++++++++ brightray/browser/special_storage_policy.h | 30 ++++++++++++++++ brightray/filenames.gypi | 2 ++ 5 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 brightray/browser/special_storage_policy.cc create mode 100644 brightray/browser/special_storage_policy.h diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index ff3be6ede18..4bf558d4293 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -8,6 +8,7 @@ #include "browser/inspectable_web_contents_impl.h" #include "browser/network_delegate.h" #include "browser/permission_manager.h" +#include "browser/special_storage_policy.h" #include "common/application_info.h" #include "base/files/file_path.h" @@ -96,6 +97,7 @@ scoped_refptr BrowserContext::From( BrowserContext::BrowserContext(const std::string& partition, bool in_memory) : in_memory_(in_memory), resource_context_(new ResourceContext), + storage_policy_(new SpecialStoragePolicy), weak_factory_(this) { if (!PathService::Get(DIR_USER_DATA, &path_)) { PathService::Get(DIR_APP_DATA, &path_); @@ -213,7 +215,7 @@ content::BrowserPluginGuestManager* BrowserContext::GetGuestManager() { } storage::SpecialStoragePolicy* BrowserContext::GetSpecialStoragePolicy() { - return nullptr; + return storage_policy_.get(); } content::PushMessagingService* BrowserContext::GetPushMessagingService() { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 3159b377bdc..3c9b68d8838 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -18,6 +18,10 @@ class PrefRegistrySimple; class PrefService; +namespace storage { +class SpecialStoragePolicy; +} + namespace brightray { class PermissionManager; @@ -112,6 +116,7 @@ class BrowserContext : public base::RefCounted, scoped_ptr resource_context_; scoped_ptr controller_; scoped_refptr url_request_getter_; + scoped_refptr storage_policy_; scoped_ptr prefs_; scoped_ptr permission_manager_; diff --git a/brightray/browser/special_storage_policy.cc b/brightray/browser/special_storage_policy.cc new file mode 100644 index 00000000000..f28e8e5caf3 --- /dev/null +++ b/brightray/browser/special_storage_policy.cc @@ -0,0 +1,39 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "browser/special_storage_policy.h" + +namespace brightray { + +SpecialStoragePolicy::SpecialStoragePolicy() { +} + +SpecialStoragePolicy::~SpecialStoragePolicy() { +} + +bool SpecialStoragePolicy::IsStorageProtected(const GURL& origin) { + return true; +} + +bool SpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { + return true; +} + +bool SpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { + return false; +} + +bool SpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { + return true; +} + +bool SpecialStoragePolicy::HasSessionOnlyOrigins() { + return false; +} + +bool SpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) { + return false; +} + +} // namespace brightray diff --git a/brightray/browser/special_storage_policy.h b/brightray/browser/special_storage_policy.h new file mode 100644 index 00000000000..9e02a4ac28c --- /dev/null +++ b/brightray/browser/special_storage_policy.h @@ -0,0 +1,30 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BRIGHTRAY_BROWSER_SPECIAL_STORAGE_POLICY_H_ +#define BRIGHTRAY_BROWSER_SPECIAL_STORAGE_POLICY_H_ + +#include "storage/browser/quota/special_storage_policy.h" + +namespace brightray { + +class SpecialStoragePolicy : public storage::SpecialStoragePolicy { + public: + SpecialStoragePolicy(); + + // storage::SpecialStoragePolicy implementation. + bool IsStorageProtected(const GURL& origin) override; + bool IsStorageUnlimited(const GURL& origin) override; + bool IsStorageSessionOnly(const GURL& origin) override; + bool CanQueryDiskSize(const GURL& origin) override; + bool HasIsolatedStorage(const GURL& origin) override; + bool HasSessionOnlyOrigins() override; + + protected: + ~SpecialStoragePolicy() override; +}; + +} // namespace brightray + +#endif // BRIGHTRAY_BROWSER_SPECIAL_STORAGE_POLICY_H_ diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index b614b6538f2..bbde28694d9 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -63,6 +63,8 @@ 'browser/platform_notification_service_impl.h', 'browser/linux/notification_presenter_linux.h', 'browser/linux/notification_presenter_linux.cc', + 'browser/special_storage_policy.cc', + 'browser/special_storage_policy.h', 'browser/url_request_context_getter.cc', 'browser/url_request_context_getter.h', 'browser/views/inspectable_web_contents_view_views.h', From ec6304c0b2d35e5ab1e6160650f008df3c84d106 Mon Sep 17 00:00:00 2001 From: Robo Date: Tue, 13 Oct 2015 18:20:12 +0530 Subject: [PATCH 0682/1195] provide request context for nss_oscp initialisation --- brightray/browser/url_request_context_getter.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 6edd4b150eb..bf837d741e8 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -44,6 +44,10 @@ #include "url/url_constants.h" #include "storage/browser/quota/special_storage_policy.h" +#if defined(USE_NSS_CERTS) +#include "net/cert_net/nss_ocsp.h" +#endif + using content::BrowserThread; namespace brightray { @@ -156,6 +160,9 @@ URLRequestContextGetter::URLRequestContextGetter( } URLRequestContextGetter::~URLRequestContextGetter() { +#if defined(USE_NSS_CERTS) + net::SetURLRequestContextForNSSHttpIO(NULL); +#endif } net::HostResolver* URLRequestContextGetter::host_resolver() { @@ -169,6 +176,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { auto& command_line = *base::CommandLine::ForCurrentProcess(); url_request_context_.reset(new net::URLRequestContext); + #if defined(USE_NSS_CERTS) + net::SetURLRequestContextForNSSHttpIO(url_request_context_.get()); + #endif + // --log-net-log net_log_->StartLogging(url_request_context_.get()); url_request_context_->set_net_log(net_log_); From abe749e6be77c5002846d0186025ce26f7bd8706 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 14 Oct 2015 09:47:22 +0800 Subject: [PATCH 0683/1195] :lipstick: --- brightray/browser/url_request_context_getter.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index bf837d741e8..bdef77d1c2e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -176,9 +176,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { auto& command_line = *base::CommandLine::ForCurrentProcess(); url_request_context_.reset(new net::URLRequestContext); - #if defined(USE_NSS_CERTS) - net::SetURLRequestContextForNSSHttpIO(url_request_context_.get()); - #endif +#if defined(USE_NSS_CERTS) + net::SetURLRequestContextForNSSHttpIO(url_request_context_.get()); +#endif // --log-net-log net_log_->StartLogging(url_request_context_.get()); From 859ef0b2980ef3f0518f38148a34cc019d95efbc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 14 Oct 2015 11:56:01 +0800 Subject: [PATCH 0684/1195] Update libchromiumcontent to latest master --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 27ccc74468a..5e9fb565eae 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 27ccc74468a444323f32dbe79219f049c9de9be6 +Subproject commit 5e9fb565eaec8f3f393551c5513c0b6f150ac256 From 73a60ea3e3ca0d68d5e60a8815e77983b29d30c1 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 16 Oct 2015 16:39:42 -0700 Subject: [PATCH 0685/1195] Create a new URLSecurityManager that allows explicit settings --- brightray/browser/url_request_context_getter.cc | 10 ++++++++++ brightray/browser/url_request_context_getter.h | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index bdef77d1c2e..5cbca4654b7 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -84,6 +84,16 @@ const char kProxyPacUrl[] = "proxy-pac-url"; } // namespace +ExplicitURLSecurityManager::ExplicitURLSecurityManager() : allow_default_creds_(false) {} + +bool ExplicitURLSecurityManager::CanUseDefaultCredentials(const GURL& auth_origin) const { + return allow_default_creds_; +} + +bool ExplicitURLSecurityManager::CanDelegate(const GURL& auth_origin) const { + return false; +} + std::string URLRequestContextGetter::Delegate::GetUserAgent() { return base::EmptyString(); } diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 4794f1bf6e5..fdbb7c68156 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -30,6 +30,21 @@ namespace brightray { class DevToolsNetworkController; class NetLog; +class ExplicitURLSecurityManager : public net::URLSecurityManager { +public: + ExplicitURLSecurityManager(); + + virtual bool CanUseDefaultCredentials(const GURL& auth_origin) const override; + virtual bool CanDelegate(const GURL& auth_origin) const override; + + void AllowNTLMCredentialsForAllDomains(bool should_allow) { allow_default_creds_ = should_allow; } + +private: + bool allow_default_creds_; + + DISALLOW_COPY_AND_ASSIGN(ExplicitURLSecurityManager); +}; + class URLRequestContextGetter : public net::URLRequestContextGetter { public: class Delegate { From 2c21f1a30459e960cec34ff5720e0cd1c7b86204 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 16 Oct 2015 16:40:07 -0700 Subject: [PATCH 0686/1195] Replace the default one with our own --- brightray/browser/url_request_context_getter.cc | 2 +- brightray/browser/url_request_context_getter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 5cbca4654b7..cfe250d2dd1 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -155,7 +155,7 @@ URLRequestContextGetter::URLRequestContextGetter( in_memory_(in_memory), io_loop_(io_loop), file_loop_(file_loop), - url_sec_mgr_(net::URLSecurityManager::Create(NULL, NULL)), + url_sec_mgr_(new ExplicitURLSecurityManager()), protocol_interceptors_(protocol_interceptors.Pass()) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index fdbb7c68156..aab7207cc56 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -95,7 +95,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr storage_; scoped_ptr url_request_context_; scoped_ptr host_mapping_rules_; - scoped_ptr url_sec_mgr_; + scoped_ptr url_sec_mgr_; content::ProtocolHandlerMap protocol_handlers_; content::URLRequestInterceptorScopedVector protocol_interceptors_; From d123c8613d4905e222bc2583d4092f1509fe7a50 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 16 Oct 2015 16:40:30 -0700 Subject: [PATCH 0687/1195] Create a new API to trump IE security settings if desired --- brightray/browser/browser_context.cc | 4 ++++ brightray/browser/browser_context.h | 2 ++ brightray/browser/url_request_context_getter.cc | 4 ++++ brightray/browser/url_request_context_getter.h | 2 ++ 4 files changed, 12 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 4bf558d4293..82de4a62101 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -232,4 +232,8 @@ content::PermissionManager* BrowserContext::GetPermissionManager() { return permission_manager_.get(); } +void BrowserContext::AllowNTLMCredentialsForAllDomains(bool should_allow) { + url_request_getter_->AllowNTLMCredentialsForAllDomains(should_allow); +} + } // namespace brightray diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 3c9b68d8838..5f16530d107 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -71,6 +71,8 @@ class BrowserContext : public base::RefCounted, void InitPrefs(); PrefService* prefs() { return prefs_.get(); } + void AllowNTLMCredentialsForAllDomains(bool should_allow); + protected: BrowserContext(const std::string& partition, bool in_memory); ~BrowserContext() override; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index cfe250d2dd1..58df7ece650 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -330,4 +330,8 @@ scoped_refptr URLRequestContextGetter::GetNetworkT return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); } +void URLRequestContextGetter::AllowNTLMCredentialsForAllDomains(bool should_allow) { + url_sec_mgr_->AllowNTLMCredentialsForAllDomains(should_allow); +} + } // namespace brightray diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index aab7207cc56..da2091fb675 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -78,6 +78,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { net::URLRequestContext* GetURLRequestContext() override; scoped_refptr GetNetworkTaskRunner() const override; + void AllowNTLMCredentialsForAllDomains(bool should_allow); + net::HostResolver* host_resolver(); private: From 66a14c5eb51e3280ca58d148a01844c4b2ceea9b Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 16 Oct 2015 16:43:03 -0700 Subject: [PATCH 0688/1195] Fallback to default behavior if boolean is false --- brightray/browser/url_request_context_getter.cc | 12 +++++++++--- brightray/browser/url_request_context_getter.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 58df7ece650..bc42f8e4600 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -84,14 +84,20 @@ const char kProxyPacUrl[] = "proxy-pac-url"; } // namespace -ExplicitURLSecurityManager::ExplicitURLSecurityManager() : allow_default_creds_(false) {} +ExplicitURLSecurityManager::ExplicitURLSecurityManager() : + allow_default_creds_(false), + orig_url_sec_mgr_(net::URLSecurityManager::Create(NULL, NULL)) {} bool ExplicitURLSecurityManager::CanUseDefaultCredentials(const GURL& auth_origin) const { - return allow_default_creds_; + if (allow_default_creds_) { + return true; + } + + return orig_url_sec_mgr_->CanUseDefaultCredentials(auth_origin); } bool ExplicitURLSecurityManager::CanDelegate(const GURL& auth_origin) const { - return false; + return orig_url_sec_mgr_->CanDelegate(auth_origin); } std::string URLRequestContextGetter::Delegate::GetUserAgent() { diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index da2091fb675..f1ed5da9d6a 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -41,6 +41,7 @@ public: private: bool allow_default_creds_; + scoped_ptr orig_url_sec_mgr_; DISALLOW_COPY_AND_ASSIGN(ExplicitURLSecurityManager); }; From 91a62640ab5577bc6e44353776be0f585616c47e Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Fri, 16 Oct 2015 16:48:07 -0700 Subject: [PATCH 0689/1195] Come Correct with cpplint --- brightray/browser/browser_client.h | 1 + brightray/browser/url_request_context_getter.h | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index f69b017e5e1..0612e56d255 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -50,6 +50,7 @@ class BrowserClient : public content::ContentBrowserClient { BrowserMainParts* browser_main_parts_; NetLog net_log_; + private: DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index f1ed5da9d6a..78dc5c4eb8e 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -31,15 +31,15 @@ class DevToolsNetworkController; class NetLog; class ExplicitURLSecurityManager : public net::URLSecurityManager { -public: + public: ExplicitURLSecurityManager(); - virtual bool CanUseDefaultCredentials(const GURL& auth_origin) const override; - virtual bool CanDelegate(const GURL& auth_origin) const override; + bool CanUseDefaultCredentials(const GURL& auth_origin) const override; + bool CanDelegate(const GURL& auth_origin) const override; void AllowNTLMCredentialsForAllDomains(bool should_allow) { allow_default_creds_ = should_allow; } -private: + private: bool allow_default_creds_; scoped_ptr orig_url_sec_mgr_; From 9d8bff7d0458e43332fa0a912b627a65d37b52d0 Mon Sep 17 00:00:00 2001 From: Dwayne Jones Date: Mon, 19 Oct 2015 15:36:08 -0400 Subject: [PATCH 0690/1195] Update to brightray.gyp : libresolv In Following with this PR https://github.com/atom/brightray/pull/153 @joshaber helped me to work out this was causing a build error Xcode 7 for libresolv --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index a93e83c3c77..4176e7ddbf6 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -134,7 +134,7 @@ '$(SDKROOT)/System/Library/Frameworks/Foundation.framework', '$(SDKROOT)/System/Library/Frameworks/Security.framework', '$(SDKROOT)/System/Library/Frameworks/SystemConfiguration.framework', - '$(SDKROOT)/usr/lib/libresolv.dylib', + '-lresolv', # media.gyp: '$(SDKROOT)/System/Library/Frameworks/AudioToolbox.framework', '$(SDKROOT)/System/Library/Frameworks/AudioUnit.framework', From 0d63eaa07be803d3b80430eadb22850c1aef2a01 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 19 Oct 2015 12:51:01 -0700 Subject: [PATCH 0691/1195] Move the NTLM check to the URLRequestContextGetter delegate --- .../browser/url_request_context_getter.cc | 41 ++++++++++++------- .../browser/url_request_context_getter.h | 38 +++++++++-------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index bc42f8e4600..08149a471a4 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -84,22 +84,24 @@ const char kProxyPacUrl[] = "proxy-pac-url"; } // namespace -ExplicitURLSecurityManager::ExplicitURLSecurityManager() : - allow_default_creds_(false), + +URLRequestContextGetter::DelegateURLSecurityManager::DelegateURLSecurityManager + (URLRequestContextGetter::Delegate* delegate) : + delegate_(delegate) {} + +bool URLRequestContextGetter::DelegateURLSecurityManager::CanUseDefaultCredentials + (const GURL& auth_origin) const { + return delegate_->AllowNTLMCredentialsForDomain(auth_origin); +} + +bool URLRequestContextGetter::DelegateURLSecurityManager::CanDelegate + (const GURL& auth_origin) const { + return delegate_->CanDelegateURLSecurity(auth_origin); +} + +URLRequestContextGetter::Delegate::Delegate() : orig_url_sec_mgr_(net::URLSecurityManager::Create(NULL, NULL)) {} -bool ExplicitURLSecurityManager::CanUseDefaultCredentials(const GURL& auth_origin) const { - if (allow_default_creds_) { - return true; - } - - return orig_url_sec_mgr_->CanUseDefaultCredentials(auth_origin); -} - -bool ExplicitURLSecurityManager::CanDelegate(const GURL& auth_origin) const { - return orig_url_sec_mgr_->CanDelegate(auth_origin); -} - std::string URLRequestContextGetter::Delegate::GetUserAgent() { return base::EmptyString(); } @@ -144,6 +146,15 @@ net::SSLConfigService* URLRequestContextGetter::Delegate::CreateSSLConfigService return new net::SSLConfigServiceDefaults; } +bool URLRequestContextGetter::Delegate::AllowNTLMCredentialsForDomain(const GURL& auth_origin) { + return orig_url_sec_mgr_->CanUseDefaultCredentials(auth_origin); +} + +bool URLRequestContextGetter::Delegate::CanDelegateURLSecurity(const GURL& auth_origin) { + return orig_url_sec_mgr_->CanDelegate(auth_origin); +} + + URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, DevToolsNetworkController* controller, @@ -161,7 +172,7 @@ URLRequestContextGetter::URLRequestContextGetter( in_memory_(in_memory), io_loop_(io_loop), file_loop_(file_loop), - url_sec_mgr_(new ExplicitURLSecurityManager()), + url_sec_mgr_(new URLRequestContextGetter::DelegateURLSecurityManager(delegate)), protocol_interceptors_(protocol_interceptors.Pass()) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 78dc5c4eb8e..ed142d47907 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -30,27 +30,11 @@ namespace brightray { class DevToolsNetworkController; class NetLog; -class ExplicitURLSecurityManager : public net::URLSecurityManager { - public: - ExplicitURLSecurityManager(); - - bool CanUseDefaultCredentials(const GURL& auth_origin) const override; - bool CanDelegate(const GURL& auth_origin) const override; - - void AllowNTLMCredentialsForAllDomains(bool should_allow) { allow_default_creds_ = should_allow; } - - private: - bool allow_default_creds_; - scoped_ptr orig_url_sec_mgr_; - - DISALLOW_COPY_AND_ASSIGN(ExplicitURLSecurityManager); -}; - class URLRequestContextGetter : public net::URLRequestContextGetter { public: class Delegate { public: - Delegate() {} + Delegate(); virtual ~Delegate() {} virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; } @@ -61,6 +45,24 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory( const base::FilePath& base_path); virtual net::SSLConfigService* CreateSSLConfigService(); + virtual bool AllowNTLMCredentialsForDomain(const GURL& auth_origin); + virtual bool CanDelegateURLSecurity(const GURL& auth_origin); + + private: + scoped_ptr orig_url_sec_mgr_; + }; + + class DelegateURLSecurityManager : public net::URLSecurityManager { + public: + DelegateURLSecurityManager(URLRequestContextGetter::Delegate* delegate); + + bool CanUseDefaultCredentials(const GURL& auth_origin) const override; + bool CanDelegate(const GURL& auth_origin) const override; + + private: + URLRequestContextGetter::Delegate* delegate_; + + DISALLOW_COPY_AND_ASSIGN(DelegateURLSecurityManager); }; URLRequestContextGetter( @@ -98,7 +100,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr storage_; scoped_ptr url_request_context_; scoped_ptr host_mapping_rules_; - scoped_ptr url_sec_mgr_; + scoped_ptr url_sec_mgr_; content::ProtocolHandlerMap protocol_handlers_; content::URLRequestInterceptorScopedVector protocol_interceptors_; From 5168b449324a4500e05176513ebf66442f4e214c Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 19 Oct 2015 12:57:32 -0700 Subject: [PATCH 0692/1195] Remove our plumbed methods --- brightray/browser/browser_context.cc | 4 ---- brightray/browser/browser_context.h | 2 -- brightray/browser/url_request_context_getter.cc | 4 ---- 3 files changed, 10 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 82de4a62101..4bf558d4293 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -232,8 +232,4 @@ content::PermissionManager* BrowserContext::GetPermissionManager() { return permission_manager_.get(); } -void BrowserContext::AllowNTLMCredentialsForAllDomains(bool should_allow) { - url_request_getter_->AllowNTLMCredentialsForAllDomains(should_allow); -} - } // namespace brightray diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 5f16530d107..3c9b68d8838 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -71,8 +71,6 @@ class BrowserContext : public base::RefCounted, void InitPrefs(); PrefService* prefs() { return prefs_.get(); } - void AllowNTLMCredentialsForAllDomains(bool should_allow); - protected: BrowserContext(const std::string& partition, bool in_memory); ~BrowserContext() override; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 08149a471a4..799560278aa 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -347,8 +347,4 @@ scoped_refptr URLRequestContextGetter::GetNetworkT return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); } -void URLRequestContextGetter::AllowNTLMCredentialsForAllDomains(bool should_allow) { - url_sec_mgr_->AllowNTLMCredentialsForAllDomains(should_allow); -} - } // namespace brightray From b7b3029e2aa8bcac9961a3546ea78b89bfd1fb9d Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 19 Oct 2015 19:42:23 -0700 Subject: [PATCH 0693/1195] Nuke old declaration --- brightray/browser/url_request_context_getter.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index ed142d47907..0cd31c4c136 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -81,8 +81,6 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { net::URLRequestContext* GetURLRequestContext() override; scoped_refptr GetNetworkTaskRunner() const override; - void AllowNTLMCredentialsForAllDomains(bool should_allow); - net::HostResolver* host_resolver(); private: From 54997db5f262fefd30b92d30f9e8716e410fab30 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 20 Oct 2015 22:38:20 +0800 Subject: [PATCH 0694/1195] No more need to call setrlimit Chrome has removed the limiations on fd, this actually became the new limitation. --- brightray/browser/browser_main_parts.cc | 4 --- brightray/browser/browser_main_parts.h | 1 - brightray/browser/browser_main_parts_mac.mm | 29 --------------------- 3 files changed, 34 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 6fc464fe7f2..b0a7e72b5f2 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -137,10 +137,6 @@ BrowserMainParts::~BrowserMainParts() { } void BrowserMainParts::PreEarlyInitialization() { -#if defined(OS_MACOSX) - IncreaseFileDescriptorLimit(); -#endif - #if defined(USE_X11) views::LinuxUI::SetInstance(BuildGtk2UI()); OverrideLinuxAppDataPath(); diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index da35d78c229..5b50516f7cc 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -49,7 +49,6 @@ class BrowserMainParts : public content::BrowserMainParts { private: #if defined(OS_MACOSX) - void IncreaseFileDescriptorLimit(); void InitializeMainNib(); #endif diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm index a795e80a69d..19d0262a101 100644 --- a/brightray/browser/browser_main_parts_mac.mm +++ b/brightray/browser/browser_main_parts_mac.mm @@ -6,35 +6,6 @@ namespace brightray { -namespace { - -// Sets the file descriptor soft limit to |max_descriptors| or the OS hard limit, whichever is -// lower. -void SetFileDescriptorLimit(rlim_t max_descriptors) { - rlimit limits; - if (getrlimit(RLIMIT_NOFILE, &limits) != 0) { - PLOG(INFO) << "Failed to get file descriptor limit"; - return; - } - - auto new_limit = max_descriptors; - if (limits.rlim_max > 0) - new_limit = std::min(new_limit, limits.rlim_max); - limits.rlim_cur = new_limit; - if (setrlimit(RLIMIT_NOFILE, &limits) != 0) - PLOG(INFO) << "Failed to set file descriptor limit"; -} - -} // namespace - -void BrowserMainParts::IncreaseFileDescriptorLimit() { - // We use quite a few file descriptors for our IPC, and the default limit on the Mac is low (256), - // so bump it up. - // See http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/chrome_browser_main_posix.cc?revision=244734#l295 - // and https://codereview.chromium.org/125151 - SetFileDescriptorLimit(1024); -} - // Replicates NSApplicationMain, but doesn't start a run loop. void BrowserMainParts::InitializeMainNib() { auto infoDictionary = base::mac::OuterBundle().infoDictionary; From 3dfb75b5302b180e491dbfd363e5f3f8e65cfa57 Mon Sep 17 00:00:00 2001 From: Robo Date: Thu, 5 Nov 2015 20:56:46 +0530 Subject: [PATCH 0695/1195] allow delegate to provide certificate verifier --- brightray/browser/url_request_context_getter.cc | 6 +++++- brightray/browser/url_request_context_getter.h | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 799560278aa..3f552b314c8 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -142,6 +142,10 @@ URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(const base::Fil BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); } +net::CertVerifier* URLRequestContextGetter::Delegate::CreateCertVerifier() { + return net::CertVerifier::CreateDefault(); +} + net::SSLConfigService* URLRequestContextGetter::Delegate::CreateSSLConfigService() { return new net::SSLConfigServiceDefaults; } @@ -286,7 +290,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { false, // auth_android_negotiate_account_type true); // negotiate_enable_port - storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); + storage_->set_cert_verifier(delegate_->CreateCertVerifier()); storage_->set_transport_security_state(new net::TransportSecurityState); storage_->set_ssl_config_service(delegate_->CreateSSLConfigService()); storage_->set_http_auth_handler_factory(auth_handler_factory); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 0cd31c4c136..c4e0f9208a1 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -44,14 +44,15 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { content::URLRequestInterceptorScopedVector* protocol_interceptors); virtual net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory( const base::FilePath& base_path); + virtual net::CertVerifier* CreateCertVerifier(); virtual net::SSLConfigService* CreateSSLConfigService(); virtual bool AllowNTLMCredentialsForDomain(const GURL& auth_origin); virtual bool CanDelegateURLSecurity(const GURL& auth_origin); - + private: scoped_ptr orig_url_sec_mgr_; }; - + class DelegateURLSecurityManager : public net::URLSecurityManager { public: DelegateURLSecurityManager(URLRequestContextGetter::Delegate* delegate); From b8cd4f7981c2670ad54179c033c3afd77913a7dc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 7 Nov 2015 12:11:12 +0800 Subject: [PATCH 0696/1195] linux: Link Xi with pkg-config Fix atom/electron#3357. --- brightray/brightray.gyp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 4176e7ddbf6..184a60efa95 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -1,7 +1,7 @@ { 'variables': { # The libraries brightray will be compiled to. - 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xrandr xext gconf-2.0 gmodule-2.0 nss' + 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xi xrandr xext gconf-2.0 gmodule-2.0 nss' }, 'includes': [ 'filenames.gypi', @@ -101,7 +101,7 @@ '-lresolv', '-lfontconfig', '-lfreetype', - '-lX11 -lXi -lXcursor -lXext -lXfixes -lXrender -lXcomposite -lXdamage -lXtst -lXrandr', + '-lX11 -lXcursor -lXext -lXfixes -lXrender -lXcomposite -lXdamage -lXtst -lXrandr', '-lexpat', ], }, From 1017ec0d875a77247c2cf0d1bc34da3a842c8b8b Mon Sep 17 00:00:00 2001 From: tejaspathak Date: Sun, 8 Nov 2015 16:13:32 +0900 Subject: [PATCH 0697/1195] Add option to build local libchromiumcontent - Currently libchromiumcontent is downloaded by default. - Now developer can choose to provide local libchromiumcontent src, shared and static path --- brightray/brightray.gypi | 5 ++-- brightray/script/bootstrap | 59 +++++++++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 4931cfc29c1..a71009c8334 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -3,16 +3,15 @@ 'vendor/download/libchromiumcontent/filenames.gypi', ], 'variables': { - 'libchromiumcontent_src_dir': '<(libchromiumcontent_root_dir)/src', 'libchromiumcontent_component%': 1, 'conditions': [ # The "libchromiumcontent_component" is defined when calling "gyp". ['libchromiumcontent_component', { - 'libchromiumcontent_dir%': '<(libchromiumcontent_root_dir)/shared_library', + 'libchromiumcontent_dir%': '<(libchromiumcontent_shared_libraries_dir)', 'libchromiumcontent_libraries%': '<(libchromiumcontent_shared_libraries)', 'libchromiumcontent_v8_libraries%': '<(libchromiumcontent_shared_v8_libraries)', }, { - 'libchromiumcontent_dir%': '<(libchromiumcontent_root_dir)/static_library', + 'libchromiumcontent_dir%': '<(libchromiumcontent_static_libraries_dir)', 'libchromiumcontent_libraries%': '<(libchromiumcontent_static_libraries)', 'libchromiumcontent_v8_libraries%': '<(libchromiumcontent_static_v8_libraries)', }], diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index 7cd1abffc06..e1a9987de08 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -14,9 +14,28 @@ DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download') def main(): args = parse_args() - + if (args.libcc_source_path != None and + args.libcc_shared_library_path != None and + args.libcc_static_library_path != None): + if (not os.path.isdir(args.libcc_source_path)): + print "Error: Directory does not exist:", args.libcc_source_path + sys.exit(0) + elif (not os.path.isdir(args.libcc_shared_library_path)): + print "Error: Directory does not exist:", args.libcc_shared_library_path + sys.exit(0) + elif (not os.path.isdir(args.libcc_static_library_path)): + print "Error: Directory does not exist:", args.libcc_static_library_path + sys.exit(0) + elif (args.libcc_source_path != None or + args.libcc_shared_library_path != None or + args.libcc_static_library_path != None): + print "Error: All options of libchromiumcontent are required OR let brightray choose it" + sys.exit(0) update_submodules() - download_libchromiumcontent(args.dev, args.commit, args.target_arch, args.url) + setup_libchromiumcontent(args.dev, args.commit, args.target_arch, args.url, + args.libcc_source_path, + args.libcc_shared_library_path, + args.libcc_static_library_path) def parse_args(): @@ -30,6 +49,12 @@ def parse_args(): parser.add_argument('url', help='The base URL from which to download ' 'libchromiumcontent (i.e., the URL you passed to ' 'libchromiumcontent\'s script/upload script') + parser.add_argument('--libcc_source_path', required=False, + help='The source path of libchromiumcontent. NOTE: All options of libchromiumcontent are required OR let brightray choose it') + parser.add_argument('--libcc_shared_library_path', required=False, + help='The shared library path of libchromiumcontent. NOTE: All options of libchromiumcontent are required OR let brightray choose it') + parser.add_argument('--libcc_static_library_path', required=False, + help='The static library path of libchromiumcontent. NOTE: All options of libchromiumcontent are required OR let brightray choose it') return parser.parse_args() @@ -39,17 +64,25 @@ def update_submodules(): '--recursive'])) -def download_libchromiumcontent(is_dev, commit, target_arch, url): - mkdir_p(DOWNLOAD_DIR) - download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', - 'download') - target_dir = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') - args = ['-f', '-c', commit, '--target_arch', target_arch, url, target_dir] - if is_dev: - subprocess.check_call([sys.executable, download] + args) - else: - subprocess.check_call([sys.executable, download, '-s'] + args) - +def setup_libchromiumcontent(is_dev, commit, target_arch, url, + libcc_source_path, + libcc_shared_library_path, + libcc_static_library_path): + mkdir_p(DOWNLOAD_DIR) + target_dir = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') + download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', + 'download') + args = ['-f', '-c', commit, '--target_arch', target_arch, url, target_dir] + if (libcc_source_path != None and + libcc_shared_library_path != None and + libcc_static_library_path != None): + args.append(['--libcc_source_path', libcc_source_path, + '--libcc_shared_library_path', libcc_shared_library_path, + '--libcc_static_library_path', libcc_static_library_path]) + if is_dev: + subprocess.check_call([sys.executable, download] + args) + else: + subprocess.check_call([sys.executable, download, '-s'] + args) def mkdir_p(path): try: From 93ebbb1c86315e093c177555924f4e29333762d4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 9 Nov 2015 16:38:09 +0800 Subject: [PATCH 0698/1195] Update libchromiumcontent for atom/electron#3310 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 5e9fb565eae..2bf9a031b05 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 5e9fb565eaec8f3f393551c5513c0b6f150ac256 +Subproject commit 2bf9a031b05c9f8b08e4370f87f9d06cd1676cad From 7720346ee7624730ad1103217a423fbaeadbeebe Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 9 Nov 2015 18:19:32 +0800 Subject: [PATCH 0699/1195] Update libchromiumcontent for filenames.gypi fix --- brightray/script/bootstrap | 31 +++++++++++++++-------------- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index e1a9987de08..3d06ebbb45b 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -68,21 +68,22 @@ def setup_libchromiumcontent(is_dev, commit, target_arch, url, libcc_source_path, libcc_shared_library_path, libcc_static_library_path): - mkdir_p(DOWNLOAD_DIR) - target_dir = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') - download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', - 'download') - args = ['-f', '-c', commit, '--target_arch', target_arch, url, target_dir] - if (libcc_source_path != None and - libcc_shared_library_path != None and - libcc_static_library_path != None): - args.append(['--libcc_source_path', libcc_source_path, - '--libcc_shared_library_path', libcc_shared_library_path, - '--libcc_static_library_path', libcc_static_library_path]) - if is_dev: - subprocess.check_call([sys.executable, download] + args) - else: - subprocess.check_call([sys.executable, download, '-s'] + args) + mkdir_p(DOWNLOAD_DIR) + target_dir = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') + download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', + 'download') + args = ['-f', '-c', commit, '--target_arch', target_arch, url, target_dir] + if (libcc_source_path != None and + libcc_shared_library_path != None and + libcc_static_library_path != None): + args.append(['--libcc_source_path', libcc_source_path, + '--libcc_shared_library_path', libcc_shared_library_path, + '--libcc_static_library_path', libcc_static_library_path]) + if is_dev: + subprocess.check_call([sys.executable, download] + args) + else: + subprocess.check_call([sys.executable, download, '-s'] + args) + def mkdir_p(path): try: diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 2bf9a031b05..f202592f932 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 2bf9a031b05c9f8b08e4370f87f9d06cd1676cad +Subproject commit f202592f932cfb8494cc6fa211f9b917f2457f3b From 498bff9e5ab5f8faa93614b6047ebe5504fe644a Mon Sep 17 00:00:00 2001 From: Jason Poon Date: Wed, 4 Nov 2015 10:13:52 -0800 Subject: [PATCH 0700/1195] Windows Toasts: Enable Basic Notifications To test this puppy out, build and open up the Chromium Dev Tools. Then, run `new Notification("Test title", {body: "Test body"});` --- brightray/brightray.gyp | 10 + .../platform_notification_service_impl.cc | 2 - .../browser/win/notification_presenter_win.cc | 75 +++ .../browser/win/notification_presenter_win.h | 38 ++ .../browser/win/windows_toast_notification.cc | 593 ++++++++++++++++++ .../browser/win/windows_toast_notification.h | 99 +++ brightray/filenames.gypi | 4 + 7 files changed, 819 insertions(+), 2 deletions(-) create mode 100644 brightray/browser/win/notification_presenter_win.cc create mode 100644 brightray/browser/win/notification_presenter_win.h create mode 100644 brightray/browser/win/windows_toast_notification.cc create mode 100644 brightray/browser/win/windows_toast_notification.h diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 4176e7ddbf6..697a4c962ed 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -161,6 +161,14 @@ ] }], # OS=="mac" ['OS=="win"', { + 'msvs_settings': { + 'VCLinkerTool': { + 'AdditionalDependencies': [ + 'runtimeobject.lib', + 'windowsapp.lib' + ], + }, + }, 'conditions': [ ['libchromiumcontent_component', { # sandbox, base_static, devtools_discovery, devtools_http_handler, @@ -195,6 +203,8 @@ 'msvs_settings': { 'VCLinkerTool': { 'AdditionalDependencies': [ + 'Shlwapi.lib', + 'Crypt32.lib', 'advapi32.lib', 'dbghelp.lib', 'delayimp.lib', diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service_impl.cc index d2b0f679a6c..db8572ee898 100644 --- a/brightray/browser/platform_notification_service_impl.cc +++ b/brightray/browser/platform_notification_service_impl.cc @@ -20,10 +20,8 @@ PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {} PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} NotificationPresenter* PlatformNotificationServiceImpl::notification_presenter() { -#if defined(OS_MACOSX) || defined(OS_LINUX) if (!notification_presenter_) notification_presenter_.reset(NotificationPresenter::Create()); -#endif return notification_presenter_.get(); } diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc new file mode 100644 index 00000000000..98cc7d04189 --- /dev/null +++ b/brightray/browser/win/notification_presenter_win.cc @@ -0,0 +1,75 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Patrick Reynolds . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/win/notification_presenter_win.h" + +#include "base/bind.h" +#include "base/logging.h" +#include "base/files/file_enumerator.h" +#include "base/strings/string_util.h" +#include "base/strings/utf_string_conversions.h" +#include "content/public/browser/desktop_notification_delegate.h" +#include "content/public/common/platform_notification_data.h" +#include "common/application_info.h" +#include +#include +#include +#include "third_party/skia/include/core/SkBitmap.h" +#include "base/win/windows_version.h" + +// Windows Header +#define WIN32_LEAN_AND_MEAN + +#include +#include +#include +#include +#include +#include "windows_toast_notification.h" + +#pragma comment(lib, "runtimeobject.lib") +#pragma comment(lib, "Crypt32.lib") + +using namespace WinToasts; +using namespace Microsoft::WRL; +using namespace ABI::Windows::UI::Notifications; +using namespace ABI::Windows::Data::Xml::Dom; +using namespace ABI::Windows::Foundation; + +namespace brightray { + +// static +NotificationPresenter* NotificationPresenter::Create() { + return new NotificationPresenterWin; +} + +NotificationPresenterWin::NotificationPresenterWin() { +} + +NotificationPresenterWin::~NotificationPresenterWin() { +} + +void NotificationPresenterWin::ShowNotification( + const content::PlatformNotificationData& data, + const SkBitmap& icon, + scoped_ptr delegate_ptr, + base::Closure* cancel_callback) { + + std::wstring title = data.title; + std::wstring body = data.body; + std::string appName = GetApplicationName(); + char* img = NULL; + + WinToasts::WindowsToastNotification* wtn = new WinToasts::WindowsToastNotification(appName.c_str()); + wtn->ShowNotification(title.c_str(), body.c_str(), img); +} + +void NotificationPresenterWin::CancelNotification() { +} + +void NotificationPresenterWin::DeleteNotification() { +} + +} // namespace brightray \ No newline at end of file diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h new file mode 100644 index 00000000000..0205422f92b --- /dev/null +++ b/brightray/browser/win/notification_presenter_win.h @@ -0,0 +1,38 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Patrick Reynolds . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_ +#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_ + +#include "base/compiler_specific.h" +#include "browser/notification_presenter.h" + +#include + +namespace brightray { + +class NotificationPresenterWin : public NotificationPresenter { + public: + NotificationPresenterWin(); + ~NotificationPresenterWin(); + + // NotificationPresenter: + void ShowNotification( + const content::PlatformNotificationData&, + const SkBitmap& icon, + scoped_ptr delegate, + base::Closure* cancel_callback) override; + + void RemoveNotification(); + + private: + + void CancelNotification(); + void DeleteNotification(); +}; + +} // namespace brightray + +#endif diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc new file mode 100644 index 00000000000..7a90ac3d3fb --- /dev/null +++ b/brightray/browser/win/windows_toast_notification.cc @@ -0,0 +1,593 @@ +// Copyright (c) 2015 Felix Rieseberg . All rights reserved. +// Copyright (c) 2015 Ryan McShane and Brandon Smith +// Thanks to both of those folks mentioned above who first thought up a bunch of this code +// and released it as MIT to the world. + +#include "windows_toast_notification.h" +#include +#include +#include +#include +#include +#include + +using namespace WinToasts; +using namespace Windows::Foundation; + +#define BREAK_IF_BAD(hr) if(!SUCCEEDED(hr)) break; +#define SHORTCUT_FORMAT "\\Microsoft\\Windows\\Start Menu\\Programs\\%s.lnk" + +char WindowsToastNotification::s_appName[MAX_PATH] = {}; +char WindowsToastNotification::s_tempDirPath[MAX_PATH] = {}; + +namespace WinToasts { + +WindowsToastNotification::WindowsToastNotification(const char* appName) +{ + sprintf_s(s_appName, ARRAYSIZE(s_appName), "%s", appName); + m_eventHandler = NULL; + m_tempFilePath = NULL; +} + +WindowsToastNotification::~WindowsToastNotification() +{ + if (m_eventHandler){ + delete m_eventHandler; + } + + if (m_tempFilePath){ + DeleteTempImageFile(); + delete m_tempFilePath; + } +} + +/*static*/ void WindowsToastNotification::InitSystemProps(char* appName, char* tempDirPath) +{ + + sprintf_s(s_tempDirPath, ARRAYSIZE(s_tempDirPath), "%s", tempDirPath); +} + +void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* msg, const char* img) +{ + // Init using WRL + Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); + + HSTRING toastNotifMgrStr = NULL; + HSTRING appId = NULL; + HSTRING toastNotifStr = NULL; + + // Create a shortcut in the user's app data folder + // (requirement for Windows 8 to show notifications - Windows 10 is fine without it) + // TODO: This shoudl be cleaned up + // HRESULT hr = EnsureShortcut(); + + do{ + HRESULT hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager, &toastNotifMgrStr); + BREAK_IF_BAD(hr); + + ComPtr toastMgr; + hr = Windows::Foundation::GetActivationFactory(toastNotifMgrStr, &toastMgr); + BREAK_IF_BAD(hr); + + ComPtr toastXml; + hr = GetToastXml(toastMgr.Get(), title, msg, img, &toastXml); + BREAK_IF_BAD(hr); + + WCHAR wAppName[MAX_PATH]; + swprintf(wAppName, ARRAYSIZE(wAppName), L"%S", s_appName); + hr = CreateHString(wAppName, &appId); + BREAK_IF_BAD(hr); + + ComPtr notifier; + toastMgr->CreateToastNotifierWithId(appId, ¬ifier); + BREAK_IF_BAD(hr); + + hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotification, &toastNotifStr); + BREAK_IF_BAD(hr); + + ComPtr toastFactory; + hr = Windows::Foundation::GetActivationFactory(toastNotifStr, &toastFactory); + BREAK_IF_BAD(hr); + + ComPtr toast; + hr = toastFactory->CreateToastNotification(toastXml.Get(), &toast); + BREAK_IF_BAD(hr); + + hr = SetupCallbacks(toast.Get()); + BREAK_IF_BAD(hr); + + hr = notifier->Show(toast.Get()); + BREAK_IF_BAD(hr); + + //m_cbFn.Reset(Isolate::GetCurrent(), cbFn); + + //todo: + //cbPtr->NotificationDisplayed(); + } while (FALSE); + + if (toastNotifMgrStr != NULL){ + WindowsDeleteString(toastNotifMgrStr); + } + + if (appId != NULL){ + WindowsDeleteString(appId); + } + + if (toastNotifStr != NULL){ + WindowsDeleteString(toastNotifStr); + } + + // if (!SUCCEEDED(hr)){ + // delete this; + // } +} + + +void WindowsToastNotification::NotificationClicked() +{ + // Local fn = Local::New(Isolate::GetCurrent(), m_cbFn); + // Handle args[1]; + // fn->Call(Isolate::GetCurrent()->GetCurrentContext()->Global(), 0, args); + // delete this; +} + + +void WindowsToastNotification::NotificationDismissed() +{ + delete this; +} + + +HRESULT WindowsToastNotification::GetToastXml(IToastNotificationManagerStatics* toastMgr, const WCHAR* title, const WCHAR* msg, const char* img, IXmlDocument** toastXml) +{ + HRESULT hr; + ToastTemplateType templateType; + if (title == NULL || msg == NULL){ + // Single line toast + templateType = img == NULL ? ToastTemplateType_ToastText01 : ToastTemplateType_ToastImageAndText01; + hr = toastMgr->GetTemplateContent(templateType, toastXml); + if (SUCCEEDED(hr)) { + const WCHAR* text = title != NULL ? title : msg; + hr = SetXmlText(*toastXml, text); + } + } else { + // Title and body toast + templateType = img == NULL ? ToastTemplateType_ToastText02 : ToastTemplateType_ToastImageAndText02; + hr = toastMgr->GetTemplateContent(templateType, toastXml); + if (SUCCEEDED(hr)) { + hr = SetXmlText(*toastXml, title, msg); + } + } + + if (img != NULL && SUCCEEDED(hr)){ + // Toast has image + hr = CreateTempImageFile(img); + if (SUCCEEDED(hr)){ + hr = SetXmlImage(*toastXml); + } + + // Don't stop a notification from showing just because an image couldn't be displayed. By default the app icon will be shown. + hr = S_OK; + } + + return hr; +} + + +HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* text) +{ + HSTRING tag = NULL; + + ComPtr nodeList; + HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 1); + do{ + BREAK_IF_BAD(hr); + + ComPtr node; + hr = nodeList->Item(0, &node); + BREAK_IF_BAD(hr); + + hr = AppendTextToXml(doc, node.Get(), text); + } while (FALSE); + + if (tag != NULL){ + WindowsDeleteString(tag); + } + + return hr; +} + + +HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* title, const WCHAR* body) +{ + HSTRING tag = NULL; + ComPtr nodeList; + HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 2); + do{ + BREAK_IF_BAD(hr); + + ComPtr node; + hr = nodeList->Item(0, &node); + BREAK_IF_BAD(hr); + + hr = AppendTextToXml(doc, node.Get(), title); + BREAK_IF_BAD(hr); + + hr = nodeList->Item(1, &node); + BREAK_IF_BAD(hr); + + hr = AppendTextToXml(doc, node.Get(), body); + } while (FALSE); + + if (tag != NULL){ + WindowsDeleteString(tag); + } + + return hr; +} + + +HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc) +{ + HSTRING tag = NULL; + HSTRING src = NULL; + HSTRING imgPath = NULL; + HRESULT hr = CreateHString(L"image", &tag); + do{ + BREAK_IF_BAD(hr); + + ComPtr nodeList; + hr = doc->GetElementsByTagName(tag, &nodeList); + BREAK_IF_BAD(hr); + + ComPtr imageNode; + hr = nodeList->Item(0, &imageNode); + BREAK_IF_BAD(hr); + + ComPtr attrs; + hr = imageNode->get_Attributes(&attrs); + BREAK_IF_BAD(hr); + + hr = CreateHString(L"src", &src); + BREAK_IF_BAD(hr); + + ComPtr srcAttr; + hr = attrs->GetNamedItem(src, &srcAttr); + BREAK_IF_BAD(hr); + + WCHAR xmlPath[MAX_PATH]; + swprintf(xmlPath, ARRAYSIZE(xmlPath), L"file:///%S", m_tempFilePath); + hr = CreateHString(xmlPath, &imgPath); + BREAK_IF_BAD(hr); + + ComPtr srcText; + hr = doc->CreateTextNode(imgPath, &srcText); + BREAK_IF_BAD(hr); + + ComPtr srcNode; + hr = srcText.As(&srcNode); + BREAK_IF_BAD(hr); + + ComPtr childNode; + hr = srcAttr->AppendChild(srcNode.Get(), &childNode); + } while (FALSE); + + if (tag != NULL){ + WindowsDeleteString(tag); + } + if (src != NULL){ + WindowsDeleteString(src); + } + if (imgPath != NULL){ + WindowsDeleteString(imgPath); + } + + return hr; +} + + +HRESULT WindowsToastNotification::GetTextNodeList(HSTRING* tag, IXmlDocument* doc, IXmlNodeList** nodeList, UINT32 reqLength) +{ + HRESULT hr = CreateHString(L"text", tag); + do{ + BREAK_IF_BAD(hr); + + hr = doc->GetElementsByTagName(*tag, nodeList); + BREAK_IF_BAD(hr); + + UINT32 nodeLength; + hr = (*nodeList)->get_Length(&nodeLength); + BREAK_IF_BAD(hr); + + if (nodeLength < reqLength) { + hr = E_INVALIDARG; + } + } while (FALSE); + + if (!SUCCEEDED(hr)){ + // Allow the caller to delete this string on success + WindowsDeleteString(*tag); + } + + return hr; +} + + +HRESULT WindowsToastNotification::AppendTextToXml(IXmlDocument* doc, IXmlNode* node, const WCHAR* text) +{ + HSTRING str = NULL; + HRESULT hr = CreateHString(text, &str); + do{ + BREAK_IF_BAD(hr); + + ComPtr xmlText; + hr = doc->CreateTextNode(str, &xmlText); + BREAK_IF_BAD(hr); + + ComPtr textNode; + hr = xmlText.As(&textNode); + BREAK_IF_BAD(hr); + + ComPtr appendNode; + hr = node->AppendChild(textNode.Get(), &appendNode); + } while (FALSE); + + if (str != NULL){ + WindowsDeleteString(str); + } + + return hr; +} + + +HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast) +{ + EventRegistrationToken activatedToken, dismissedToken; + m_eventHandler = new ToastEventHandler(this); + ComPtr eventHandler(m_eventHandler); + HRESULT hr = toast->add_Activated(eventHandler.Get(), &activatedToken); + if (SUCCEEDED(hr)) { + hr = toast->add_Dismissed(eventHandler.Get(), &dismissedToken); + } + + return hr; +} + + +HRESULT WindowsToastNotification::CreateHString(const WCHAR* source, HSTRING* dest) +{ + if (source == NULL || dest == NULL) { + return E_INVALIDARG; + } + + HRESULT hr = WindowsCreateString(source, wcslen(source), dest); + return hr; +} + + +HRESULT WindowsToastNotification::CreateTempImageFile(const char* base64) +{ + BYTE* buff = NULL; + HRESULT hr = EnsureTempDir(); + do{ + BREAK_IF_BAD(hr); + + DWORD buffLen; + hr = ConvertBase64DataToImage(base64, &buff, &buffLen); + BREAK_IF_BAD(hr); + + hr = WriteToFile(buff, buffLen); + } while (FALSE); + + if (buff != NULL){ + delete buff; + } + + return hr; +} + + +HRESULT WindowsToastNotification::ConvertBase64DataToImage(const char* base64, BYTE** buff, DWORD* buffLen) +{ + HRESULT hr = E_FAIL; + *buffLen = 0; + DWORD reqSize; + if (CryptStringToBinary((LPCWSTR)base64, 0, CRYPT_STRING_BASE64, NULL, &reqSize, NULL, NULL)){ + *buff = new BYTE[reqSize]; + if (CryptStringToBinary((LPCWSTR)base64, 0, CRYPT_STRING_BASE64, *buff, &reqSize, NULL, NULL)){ + *buffLen = reqSize; + hr = S_OK; + } + } + + return hr; +} + + +HRESULT WindowsToastNotification::WriteToFile(BYTE* buff, DWORD buffLen) +{ + HRESULT hr = E_FAIL; + + GUID guid; + hr = CoCreateGuid(&guid); + if (SUCCEEDED(hr)){ + WCHAR randomName[MAX_PATH]; + StringFromGUID2(guid, randomName, ARRAYSIZE(randomName)); + + m_tempFilePath = new char[MAX_PATH]; + sprintf(m_tempFilePath, "%s\\%S", s_tempDirPath, randomName); + HANDLE file = CreateFile((LPCWSTR)m_tempFilePath, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); + if (file != INVALID_HANDLE_VALUE){ + DWORD bytesWritten; + if (WriteFile(file, buff, buffLen, &bytesWritten, NULL)){ + hr = S_OK; + } + else{ + DeleteTempImageFile(); + } + + CloseHandle(file); + } + } + + if (!SUCCEEDED(hr) && m_tempFilePath){ + delete m_tempFilePath; + m_tempFilePath = NULL; + } + + + return hr; +} + + +HRESULT WindowsToastNotification::EnsureTempDir() +{ + // Check for the Dir already existing or easy creation + HRESULT hr = E_FAIL; + if (CreateDirectory((LPCWSTR)s_tempDirPath, NULL) || GetLastError() == ERROR_ALREADY_EXISTS){ + hr = S_OK; + } else { + // NOTE: This makes an assumption that the path is a FULL LENGTH PATH. Therefore the first folder starts at the + // 4th character. ie. "c:\path\to\temp\dir" + + // It's possible that multiple directories need to be created. + for (int i = 3; i < ARRAYSIZE(s_tempDirPath); i++) { + char c = s_tempDirPath[i]; + if (c == '\\'){ + //Substring until this char + char* temp = new char[i + 1]; + strncpy(temp, s_tempDirPath, i); + temp[i] = 0; + if (!CreateDirectory((LPCWSTR)temp, NULL) && GetLastError() != ERROR_ALREADY_EXISTS){ + delete temp; + return hr; + } + + delete temp; + } + } + + //Try to create the full path one more time. This will take care of paths that don't end with a slash + if (CreateDirectory((LPCWSTR)s_tempDirPath, NULL) || GetLastError() == ERROR_ALREADY_EXISTS){ + hr = S_OK; + } + } + + return hr; +} + + +HRESULT WindowsToastNotification::DeleteTempImageFile() +{ + if (DeleteFile((LPCWSTR)m_tempFilePath)){ + return S_OK; + } + + return E_FAIL; +} + + +HRESULT WindowsToastNotification::EnsureShortcut() +{ + HRESULT hr = E_FAIL; + char shortcut[MAX_PATH]; + DWORD charsWritten = GetEnvironmentVariable(L"APPDATA", (LPWSTR)shortcut, MAX_PATH); + + if (charsWritten > 0) { + char shortcutCat[MAX_PATH]; + sprintf(shortcutCat, SHORTCUT_FORMAT, s_appName); + errno_t concatErr = strcat_s(shortcut, ARRAYSIZE(shortcut), shortcutCat); + if (concatErr == 0) { + DWORD attr = GetFileAttributes((LPCWSTR)shortcut); + bool exists = attr < 0xFFFFFFF; + if (exists){ + hr = S_OK; + } + else{ + WCHAR path[MAX_PATH]; + mbstowcs(path, shortcut, ARRAYSIZE(path)); + hr = CreateShortcut(path); + } + } + } + + return hr; +} + + +HRESULT WindowsToastNotification::CreateShortcut(WCHAR* path) +{ + HRESULT hr = E_FAIL; + char exePath[MAX_PATH]; + DWORD charsWritten = GetModuleFileNameEx(GetCurrentProcess(), nullptr, (LPWSTR)exePath, ARRAYSIZE(exePath)); + if (charsWritten > 0) { + PROPVARIANT propVariant; + ComPtr shellLink; + hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); + do{ + BREAK_IF_BAD(hr); + + hr = shellLink->SetPath((LPCWSTR)exePath); + BREAK_IF_BAD(hr); + + ComPtr propStore; + hr = shellLink.As(&propStore); + BREAK_IF_BAD(hr); + + WCHAR wAppName[MAX_PATH]; + swprintf(wAppName, ARRAYSIZE(wAppName), L"%S", s_appName); + hr = InitPropVariantFromString(wAppName, &propVariant); + BREAK_IF_BAD(hr); + + hr = propStore->SetValue(PKEY_AppUserModel_ID, propVariant); + BREAK_IF_BAD(hr); + + hr = propStore->Commit(); + BREAK_IF_BAD(hr); + + ComPtr persistFile; + hr = shellLink.As(&persistFile); + BREAK_IF_BAD(hr); + + hr = persistFile->Save(path, TRUE); + } while (FALSE); + + PropVariantClear(&propVariant); + } + + return hr; +} + +ToastEventHandler::ToastEventHandler(WindowsToastNotification* notification) +{ + m_ref = 1; + m_notification = notification; +} + + +ToastEventHandler::~ToastEventHandler() +{ + // Empty +} + + +IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IInspectable* args) +{ + //Notification "activated" (clicked) + if (m_notification != NULL){ + m_notification->NotificationClicked(); + } + return S_OK; +} + + +IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IToastDismissedEventArgs* e) +{ + //Notification dismissed + if (m_notification != NULL){ + m_notification->NotificationDismissed(); + } + return S_OK; +} + +} //namespace \ No newline at end of file diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h new file mode 100644 index 00000000000..ff745a8aac1 --- /dev/null +++ b/brightray/browser/win/windows_toast_notification.h @@ -0,0 +1,99 @@ +#ifndef __WINDOWS_TOAST_NOTIFICATION_H__ +#define __WINDOWS_TOAST_NOTIFICATION_H__ + +#define WIN32_LEAN_AND_MEAN + +#include +#include +#include +#include + +using namespace Microsoft::WRL; +using namespace ABI::Windows::UI::Notifications; +using namespace ABI::Windows::Foundation; +using namespace ABI::Windows::Data::Xml::Dom; + +namespace WinToasts{ + + typedef ITypedEventHandler DesktopToastActivatedEventHandler; + typedef ITypedEventHandler DesktopToastDismissedEventHandler; + + class ToastEventHandler; + + class WindowsToastNotification + { + private: + static char s_appName[MAX_PATH]; + static char s_tempDirPath[MAX_PATH]; + + char* m_tempFilePath; + ToastEventHandler* m_eventHandler; + + HRESULT GetToastXml(IToastNotificationManagerStatics* toastMgr, const WCHAR* title, const WCHAR* msg, const char* img, IXmlDocument** toastXml); + HRESULT SetXmlText(IXmlDocument* doc, const WCHAR* text); + HRESULT SetXmlText(IXmlDocument* doc, const WCHAR* title, const WCHAR* body); + HRESULT SetXmlImage(IXmlDocument* doc); + HRESULT GetTextNodeList(HSTRING* tag, IXmlDocument* doc, IXmlNodeList** nodeList, UINT32 reqLength); + HRESULT AppendTextToXml(IXmlDocument* doc, IXmlNode* node, const WCHAR* text); + HRESULT SetupCallbacks(IToastNotification* toast); + HRESULT CreateHString(const WCHAR* source, HSTRING* dest); + HRESULT CreateTempImageFile(const char* base64); + HRESULT ConvertBase64DataToImage(const char* base64, BYTE** buff, DWORD* buffLen); + HRESULT WriteToFile(BYTE* buff, DWORD buffLen); + HRESULT EnsureTempDir(); + HRESULT DeleteTempImageFile(); + HRESULT EnsureShortcut(); + HRESULT CreateShortcut(WCHAR* path); + + public: + WindowsToastNotification(const char* appName); + ~WindowsToastNotification(); + void ShowNotification(const WCHAR* title, const WCHAR* msg, const char* img); + void NotificationClicked(); + void NotificationDismissed(); + + static void InitSystemProps(char* appName, char* tempDirPath); + }; + + + class ToastEventHandler : + public Implements < DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler > + { + private: + ULONG m_ref; + WindowsToastNotification* m_notification; + + public: + ToastEventHandler(WindowsToastNotification* notification); + ~ToastEventHandler(); + IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args); + IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e); + IFACEMETHODIMP_(ULONG) AddRef() { return InterlockedIncrement(&m_ref); } + + IFACEMETHODIMP_(ULONG) Release() { + ULONG l = InterlockedDecrement(&m_ref); + if (l == 0) delete this; + return l; + } + + IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _COM_Outptr_ void **ppv) { + if (IsEqualIID(riid, IID_IUnknown)) + *ppv = static_cast(static_cast(this)); + else if (IsEqualIID(riid, __uuidof(DesktopToastActivatedEventHandler))) + *ppv = static_cast(this); + else if (IsEqualIID(riid, __uuidof(DesktopToastDismissedEventHandler))) + *ppv = static_cast(this); + else *ppv = nullptr; + + if (*ppv) { + reinterpret_cast(*ppv)->AddRef(); + return S_OK; + } + + return E_NOINTERFACE; + } + }; + +} // namespace + +#endif //__WINDOWS_TOAST_NOTIFICATION_H__ \ No newline at end of file diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index bbde28694d9..84dc4291ed2 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -63,6 +63,10 @@ 'browser/platform_notification_service_impl.h', 'browser/linux/notification_presenter_linux.h', 'browser/linux/notification_presenter_linux.cc', + 'browser/win/notification_presenter_win.h', + 'browser/win/notification_presenter_win.cc', + 'browser/win/windows_toast_notification.h', + 'browser/win/windows_toast_notification.cc', 'browser/special_storage_policy.cc', 'browser/special_storage_policy.h', 'browser/url_request_context_getter.cc', From 86ea0759d8634b3dab8f222356d459cd475fd8f3 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Sat, 7 Nov 2015 19:41:29 -0800 Subject: [PATCH 0701/1195] Windows Toasts: Icons, Events, Cleanup, Documentation - Enable documentations - Add a small usage example to the header - Final cleanups --- .../browser/win/notification_presenter_win.cc | 24 +- .../browser/win/notification_presenter_win.h | 13 +- .../browser/win/windows_toast_notification.cc | 340 ++++-------------- .../browser/win/windows_toast_notification.h | 34 +- 4 files changed, 107 insertions(+), 304 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 98cc7d04189..925fab17e19 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -1,30 +1,26 @@ // Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2013 Patrick Reynolds . All rights reserved. +// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. #include "browser/win/notification_presenter_win.h" - -#include "base/bind.h" -#include "base/logging.h" -#include "base/files/file_enumerator.h" #include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" +#include "base/win/windows_version.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" +#include "third_party/skia/include/core/SkBitmap.h" #include "common/application_info.h" + #include #include #include -#include "third_party/skia/include/core/SkBitmap.h" -#include "base/win/windows_version.h" // Windows Header #define WIN32_LEAN_AND_MEAN #include -#include #include +#include #include #include #include "windows_toast_notification.h" @@ -58,18 +54,20 @@ void NotificationPresenterWin::ShowNotification( base::Closure* cancel_callback) { std::wstring title = data.title; - std::wstring body = data.body; + std::wstring body = data.body; + std::string iconPath = data.icon.spec(); std::string appName = GetApplicationName(); - char* img = NULL; - WinToasts::WindowsToastNotification* wtn = new WinToasts::WindowsToastNotification(appName.c_str()); - wtn->ShowNotification(title.c_str(), body.c_str(), img); + WinToasts::WindowsToastNotification* wtn = new WinToasts::WindowsToastNotification(appName.c_str(), delegate_ptr.release()); + wtn->ShowNotification(title.c_str(), body.c_str(), iconPath); } void NotificationPresenterWin::CancelNotification() { + // No can do. } void NotificationPresenterWin::DeleteNotification() { + // No can do. } } // namespace brightray \ No newline at end of file diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index 0205422f92b..bed6eea9902 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -1,8 +1,19 @@ // Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2013 Patrick Reynolds . All rights reserved. +// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. +// Usage Example (JavaScript: +// var windowsNotification = new Notification("Test Title", { +// body: "Hi, I'm an example body. How are you?", +// icon: "file:///C:/Path/To/Your/Image.png" +// }); + +// windowsNotification.onshow = function () { console.log("Notification shown") }; +// windowsNotification.onclick = function () { console.log("Notification clicked") }; +// windowsNotification.onclose = function () { console.log("Notification dismissed") }; + + #ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_ diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 7a90ac3d3fb..2bf262e2175 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -1,53 +1,47 @@ -// Copyright (c) 2015 Felix Rieseberg . All rights reserved. +// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. // Copyright (c) 2015 Ryan McShane and Brandon Smith // Thanks to both of those folks mentioned above who first thought up a bunch of this code // and released it as MIT to the world. #include "windows_toast_notification.h" +#include "content/public/browser/desktop_notification_delegate.h" + #include #include #include #include #include #include +#include using namespace WinToasts; using namespace Windows::Foundation; #define BREAK_IF_BAD(hr) if(!SUCCEEDED(hr)) break; -#define SHORTCUT_FORMAT "\\Microsoft\\Windows\\Start Menu\\Programs\\%s.lnk" char WindowsToastNotification::s_appName[MAX_PATH] = {}; -char WindowsToastNotification::s_tempDirPath[MAX_PATH] = {}; namespace WinToasts { -WindowsToastNotification::WindowsToastNotification(const char* appName) +WindowsToastNotification::WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate) { sprintf_s(s_appName, ARRAYSIZE(s_appName), "%s", appName); m_eventHandler = NULL; - m_tempFilePath = NULL; + n_delegate = delegate; } WindowsToastNotification::~WindowsToastNotification() { - if (m_eventHandler){ + if (m_eventHandler) { delete m_eventHandler; } - - if (m_tempFilePath){ - DeleteTempImageFile(); - delete m_tempFilePath; + + if (n_delegate) { + delete n_delegate; } } -/*static*/ void WindowsToastNotification::InitSystemProps(char* appName, char* tempDirPath) -{ - - sprintf_s(s_tempDirPath, ARRAYSIZE(s_tempDirPath), "%s", tempDirPath); -} - -void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* msg, const char* img) +void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath) { // Init using WRL Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); @@ -55,14 +49,10 @@ void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* HSTRING toastNotifMgrStr = NULL; HSTRING appId = NULL; HSTRING toastNotifStr = NULL; - - // Create a shortcut in the user's app data folder - // (requirement for Windows 8 to show notifications - Windows 10 is fine without it) - // TODO: This shoudl be cleaned up - // HRESULT hr = EnsureShortcut(); + HRESULT hr; - do{ - HRESULT hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager, &toastNotifMgrStr); + do { + hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager, &toastNotifMgrStr); BREAK_IF_BAD(hr); ComPtr toastMgr; @@ -70,7 +60,7 @@ void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* BREAK_IF_BAD(hr); ComPtr toastXml; - hr = GetToastXml(toastMgr.Get(), title, msg, img, &toastXml); + hr = GetToastXml(toastMgr.Get(), title, msg, iconPath, &toastXml); BREAK_IF_BAD(hr); WCHAR wAppName[MAX_PATH]; @@ -99,52 +89,48 @@ void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* hr = notifier->Show(toast.Get()); BREAK_IF_BAD(hr); - //m_cbFn.Reset(Isolate::GetCurrent(), cbFn); - - //todo: - //cbPtr->NotificationDisplayed(); + n_delegate->NotificationDisplayed(); } while (FALSE); - if (toastNotifMgrStr != NULL){ + if (toastNotifMgrStr != NULL) { WindowsDeleteString(toastNotifMgrStr); } - if (appId != NULL){ + if (appId != NULL) { WindowsDeleteString(appId); } - if (toastNotifStr != NULL){ + if (toastNotifStr != NULL) { WindowsDeleteString(toastNotifStr); } - // if (!SUCCEEDED(hr)){ - // delete this; - // } + if (!SUCCEEDED(hr)) { + delete this; + } } - void WindowsToastNotification::NotificationClicked() { - // Local fn = Local::New(Isolate::GetCurrent(), m_cbFn); - // Handle args[1]; - // fn->Call(Isolate::GetCurrent()->GetCurrentContext()->Global(), 0, args); - // delete this; + delete this; } - void WindowsToastNotification::NotificationDismissed() { delete this; } - -HRESULT WindowsToastNotification::GetToastXml(IToastNotificationManagerStatics* toastMgr, const WCHAR* title, const WCHAR* msg, const char* img, IXmlDocument** toastXml) -{ +HRESULT WindowsToastNotification::GetToastXml( + IToastNotificationManagerStatics* toastMgr, + const WCHAR* title, + const WCHAR* msg, + std::string iconPath, + IXmlDocument** toastXml) { + HRESULT hr; ToastTemplateType templateType; - if (title == NULL || msg == NULL){ + if (title == NULL || msg == NULL) { // Single line toast - templateType = img == NULL ? ToastTemplateType_ToastText01 : ToastTemplateType_ToastImageAndText01; + templateType = iconPath.length() == 0 ? ToastTemplateType_ToastText01 : ToastTemplateType_ToastImageAndText01; hr = toastMgr->GetTemplateContent(templateType, toastXml); if (SUCCEEDED(hr)) { const WCHAR* text = title != NULL ? title : msg; @@ -152,18 +138,17 @@ HRESULT WindowsToastNotification::GetToastXml(IToastNotificationManagerStatics* } } else { // Title and body toast - templateType = img == NULL ? ToastTemplateType_ToastText02 : ToastTemplateType_ToastImageAndText02; + templateType = iconPath.length() == 0 ? ToastTemplateType_ToastText02 : ToastTemplateType_ToastImageAndText02; hr = toastMgr->GetTemplateContent(templateType, toastXml); if (SUCCEEDED(hr)) { hr = SetXmlText(*toastXml, title, msg); } } - if (img != NULL && SUCCEEDED(hr)){ + if (iconPath.length() != 0 && SUCCEEDED(hr)) { // Toast has image - hr = CreateTempImageFile(img); - if (SUCCEEDED(hr)){ - hr = SetXmlImage(*toastXml); + if (SUCCEEDED(hr)) { + hr = SetXmlImage(*toastXml, iconPath); } // Don't stop a notification from showing just because an image couldn't be displayed. By default the app icon will be shown. @@ -173,7 +158,6 @@ HRESULT WindowsToastNotification::GetToastXml(IToastNotificationManagerStatics* return hr; } - HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* text) { HSTRING tag = NULL; @@ -190,14 +174,13 @@ HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* tex hr = AppendTextToXml(doc, node.Get(), text); } while (FALSE); - if (tag != NULL){ + if (tag != NULL) { WindowsDeleteString(tag); } return hr; } - HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* title, const WCHAR* body) { HSTRING tag = NULL; @@ -219,21 +202,21 @@ HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* tit hr = AppendTextToXml(doc, node.Get(), body); } while (FALSE); - if (tag != NULL){ + if (tag != NULL) { WindowsDeleteString(tag); } return hr; } - -HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc) +HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc, std::string iconPath) { HSTRING tag = NULL; HSTRING src = NULL; HSTRING imgPath = NULL; HRESULT hr = CreateHString(L"image", &tag); - do{ + + do { BREAK_IF_BAD(hr); ComPtr nodeList; @@ -256,7 +239,7 @@ HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc) BREAK_IF_BAD(hr); WCHAR xmlPath[MAX_PATH]; - swprintf(xmlPath, ARRAYSIZE(xmlPath), L"file:///%S", m_tempFilePath); + swprintf(xmlPath, ARRAYSIZE(xmlPath), L"%S", iconPath); hr = CreateHString(xmlPath, &imgPath); BREAK_IF_BAD(hr); @@ -272,20 +255,19 @@ HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc) hr = srcAttr->AppendChild(srcNode.Get(), &childNode); } while (FALSE); - if (tag != NULL){ + if (tag != NULL) { WindowsDeleteString(tag); } - if (src != NULL){ + if (src != NULL) { WindowsDeleteString(src); } - if (imgPath != NULL){ + if (imgPath != NULL) { WindowsDeleteString(imgPath); } return hr; } - HRESULT WindowsToastNotification::GetTextNodeList(HSTRING* tag, IXmlDocument* doc, IXmlNodeList** nodeList, UINT32 reqLength) { HRESULT hr = CreateHString(L"text", tag); @@ -304,7 +286,7 @@ HRESULT WindowsToastNotification::GetTextNodeList(HSTRING* tag, IXmlDocument* do } } while (FALSE); - if (!SUCCEEDED(hr)){ + if (!SUCCEEDED(hr)) { // Allow the caller to delete this string on success WindowsDeleteString(*tag); } @@ -312,12 +294,11 @@ HRESULT WindowsToastNotification::GetTextNodeList(HSTRING* tag, IXmlDocument* do return hr; } - HRESULT WindowsToastNotification::AppendTextToXml(IXmlDocument* doc, IXmlNode* node, const WCHAR* text) { HSTRING str = NULL; HRESULT hr = CreateHString(text, &str); - do{ + do { BREAK_IF_BAD(hr); ComPtr xmlText; @@ -332,20 +313,20 @@ HRESULT WindowsToastNotification::AppendTextToXml(IXmlDocument* doc, IXmlNode* n hr = node->AppendChild(textNode.Get(), &appendNode); } while (FALSE); - if (str != NULL){ + if (str != NULL) { WindowsDeleteString(str); } return hr; } - HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast) { EventRegistrationToken activatedToken, dismissedToken; - m_eventHandler = new ToastEventHandler(this); + m_eventHandler = new ToastEventHandler(this, n_delegate); ComPtr eventHandler(m_eventHandler); HRESULT hr = toast->add_Activated(eventHandler.Get(), &activatedToken); + if (SUCCEEDED(hr)) { hr = toast->add_Dismissed(eventHandler.Get(), &dismissedToken); } @@ -353,7 +334,6 @@ HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast) return hr; } - HRESULT WindowsToastNotification::CreateHString(const WCHAR* source, HSTRING* dest) { if (source == NULL || dest == NULL) { @@ -364,229 +344,43 @@ HRESULT WindowsToastNotification::CreateHString(const WCHAR* source, HSTRING* de return hr; } - -HRESULT WindowsToastNotification::CreateTempImageFile(const char* base64) -{ - BYTE* buff = NULL; - HRESULT hr = EnsureTempDir(); - do{ - BREAK_IF_BAD(hr); - - DWORD buffLen; - hr = ConvertBase64DataToImage(base64, &buff, &buffLen); - BREAK_IF_BAD(hr); - - hr = WriteToFile(buff, buffLen); - } while (FALSE); - - if (buff != NULL){ - delete buff; - } - - return hr; -} - - -HRESULT WindowsToastNotification::ConvertBase64DataToImage(const char* base64, BYTE** buff, DWORD* buffLen) -{ - HRESULT hr = E_FAIL; - *buffLen = 0; - DWORD reqSize; - if (CryptStringToBinary((LPCWSTR)base64, 0, CRYPT_STRING_BASE64, NULL, &reqSize, NULL, NULL)){ - *buff = new BYTE[reqSize]; - if (CryptStringToBinary((LPCWSTR)base64, 0, CRYPT_STRING_BASE64, *buff, &reqSize, NULL, NULL)){ - *buffLen = reqSize; - hr = S_OK; - } - } - - return hr; -} - - -HRESULT WindowsToastNotification::WriteToFile(BYTE* buff, DWORD buffLen) -{ - HRESULT hr = E_FAIL; - - GUID guid; - hr = CoCreateGuid(&guid); - if (SUCCEEDED(hr)){ - WCHAR randomName[MAX_PATH]; - StringFromGUID2(guid, randomName, ARRAYSIZE(randomName)); - - m_tempFilePath = new char[MAX_PATH]; - sprintf(m_tempFilePath, "%s\\%S", s_tempDirPath, randomName); - HANDLE file = CreateFile((LPCWSTR)m_tempFilePath, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); - if (file != INVALID_HANDLE_VALUE){ - DWORD bytesWritten; - if (WriteFile(file, buff, buffLen, &bytesWritten, NULL)){ - hr = S_OK; - } - else{ - DeleteTempImageFile(); - } - - CloseHandle(file); - } - } - - if (!SUCCEEDED(hr) && m_tempFilePath){ - delete m_tempFilePath; - m_tempFilePath = NULL; - } - - - return hr; -} - - -HRESULT WindowsToastNotification::EnsureTempDir() -{ - // Check for the Dir already existing or easy creation - HRESULT hr = E_FAIL; - if (CreateDirectory((LPCWSTR)s_tempDirPath, NULL) || GetLastError() == ERROR_ALREADY_EXISTS){ - hr = S_OK; - } else { - // NOTE: This makes an assumption that the path is a FULL LENGTH PATH. Therefore the first folder starts at the - // 4th character. ie. "c:\path\to\temp\dir" - - // It's possible that multiple directories need to be created. - for (int i = 3; i < ARRAYSIZE(s_tempDirPath); i++) { - char c = s_tempDirPath[i]; - if (c == '\\'){ - //Substring until this char - char* temp = new char[i + 1]; - strncpy(temp, s_tempDirPath, i); - temp[i] = 0; - if (!CreateDirectory((LPCWSTR)temp, NULL) && GetLastError() != ERROR_ALREADY_EXISTS){ - delete temp; - return hr; - } - - delete temp; - } - } - - //Try to create the full path one more time. This will take care of paths that don't end with a slash - if (CreateDirectory((LPCWSTR)s_tempDirPath, NULL) || GetLastError() == ERROR_ALREADY_EXISTS){ - hr = S_OK; - } - } - - return hr; -} - - -HRESULT WindowsToastNotification::DeleteTempImageFile() -{ - if (DeleteFile((LPCWSTR)m_tempFilePath)){ - return S_OK; - } - - return E_FAIL; -} - - -HRESULT WindowsToastNotification::EnsureShortcut() -{ - HRESULT hr = E_FAIL; - char shortcut[MAX_PATH]; - DWORD charsWritten = GetEnvironmentVariable(L"APPDATA", (LPWSTR)shortcut, MAX_PATH); - - if (charsWritten > 0) { - char shortcutCat[MAX_PATH]; - sprintf(shortcutCat, SHORTCUT_FORMAT, s_appName); - errno_t concatErr = strcat_s(shortcut, ARRAYSIZE(shortcut), shortcutCat); - if (concatErr == 0) { - DWORD attr = GetFileAttributes((LPCWSTR)shortcut); - bool exists = attr < 0xFFFFFFF; - if (exists){ - hr = S_OK; - } - else{ - WCHAR path[MAX_PATH]; - mbstowcs(path, shortcut, ARRAYSIZE(path)); - hr = CreateShortcut(path); - } - } - } - - return hr; -} - - -HRESULT WindowsToastNotification::CreateShortcut(WCHAR* path) -{ - HRESULT hr = E_FAIL; - char exePath[MAX_PATH]; - DWORD charsWritten = GetModuleFileNameEx(GetCurrentProcess(), nullptr, (LPWSTR)exePath, ARRAYSIZE(exePath)); - if (charsWritten > 0) { - PROPVARIANT propVariant; - ComPtr shellLink; - hr = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink)); - do{ - BREAK_IF_BAD(hr); - - hr = shellLink->SetPath((LPCWSTR)exePath); - BREAK_IF_BAD(hr); - - ComPtr propStore; - hr = shellLink.As(&propStore); - BREAK_IF_BAD(hr); - - WCHAR wAppName[MAX_PATH]; - swprintf(wAppName, ARRAYSIZE(wAppName), L"%S", s_appName); - hr = InitPropVariantFromString(wAppName, &propVariant); - BREAK_IF_BAD(hr); - - hr = propStore->SetValue(PKEY_AppUserModel_ID, propVariant); - BREAK_IF_BAD(hr); - - hr = propStore->Commit(); - BREAK_IF_BAD(hr); - - ComPtr persistFile; - hr = shellLink.As(&persistFile); - BREAK_IF_BAD(hr); - - hr = persistFile->Save(path, TRUE); - } while (FALSE); - - PropVariantClear(&propVariant); - } - - return hr; -} - -ToastEventHandler::ToastEventHandler(WindowsToastNotification* notification) +/* +/ Toast Event Handler +*/ +ToastEventHandler::ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate) { m_ref = 1; m_notification = notification; + n_delegate = delegate; } - ToastEventHandler::~ToastEventHandler() { // Empty } - IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IInspectable* args) { - //Notification "activated" (clicked) - if (m_notification != NULL){ + // Notification "activated" (clicked) + n_delegate->NotificationClick(); + + if (m_notification != NULL) { m_notification->NotificationClicked(); } + return S_OK; } - IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IToastDismissedEventArgs* e) -{ - //Notification dismissed - if (m_notification != NULL){ +{ + // Notification dismissed + n_delegate->NotificationClosed(); + + if (m_notification != NULL) { m_notification->NotificationDismissed(); + } + return S_OK; } diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index ff745a8aac1..8c43326ad05 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -1,12 +1,22 @@ +// Copyright (c) 2015 Felix Rieseberg . All rights reserved. +// Copyright (c) 2015 Ryan McShane and Brandon Smith +// Thanks to both of those folks mentioned above who first thought up a bunch of this code +// and released it as MIT to the world. + #ifndef __WINDOWS_TOAST_NOTIFICATION_H__ #define __WINDOWS_TOAST_NOTIFICATION_H__ #define WIN32_LEAN_AND_MEAN +#include "content/public/browser/desktop_notification_delegate.h" +#include "content/public/common/platform_notification_data.h" +#include "base/bind.h" + #include #include #include #include +#include using namespace Microsoft::WRL; using namespace ABI::Windows::UI::Notifications; @@ -24,35 +34,24 @@ namespace WinToasts{ { private: static char s_appName[MAX_PATH]; - static char s_tempDirPath[MAX_PATH]; - - char* m_tempFilePath; ToastEventHandler* m_eventHandler; + content::DesktopNotificationDelegate* n_delegate; - HRESULT GetToastXml(IToastNotificationManagerStatics* toastMgr, const WCHAR* title, const WCHAR* msg, const char* img, IXmlDocument** toastXml); + HRESULT GetToastXml(IToastNotificationManagerStatics* toastMgr, const WCHAR* title, const WCHAR* msg, std::string iconPath, IXmlDocument** toastXml); HRESULT SetXmlText(IXmlDocument* doc, const WCHAR* text); HRESULT SetXmlText(IXmlDocument* doc, const WCHAR* title, const WCHAR* body); - HRESULT SetXmlImage(IXmlDocument* doc); + HRESULT SetXmlImage(IXmlDocument* doc, std::string iconPath); HRESULT GetTextNodeList(HSTRING* tag, IXmlDocument* doc, IXmlNodeList** nodeList, UINT32 reqLength); HRESULT AppendTextToXml(IXmlDocument* doc, IXmlNode* node, const WCHAR* text); HRESULT SetupCallbacks(IToastNotification* toast); HRESULT CreateHString(const WCHAR* source, HSTRING* dest); - HRESULT CreateTempImageFile(const char* base64); - HRESULT ConvertBase64DataToImage(const char* base64, BYTE** buff, DWORD* buffLen); - HRESULT WriteToFile(BYTE* buff, DWORD buffLen); - HRESULT EnsureTempDir(); - HRESULT DeleteTempImageFile(); - HRESULT EnsureShortcut(); - HRESULT CreateShortcut(WCHAR* path); public: - WindowsToastNotification(const char* appName); + WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate); ~WindowsToastNotification(); - void ShowNotification(const WCHAR* title, const WCHAR* msg, const char* img); + void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath); void NotificationClicked(); void NotificationDismissed(); - - static void InitSystemProps(char* appName, char* tempDirPath); }; @@ -62,9 +61,10 @@ namespace WinToasts{ private: ULONG m_ref; WindowsToastNotification* m_notification; + content::DesktopNotificationDelegate* n_delegate; public: - ToastEventHandler(WindowsToastNotification* notification); + ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate); ~ToastEventHandler(); IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args); IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e); From 8dbeca8c7fda975c0204dfa3c693da31f7870adc Mon Sep 17 00:00:00 2001 From: Jason Poon Date: Sat, 7 Nov 2015 22:11:15 -0800 Subject: [PATCH 0702/1195] Windows Toasts: Hide(), Runtime Check, Header Cleanup --- .../browser/win/notification_presenter_win.cc | 42 ++++---- .../browser/win/notification_presenter_win.h | 16 ++-- .../browser/win/windows_toast_notification.cc | 96 ++++++++----------- .../browser/win/windows_toast_notification.h | 54 +++++------ 4 files changed, 94 insertions(+), 114 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 925fab17e19..8870de36e3e 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -1,30 +1,15 @@ // Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. +// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. #include "browser/win/notification_presenter_win.h" -#include "base/strings/string_util.h" #include "base/win/windows_version.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" #include "third_party/skia/include/core/SkBitmap.h" #include "common/application_info.h" -#include -#include -#include - -// Windows Header -#define WIN32_LEAN_AND_MEAN - -#include -#include -#include -#include -#include -#include "windows_toast_notification.h" - #pragma comment(lib, "runtimeobject.lib") #pragma comment(lib, "Crypt32.lib") @@ -42,6 +27,7 @@ NotificationPresenter* NotificationPresenter::Create() { } NotificationPresenterWin::NotificationPresenterWin() { + m_lastNotification = nullptr; } NotificationPresenterWin::~NotificationPresenterWin() { @@ -57,17 +43,25 @@ void NotificationPresenterWin::ShowNotification( std::wstring body = data.body; std::string iconPath = data.icon.spec(); std::string appName = GetApplicationName(); + + // toast notification supported in version >= Windows 8 + // for prior versions, use Tray.displayBalloon + if (base::win::GetVersion() >= base::win::VERSION_WIN8) { + wtn = new WindowsToastNotification(appName.c_str(), delegate_ptr.release()); + wtn->ShowNotification(title.c_str(), body.c_str(), iconPath, m_lastNotification); + } - WinToasts::WindowsToastNotification* wtn = new WinToasts::WindowsToastNotification(appName.c_str(), delegate_ptr.release()); - wtn->ShowNotification(title.c_str(), body.c_str(), iconPath); + if (cancel_callback) { + *cancel_callback = base::Bind( + &NotificationPresenterWin::RemoveNotification, + base::Unretained(this)); + } } -void NotificationPresenterWin::CancelNotification() { - // No can do. -} - -void NotificationPresenterWin::DeleteNotification() { - // No can do. +void NotificationPresenterWin::RemoveNotification() { + if (m_lastNotification != nullptr && wtn != NULL) { + wtn->DismissNotification(m_lastNotification); + } } } // namespace brightray \ No newline at end of file diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index bed6eea9902..a2ecd81b952 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -1,5 +1,5 @@ // Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. +// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. @@ -19,8 +19,12 @@ #include "base/compiler_specific.h" #include "browser/notification_presenter.h" +#include "windows_toast_notification.h" #include +#include +#include +#include namespace brightray { @@ -29,7 +33,6 @@ class NotificationPresenterWin : public NotificationPresenter { NotificationPresenterWin(); ~NotificationPresenterWin(); - // NotificationPresenter: void ShowNotification( const content::PlatformNotificationData&, const SkBitmap& icon, @@ -39,11 +42,10 @@ class NotificationPresenterWin : public NotificationPresenter { void RemoveNotification(); private: - - void CancelNotification(); - void DeleteNotification(); + WinToasts::WindowsToastNotification* wtn; + Microsoft::WRL::ComPtr m_lastNotification; }; -} // namespace brightray +} // namespace -#endif +#endif // BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_ diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 2bf262e2175..5d306032d68 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. +// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. // Copyright (c) 2015 Ryan McShane and Brandon Smith // Thanks to both of those folks mentioned above who first thought up a bunch of this code // and released it as MIT to the world. @@ -6,26 +6,41 @@ #include "windows_toast_notification.h" #include "content/public/browser/desktop_notification_delegate.h" -#include -#include -#include -#include -#include -#include -#include - using namespace WinToasts; -using namespace Windows::Foundation; +using namespace Microsoft::WRL; +using namespace ABI::Windows::UI::Notifications; +using namespace ABI::Windows::Data::Xml::Dom; #define BREAK_IF_BAD(hr) if(!SUCCEEDED(hr)) break; -char WindowsToastNotification::s_appName[MAX_PATH] = {}; - namespace WinToasts { +// Initialize Windows Runtime +static HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); + WindowsToastNotification::WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate) { - sprintf_s(s_appName, ARRAYSIZE(s_appName), "%s", appName); + HSTRING toastNotifMgrStr = NULL; + HSTRING appId = NULL; + + HRESULT hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager, &toastNotifMgrStr); + + hr = Windows::Foundation::GetActivationFactory(toastNotifMgrStr, &m_toastManager); + + WCHAR wAppName[MAX_PATH]; + swprintf(wAppName, ARRAYSIZE(wAppName), L"%S", appName); + hr = CreateHString(wAppName, &appId); + + m_toastManager->CreateToastNotifierWithId(appId, &m_toastNotifier); + + if (toastNotifMgrStr != NULL) { + WindowsDeleteString(toastNotifMgrStr); + } + + if (appId != NULL) { + WindowsDeleteString(appId); + } + m_eventHandler = NULL; n_delegate = delegate; } @@ -41,35 +56,14 @@ WindowsToastNotification::~WindowsToastNotification() } } -void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath) +void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr& toast) { - // Init using WRL - Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); - - HSTRING toastNotifMgrStr = NULL; - HSTRING appId = NULL; - HSTRING toastNotifStr = NULL; HRESULT hr; + HSTRING toastNotifStr = NULL; do { - hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager, &toastNotifMgrStr); - BREAK_IF_BAD(hr); - - ComPtr toastMgr; - hr = Windows::Foundation::GetActivationFactory(toastNotifMgrStr, &toastMgr); - BREAK_IF_BAD(hr); - ComPtr toastXml; - hr = GetToastXml(toastMgr.Get(), title, msg, iconPath, &toastXml); - BREAK_IF_BAD(hr); - - WCHAR wAppName[MAX_PATH]; - swprintf(wAppName, ARRAYSIZE(wAppName), L"%S", s_appName); - hr = CreateHString(wAppName, &appId); - BREAK_IF_BAD(hr); - - ComPtr notifier; - toastMgr->CreateToastNotifierWithId(appId, ¬ifier); + hr = GetToastXml(m_toastManager.Get(), title, msg, iconPath, &toastXml); BREAK_IF_BAD(hr); hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotification, &toastNotifStr); @@ -79,34 +73,26 @@ void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* hr = Windows::Foundation::GetActivationFactory(toastNotifStr, &toastFactory); BREAK_IF_BAD(hr); - ComPtr toast; hr = toastFactory->CreateToastNotification(toastXml.Get(), &toast); BREAK_IF_BAD(hr); hr = SetupCallbacks(toast.Get()); BREAK_IF_BAD(hr); - hr = notifier->Show(toast.Get()); + hr = m_toastNotifier->Show(toast.Get()); BREAK_IF_BAD(hr); n_delegate->NotificationDisplayed(); } while (FALSE); - if (toastNotifMgrStr != NULL) { - WindowsDeleteString(toastNotifMgrStr); - } - - if (appId != NULL) { - WindowsDeleteString(appId); - } - if (toastNotifStr != NULL) { WindowsDeleteString(toastNotifStr); } +} - if (!SUCCEEDED(hr)) { - delete this; - } +void WindowsToastNotification::DismissNotification(ComPtr toast) +{ + m_toastNotifier->Hide(toast.Get()); } void WindowsToastNotification::NotificationClicked() @@ -120,7 +106,7 @@ void WindowsToastNotification::NotificationDismissed() } HRESULT WindowsToastNotification::GetToastXml( - IToastNotificationManagerStatics* toastMgr, + IToastNotificationManagerStatics* toastManager, const WCHAR* title, const WCHAR* msg, std::string iconPath, @@ -131,7 +117,7 @@ HRESULT WindowsToastNotification::GetToastXml( if (title == NULL || msg == NULL) { // Single line toast templateType = iconPath.length() == 0 ? ToastTemplateType_ToastText01 : ToastTemplateType_ToastImageAndText01; - hr = toastMgr->GetTemplateContent(templateType, toastXml); + hr = m_toastManager->GetTemplateContent(templateType, toastXml); if (SUCCEEDED(hr)) { const WCHAR* text = title != NULL ? title : msg; hr = SetXmlText(*toastXml, text); @@ -139,7 +125,7 @@ HRESULT WindowsToastNotification::GetToastXml( } else { // Title and body toast templateType = iconPath.length() == 0 ? ToastTemplateType_ToastText02 : ToastTemplateType_ToastImageAndText02; - hr = toastMgr->GetTemplateContent(templateType, toastXml); + hr = toastManager->GetTemplateContent(templateType, toastXml); if (SUCCEEDED(hr)) { hr = SetXmlText(*toastXml, title, msg); } @@ -164,7 +150,7 @@ HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* tex ComPtr nodeList; HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 1); - do{ + do { BREAK_IF_BAD(hr); ComPtr node; @@ -186,7 +172,7 @@ HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* tit HSTRING tag = NULL; ComPtr nodeList; HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 2); - do{ + do { BREAK_IF_BAD(hr); ComPtr node; diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index 8c43326ad05..474d55c767d 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -1,4 +1,4 @@ -// Copyright (c) 2015 Felix Rieseberg . All rights reserved. +// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. // Copyright (c) 2015 Ryan McShane and Brandon Smith // Thanks to both of those folks mentioned above who first thought up a bunch of this code // and released it as MIT to the world. @@ -6,24 +6,19 @@ #ifndef __WINDOWS_TOAST_NOTIFICATION_H__ #define __WINDOWS_TOAST_NOTIFICATION_H__ -#define WIN32_LEAN_AND_MEAN - #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" #include "base/bind.h" #include #include -#include #include -#include using namespace Microsoft::WRL; using namespace ABI::Windows::UI::Notifications; using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Data::Xml::Dom; -namespace WinToasts{ +namespace WinToasts { typedef ITypedEventHandler DesktopToastActivatedEventHandler; typedef ITypedEventHandler DesktopToastDismissedEventHandler; @@ -32,37 +27,35 @@ namespace WinToasts{ class WindowsToastNotification { - private: - static char s_appName[MAX_PATH]; - ToastEventHandler* m_eventHandler; - content::DesktopNotificationDelegate* n_delegate; - - HRESULT GetToastXml(IToastNotificationManagerStatics* toastMgr, const WCHAR* title, const WCHAR* msg, std::string iconPath, IXmlDocument** toastXml); - HRESULT SetXmlText(IXmlDocument* doc, const WCHAR* text); - HRESULT SetXmlText(IXmlDocument* doc, const WCHAR* title, const WCHAR* body); - HRESULT SetXmlImage(IXmlDocument* doc, std::string iconPath); - HRESULT GetTextNodeList(HSTRING* tag, IXmlDocument* doc, IXmlNodeList** nodeList, UINT32 reqLength); - HRESULT AppendTextToXml(IXmlDocument* doc, IXmlNode* node, const WCHAR* text); - HRESULT SetupCallbacks(IToastNotification* toast); - HRESULT CreateHString(const WCHAR* source, HSTRING* dest); - public: WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate); ~WindowsToastNotification(); - void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath); + void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr& toast); + void DismissNotification(ComPtr toast); void NotificationClicked(); void NotificationDismissed(); + + private: + ToastEventHandler* m_eventHandler; + + content::DesktopNotificationDelegate* n_delegate; + ComPtr m_toastManager; + ComPtr m_toastNotifier; + + HRESULT GetToastXml(IToastNotificationManagerStatics* toastManager, const WCHAR* title, const WCHAR* msg, std::string iconPath, ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); + HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* text); + HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* title, const WCHAR* body); + HRESULT SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, std::string iconPath); + HRESULT GetTextNodeList(HSTRING* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, UINT32 reqLength); + HRESULT AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const WCHAR* text); + HRESULT SetupCallbacks(IToastNotification* toast); + HRESULT CreateHString(const WCHAR* source, HSTRING* dest); }; class ToastEventHandler : - public Implements < DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler > + public Implements { - private: - ULONG m_ref; - WindowsToastNotification* m_notification; - content::DesktopNotificationDelegate* n_delegate; - public: ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate); ~ToastEventHandler(); @@ -92,6 +85,11 @@ namespace WinToasts{ return E_NOINTERFACE; } + + private: + ULONG m_ref; + WindowsToastNotification* m_notification; + content::DesktopNotificationDelegate* n_delegate; }; } // namespace From 8f5463faab51b87787dbc315ef4b97812bada466 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Mon, 9 Nov 2015 20:47:18 +0100 Subject: [PATCH 0703/1195] Simplify ToastEventHandler using WRL::RuntimeClass, which implements the IUnknown interface --- .../browser/win/windows_toast_notification.cc | 14 +++------ .../browser/win/windows_toast_notification.h | 29 ++----------------- 2 files changed, 6 insertions(+), 37 deletions(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 5d306032d68..804cd55289b 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -41,16 +41,11 @@ WindowsToastNotification::WindowsToastNotification(const char* appName, content: WindowsDeleteString(appId); } - m_eventHandler = NULL; n_delegate = delegate; } WindowsToastNotification::~WindowsToastNotification() { - if (m_eventHandler) { - delete m_eventHandler; - } - if (n_delegate) { delete n_delegate; } @@ -309,12 +304,11 @@ HRESULT WindowsToastNotification::AppendTextToXml(IXmlDocument* doc, IXmlNode* n HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast) { EventRegistrationToken activatedToken, dismissedToken; - m_eventHandler = new ToastEventHandler(this, n_delegate); - ComPtr eventHandler(m_eventHandler); - HRESULT hr = toast->add_Activated(eventHandler.Get(), &activatedToken); - + m_eventHandler = Make(this, n_delegate); + HRESULT hr = toast->add_Activated(m_eventHandler.Get(), &activatedToken); + if (SUCCEEDED(hr)) { - hr = toast->add_Dismissed(eventHandler.Get(), &dismissedToken); + hr = toast->add_Dismissed(m_eventHandler.Get(), &dismissedToken); } return hr; diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index 474d55c767d..d501954ec5c 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -36,7 +36,7 @@ namespace WinToasts { void NotificationDismissed(); private: - ToastEventHandler* m_eventHandler; + ComPtr m_eventHandler; content::DesktopNotificationDelegate* n_delegate; ComPtr m_toastManager; @@ -54,40 +54,15 @@ namespace WinToasts { class ToastEventHandler : - public Implements + public RuntimeClass, DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler> { public: ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate); ~ToastEventHandler(); IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args); IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e); - IFACEMETHODIMP_(ULONG) AddRef() { return InterlockedIncrement(&m_ref); } - - IFACEMETHODIMP_(ULONG) Release() { - ULONG l = InterlockedDecrement(&m_ref); - if (l == 0) delete this; - return l; - } - - IFACEMETHODIMP QueryInterface(_In_ REFIID riid, _COM_Outptr_ void **ppv) { - if (IsEqualIID(riid, IID_IUnknown)) - *ppv = static_cast(static_cast(this)); - else if (IsEqualIID(riid, __uuidof(DesktopToastActivatedEventHandler))) - *ppv = static_cast(this); - else if (IsEqualIID(riid, __uuidof(DesktopToastDismissedEventHandler))) - *ppv = static_cast(this); - else *ppv = nullptr; - - if (*ppv) { - reinterpret_cast(*ppv)->AddRef(); - return S_OK; - } - - return E_NOINTERFACE; - } private: - ULONG m_ref; WindowsToastNotification* m_notification; content::DesktopNotificationDelegate* n_delegate; }; From 995b09485896ad4bef26cf272fc0fbdc0a415614 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Mon, 9 Nov 2015 09:51:52 -0800 Subject: [PATCH 0704/1195] Ensure Notifications are Windows 8 and up only --- .../browser/platform_notification_service_impl.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service_impl.cc index db8572ee898..36045f6db4f 100644 --- a/brightray/browser/platform_notification_service_impl.cc +++ b/brightray/browser/platform_notification_service_impl.cc @@ -8,6 +8,10 @@ #include "content/public/browser/desktop_notification_delegate.h" +#if defined(OS_WIN) +#include "base/win/windows_version.h" +#endif + namespace brightray { // static @@ -20,8 +24,16 @@ PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {} PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} NotificationPresenter* PlatformNotificationServiceImpl::notification_presenter() { - if (!notification_presenter_) + if (!notification_presenter_) { + #if defined(OS_WIN) + // Bail out if on Windows 7 or even lower, no operating will follow + if (base::win::GetVersion() < base::win::VERSION_WIN8) { + return notification_presenter_.get(); + } + #endif + // Create a new presenter if on OS X, Linux, or Windows 8+ notification_presenter_.reset(NotificationPresenter::Create()); + } return notification_presenter_.get(); } From 37a89ee0d98ab59b9f5291c6a79181e16fe48e1e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Nov 2015 18:04:46 +0800 Subject: [PATCH 0705/1195] Fix compilation error --- brightray/browser/win/windows_toast_notification.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 804cd55289b..830a6f67003 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -329,7 +329,6 @@ HRESULT WindowsToastNotification::CreateHString(const WCHAR* source, HSTRING* de */ ToastEventHandler::ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate) { - m_ref = 1; m_notification = notification; n_delegate = delegate; } @@ -364,4 +363,4 @@ IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IToastDismi return S_OK; } -} //namespace \ No newline at end of file +} //namespace From 1b9c9e40e3b5618ea8d93f5a8476e7fd3f7ad6ea Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Nov 2015 18:27:18 +0800 Subject: [PATCH 0706/1195] Code cleanup with Chromium's coding style --- brightray/brightray.gyp | 7 +- .../browser/win/notification_presenter_win.cc | 18 +- .../browser/win/notification_presenter_win.h | 9 +- .../browser/win/windows_toast_notification.cc | 589 +++++++++--------- .../browser/win/windows_toast_notification.h | 93 +-- 5 files changed, 358 insertions(+), 358 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index db04f5672ce..9b548e70a7f 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -164,8 +164,11 @@ 'msvs_settings': { 'VCLinkerTool': { 'AdditionalDependencies': [ + # Windows Runtime. + 'crypt32.lib', 'runtimeobject.lib', - 'windowsapp.lib' + 'shlwapi.lib', + 'windowsapp.lib', ], }, }, @@ -203,8 +206,6 @@ 'msvs_settings': { 'VCLinkerTool': { 'AdditionalDependencies': [ - 'Shlwapi.lib', - 'Crypt32.lib', 'advapi32.lib', 'dbghelp.lib', 'delayimp.lib', diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 8870de36e3e..20b2a3333a8 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -5,13 +5,12 @@ #include "browser/win/notification_presenter_win.h" #include "base/win/windows_version.h" +#include "common/application_info.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" #include "third_party/skia/include/core/SkBitmap.h" -#include "common/application_info.h" #pragma comment(lib, "runtimeobject.lib") -#pragma comment(lib, "Crypt32.lib") using namespace WinToasts; using namespace Microsoft::WRL; @@ -34,14 +33,13 @@ NotificationPresenterWin::~NotificationPresenterWin() { } void NotificationPresenterWin::ShowNotification( - const content::PlatformNotificationData& data, - const SkBitmap& icon, - scoped_ptr delegate_ptr, - base::Closure* cancel_callback) { - + const content::PlatformNotificationData& data, + const SkBitmap& icon, + scoped_ptr delegate_ptr, + base::Closure* cancel_callback) { std::wstring title = data.title; std::wstring body = data.body; - std::string iconPath = data.icon.spec(); + std::string iconPath = data.icon.spec(); std::string appName = GetApplicationName(); // toast notification supported in version >= Windows 8 @@ -50,7 +48,7 @@ void NotificationPresenterWin::ShowNotification( wtn = new WindowsToastNotification(appName.c_str(), delegate_ptr.release()); wtn->ShowNotification(title.c_str(), body.c_str(), iconPath, m_lastNotification); } - + if (cancel_callback) { *cancel_callback = base::Bind( &NotificationPresenterWin::RemoveNotification, @@ -64,4 +62,4 @@ void NotificationPresenterWin::RemoveNotification() { } } -} // namespace brightray \ No newline at end of file +} // namespace brightray diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index a2ecd81b952..fa7ccf40d1f 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -13,9 +13,8 @@ // windowsNotification.onclick = function () { console.log("Notification clicked") }; // windowsNotification.onclose = function () { console.log("Notification dismissed") }; - -#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_ -#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_ +#ifndef BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ +#define BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ #include "base/compiler_specific.h" #include "browser/notification_presenter.h" @@ -38,7 +37,7 @@ class NotificationPresenterWin : public NotificationPresenter { const SkBitmap& icon, scoped_ptr delegate, base::Closure* cancel_callback) override; - + void RemoveNotification(); private: @@ -48,4 +47,4 @@ class NotificationPresenterWin : public NotificationPresenter { } // namespace -#endif // BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_WIN_H_ +#endif // BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 830a6f67003..79aa2b4a0e6 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -3,100 +3,100 @@ // Thanks to both of those folks mentioned above who first thought up a bunch of this code // and released it as MIT to the world. -#include "windows_toast_notification.h" +#include "browser/win/windows_toast_notification.h" + #include "content/public/browser/desktop_notification_delegate.h" using namespace WinToasts; -using namespace Microsoft::WRL; -using namespace ABI::Windows::UI::Notifications; using namespace ABI::Windows::Data::Xml::Dom; -#define BREAK_IF_BAD(hr) if(!SUCCEEDED(hr)) break; +#define BREAK_IF_BAD(hr) if(!SUCCEEDED(hr)) break; namespace WinToasts { +namespace { + // Initialize Windows Runtime -static HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); +HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); -WindowsToastNotification::WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate) -{ - HSTRING toastNotifMgrStr = NULL; - HSTRING appId = NULL; +} // namespace - HRESULT hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager, &toastNotifMgrStr); +WindowsToastNotification::WindowsToastNotification( + const char* appName, content::DesktopNotificationDelegate* delegate) { + HSTRING toastNotifMgrStr = nullptr; + HSTRING appId = nullptr; - hr = Windows::Foundation::GetActivationFactory(toastNotifMgrStr, &m_toastManager); + HRESULT hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager, &toastNotifMgrStr); - WCHAR wAppName[MAX_PATH]; - swprintf(wAppName, ARRAYSIZE(wAppName), L"%S", appName); - hr = CreateHString(wAppName, &appId); + hr = Windows::Foundation::GetActivationFactory(toastNotifMgrStr, &m_toastManager); - m_toastManager->CreateToastNotifierWithId(appId, &m_toastNotifier); + WCHAR wAppName[MAX_PATH]; + swprintf(wAppName, ARRAYSIZE(wAppName), L"%S", appName); + hr = CreateHString(wAppName, &appId); - if (toastNotifMgrStr != NULL) { - WindowsDeleteString(toastNotifMgrStr); - } + m_toastManager->CreateToastNotifierWithId(appId, &m_toastNotifier); - if (appId != NULL) { - WindowsDeleteString(appId); - } + if (toastNotifMgrStr) { + WindowsDeleteString(toastNotifMgrStr); + } - n_delegate = delegate; + if (appId) { + WindowsDeleteString(appId); + } + + n_delegate = delegate; } -WindowsToastNotification::~WindowsToastNotification() -{ - if (n_delegate) { - delete n_delegate; - } +WindowsToastNotification::~WindowsToastNotification() { + if (n_delegate) { + delete n_delegate; + } } -void WindowsToastNotification::ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr& toast) -{ - HRESULT hr; - HSTRING toastNotifStr = NULL; +void WindowsToastNotification::ShowNotification( + const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr& toast) { + HRESULT hr; + HSTRING toastNotifStr = nullptr; - do { - ComPtr toastXml; - hr = GetToastXml(m_toastManager.Get(), title, msg, iconPath, &toastXml); - BREAK_IF_BAD(hr); + do { + ComPtr toastXml; + hr = GetToastXml(m_toastManager.Get(), title, msg, iconPath, &toastXml); + BREAK_IF_BAD(hr); - hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotification, &toastNotifStr); - BREAK_IF_BAD(hr); + hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotification, &toastNotifStr); + BREAK_IF_BAD(hr); - ComPtr toastFactory; - hr = Windows::Foundation::GetActivationFactory(toastNotifStr, &toastFactory); - BREAK_IF_BAD(hr); + ComPtr toastFactory; + hr = Windows::Foundation::GetActivationFactory(toastNotifStr, &toastFactory); + BREAK_IF_BAD(hr); - hr = toastFactory->CreateToastNotification(toastXml.Get(), &toast); - BREAK_IF_BAD(hr); + hr = toastFactory->CreateToastNotification(toastXml.Get(), &toast); + BREAK_IF_BAD(hr); - hr = SetupCallbacks(toast.Get()); - BREAK_IF_BAD(hr); + hr = SetupCallbacks(toast.Get()); + BREAK_IF_BAD(hr); - hr = m_toastNotifier->Show(toast.Get()); - BREAK_IF_BAD(hr); + hr = m_toastNotifier->Show(toast.Get()); + BREAK_IF_BAD(hr); - n_delegate->NotificationDisplayed(); - } while (FALSE); + n_delegate->NotificationDisplayed(); + } while (FALSE); - if (toastNotifStr != NULL) { - WindowsDeleteString(toastNotifStr); - } + if (toastNotifStr) { + WindowsDeleteString(toastNotifStr); + } } -void WindowsToastNotification::DismissNotification(ComPtr toast) -{ - m_toastNotifier->Hide(toast.Get()); +void WindowsToastNotification::DismissNotification( + ComPtr toast) { + m_toastNotifier->Hide(toast.Get()); } -void WindowsToastNotification::NotificationClicked() -{ +void WindowsToastNotification::NotificationClicked() { delete this; } -void WindowsToastNotification::NotificationDismissed() -{ +void WindowsToastNotification::NotificationDismissed() { delete this; } @@ -106,261 +106,260 @@ HRESULT WindowsToastNotification::GetToastXml( const WCHAR* msg, std::string iconPath, IXmlDocument** toastXml) { - - HRESULT hr; - ToastTemplateType templateType; - if (title == NULL || msg == NULL) { - // Single line toast - templateType = iconPath.length() == 0 ? ToastTemplateType_ToastText01 : ToastTemplateType_ToastImageAndText01; - hr = m_toastManager->GetTemplateContent(templateType, toastXml); - if (SUCCEEDED(hr)) { - const WCHAR* text = title != NULL ? title : msg; - hr = SetXmlText(*toastXml, text); - } - } else { - // Title and body toast - templateType = iconPath.length() == 0 ? ToastTemplateType_ToastText02 : ToastTemplateType_ToastImageAndText02; - hr = toastManager->GetTemplateContent(templateType, toastXml); - if (SUCCEEDED(hr)) { - hr = SetXmlText(*toastXml, title, msg); - } - } - - if (iconPath.length() != 0 && SUCCEEDED(hr)) { - // Toast has image - if (SUCCEEDED(hr)) { - hr = SetXmlImage(*toastXml, iconPath); - } - - // Don't stop a notification from showing just because an image couldn't be displayed. By default the app icon will be shown. - hr = S_OK; - } - - return hr; -} - -HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* text) -{ - HSTRING tag = NULL; - - ComPtr nodeList; - HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 1); - do { - BREAK_IF_BAD(hr); - - ComPtr node; - hr = nodeList->Item(0, &node); - BREAK_IF_BAD(hr); - - hr = AppendTextToXml(doc, node.Get(), text); - } while (FALSE); - - if (tag != NULL) { - WindowsDeleteString(tag); - } - - return hr; -} - -HRESULT WindowsToastNotification::SetXmlText(IXmlDocument* doc, const WCHAR* title, const WCHAR* body) -{ - HSTRING tag = NULL; - ComPtr nodeList; - HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 2); - do { - BREAK_IF_BAD(hr); - - ComPtr node; - hr = nodeList->Item(0, &node); - BREAK_IF_BAD(hr); - - hr = AppendTextToXml(doc, node.Get(), title); - BREAK_IF_BAD(hr); - - hr = nodeList->Item(1, &node); - BREAK_IF_BAD(hr); - - hr = AppendTextToXml(doc, node.Get(), body); - } while (FALSE); - - if (tag != NULL) { - WindowsDeleteString(tag); - } - - return hr; -} - -HRESULT WindowsToastNotification::SetXmlImage(IXmlDocument* doc, std::string iconPath) -{ - HSTRING tag = NULL; - HSTRING src = NULL; - HSTRING imgPath = NULL; - HRESULT hr = CreateHString(L"image", &tag); - - do { - BREAK_IF_BAD(hr); - - ComPtr nodeList; - hr = doc->GetElementsByTagName(tag, &nodeList); - BREAK_IF_BAD(hr); - - ComPtr imageNode; - hr = nodeList->Item(0, &imageNode); - BREAK_IF_BAD(hr); - - ComPtr attrs; - hr = imageNode->get_Attributes(&attrs); - BREAK_IF_BAD(hr); - - hr = CreateHString(L"src", &src); - BREAK_IF_BAD(hr); - - ComPtr srcAttr; - hr = attrs->GetNamedItem(src, &srcAttr); - BREAK_IF_BAD(hr); - - WCHAR xmlPath[MAX_PATH]; - swprintf(xmlPath, ARRAYSIZE(xmlPath), L"%S", iconPath); - hr = CreateHString(xmlPath, &imgPath); - BREAK_IF_BAD(hr); - - ComPtr srcText; - hr = doc->CreateTextNode(imgPath, &srcText); - BREAK_IF_BAD(hr); - - ComPtr srcNode; - hr = srcText.As(&srcNode); - BREAK_IF_BAD(hr); - - ComPtr childNode; - hr = srcAttr->AppendChild(srcNode.Get(), &childNode); - } while (FALSE); - - if (tag != NULL) { - WindowsDeleteString(tag); - } - if (src != NULL) { - WindowsDeleteString(src); - } - if (imgPath != NULL) { - WindowsDeleteString(imgPath); - } - - return hr; -} - -HRESULT WindowsToastNotification::GetTextNodeList(HSTRING* tag, IXmlDocument* doc, IXmlNodeList** nodeList, UINT32 reqLength) -{ - HRESULT hr = CreateHString(L"text", tag); - do{ - BREAK_IF_BAD(hr); - - hr = doc->GetElementsByTagName(*tag, nodeList); - BREAK_IF_BAD(hr); - - UINT32 nodeLength; - hr = (*nodeList)->get_Length(&nodeLength); - BREAK_IF_BAD(hr); - - if (nodeLength < reqLength) { - hr = E_INVALIDARG; - } - } while (FALSE); - - if (!SUCCEEDED(hr)) { - // Allow the caller to delete this string on success - WindowsDeleteString(*tag); - } - - return hr; -} - -HRESULT WindowsToastNotification::AppendTextToXml(IXmlDocument* doc, IXmlNode* node, const WCHAR* text) -{ - HSTRING str = NULL; - HRESULT hr = CreateHString(text, &str); - do { - BREAK_IF_BAD(hr); - - ComPtr xmlText; - hr = doc->CreateTextNode(str, &xmlText); - BREAK_IF_BAD(hr); - - ComPtr textNode; - hr = xmlText.As(&textNode); - BREAK_IF_BAD(hr); - - ComPtr appendNode; - hr = node->AppendChild(textNode.Get(), &appendNode); - } while (FALSE); - - if (str != NULL) { - WindowsDeleteString(str); - } - - return hr; -} - -HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast) -{ - EventRegistrationToken activatedToken, dismissedToken; - m_eventHandler = Make(this, n_delegate); - HRESULT hr = toast->add_Activated(m_eventHandler.Get(), &activatedToken); - + HRESULT hr; + ToastTemplateType templateType; + if (title == NULL || msg == NULL) { + // Single line toast + templateType = iconPath.length() == 0 ? ToastTemplateType_ToastText01 : ToastTemplateType_ToastImageAndText01; + hr = m_toastManager->GetTemplateContent(templateType, toastXml); if (SUCCEEDED(hr)) { - hr = toast->add_Dismissed(m_eventHandler.Get(), &dismissedToken); + const WCHAR* text = title != NULL ? title : msg; + hr = SetXmlText(*toastXml, text); + } + } else { + // Title and body toast + templateType = iconPath.length() == 0 ? ToastTemplateType_ToastText02 : ToastTemplateType_ToastImageAndText02; + hr = toastManager->GetTemplateContent(templateType, toastXml); + if (SUCCEEDED(hr)) { + hr = SetXmlText(*toastXml, title, msg); + } + } + + if (iconPath.length() != 0 && SUCCEEDED(hr)) { + // Toast has image + if (SUCCEEDED(hr)) { + hr = SetXmlImage(*toastXml, iconPath); } - return hr; + // Don't stop a notification from showing just because an image couldn't be displayed. By default the app icon will be shown. + hr = S_OK; + } + + return hr; } -HRESULT WindowsToastNotification::CreateHString(const WCHAR* source, HSTRING* dest) -{ - if (source == NULL || dest == NULL) { - return E_INVALIDARG; - } +HRESULT WindowsToastNotification::SetXmlText( + IXmlDocument* doc, const WCHAR* text) { + HSTRING tag = NULL; - HRESULT hr = WindowsCreateString(source, wcslen(source), dest); - return hr; + ComPtr nodeList; + HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 1); + do { + BREAK_IF_BAD(hr); + + ComPtr node; + hr = nodeList->Item(0, &node); + BREAK_IF_BAD(hr); + + hr = AppendTextToXml(doc, node.Get(), text); + } while (FALSE); + + if (tag != NULL) { + WindowsDeleteString(tag); + } + + return hr; +} + +HRESULT WindowsToastNotification::SetXmlText( + IXmlDocument* doc, const WCHAR* title, const WCHAR* body) { + HSTRING tag = NULL; + ComPtr nodeList; + HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 2); + do { + BREAK_IF_BAD(hr); + + ComPtr node; + hr = nodeList->Item(0, &node); + BREAK_IF_BAD(hr); + + hr = AppendTextToXml(doc, node.Get(), title); + BREAK_IF_BAD(hr); + + hr = nodeList->Item(1, &node); + BREAK_IF_BAD(hr); + + hr = AppendTextToXml(doc, node.Get(), body); + } while (FALSE); + + if (tag != NULL) { + WindowsDeleteString(tag); + } + + return hr; +} + +HRESULT WindowsToastNotification::SetXmlImage( + IXmlDocument* doc, std::string iconPath) { + HSTRING tag = NULL; + HSTRING src = NULL; + HSTRING imgPath = NULL; + HRESULT hr = CreateHString(L"image", &tag); + + do { + BREAK_IF_BAD(hr); + + ComPtr nodeList; + hr = doc->GetElementsByTagName(tag, &nodeList); + BREAK_IF_BAD(hr); + + ComPtr imageNode; + hr = nodeList->Item(0, &imageNode); + BREAK_IF_BAD(hr); + + ComPtr attrs; + hr = imageNode->get_Attributes(&attrs); + BREAK_IF_BAD(hr); + + hr = CreateHString(L"src", &src); + BREAK_IF_BAD(hr); + + ComPtr srcAttr; + hr = attrs->GetNamedItem(src, &srcAttr); + BREAK_IF_BAD(hr); + + WCHAR xmlPath[MAX_PATH]; + swprintf(xmlPath, ARRAYSIZE(xmlPath), L"%S", iconPath); + hr = CreateHString(xmlPath, &imgPath); + BREAK_IF_BAD(hr); + + ComPtr srcText; + hr = doc->CreateTextNode(imgPath, &srcText); + BREAK_IF_BAD(hr); + + ComPtr srcNode; + hr = srcText.As(&srcNode); + BREAK_IF_BAD(hr); + + ComPtr childNode; + hr = srcAttr->AppendChild(srcNode.Get(), &childNode); + } while (FALSE); + + if (tag != NULL) { + WindowsDeleteString(tag); + } + if (src != NULL) { + WindowsDeleteString(src); + } + if (imgPath != NULL) { + WindowsDeleteString(imgPath); + } + + return hr; +} + +HRESULT WindowsToastNotification::GetTextNodeList( + HSTRING* tag, + IXmlDocument* doc, + IXmlNodeList** nodeList, + UINT32 reqLength) { + HRESULT hr = CreateHString(L"text", tag); + do { + BREAK_IF_BAD(hr); + + hr = doc->GetElementsByTagName(*tag, nodeList); + BREAK_IF_BAD(hr); + + UINT32 nodeLength; + hr = (*nodeList)->get_Length(&nodeLength); + BREAK_IF_BAD(hr); + + if (nodeLength < reqLength) { + hr = E_INVALIDARG; + } + } while (FALSE); + + if (!SUCCEEDED(hr)) { + // Allow the caller to delete this string on success + WindowsDeleteString(*tag); + } + + return hr; +} + +HRESULT WindowsToastNotification::AppendTextToXml( + IXmlDocument* doc, IXmlNode* node, const WCHAR* text) { + HSTRING str = NULL; + HRESULT hr = CreateHString(text, &str); + do { + BREAK_IF_BAD(hr); + + ComPtr xmlText; + hr = doc->CreateTextNode(str, &xmlText); + BREAK_IF_BAD(hr); + + ComPtr textNode; + hr = xmlText.As(&textNode); + BREAK_IF_BAD(hr); + + ComPtr appendNode; + hr = node->AppendChild(textNode.Get(), &appendNode); + } while (FALSE); + + if (str != NULL) { + WindowsDeleteString(str); + } + + return hr; +} + +HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast) { + EventRegistrationToken activatedToken, dismissedToken; + m_eventHandler = Make(this, n_delegate); + HRESULT hr = toast->add_Activated(m_eventHandler.Get(), &activatedToken); + + if (SUCCEEDED(hr)) { + hr = toast->add_Dismissed(m_eventHandler.Get(), &dismissedToken); + } + + return hr; +} + +HRESULT WindowsToastNotification::CreateHString( + const WCHAR* source, HSTRING* dest) { + if (source == NULL || dest == NULL) { + return E_INVALIDARG; + } + + HRESULT hr = WindowsCreateString(source, wcslen(source), dest); + return hr; } /* / Toast Event Handler */ -ToastEventHandler::ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate) -{ - m_notification = notification; - n_delegate = delegate; +ToastEventHandler::ToastEventHandler( + WindowsToastNotification* notification, + content::DesktopNotificationDelegate* delegate) { + m_notification = notification; + n_delegate = delegate; } -ToastEventHandler::~ToastEventHandler() -{ - // Empty +ToastEventHandler::~ToastEventHandler() { } -IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IInspectable* args) -{ - // Notification "activated" (clicked) - n_delegate->NotificationClick(); - - if (m_notification != NULL) { - m_notification->NotificationClicked(); - } - - return S_OK; +IFACEMETHODIMP ToastEventHandler::Invoke( + IToastNotification* sender, IInspectable* args) { + // Notification "activated" (clicked) + n_delegate->NotificationClick(); + + if (m_notification != NULL) { + m_notification->NotificationClicked(); + } + + return S_OK; } -IFACEMETHODIMP ToastEventHandler::Invoke(IToastNotification* sender, IToastDismissedEventArgs* e) -{ - // Notification dismissed - n_delegate->NotificationClosed(); +IFACEMETHODIMP ToastEventHandler::Invoke( + IToastNotification* sender, IToastDismissedEventArgs* e) { + // Notification dismissed + n_delegate->NotificationClosed(); - if (m_notification != NULL) { - m_notification->NotificationDismissed(); - - } - - return S_OK; + if (m_notification != NULL) { + m_notification->NotificationDismissed(); + } + + return S_OK; } } //namespace diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index d501954ec5c..8b354309742 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -3,70 +3,73 @@ // Thanks to both of those folks mentioned above who first thought up a bunch of this code // and released it as MIT to the world. -#ifndef __WINDOWS_TOAST_NOTIFICATION_H__ -#define __WINDOWS_TOAST_NOTIFICATION_H__ - -#include "content/public/browser/desktop_notification_delegate.h" -#include "content/public/common/platform_notification_data.h" -#include "base/bind.h" +#ifndef BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_ +#define BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_ #include #include #include +#include "base/bind.h" +#include "content/public/browser/desktop_notification_delegate.h" +#include "content/public/common/platform_notification_data.h" + using namespace Microsoft::WRL; using namespace ABI::Windows::UI::Notifications; using namespace ABI::Windows::Foundation; namespace WinToasts { - typedef ITypedEventHandler DesktopToastActivatedEventHandler; - typedef ITypedEventHandler DesktopToastDismissedEventHandler; +using DesktopToastActivatedEventHandler = + ITypedEventHandler; +using DesktopToastDismissedEventHandler = + ITypedEventHandler; - class ToastEventHandler; +class ToastEventHandler; - class WindowsToastNotification - { - public: - WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate); - ~WindowsToastNotification(); - void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr& toast); - void DismissNotification(ComPtr toast); - void NotificationClicked(); - void NotificationDismissed(); +class WindowsToastNotification { + public: + WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate); + ~WindowsToastNotification(); - private: - ComPtr m_eventHandler; + void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr& toast); + void DismissNotification(ComPtr toast); + void NotificationClicked(); + void NotificationDismissed(); - content::DesktopNotificationDelegate* n_delegate; - ComPtr m_toastManager; - ComPtr m_toastNotifier; + private: + ComPtr m_eventHandler; - HRESULT GetToastXml(IToastNotificationManagerStatics* toastManager, const WCHAR* title, const WCHAR* msg, std::string iconPath, ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); - HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* text); - HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* title, const WCHAR* body); - HRESULT SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, std::string iconPath); - HRESULT GetTextNodeList(HSTRING* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, UINT32 reqLength); - HRESULT AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const WCHAR* text); - HRESULT SetupCallbacks(IToastNotification* toast); - HRESULT CreateHString(const WCHAR* source, HSTRING* dest); - }; + content::DesktopNotificationDelegate* n_delegate; + ComPtr m_toastManager; + ComPtr m_toastNotifier; + + HRESULT GetToastXml(IToastNotificationManagerStatics* toastManager, const WCHAR* title, const WCHAR* msg, std::string iconPath, ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); + HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* text); + HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* title, const WCHAR* body); + HRESULT SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, std::string iconPath); + HRESULT GetTextNodeList(HSTRING* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, UINT32 reqLength); + HRESULT AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const WCHAR* text); + HRESULT SetupCallbacks(IToastNotification* toast); + HRESULT CreateHString(const WCHAR* source, HSTRING* dest); +}; - class ToastEventHandler : - public RuntimeClass, DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler> - { - public: - ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate); - ~ToastEventHandler(); - IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args); - IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e); +class ToastEventHandler : public RuntimeClass, + DesktopToastActivatedEventHandler, + DesktopToastDismissedEventHandler> { + public: + ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate); + ~ToastEventHandler(); - private: - WindowsToastNotification* m_notification; - content::DesktopNotificationDelegate* n_delegate; - }; + IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args); + IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e); + + private: + WindowsToastNotification* m_notification; + content::DesktopNotificationDelegate* n_delegate; +}; } // namespace -#endif //__WINDOWS_TOAST_NOTIFICATION_H__ \ No newline at end of file +#endif // BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_ From 6b9371c4cd71effd33aa4b51756bed5e5309f2a7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Nov 2015 19:50:38 +0800 Subject: [PATCH 0707/1195] Use smart pointer for everything --- .../browser/win/notification_presenter_win.cc | 4 +- brightray/browser/win/scoped_hstring.cc | 28 ++ brightray/browser/win/scoped_hstring.h | 36 ++ .../browser/win/windows_toast_notification.cc | 403 +++++++----------- .../browser/win/windows_toast_notification.h | 35 +- brightray/filenames.gypi | 2 + 6 files changed, 240 insertions(+), 268 deletions(-) create mode 100644 brightray/browser/win/scoped_hstring.cc create mode 100644 brightray/browser/win/scoped_hstring.h diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 20b2a3333a8..23ec1303c7c 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -35,7 +35,7 @@ NotificationPresenterWin::~NotificationPresenterWin() { void NotificationPresenterWin::ShowNotification( const content::PlatformNotificationData& data, const SkBitmap& icon, - scoped_ptr delegate_ptr, + scoped_ptr delegate, base::Closure* cancel_callback) { std::wstring title = data.title; std::wstring body = data.body; @@ -45,7 +45,7 @@ void NotificationPresenterWin::ShowNotification( // toast notification supported in version >= Windows 8 // for prior versions, use Tray.displayBalloon if (base::win::GetVersion() >= base::win::VERSION_WIN8) { - wtn = new WindowsToastNotification(appName.c_str(), delegate_ptr.release()); + wtn = new WindowsToastNotification(appName.c_str(), delegate.Pass()); wtn->ShowNotification(title.c_str(), body.c_str(), iconPath, m_lastNotification); } diff --git a/brightray/browser/win/scoped_hstring.cc b/brightray/browser/win/scoped_hstring.cc new file mode 100644 index 00000000000..7954bf1552f --- /dev/null +++ b/brightray/browser/win/scoped_hstring.cc @@ -0,0 +1,28 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/win/scoped_hstring.h" + +#include + +ScopedHString::ScopedHString(const wchar_t* source) + : str_(nullptr) { + Set(source); +} + +ScopedHString::ScopedHString() : str_(nullptr) { +} + +ScopedHString::~ScopedHString() { + if (str_) + WindowsDeleteString(str_); +} + +void ScopedHString::Set(const wchar_t* source) { + if (str_) { + WindowsDeleteString(str_); + str_ = nullptr; + } + WindowsCreateString(source, wcslen(source), &str_); +} diff --git a/brightray/browser/win/scoped_hstring.h b/brightray/browser/win/scoped_hstring.h new file mode 100644 index 00000000000..71c8bfcbe03 --- /dev/null +++ b/brightray/browser/win/scoped_hstring.h @@ -0,0 +1,36 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_ +#define BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_ + +#include +#include + +#include "base/basictypes.h" + +class ScopedHString { + public: + // Copy from |source|. + ScopedHString(const wchar_t* source); + // Create empty string. + ScopedHString(); + ~ScopedHString(); + + // Sets to |source|. + void Set(const wchar_t* source); + + // Returns string. + operator HSTRING() const { return str_; } + + // Whether there is a string created. + bool success() const { return str_; } + + private: + HSTRING str_; + + DISALLOW_COPY_AND_ASSIGN(ScopedHString); +}; + +#endif // BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_ diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 79aa2b4a0e6..192b5a25db5 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -5,6 +5,8 @@ #include "browser/win/windows_toast_notification.h" +#include "base/strings/utf_string_conversions.h" +#include "browser/win/scoped_hstring.h" #include "content/public/browser/desktop_notification_delegate.h" using namespace WinToasts; @@ -22,317 +24,232 @@ HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); } // namespace WindowsToastNotification::WindowsToastNotification( - const char* appName, content::DesktopNotificationDelegate* delegate) { - HSTRING toastNotifMgrStr = nullptr; - HSTRING appId = nullptr; + const char* app_name, + scoped_ptr delegate) + : delegate_(delegate.Pass()) { + ScopedHString toast_manager_str( + RuntimeClass_Windows_UI_Notifications_ToastNotificationManager); + if (!toast_manager_str.success()) + return; + HRESULT hr = Windows::Foundation::GetActivationFactory( + toast_manager_str, &toast_manager_); + if (FAILED(hr)) + return; - HRESULT hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotificationManager, &toastNotifMgrStr); + ScopedHString app_id(base::UTF8ToUTF16(app_name).c_str()); + if (!app_id.success()) + return; - hr = Windows::Foundation::GetActivationFactory(toastNotifMgrStr, &m_toastManager); - - WCHAR wAppName[MAX_PATH]; - swprintf(wAppName, ARRAYSIZE(wAppName), L"%S", appName); - hr = CreateHString(wAppName, &appId); - - m_toastManager->CreateToastNotifierWithId(appId, &m_toastNotifier); - - if (toastNotifMgrStr) { - WindowsDeleteString(toastNotifMgrStr); - } - - if (appId) { - WindowsDeleteString(appId); - } - - n_delegate = delegate; + toast_manager_->CreateToastNotifierWithId(app_id, &toast_notifier_); } WindowsToastNotification::~WindowsToastNotification() { - if (n_delegate) { - delete n_delegate; - } } void WindowsToastNotification::ShowNotification( - const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr& toast) { - HRESULT hr; - HSTRING toastNotifStr = nullptr; + const WCHAR* title, + const WCHAR* msg, + std::string icon_path, + ComPtr& toast) { + ComPtr toast_xml; + if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, &toast_xml))) + return; - do { - ComPtr toastXml; - hr = GetToastXml(m_toastManager.Get(), title, msg, iconPath, &toastXml); - BREAK_IF_BAD(hr); + ScopedHString toast_str( + RuntimeClass_Windows_UI_Notifications_ToastNotification); + if (!toast_str.success()) + return; - hr = CreateHString(RuntimeClass_Windows_UI_Notifications_ToastNotification, &toastNotifStr); - BREAK_IF_BAD(hr); + ComPtr toastFactory; + if (FAILED(Windows::Foundation::GetActivationFactory(toast_str, &toastFactory))) + return; - ComPtr toastFactory; - hr = Windows::Foundation::GetActivationFactory(toastNotifStr, &toastFactory); - BREAK_IF_BAD(hr); + if (FAILED(toastFactory->CreateToastNotification(toast_xml.Get(), &toast))) + return; - hr = toastFactory->CreateToastNotification(toastXml.Get(), &toast); - BREAK_IF_BAD(hr); + if (FAILED(SetupCallbacks(toast.Get()))) + return; - hr = SetupCallbacks(toast.Get()); - BREAK_IF_BAD(hr); + if (FAILED(toast_notifier_->Show(toast.Get()))) + return; - hr = m_toastNotifier->Show(toast.Get()); - BREAK_IF_BAD(hr); - - n_delegate->NotificationDisplayed(); - } while (FALSE); - - if (toastNotifStr) { - WindowsDeleteString(toastNotifStr); - } + delegate_->NotificationDisplayed(); } void WindowsToastNotification::DismissNotification( ComPtr toast) { - m_toastNotifier->Hide(toast.Get()); + toast_notifier_->Hide(toast.Get()); } void WindowsToastNotification::NotificationClicked() { - delete this; + delegate_->NotificationClick(); + delete this; } void WindowsToastNotification::NotificationDismissed() { - delete this; + delegate_->NotificationClosed(); + delete this; } -HRESULT WindowsToastNotification::GetToastXml( +bool WindowsToastNotification::GetToastXml( IToastNotificationManagerStatics* toastManager, const WCHAR* title, const WCHAR* msg, - std::string iconPath, - IXmlDocument** toastXml) { - HRESULT hr; - ToastTemplateType templateType; - if (title == NULL || msg == NULL) { - // Single line toast - templateType = iconPath.length() == 0 ? ToastTemplateType_ToastText01 : ToastTemplateType_ToastImageAndText01; - hr = m_toastManager->GetTemplateContent(templateType, toastXml); - if (SUCCEEDED(hr)) { - const WCHAR* text = title != NULL ? title : msg; - hr = SetXmlText(*toastXml, text); - } + std::string icon_path, + IXmlDocument** toast_xml) { + ToastTemplateType template_type; + if (!title || !msg) { + // Single line toast. + template_type = icon_path.empty() ? ToastTemplateType_ToastText01 : + ToastTemplateType_ToastImageAndText01; + if (FAILED(toast_manager_->GetTemplateContent(template_type, toast_xml))) + return false; + if (!SetXmlText(*toast_xml, title ? title : msg)) + return false; } else { - // Title and body toast - templateType = iconPath.length() == 0 ? ToastTemplateType_ToastText02 : ToastTemplateType_ToastImageAndText02; - hr = toastManager->GetTemplateContent(templateType, toastXml); - if (SUCCEEDED(hr)) { - hr = SetXmlText(*toastXml, title, msg); - } + // Title and body toast. + template_type = icon_path.empty() ? ToastTemplateType_ToastText02 : + ToastTemplateType_ToastImageAndText02; + if (FAILED(toastManager->GetTemplateContent(template_type, toast_xml))) + return false; + if (!SetXmlText(*toast_xml, title, msg)) + return false; } - if (iconPath.length() != 0 && SUCCEEDED(hr)) { - // Toast has image - if (SUCCEEDED(hr)) { - hr = SetXmlImage(*toastXml, iconPath); - } + // Toast has image + if (!icon_path.empty()) + return SetXmlImage(*toast_xml, icon_path); - // Don't stop a notification from showing just because an image couldn't be displayed. By default the app icon will be shown. - hr = S_OK; - } - - return hr; + return true; } -HRESULT WindowsToastNotification::SetXmlText( +bool WindowsToastNotification::SetXmlText( IXmlDocument* doc, const WCHAR* text) { - HSTRING tag = NULL; + ScopedHString tag; + ComPtr node_list; + if (!GetTextNodeList(&tag, doc, &node_list, 1)) + return false; - ComPtr nodeList; - HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 1); - do { - BREAK_IF_BAD(hr); + ComPtr node; + if (FAILED(node_list->Item(0, &node))) + return false; - ComPtr node; - hr = nodeList->Item(0, &node); - BREAK_IF_BAD(hr); - - hr = AppendTextToXml(doc, node.Get(), text); - } while (FALSE); - - if (tag != NULL) { - WindowsDeleteString(tag); - } - - return hr; + return AppendTextToXml(doc, node.Get(), text); } -HRESULT WindowsToastNotification::SetXmlText( +bool WindowsToastNotification::SetXmlText( IXmlDocument* doc, const WCHAR* title, const WCHAR* body) { - HSTRING tag = NULL; - ComPtr nodeList; - HRESULT hr = GetTextNodeList(&tag, doc, &nodeList, 2); - do { - BREAK_IF_BAD(hr); + ScopedHString tag; + ComPtr node_list; + if (!GetTextNodeList(&tag, doc, &node_list, 2)) + return false; - ComPtr node; - hr = nodeList->Item(0, &node); - BREAK_IF_BAD(hr); + ComPtr node; + if (FAILED(node_list->Item(0, &node))) + return false; - hr = AppendTextToXml(doc, node.Get(), title); - BREAK_IF_BAD(hr); + if (!AppendTextToXml(doc, node.Get(), title)) + return false; - hr = nodeList->Item(1, &node); - BREAK_IF_BAD(hr); + if (FAILED(node_list->Item(1, &node))) + return false; - hr = AppendTextToXml(doc, node.Get(), body); - } while (FALSE); - - if (tag != NULL) { - WindowsDeleteString(tag); - } - - return hr; + return AppendTextToXml(doc, node.Get(), body); } -HRESULT WindowsToastNotification::SetXmlImage( - IXmlDocument* doc, std::string iconPath) { - HSTRING tag = NULL; - HSTRING src = NULL; - HSTRING imgPath = NULL; - HRESULT hr = CreateHString(L"image", &tag); +bool WindowsToastNotification::SetXmlImage( + IXmlDocument* doc, std::string icon_path) { + ScopedHString tag(L"imag"); + if (!tag.success()) + return false; - do { - BREAK_IF_BAD(hr); + ComPtr node_list; + if (FAILED(doc->GetElementsByTagName(tag, &node_list))) + return false; - ComPtr nodeList; - hr = doc->GetElementsByTagName(tag, &nodeList); - BREAK_IF_BAD(hr); + ComPtr image_node; + if (FAILED(node_list->Item(0, &image_node))) + return false; - ComPtr imageNode; - hr = nodeList->Item(0, &imageNode); - BREAK_IF_BAD(hr); + ComPtr attrs; + if (FAILED(image_node->get_Attributes(&attrs))) + return false; - ComPtr attrs; - hr = imageNode->get_Attributes(&attrs); - BREAK_IF_BAD(hr); + ScopedHString src(L"src"); + if (!src.success()) + return false; - hr = CreateHString(L"src", &src); - BREAK_IF_BAD(hr); + ComPtr src_attr; + if (FAILED(attrs->GetNamedItem(src, &src_attr))) + return false; - ComPtr srcAttr; - hr = attrs->GetNamedItem(src, &srcAttr); - BREAK_IF_BAD(hr); + ScopedHString img_path(base::UTF8ToUTF16(icon_path).c_str()); + if (!img_path.success()) + return false; - WCHAR xmlPath[MAX_PATH]; - swprintf(xmlPath, ARRAYSIZE(xmlPath), L"%S", iconPath); - hr = CreateHString(xmlPath, &imgPath); - BREAK_IF_BAD(hr); + ComPtr src_text; + if (FAILED(doc->CreateTextNode(img_path, &src_text))) + return false; - ComPtr srcText; - hr = doc->CreateTextNode(imgPath, &srcText); - BREAK_IF_BAD(hr); + ComPtr src_node; + if (FAILED(src_text.As(&src_node))) + return false; - ComPtr srcNode; - hr = srcText.As(&srcNode); - BREAK_IF_BAD(hr); - - ComPtr childNode; - hr = srcAttr->AppendChild(srcNode.Get(), &childNode); - } while (FALSE); - - if (tag != NULL) { - WindowsDeleteString(tag); - } - if (src != NULL) { - WindowsDeleteString(src); - } - if (imgPath != NULL) { - WindowsDeleteString(imgPath); - } - - return hr; + ComPtr child_node; + return SUCCEEDED(src_attr->AppendChild(src_node.Get(), &child_node)); } -HRESULT WindowsToastNotification::GetTextNodeList( - HSTRING* tag, +bool WindowsToastNotification::GetTextNodeList( + ScopedHString* tag, IXmlDocument* doc, - IXmlNodeList** nodeList, - UINT32 reqLength) { - HRESULT hr = CreateHString(L"text", tag); - do { - BREAK_IF_BAD(hr); + IXmlNodeList** node_list, + UINT32 req_length) { + tag->Set(L"text"); + if (!tag->success()) + return false; - hr = doc->GetElementsByTagName(*tag, nodeList); - BREAK_IF_BAD(hr); + if (FAILED(doc->GetElementsByTagName(*tag, node_list))) + return false; - UINT32 nodeLength; - hr = (*nodeList)->get_Length(&nodeLength); - BREAK_IF_BAD(hr); + UINT32 node_length; + if (FAILED((*node_list)->get_Length(&node_length))) + return false; - if (nodeLength < reqLength) { - hr = E_INVALIDARG; - } - } while (FALSE); - - if (!SUCCEEDED(hr)) { - // Allow the caller to delete this string on success - WindowsDeleteString(*tag); - } - - return hr; + return node_length >= req_length; } -HRESULT WindowsToastNotification::AppendTextToXml( +bool WindowsToastNotification::AppendTextToXml( IXmlDocument* doc, IXmlNode* node, const WCHAR* text) { - HSTRING str = NULL; - HRESULT hr = CreateHString(text, &str); - do { - BREAK_IF_BAD(hr); + ScopedHString str(text); + if (!str.success()) + return false; - ComPtr xmlText; - hr = doc->CreateTextNode(str, &xmlText); - BREAK_IF_BAD(hr); + ComPtr xml_text; + if (FAILED(doc->CreateTextNode(str, &xml_text))) + return false; - ComPtr textNode; - hr = xmlText.As(&textNode); - BREAK_IF_BAD(hr); + ComPtr text_node; + if (FAILED(xml_text.As(&text_node))) + return false; - ComPtr appendNode; - hr = node->AppendChild(textNode.Get(), &appendNode); - } while (FALSE); - - if (str != NULL) { - WindowsDeleteString(str); - } - - return hr; + ComPtr append_node; + return SUCCEEDED(node->AppendChild(text_node.Get(), &append_node)); } -HRESULT WindowsToastNotification::SetupCallbacks(IToastNotification* toast) { +bool WindowsToastNotification::SetupCallbacks(IToastNotification* toast) { EventRegistrationToken activatedToken, dismissedToken; - m_eventHandler = Make(this, n_delegate); - HRESULT hr = toast->add_Activated(m_eventHandler.Get(), &activatedToken); + event_handler_ = Make(this); + if (FAILED(toast->add_Activated(event_handler_.Get(), &activatedToken))) + return false; - if (SUCCEEDED(hr)) { - hr = toast->add_Dismissed(m_eventHandler.Get(), &dismissedToken); - } - - return hr; -} - -HRESULT WindowsToastNotification::CreateHString( - const WCHAR* source, HSTRING* dest) { - if (source == NULL || dest == NULL) { - return E_INVALIDARG; - } - - HRESULT hr = WindowsCreateString(source, wcslen(source), dest); - return hr; + return SUCCEEDED(toast->add_Dismissed(event_handler_.Get(), &dismissedToken)); } /* / Toast Event Handler */ -ToastEventHandler::ToastEventHandler( - WindowsToastNotification* notification, - content::DesktopNotificationDelegate* delegate) { - m_notification = notification; - n_delegate = delegate; +ToastEventHandler::ToastEventHandler(WindowsToastNotification* notification) + : notification_(notification) { } ToastEventHandler::~ToastEventHandler() { @@ -340,26 +257,14 @@ ToastEventHandler::~ToastEventHandler() { IFACEMETHODIMP ToastEventHandler::Invoke( IToastNotification* sender, IInspectable* args) { - // Notification "activated" (clicked) - n_delegate->NotificationClick(); - - if (m_notification != NULL) { - m_notification->NotificationClicked(); - } - + notification_->NotificationClicked(); return S_OK; } IFACEMETHODIMP ToastEventHandler::Invoke( IToastNotification* sender, IToastDismissedEventArgs* e) { - // Notification dismissed - n_delegate->NotificationClosed(); - - if (m_notification != NULL) { - m_notification->NotificationDismissed(); - } - + notification_->NotificationDismissed(); return S_OK; } -} //namespace +} // namespace WinToasts diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index 8b354309742..6dee88698b6 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -18,6 +18,8 @@ using namespace Microsoft::WRL; using namespace ABI::Windows::UI::Notifications; using namespace ABI::Windows::Foundation; +class ScopedHString; + namespace WinToasts { using DesktopToastActivatedEventHandler = @@ -29,7 +31,9 @@ class ToastEventHandler; class WindowsToastNotification { public: - WindowsToastNotification(const char* appName, content::DesktopNotificationDelegate* delegate); + WindowsToastNotification( + const char* app_name, + scoped_ptr delegate); ~WindowsToastNotification(); void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr& toast); @@ -38,20 +42,18 @@ class WindowsToastNotification { void NotificationDismissed(); private: - ComPtr m_eventHandler; + scoped_ptr delegate_; + ComPtr event_handler_; + ComPtr toast_manager_; + ComPtr toast_notifier_; - content::DesktopNotificationDelegate* n_delegate; - ComPtr m_toastManager; - ComPtr m_toastNotifier; - - HRESULT GetToastXml(IToastNotificationManagerStatics* toastManager, const WCHAR* title, const WCHAR* msg, std::string iconPath, ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); - HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* text); - HRESULT SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* title, const WCHAR* body); - HRESULT SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, std::string iconPath); - HRESULT GetTextNodeList(HSTRING* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, UINT32 reqLength); - HRESULT AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const WCHAR* text); - HRESULT SetupCallbacks(IToastNotification* toast); - HRESULT CreateHString(const WCHAR* source, HSTRING* dest); + bool GetToastXml(IToastNotificationManagerStatics* toastManager, const WCHAR* title, const WCHAR* msg, std::string iconPath, ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); + bool SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* text); + bool SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* title, const WCHAR* body); + bool SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, std::string iconPath); + bool GetTextNodeList(ScopedHString* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, UINT32 reqLength); + bool AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const WCHAR* text); + bool SetupCallbacks(IToastNotification* toast); }; @@ -59,15 +61,14 @@ class ToastEventHandler : public RuntimeClass, DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler> { public: - ToastEventHandler(WindowsToastNotification* notification, content::DesktopNotificationDelegate* delegate); + ToastEventHandler(WindowsToastNotification* notification); ~ToastEventHandler(); IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args); IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e); private: - WindowsToastNotification* m_notification; - content::DesktopNotificationDelegate* n_delegate; + WindowsToastNotification* notification_; // weak ref. }; } // namespace diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 84dc4291ed2..5b0fd733c99 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -67,6 +67,8 @@ 'browser/win/notification_presenter_win.cc', 'browser/win/windows_toast_notification.h', 'browser/win/windows_toast_notification.cc', + 'browser/win/scoped_hstring.h', + 'browser/win/scoped_hstring.cc', 'browser/special_storage_policy.cc', 'browser/special_storage_policy.h', 'browser/url_request_context_getter.cc', From 4f73de0930a0274aeba9544c2ca52bc3e09b7eff Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Nov 2015 20:07:12 +0800 Subject: [PATCH 0708/1195] Make the toast type really work --- .../browser/win/notification_presenter_win.cc | 5 +-- .../browser/win/notification_presenter_win.h | 13 ++++--- brightray/browser/win/scoped_hstring.cc | 5 +++ brightray/browser/win/scoped_hstring.h | 3 ++ .../browser/win/windows_toast_notification.cc | 25 ++++++-------- .../browser/win/windows_toast_notification.h | 34 ++++++++++++++----- 6 files changed, 53 insertions(+), 32 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 23ec1303c7c..87fc6da55e4 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -4,7 +4,9 @@ // found in the LICENSE-CHROMIUM file. #include "browser/win/notification_presenter_win.h" + #include "base/win/windows_version.h" +#include "browser/win/windows_toast_notification.h" #include "common/application_info.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" @@ -12,7 +14,6 @@ #pragma comment(lib, "runtimeobject.lib") -using namespace WinToasts; using namespace Microsoft::WRL; using namespace ABI::Windows::UI::Notifications; using namespace ABI::Windows::Data::Xml::Dom; @@ -46,7 +47,7 @@ void NotificationPresenterWin::ShowNotification( // for prior versions, use Tray.displayBalloon if (base::win::GetVersion() >= base::win::VERSION_WIN8) { wtn = new WindowsToastNotification(appName.c_str(), delegate.Pass()); - wtn->ShowNotification(title.c_str(), body.c_str(), iconPath, m_lastNotification); + wtn->ShowNotification(title, body, iconPath, m_lastNotification); } if (cancel_callback) { diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index fa7ccf40d1f..9a1a1d6576b 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -16,17 +16,16 @@ #ifndef BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ #define BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ -#include "base/compiler_specific.h" -#include "browser/notification_presenter.h" -#include "windows_toast_notification.h" - -#include #include -#include #include +#include "base/compiler_specific.h" +#include "browser/notification_presenter.h" + namespace brightray { +class WindowsToastNotification; + class NotificationPresenterWin : public NotificationPresenter { public: NotificationPresenterWin(); @@ -41,7 +40,7 @@ class NotificationPresenterWin : public NotificationPresenter { void RemoveNotification(); private: - WinToasts::WindowsToastNotification* wtn; + WindowsToastNotification* wtn; Microsoft::WRL::ComPtr m_lastNotification; }; diff --git a/brightray/browser/win/scoped_hstring.cc b/brightray/browser/win/scoped_hstring.cc index 7954bf1552f..e3f5cbd29bb 100644 --- a/brightray/browser/win/scoped_hstring.cc +++ b/brightray/browser/win/scoped_hstring.cc @@ -11,6 +11,11 @@ ScopedHString::ScopedHString(const wchar_t* source) Set(source); } +ScopedHString::ScopedHString(const std::wstring& source) + : str_(nullptr) { + WindowsCreateString(source.c_str(), source.length(), &str_); +} + ScopedHString::ScopedHString() : str_(nullptr) { } diff --git a/brightray/browser/win/scoped_hstring.h b/brightray/browser/win/scoped_hstring.h index 71c8bfcbe03..de03c0469b3 100644 --- a/brightray/browser/win/scoped_hstring.h +++ b/brightray/browser/win/scoped_hstring.h @@ -5,6 +5,8 @@ #ifndef BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_ #define BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_ +#include + #include #include @@ -14,6 +16,7 @@ class ScopedHString { public: // Copy from |source|. ScopedHString(const wchar_t* source); + ScopedHString(const std::wstring& source); // Create empty string. ScopedHString(); ~ScopedHString(); diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 192b5a25db5..2187788332a 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -9,12 +9,9 @@ #include "browser/win/scoped_hstring.h" #include "content/public/browser/desktop_notification_delegate.h" -using namespace WinToasts; using namespace ABI::Windows::Data::Xml::Dom; -#define BREAK_IF_BAD(hr) if(!SUCCEEDED(hr)) break; - -namespace WinToasts { +namespace brightray { namespace { @@ -47,8 +44,8 @@ WindowsToastNotification::~WindowsToastNotification() { } void WindowsToastNotification::ShowNotification( - const WCHAR* title, - const WCHAR* msg, + const std::wstring& title, + const std::wstring& msg, std::string icon_path, ComPtr& toast) { ComPtr toast_xml; @@ -93,18 +90,18 @@ void WindowsToastNotification::NotificationDismissed() { bool WindowsToastNotification::GetToastXml( IToastNotificationManagerStatics* toastManager, - const WCHAR* title, - const WCHAR* msg, + const std::wstring& title, + const std::wstring& msg, std::string icon_path, IXmlDocument** toast_xml) { ToastTemplateType template_type; - if (!title || !msg) { + if (title.empty() || msg.empty()) { // Single line toast. template_type = icon_path.empty() ? ToastTemplateType_ToastText01 : ToastTemplateType_ToastImageAndText01; if (FAILED(toast_manager_->GetTemplateContent(template_type, toast_xml))) return false; - if (!SetXmlText(*toast_xml, title ? title : msg)) + if (!SetXmlText(*toast_xml, title.empty() ? msg : title)) return false; } else { // Title and body toast. @@ -124,7 +121,7 @@ bool WindowsToastNotification::GetToastXml( } bool WindowsToastNotification::SetXmlText( - IXmlDocument* doc, const WCHAR* text) { + IXmlDocument* doc, const std::wstring& text) { ScopedHString tag; ComPtr node_list; if (!GetTextNodeList(&tag, doc, &node_list, 1)) @@ -138,7 +135,7 @@ bool WindowsToastNotification::SetXmlText( } bool WindowsToastNotification::SetXmlText( - IXmlDocument* doc, const WCHAR* title, const WCHAR* body) { + IXmlDocument* doc, const std::wstring& title, const std::wstring& body) { ScopedHString tag; ComPtr node_list; if (!GetTextNodeList(&tag, doc, &node_list, 2)) @@ -219,7 +216,7 @@ bool WindowsToastNotification::GetTextNodeList( } bool WindowsToastNotification::AppendTextToXml( - IXmlDocument* doc, IXmlNode* node, const WCHAR* text) { + IXmlDocument* doc, IXmlNode* node, const std::wstring& text) { ScopedHString str(text); if (!str.success()) return false; @@ -267,4 +264,4 @@ IFACEMETHODIMP ToastEventHandler::Invoke( return S_OK; } -} // namespace WinToasts +} // namespace brightray diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index 6dee88698b6..8a8c5293529 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -20,7 +20,7 @@ using namespace ABI::Windows::Foundation; class ScopedHString; -namespace WinToasts { +namespace brightray { using DesktopToastActivatedEventHandler = ITypedEventHandler; @@ -36,7 +36,10 @@ class WindowsToastNotification { scoped_ptr delegate); ~WindowsToastNotification(); - void ShowNotification(const WCHAR* title, const WCHAR* msg, std::string iconPath, ComPtr& toast); + void ShowNotification(const std::wstring& title, + const std::wstring& msg, + std::string icon_path, + ComPtr& toast); void DismissNotification(ComPtr toast); void NotificationClicked(); void NotificationDismissed(); @@ -47,12 +50,25 @@ class WindowsToastNotification { ComPtr toast_manager_; ComPtr toast_notifier_; - bool GetToastXml(IToastNotificationManagerStatics* toastManager, const WCHAR* title, const WCHAR* msg, std::string iconPath, ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); - bool SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* text); - bool SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const WCHAR* title, const WCHAR* body); - bool SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, std::string iconPath); - bool GetTextNodeList(ScopedHString* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, UINT32 reqLength); - bool AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const WCHAR* text); + bool GetToastXml(IToastNotificationManagerStatics* toastManager, + const std::wstring& title, + const std::wstring& msg, + std::string icon_path, + ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); + bool SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, + const std::wstring& text); + bool SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, + const std::wstring& title, + const std::wstring& body); + bool SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, + std::string icon_path); + bool GetTextNodeList(ScopedHString* tag, + ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, + ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, + UINT32 reqLength); + bool AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, + ABI::Windows::Data::Xml::Dom::IXmlNode* node, + const std::wstring& text); bool SetupCallbacks(IToastNotification* toast); }; @@ -71,6 +87,6 @@ class ToastEventHandler : public RuntimeClass, WindowsToastNotification* notification_; // weak ref. }; -} // namespace +} // namespace brightray #endif // BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_ From f9f8a289d90e3c308933936684062e52a82121f7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 10 Nov 2015 20:23:08 +0800 Subject: [PATCH 0709/1195] Simplify the management of objects --- .../platform_notification_service_impl.cc | 12 +++---- .../browser/win/notification_presenter_win.cc | 34 ++++++++---------- .../browser/win/notification_presenter_win.h | 11 +----- .../browser/win/windows_toast_notification.cc | 25 ++++++------- .../browser/win/windows_toast_notification.h | 36 ++++++++++++------- 5 files changed, 58 insertions(+), 60 deletions(-) diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service_impl.cc index 36045f6db4f..e93408ebe10 100644 --- a/brightray/browser/platform_notification_service_impl.cc +++ b/brightray/browser/platform_notification_service_impl.cc @@ -24,13 +24,13 @@ PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {} PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} NotificationPresenter* PlatformNotificationServiceImpl::notification_presenter() { + #if defined(OS_WIN) + // Bail out if on Windows 7 or even lower, no operating will follow + if (base::win::GetVersion() < base::win::VERSION_WIN8) + return nullptr; + #endif + if (!notification_presenter_) { - #if defined(OS_WIN) - // Bail out if on Windows 7 or even lower, no operating will follow - if (base::win::GetVersion() < base::win::VERSION_WIN8) { - return notification_presenter_.get(); - } - #endif // Create a new presenter if on OS X, Linux, or Windows 8+ notification_presenter_.reset(NotificationPresenter::Create()); } diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 87fc6da55e4..9b981443dcb 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -21,13 +21,21 @@ using namespace ABI::Windows::Foundation; namespace brightray { +namespace { + +void RemoveNotification(base::WeakPtr notification) { + if (notification) + notification->DismissNotification(); +} + +} // namespace + // static NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterWin; } NotificationPresenterWin::NotificationPresenterWin() { - m_lastNotification = nullptr; } NotificationPresenterWin::~NotificationPresenterWin() { @@ -38,28 +46,14 @@ void NotificationPresenterWin::ShowNotification( const SkBitmap& icon, scoped_ptr delegate, base::Closure* cancel_callback) { - std::wstring title = data.title; - std::wstring body = data.body; - std::string iconPath = data.icon.spec(); - std::string appName = GetApplicationName(); - - // toast notification supported in version >= Windows 8 - // for prior versions, use Tray.displayBalloon - if (base::win::GetVersion() >= base::win::VERSION_WIN8) { - wtn = new WindowsToastNotification(appName.c_str(), delegate.Pass()); - wtn->ShowNotification(title, body, iconPath, m_lastNotification); - } + // This class manages itself. + auto notification = new WindowsToastNotification( + GetApplicationName(), delegate.Pass()); + notification->ShowNotification(data.title, data.body, data.icon.spec()); if (cancel_callback) { *cancel_callback = base::Bind( - &NotificationPresenterWin::RemoveNotification, - base::Unretained(this)); - } -} - -void NotificationPresenterWin::RemoveNotification() { - if (m_lastNotification != nullptr && wtn != NULL) { - wtn->DismissNotification(m_lastNotification); + &RemoveNotification, notification->GetWeakPtr()); } } diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index 9a1a1d6576b..5bc84feb92a 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -16,16 +16,10 @@ #ifndef BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ #define BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ -#include -#include - -#include "base/compiler_specific.h" #include "browser/notification_presenter.h" namespace brightray { -class WindowsToastNotification; - class NotificationPresenterWin : public NotificationPresenter { public: NotificationPresenterWin(); @@ -37,11 +31,8 @@ class NotificationPresenterWin : public NotificationPresenter { scoped_ptr delegate, base::Closure* cancel_callback) override; - void RemoveNotification(); - private: - WindowsToastNotification* wtn; - Microsoft::WRL::ComPtr m_lastNotification; + DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin); }; } // namespace diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 2187788332a..cbeda90c360 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -21,9 +21,10 @@ HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); } // namespace WindowsToastNotification::WindowsToastNotification( - const char* app_name, + const std::string& app_name, scoped_ptr delegate) - : delegate_(delegate.Pass()) { + : delegate_(delegate.Pass()), + weak_factory_(this) { ScopedHString toast_manager_str( RuntimeClass_Windows_UI_Notifications_ToastNotificationManager); if (!toast_manager_str.success()) @@ -46,8 +47,7 @@ WindowsToastNotification::~WindowsToastNotification() { void WindowsToastNotification::ShowNotification( const std::wstring& title, const std::wstring& msg, - std::string icon_path, - ComPtr& toast) { + std::string icon_path) { ComPtr toast_xml; if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, &toast_xml))) return; @@ -57,25 +57,26 @@ void WindowsToastNotification::ShowNotification( if (!toast_str.success()) return; - ComPtr toastFactory; - if (FAILED(Windows::Foundation::GetActivationFactory(toast_str, &toastFactory))) + ComPtr toast_factory; + if (FAILED(Windows::Foundation::GetActivationFactory(toast_str, + &toast_factory))) return; - if (FAILED(toastFactory->CreateToastNotification(toast_xml.Get(), &toast))) + if (FAILED(toast_factory->CreateToastNotification(toast_xml.Get(), + &toast_notification_))) return; - if (FAILED(SetupCallbacks(toast.Get()))) + if (FAILED(SetupCallbacks(toast_notification_.Get()))) return; - if (FAILED(toast_notifier_->Show(toast.Get()))) + if (FAILED(toast_notifier_->Show(toast_notification_.Get()))) return; delegate_->NotificationDisplayed(); } -void WindowsToastNotification::DismissNotification( - ComPtr toast) { - toast_notifier_->Hide(toast.Get()); +void WindowsToastNotification::DismissNotification() { + toast_notifier_->Hide(toast_notification_.Get()); } void WindowsToastNotification::NotificationClicked() { diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index 8a8c5293529..bab6612c9f3 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -11,6 +11,7 @@ #include #include "base/bind.h" +#include "base/memory/weak_ptr.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" @@ -27,28 +28,27 @@ using DesktopToastActivatedEventHandler = using DesktopToastDismissedEventHandler = ITypedEventHandler; -class ToastEventHandler; - class WindowsToastNotification { public: WindowsToastNotification( - const char* app_name, + const std::string& app_name, scoped_ptr delegate); ~WindowsToastNotification(); void ShowNotification(const std::wstring& title, const std::wstring& msg, - std::string icon_path, - ComPtr& toast); - void DismissNotification(ComPtr toast); - void NotificationClicked(); - void NotificationDismissed(); + std::string icon_path); + void DismissNotification(); + + base::WeakPtr GetWeakPtr() { + return weak_factory_.GetWeakPtr(); + } private: - scoped_ptr delegate_; - ComPtr event_handler_; - ComPtr toast_manager_; - ComPtr toast_notifier_; + friend class ToastEventHandler; + + void NotificationClicked(); + void NotificationDismissed(); bool GetToastXml(IToastNotificationManagerStatics* toastManager, const std::wstring& title, @@ -70,6 +70,16 @@ class WindowsToastNotification { ABI::Windows::Data::Xml::Dom::IXmlNode* node, const std::wstring& text); bool SetupCallbacks(IToastNotification* toast); + + scoped_ptr delegate_; + ComPtr event_handler_; + ComPtr toast_manager_; + ComPtr toast_notifier_; + ComPtr toast_notification_; + + base::WeakPtrFactory weak_factory_; + + DISALLOW_COPY_AND_ASSIGN(WindowsToastNotification); }; @@ -85,6 +95,8 @@ class ToastEventHandler : public RuntimeClass, private: WindowsToastNotification* notification_; // weak ref. + + DISALLOW_COPY_AND_ASSIGN(ToastEventHandler); }; } // namespace brightray From 90d142b6415c316b7b1af00bf72788a2f03e01e1 Mon Sep 17 00:00:00 2001 From: tejaspathak Date: Tue, 10 Nov 2015 23:26:42 +0900 Subject: [PATCH 0710/1195] Fix build error --- brightray/script/bootstrap | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index 3d06ebbb45b..e0f373cecf3 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -29,7 +29,8 @@ def main(): elif (args.libcc_source_path != None or args.libcc_shared_library_path != None or args.libcc_static_library_path != None): - print "Error: All options of libchromiumcontent are required OR let brightray choose it" + print "Error: All options of libchromiumcontent are required OR let " \ + "brightray choose it" sys.exit(0) update_submodules() setup_libchromiumcontent(args.dev, args.commit, args.target_arch, args.url, @@ -50,11 +51,17 @@ def parse_args(): 'libchromiumcontent (i.e., the URL you passed to ' 'libchromiumcontent\'s script/upload script') parser.add_argument('--libcc_source_path', required=False, - help='The source path of libchromiumcontent. NOTE: All options of libchromiumcontent are required OR let brightray choose it') + help='The source path of libchromiumcontent. ' \ + 'NOTE: All options of libchromiumcontent are ' + 'required OR let brightray choose it') parser.add_argument('--libcc_shared_library_path', required=False, - help='The shared library path of libchromiumcontent. NOTE: All options of libchromiumcontent are required OR let brightray choose it') + help='The shared library path of libchromiumcontent. ' \ + 'NOTE: All options of libchromiumcontent are ' \ + 'required OR let brightray choose it') parser.add_argument('--libcc_static_library_path', required=False, - help='The static library path of libchromiumcontent. NOTE: All options of libchromiumcontent are required OR let brightray choose it') + help='The static library path of libchromiumcontent. ' \ + 'NOTE: All options of libchromiumcontent are ' \ + 'required OR let brightray choose it') return parser.parse_args() @@ -68,7 +75,6 @@ def setup_libchromiumcontent(is_dev, commit, target_arch, url, libcc_source_path, libcc_shared_library_path, libcc_static_library_path): - mkdir_p(DOWNLOAD_DIR) target_dir = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', 'download') @@ -76,9 +82,12 @@ def setup_libchromiumcontent(is_dev, commit, target_arch, url, if (libcc_source_path != None and libcc_shared_library_path != None and libcc_static_library_path != None): - args.append(['--libcc_source_path', libcc_source_path, - '--libcc_shared_library_path', libcc_shared_library_path, - '--libcc_static_library_path', libcc_static_library_path]) + args += ['--libcc_source_path', libcc_source_path, + '--libcc_shared_library_path', libcc_shared_library_path, + '--libcc_static_library_path', libcc_static_library_path] + mkdir_p(target_dir) + else: + mkdir_p(DOWNLOAD_DIR) if is_dev: subprocess.check_call([sys.executable, download] + args) else: From 71d582bc68637056af283773e05422914f64ab49 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Tue, 10 Nov 2015 22:18:24 +0100 Subject: [PATCH 0711/1195] Call [NSUserNotification setContentImage] conditionally using respondsToSelector instead of hardcoded OS X version check --- brightray/browser/notification_presenter_mac.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm index 81527772ffb..d7dfe015663 100644 --- a/brightray/browser/notification_presenter_mac.mm +++ b/brightray/browser/notification_presenter_mac.mm @@ -48,7 +48,7 @@ void NotificationPresenterMac::ShowNotification( notification.title = base::SysUTF16ToNSString(data.title); notification.informativeText = base::SysUTF16ToNSString(data.body); - if (base::mac::IsOSYosemiteOrLater() && !icon.drawsNothing()) + if ([notification respondsToSelector:@selector(setContentImage:)] && !icon.drawsNothing()) notification.contentImage = gfx::SkBitmapToNSImageWithColorSpace(icon, base::mac::GetGenericRGBColorSpace()); notifications_map_[delegate.get()].reset(notification); From 2c84d70f8f4f96c1a4e0d648a75b13c0823f5743 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Tue, 10 Nov 2015 18:04:09 -0800 Subject: [PATCH 0712/1195] Delay Load WinRT Libraries --- brightray/brightray.gyp | 14 +++--------- .../browser/win/notification_presenter_win.cc | 5 ----- .../browser/win/windows_toast_notification.cc | 22 ++++++++++--------- .../browser/win/windows_toast_notification.h | 22 +++++++++---------- 4 files changed, 26 insertions(+), 37 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 9b548e70a7f..62bcb8c2828 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -161,17 +161,6 @@ ] }], # OS=="mac" ['OS=="win"', { - 'msvs_settings': { - 'VCLinkerTool': { - 'AdditionalDependencies': [ - # Windows Runtime. - 'crypt32.lib', - 'runtimeobject.lib', - 'shlwapi.lib', - 'windowsapp.lib', - ], - }, - }, 'conditions': [ ['libchromiumcontent_component', { # sandbox, base_static, devtools_discovery, devtools_http_handler, @@ -231,6 +220,9 @@ 'BluetoothApis.dll', 'Bthprops.cpl', 'setupapi.dll', + # windows runtime + 'API-MS-WIN-CORE-WINRT-L1-1-0.DLL', + 'API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL', ], }, }, diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 9b981443dcb..6fc4001a339 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -14,11 +14,6 @@ #pragma comment(lib, "runtimeobject.lib") -using namespace Microsoft::WRL; -using namespace ABI::Windows::UI::Notifications; -using namespace ABI::Windows::Data::Xml::Dom; -using namespace ABI::Windows::Foundation; - namespace brightray { namespace { diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index cbeda90c360..f2b155b3acf 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -16,6 +16,7 @@ namespace brightray { namespace { // Initialize Windows Runtime + HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); } // namespace @@ -57,7 +58,7 @@ void WindowsToastNotification::ShowNotification( if (!toast_str.success()) return; - ComPtr toast_factory; + ComPtr toast_factory; if (FAILED(Windows::Foundation::GetActivationFactory(toast_str, &toast_factory))) return; @@ -90,24 +91,24 @@ void WindowsToastNotification::NotificationDismissed() { } bool WindowsToastNotification::GetToastXml( - IToastNotificationManagerStatics* toastManager, + ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager, const std::wstring& title, const std::wstring& msg, std::string icon_path, IXmlDocument** toast_xml) { - ToastTemplateType template_type; + ABI::Windows::UI::Notifications::ToastTemplateType template_type; if (title.empty() || msg.empty()) { // Single line toast. - template_type = icon_path.empty() ? ToastTemplateType_ToastText01 : - ToastTemplateType_ToastImageAndText01; + template_type = icon_path.empty() ? ABI::Windows::UI::Notifications::ToastTemplateType_ToastText01 : + ABI::Windows::UI::Notifications::ToastTemplateType_ToastImageAndText01; if (FAILED(toast_manager_->GetTemplateContent(template_type, toast_xml))) return false; if (!SetXmlText(*toast_xml, title.empty() ? msg : title)) return false; } else { // Title and body toast. - template_type = icon_path.empty() ? ToastTemplateType_ToastText02 : - ToastTemplateType_ToastImageAndText02; + template_type = icon_path.empty() ? ABI::Windows::UI::Notifications::ToastTemplateType_ToastText02 : + ABI::Windows::UI::Notifications::ToastTemplateType_ToastImageAndText02; if (FAILED(toastManager->GetTemplateContent(template_type, toast_xml))) return false; if (!SetXmlText(*toast_xml, title, msg)) @@ -234,7 +235,7 @@ bool WindowsToastNotification::AppendTextToXml( return SUCCEEDED(node->AppendChild(text_node.Get(), &append_node)); } -bool WindowsToastNotification::SetupCallbacks(IToastNotification* toast) { +bool WindowsToastNotification::SetupCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast) { EventRegistrationToken activatedToken, dismissedToken; event_handler_ = Make(this); if (FAILED(toast->add_Activated(event_handler_.Get(), &activatedToken))) @@ -254,13 +255,14 @@ ToastEventHandler::~ToastEventHandler() { } IFACEMETHODIMP ToastEventHandler::Invoke( - IToastNotification* sender, IInspectable* args) { + ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args) { notification_->NotificationClicked(); return S_OK; } IFACEMETHODIMP ToastEventHandler::Invoke( - IToastNotification* sender, IToastDismissedEventArgs* e) { + ABI::Windows::UI::Notifications::IToastNotification* sender, + ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e) { notification_->NotificationDismissed(); return S_OK; } diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index bab6612c9f3..8a24e44af29 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -16,17 +16,17 @@ #include "content/public/common/platform_notification_data.h" using namespace Microsoft::WRL; -using namespace ABI::Windows::UI::Notifications; -using namespace ABI::Windows::Foundation; class ScopedHString; namespace brightray { using DesktopToastActivatedEventHandler = - ITypedEventHandler; + ABI::Windows::Foundation::ITypedEventHandler; using DesktopToastDismissedEventHandler = - ITypedEventHandler; + ABI::Windows::Foundation::ITypedEventHandler; class WindowsToastNotification { public: @@ -50,7 +50,7 @@ class WindowsToastNotification { void NotificationClicked(); void NotificationDismissed(); - bool GetToastXml(IToastNotificationManagerStatics* toastManager, + bool GetToastXml(ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager, const std::wstring& title, const std::wstring& msg, std::string icon_path, @@ -69,13 +69,13 @@ class WindowsToastNotification { bool AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const std::wstring& text); - bool SetupCallbacks(IToastNotification* toast); + bool SetupCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast); scoped_ptr delegate_; ComPtr event_handler_; - ComPtr toast_manager_; - ComPtr toast_notifier_; - ComPtr toast_notification_; + ComPtr toast_manager_; + ComPtr toast_notifier_; + ComPtr toast_notification_; base::WeakPtrFactory weak_factory_; @@ -90,8 +90,8 @@ class ToastEventHandler : public RuntimeClass, ToastEventHandler(WindowsToastNotification* notification); ~ToastEventHandler(); - IFACEMETHODIMP Invoke(IToastNotification* sender, IInspectable* args); - IFACEMETHODIMP Invoke(IToastNotification* sender, IToastDismissedEventArgs* e); + IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args); + IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e); private: WindowsToastNotification* notification_; // weak ref. From b4ac9547c4e716508f852ad0899b0e5018e2d5e2 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Tue, 10 Nov 2015 18:37:43 -0800 Subject: [PATCH 0713/1195] Windows Toasts: Don't call WFI statically --- brightray/browser/win/windows_toast_notification.cc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index f2b155b3acf..f353987876c 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -12,20 +12,15 @@ using namespace ABI::Windows::Data::Xml::Dom; namespace brightray { - -namespace { - -// Initialize Windows Runtime - -HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); - -} // namespace - + WindowsToastNotification::WindowsToastNotification( const std::string& app_name, scoped_ptr delegate) : delegate_(delegate.Pass()), weak_factory_(this) { + // If it wasn't for Windows 7, we could do this statically + HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); + ScopedHString toast_manager_str( RuntimeClass_Windows_UI_Notifications_ToastNotificationManager); if (!toast_manager_str.success()) From dedf3553e2bb2063bbd73b2fb29a052fad50a2d7 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Tue, 10 Nov 2015 20:39:24 +0100 Subject: [PATCH 0714/1195] Call content::DesktopNotificationDelegate::NotificationError when toast notification fails on Windows --- .../browser/win/windows_toast_notification.cc | 19 +++++++++++++++++-- .../browser/win/windows_toast_notification.h | 8 +++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index f353987876c..dd060d10e39 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -85,6 +85,11 @@ void WindowsToastNotification::NotificationDismissed() { delete this; } +void WindowsToastNotification::NotificationFailed() { + delegate_->NotificationError(); + delete this; +} + bool WindowsToastNotification::GetToastXml( ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager, const std::wstring& title, @@ -231,12 +236,15 @@ bool WindowsToastNotification::AppendTextToXml( } bool WindowsToastNotification::SetupCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast) { - EventRegistrationToken activatedToken, dismissedToken; + EventRegistrationToken activatedToken, dismissedToken, failedToken; event_handler_ = Make(this); if (FAILED(toast->add_Activated(event_handler_.Get(), &activatedToken))) return false; - return SUCCEEDED(toast->add_Dismissed(event_handler_.Get(), &dismissedToken)); + if (FAILED(toast->add_Dismissed(event_handler_.Get(), &dismissedToken))) + return false; + + return SUCCEEDED(toast->add_Failed(event_handler_.Get(), &failedToken)); } /* @@ -262,4 +270,11 @@ IFACEMETHODIMP ToastEventHandler::Invoke( return S_OK; } +IFACEMETHODIMP ToastEventHandler::Invoke( + ABI::Windows::UI::Notifications::IToastNotification* sender, + ABI::Windows::UI::Notifications::IToastFailedEventArgs* e) { + notification_->NotificationFailed(); + return S_OK; +} + } // namespace brightray diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index 8a24e44af29..91f0537a7a9 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -27,6 +27,9 @@ using DesktopToastActivatedEventHandler = using DesktopToastDismissedEventHandler = ABI::Windows::Foundation::ITypedEventHandler; +using DesktopToastFailedEventHandler = + ABI::Windows::Foundation::ITypedEventHandler; class WindowsToastNotification { public: @@ -49,6 +52,7 @@ class WindowsToastNotification { void NotificationClicked(); void NotificationDismissed(); + void NotificationFailed(); bool GetToastXml(ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager, const std::wstring& title, @@ -85,13 +89,15 @@ class WindowsToastNotification { class ToastEventHandler : public RuntimeClass, DesktopToastActivatedEventHandler, - DesktopToastDismissedEventHandler> { + DesktopToastDismissedEventHandler, + DesktopToastFailedEventHandler> { public: ToastEventHandler(WindowsToastNotification* notification); ~ToastEventHandler(); IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args); IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e); + IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastFailedEventArgs* e); private: WindowsToastNotification* notification_; // weak ref. From 8ff0b050f878157bcdc38c29a4dfb49ec5f2c016 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 16 Nov 2015 16:47:34 +0800 Subject: [PATCH 0715/1195] There is no more NotificationError --- brightray/browser/win/windows_toast_notification.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index dd060d10e39..b3701dedbdf 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -12,7 +12,7 @@ using namespace ABI::Windows::Data::Xml::Dom; namespace brightray { - + WindowsToastNotification::WindowsToastNotification( const std::string& app_name, scoped_ptr delegate) @@ -20,7 +20,7 @@ WindowsToastNotification::WindowsToastNotification( weak_factory_(this) { // If it wasn't for Windows 7, we could do this statically HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); - + ScopedHString toast_manager_str( RuntimeClass_Windows_UI_Notifications_ToastNotificationManager); if (!toast_manager_str.success()) @@ -86,7 +86,6 @@ void WindowsToastNotification::NotificationDismissed() { } void WindowsToastNotification::NotificationFailed() { - delegate_->NotificationError(); delete this; } From 571b595571401ee9c1c694445e572bc05c5311d5 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Mon, 16 Nov 2015 07:41:37 -0800 Subject: [PATCH 0716/1195] Fix Tag Typo We should probably have tests for Windows notifications ;-) --- brightray/browser/win/windows_toast_notification.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index b3701dedbdf..ec2d85f31c0 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -157,7 +157,7 @@ bool WindowsToastNotification::SetXmlText( bool WindowsToastNotification::SetXmlImage( IXmlDocument* doc, std::string icon_path) { - ScopedHString tag(L"imag"); + ScopedHString tag(L"image"); if (!tag.success()) return false; From aa8d1640363a840639db005c6424952069de8a8b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 20 Nov 2015 13:28:37 +0800 Subject: [PATCH 0717/1195] Use AppUserModelID as app id --- .../browser/win/notification_presenter_win.cc | 3 +-- .../browser/win/windows_toast_notification.cc | 21 ++++++++++++++++--- .../browser/win/windows_toast_notification.h | 1 - 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 6fc4001a339..8d4fe8bace0 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -42,8 +42,7 @@ void NotificationPresenterWin::ShowNotification( scoped_ptr delegate, base::Closure* cancel_callback) { // This class manages itself. - auto notification = new WindowsToastNotification( - GetApplicationName(), delegate.Pass()); + auto notification = new WindowsToastNotification(delegate.Pass()); notification->ShowNotification(data.title, data.body, data.icon.spec()); if (cancel_callback) { diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index ec2d85f31c0..60a20dc329f 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -5,6 +5,8 @@ #include "browser/win/windows_toast_notification.h" +#include + #include "base/strings/utf_string_conversions.h" #include "browser/win/scoped_hstring.h" #include "content/public/browser/desktop_notification_delegate.h" @@ -13,8 +15,21 @@ using namespace ABI::Windows::Data::Xml::Dom; namespace brightray { +namespace { + +bool GetAppUserModelId(ScopedHString* app_id) { + PWSTR current_app_id; + if (FAILED(GetCurrentProcessExplicitAppUserModelID(¤t_app_id))) + return false; + + app_id->Set(current_app_id); + CoTaskMemFree(current_app_id); + return app_id->success(); +} + +} // namespace + WindowsToastNotification::WindowsToastNotification( - const std::string& app_name, scoped_ptr delegate) : delegate_(delegate.Pass()), weak_factory_(this) { @@ -30,8 +45,8 @@ WindowsToastNotification::WindowsToastNotification( if (FAILED(hr)) return; - ScopedHString app_id(base::UTF8ToUTF16(app_name).c_str()); - if (!app_id.success()) + ScopedHString app_id; + if (!GetAppUserModelId(&app_id)) return; toast_manager_->CreateToastNotifierWithId(app_id, &toast_notifier_); diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index 91f0537a7a9..87dffae438b 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -34,7 +34,6 @@ using DesktopToastFailedEventHandler = class WindowsToastNotification { public: WindowsToastNotification( - const std::string& app_name, scoped_ptr delegate); ~WindowsToastNotification(); From 1a18c3a3afce843f8a630edc0f207589e0fffafb Mon Sep 17 00:00:00 2001 From: Eran Tiktin Date: Sun, 22 Nov 2015 22:56:35 +0200 Subject: [PATCH 0718/1195] Add support for --proxy-bypass-list --- brightray/browser/url_request_context_getter.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 3f552b314c8..7962b7a1b4a 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -26,6 +26,7 @@ #include "net/http/http_server_properties_impl.h" #include "net/log/net_log.h" #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" +#include "net/proxy/proxy_config.h" #include "net/proxy/proxy_config_service.h" #include "net/proxy/proxy_script_fetcher_impl.h" #include "net/proxy/proxy_service.h" @@ -79,6 +80,10 @@ const char kNoProxyServer[] = "no-proxy-server"; // affects HTTP and HTTPS requests. const char kProxyServer[] = "proxy-server"; +// Bypass specified proxy for the given semi-colon-separated list of hosts. This +// flag has an effect only when --proxy-server is set. +const char kProxyBypassList[] = "proxy-bypass-list"; + // Uses the pac script at the given URL. const char kProxyPacUrl[] = "proxy-pac-url"; @@ -255,8 +260,12 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { if (command_line.HasSwitch(kNoProxyServer)) { storage_->set_proxy_service(net::ProxyService::CreateDirect()); } else if (command_line.HasSwitch(kProxyServer)) { - storage_->set_proxy_service(net::ProxyService::CreateFixed( - command_line.GetSwitchValueASCII(kProxyServer))); + net::ProxyConfig proxy_config; + proxy_config.proxy_rules().ParseFromString( + command_line.GetSwitchValueASCII(kProxyServer)); + proxy_config.proxy_rules().bypass_rules.ParseFromString( + command_line.GetSwitchValueASCII(kProxyBypassList)); + storage_->set_proxy_service(net::ProxyService::CreateFixed(proxy_config)); } else if (command_line.HasSwitch(kProxyPacUrl)) { auto proxy_config = net::ProxyConfig::CreateFromCustomPacURL( GURL(command_line.GetSwitchValueASCII(kProxyPacUrl))); From c060539562523507833b3d55641d7a7e9439cac8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 24 Nov 2015 14:40:58 +0800 Subject: [PATCH 0719/1195] Only create NotificationPresenter when succeeded to initailize toast manager This fix crash when we failed to initailize toast manager. --- .../browser/win/notification_presenter_win.cc | 5 ++- .../browser/win/windows_toast_notification.cc | 38 ++++++++++++------- .../browser/win/windows_toast_notification.h | 8 +++- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 8d4fe8bace0..63feb44224e 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -27,7 +27,10 @@ void RemoveNotification(base::WeakPtr notification) { // static NotificationPresenter* NotificationPresenter::Create() { - return new NotificationPresenterWin; + if (WindowsToastNotification::Initialize()) + return new NotificationPresenterWin; + else + return nullptr; } NotificationPresenterWin::NotificationPresenterWin() { diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 60a20dc329f..64806430a7e 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -29,27 +29,39 @@ bool GetAppUserModelId(ScopedHString* app_id) { } // namespace -WindowsToastNotification::WindowsToastNotification( - scoped_ptr delegate) - : delegate_(delegate.Pass()), - weak_factory_(this) { - // If it wasn't for Windows 7, we could do this statically - HRESULT init = Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); +// static +ComPtr + WindowsToastNotification::toast_manager_; + +// static +ComPtr + WindowsToastNotification::toast_notifier_; + +// static +bool WindowsToastNotification::Initialize() { + // Just initialize, don't care if it fails or already initialized. + Windows::Foundation::Initialize(RO_INIT_MULTITHREADED); ScopedHString toast_manager_str( RuntimeClass_Windows_UI_Notifications_ToastNotificationManager); if (!toast_manager_str.success()) - return; - HRESULT hr = Windows::Foundation::GetActivationFactory( - toast_manager_str, &toast_manager_); - if (FAILED(hr)) - return; + return false; + if (FAILED(Windows::Foundation::GetActivationFactory(toast_manager_str, + &toast_manager_))) + return false; ScopedHString app_id; if (!GetAppUserModelId(&app_id)) - return; + return false; - toast_manager_->CreateToastNotifierWithId(app_id, &toast_notifier_); + return SUCCEEDED( + toast_manager_->CreateToastNotifierWithId(app_id, &toast_notifier_)); +} + +WindowsToastNotification::WindowsToastNotification( + scoped_ptr delegate) + : delegate_(delegate.Pass()), + weak_factory_(this) { } WindowsToastNotification::~WindowsToastNotification() { diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index 87dffae438b..acae591bc47 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -33,6 +33,9 @@ using DesktopToastFailedEventHandler = class WindowsToastNotification { public: + // Should be called before using this class. + static bool Initialize(); + WindowsToastNotification( scoped_ptr delegate); ~WindowsToastNotification(); @@ -74,10 +77,11 @@ class WindowsToastNotification { const std::wstring& text); bool SetupCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast); + static ComPtr toast_manager_; + static ComPtr toast_notifier_; + scoped_ptr delegate_; ComPtr event_handler_; - ComPtr toast_manager_; - ComPtr toast_notifier_; ComPtr toast_notification_; base::WeakPtrFactory weak_factory_; From 087eeedab89120b3a1004d0574d41d224d041a12 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 24 Nov 2015 15:11:43 +0800 Subject: [PATCH 0720/1195] Use application name when app user model ID is not available --- .../browser/win/notification_presenter_win.cc | 1 - brightray/browser/win/scoped_hstring.cc | 18 +++++++++++++----- brightray/browser/win/scoped_hstring.h | 4 +++- .../browser/win/windows_toast_notification.cc | 14 ++++++++------ 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 63feb44224e..447125f3911 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -7,7 +7,6 @@ #include "base/win/windows_version.h" #include "browser/win/windows_toast_notification.h" -#include "common/application_info.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" #include "third_party/skia/include/core/SkBitmap.h" diff --git a/brightray/browser/win/scoped_hstring.cc b/brightray/browser/win/scoped_hstring.cc index e3f5cbd29bb..082ebe76227 100644 --- a/brightray/browser/win/scoped_hstring.cc +++ b/brightray/browser/win/scoped_hstring.cc @@ -8,26 +8,34 @@ ScopedHString::ScopedHString(const wchar_t* source) : str_(nullptr) { - Set(source); + Reset(source); } ScopedHString::ScopedHString(const std::wstring& source) : str_(nullptr) { - WindowsCreateString(source.c_str(), source.length(), &str_); + Reset(source); } ScopedHString::ScopedHString() : str_(nullptr) { } ScopedHString::~ScopedHString() { - if (str_) - WindowsDeleteString(str_); + Reset(); } -void ScopedHString::Set(const wchar_t* source) { +void ScopedHString::Reset() { if (str_) { WindowsDeleteString(str_); str_ = nullptr; } +} + +void ScopedHString::Reset(const wchar_t* source) { + Reset(); WindowsCreateString(source, wcslen(source), &str_); } + +void ScopedHString::Reset(const std::wstring& source) { + Reset(); + WindowsCreateString(source.c_str(), source.length(), &str_); +} diff --git a/brightray/browser/win/scoped_hstring.h b/brightray/browser/win/scoped_hstring.h index de03c0469b3..5494df2fc5c 100644 --- a/brightray/browser/win/scoped_hstring.h +++ b/brightray/browser/win/scoped_hstring.h @@ -22,7 +22,9 @@ class ScopedHString { ~ScopedHString(); // Sets to |source|. - void Set(const wchar_t* source); + void Reset(); + void Reset(const wchar_t* source); + void Reset(const std::wstring& source); // Returns string. operator HSTRING() const { return str_; } diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 64806430a7e..58b4756fed9 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -9,6 +9,7 @@ #include "base/strings/utf_string_conversions.h" #include "browser/win/scoped_hstring.h" +#include "common/application_info.h" #include "content/public/browser/desktop_notification_delegate.h" using namespace ABI::Windows::Data::Xml::Dom; @@ -19,11 +20,12 @@ namespace { bool GetAppUserModelId(ScopedHString* app_id) { PWSTR current_app_id; - if (FAILED(GetCurrentProcessExplicitAppUserModelID(¤t_app_id))) - return false; - - app_id->Set(current_app_id); - CoTaskMemFree(current_app_id); + if (SUCCEEDED(GetCurrentProcessExplicitAppUserModelID(¤t_app_id))) { + app_id->Reset(current_app_id); + CoTaskMemFree(current_app_id); + } else { + app_id->Reset(base::UTF8ToUTF16(GetApplicationName())); + } return app_id->success(); } @@ -229,7 +231,7 @@ bool WindowsToastNotification::GetTextNodeList( IXmlDocument* doc, IXmlNodeList** node_list, UINT32 req_length) { - tag->Set(L"text"); + tag->Reset(L"text"); if (!tag->success()) return false; From 77f7cfc938d481fec022bc33c0bf227656aa7de9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Nov 2015 18:52:07 +0800 Subject: [PATCH 0721/1195] Change how we detect Helper process --- brightray/common/mac/main_application_bundle.mm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/brightray/common/mac/main_application_bundle.mm b/brightray/common/mac/main_application_bundle.mm index 730eb36207b..bfdf8f74818 100644 --- a/brightray/common/mac/main_application_bundle.mm +++ b/brightray/common/mac/main_application_bundle.mm @@ -5,10 +5,10 @@ #import "common/mac/main_application_bundle.h" -#import "common/mac/foundation_util.h" - -#import "base/files/file_path.h" -#import "base/path_service.h" +#include "base/files/file_path.h" +#include "base/mac/foundation_util.h" +#include "base/path_service.h" +#include "base/strings/string_util.h" namespace brightray { @@ -18,7 +18,7 @@ base::FilePath MainApplicationBundlePath() { PathService::Get(base::FILE_EXE, &path); // Up to Contents. - if (base::mac::IsBackgroundOnlyProcess()) { + if (base::EndsWith(path.value(), " Helper", base::CompareCase::SENSITIVE)) { // The running executable is the helper. Go up five steps: // Contents/Frameworks/Helper.app/Contents/MacOS/Helper // ^ to here ^ from here From b81876775e245dbdd917fbaed36cef1d4c07d86a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Nov 2015 19:07:03 +0800 Subject: [PATCH 0722/1195] Check ElectronMainProcess key in Info.plist --- brightray/common/mac/main_application_bundle.mm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/brightray/common/mac/main_application_bundle.mm b/brightray/common/mac/main_application_bundle.mm index bfdf8f74818..3e386b40dc5 100644 --- a/brightray/common/mac/main_application_bundle.mm +++ b/brightray/common/mac/main_application_bundle.mm @@ -6,19 +6,30 @@ #import "common/mac/main_application_bundle.h" #include "base/files/file_path.h" +#include "base/mac/bundle_locations.h" #include "base/mac/foundation_util.h" #include "base/path_service.h" #include "base/strings/string_util.h" namespace brightray { +namespace { + +bool HasMainProcessKey() { + NSDictionary* info_dictionary = [base::mac::MainBundle() infoDictionary]; + return [[info_dictionary objectForKey:@"ElectronMainProcess"] boolValue] != NO; +} + +} // namespace + base::FilePath MainApplicationBundlePath() { // Start out with the path to the running executable. base::FilePath path; PathService::Get(base::FILE_EXE, &path); // Up to Contents. - if (base::EndsWith(path.value(), " Helper", base::CompareCase::SENSITIVE)) { + if (!HasMainProcessKey() && + base::EndsWith(path.value(), " Helper", base::CompareCase::SENSITIVE)) { // The running executable is the helper. Go up five steps: // Contents/Frameworks/Helper.app/Contents/MacOS/Helper // ^ to here ^ from here @@ -40,4 +51,4 @@ NSBundle* MainApplicationBundle() { return [NSBundle bundleWithPath:base::mac::FilePathToNSString(MainApplicationBundlePath())]; } -} +} // namespace brightray From 75d0bc848d46450c6bf74b20bdd23fe02570a5e5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 7 Dec 2015 19:55:01 +0800 Subject: [PATCH 0723/1195] Update to API changes of Chrome 47 --- brightray/browser/browser_context.cc | 2 +- .../browser/devtools_manager_delegate.cc | 7 +++ brightray/browser/devtools_ui.cc | 20 ++++--- .../mac/bry_inspectable_web_contents_view.mm | 4 +- .../media/media_capture_devices_dispatcher.cc | 2 +- .../media/media_capture_devices_dispatcher.h | 2 +- .../net/devtools_network_interceptor.h | 2 +- .../net/devtools_network_transaction.cc | 9 ++++ .../net/devtools_network_transaction.h | 2 + brightray/browser/network_delegate.cc | 16 ++++-- brightray/browser/network_delegate.h | 7 ++- brightray/browser/permission_manager.cc | 10 ++-- brightray/browser/permission_manager.h | 8 +-- .../platform_notification_service_impl.cc | 2 +- .../platform_notification_service_impl.h | 2 +- brightray/browser/special_storage_policy.cc | 4 ++ brightray/browser/special_storage_policy.h | 1 + .../browser/url_request_context_getter.cc | 52 +++++++++++-------- .../browser/url_request_context_getter.h | 4 +- .../browser/web_ui_controller_factory.cc | 2 +- brightray/browser/web_ui_controller_factory.h | 4 +- 21 files changed, 103 insertions(+), 59 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 4bf558d4293..67ad5c8d540 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -40,7 +40,7 @@ namespace { // Convert string to lower case and escape it. std::string MakePartitionName(const std::string& input) { - return net::EscapePath(base::StringToLowerASCII(input)); + return net::EscapePath(base::ToLowerASCII(input)); } } // namespace diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index 95b6fb3b5b2..4e36d204bf7 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -99,6 +99,8 @@ class DevToolsDelegate : std::string GetDiscoveryPageHTML() override; std::string GetFrontendResource(const std::string& path) override; std::string GetPageThumbnailData(const GURL& url) override; + content::DevToolsExternalAgentProxyDelegate* HandleWebSocketConnection( + const std::string& path) override; private: DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); @@ -125,6 +127,11 @@ std::string DevToolsDelegate::GetPageThumbnailData(const GURL& url) { return std::string(); } +content::DevToolsExternalAgentProxyDelegate* +DevToolsDelegate::HandleWebSocketConnection(const std::string& path) { + return nullptr; +} + } // namespace // DevToolsManagerDelegate --------------------------------------------------- diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 390a2dbf216..6f5bdc7bfa5 100644 --- a/brightray/browser/devtools_ui.cc +++ b/brightray/browser/devtools_ui.cc @@ -30,19 +30,25 @@ std::string PathWithoutParams(const std::string& path) { std::string GetMimeTypeForPath(const std::string& path) { std::string filename = PathWithoutParams(path); - if (base::EndsWith(filename, ".html", false)) { + if (base::EndsWith(filename, ".html", base::CompareCase::INSENSITIVE_ASCII)) { return "text/html"; - } else if (base::EndsWith(filename, ".css", false)) { + } else if (base::EndsWith(filename, ".css", + base::CompareCase::INSENSITIVE_ASCII)) { return "text/css"; - } else if (base::EndsWith(filename, ".js", false)) { + } else if (base::EndsWith(filename, ".js", + base::CompareCase::INSENSITIVE_ASCII)) { return "application/javascript"; - } else if (base::EndsWith(filename, ".png", false)) { + } else if (base::EndsWith(filename, ".png", + base::CompareCase::INSENSITIVE_ASCII)) { return "image/png"; - } else if (base::EndsWith(filename, ".gif", false)) { + } else if (base::EndsWith(filename, ".gif", + base::CompareCase::INSENSITIVE_ASCII)) { return "image/gif"; - } else if (base::EndsWith(filename, ".svg", false)) { + } else if (base::EndsWith(filename, ".svg", + base::CompareCase::INSENSITIVE_ASCII)) { return "image/svg+xml"; - } else if (base::EndsWith(filename, ".manifest", false)) { + } else if (base::EndsWith(filename, ".manifest", + base::CompareCase::INSENSITIVE_ASCII)) { return "text/cache-manifest"; } return "text/html"; diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 53afef7b6e5..a1b8dd3c054 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -6,7 +6,7 @@ #include "content/public/browser/render_widget_host_view.h" #import "ui/base/cocoa/underlay_opengl_hosting_window.h" -#include "ui/gfx/mac/scoped_ns_disable_screen_updates.h" +#include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" using namespace brightray; @@ -89,7 +89,7 @@ using namespace brightray; // Focus on web view. devToolsWebContents->RestoreFocus(); } else { - gfx::ScopedNSDisableScreenUpdates disabler; + gfx::ScopedCocoaDisableScreenUpdates disabler; [devToolsView removeFromSuperview]; [self adjustSubviews]; } diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index 1c99d89765a..09c71b82a49 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -37,7 +37,7 @@ const MediaStreamDevices& EmptyDevices() { } // namespace MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() { - return Singleton::get(); + return base::Singleton::get(); } MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index be369a2ff61..c62a917572d 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -64,7 +64,7 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { int render_view_id) override; private: - friend struct DefaultSingletonTraits; + friend struct base::DefaultSingletonTraits; MediaCaptureDevicesDispatcher(); virtual ~MediaCaptureDevicesDispatcher(); diff --git a/brightray/browser/net/devtools_network_interceptor.h b/brightray/browser/net/devtools_network_interceptor.h index 330a7340bd5..60093d0ad63 100644 --- a/brightray/browser/net/devtools_network_interceptor.h +++ b/brightray/browser/net/devtools_network_interceptor.h @@ -68,7 +68,7 @@ class DevToolsNetworkInterceptor { // Transactions waiting certain amount of transfer to be accounted. std::vector throttled_transactions_; - base::OneShotTimer timer_; + base::OneShotTimer timer_; base::TimeTicks offset_; base::TimeDelta tick_length_; base::TimeDelta latency_length_; diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc index c8c74a67999..27e55f757c6 100644 --- a/brightray/browser/net/devtools_network_transaction.cc +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -151,6 +151,10 @@ int64_t DevToolsNetworkTransaction::GetTotalReceivedBytes() const { return transaction_->GetTotalReceivedBytes(); } +int64_t DevToolsNetworkTransaction::GetTotalSentBytes() const { + return transaction_->GetTotalSentBytes(); +} + void DevToolsNetworkTransaction::DoneReading() { transaction_->DoneReading(); } @@ -178,6 +182,11 @@ bool DevToolsNetworkTransaction::GetLoadTimingInfo( return transaction_->GetLoadTimingInfo(info); } +bool DevToolsNetworkTransaction::GetRemoteEndpoint( + net::IPEndPoint* endpoint) const { + return transaction_->GetRemoteEndpoint(endpoint); +} + void DevToolsNetworkTransaction::SetPriority(net::RequestPriority priority) { transaction_->SetPriority(priority); } diff --git a/brightray/browser/net/devtools_network_transaction.h b/brightray/browser/net/devtools_network_transaction.h index 19295bf0dc7..a03fe5106a4 100644 --- a/brightray/browser/net/devtools_network_transaction.h +++ b/brightray/browser/net/devtools_network_transaction.h @@ -55,12 +55,14 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { void StopCaching() override; bool GetFullRequestHeaders(net::HttpRequestHeaders* headers) const override; int64_t GetTotalReceivedBytes() const override; + int64_t GetTotalSentBytes() const override; void DoneReading() override; const net::HttpResponseInfo* GetResponseInfo() const override; net::LoadState GetLoadState() const override; net::UploadProgress GetUploadProgress() const override; void SetQuicServerInfo(net::QuicServerInfo* quic_server_info) override; bool GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override; + bool GetRemoteEndpoint(net::IPEndPoint* endpoint) const override; void SetPriority(net::RequestPriority priority) override; void SetWebSocketHandshakeStreamCreateHelper( net::WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index dbaeeeed3e2..8a1f8ee828c 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -26,7 +26,8 @@ NetworkDelegate::NetworkDelegate() { auto command_line = base::CommandLine::ForCurrentProcess(); if (command_line->HasSwitch(kIgnoreConnectionsLimit)) { std::string value = command_line->GetSwitchValueASCII(kIgnoreConnectionsLimit); - base::SplitString(value, ',', &ignore_connections_limit_domains_); + ignore_connections_limit_domains_ = base::SplitString( + value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); } } @@ -38,7 +39,7 @@ int NetworkDelegate::OnBeforeURLRequest( const net::CompletionCallback& callback, GURL* new_url) { for (const auto& domain : ignore_connections_limit_domains_) { - if (request->url().DomainIs(domain.c_str(), domain.size())) { + if (request->url().DomainIs(domain)) { // Allow unlimited concurrent connections. request->SetPriority(net::MAXIMUM_PRIORITY); request->SetLoadFlags(request->load_flags() | net::LOAD_IGNORE_LIMITS); @@ -91,8 +92,15 @@ void NetworkDelegate::OnBeforeRedirect(net::URLRequest* request, void NetworkDelegate::OnResponseStarted(net::URLRequest* request) { } -void NetworkDelegate::OnRawBytesRead(const net::URLRequest& request, - int bytes_read) { +void NetworkDelegate::OnURLRequestJobOrphaned(net::URLRequest* request) { +} + +void NetworkDelegate::OnNetworkBytesReceived(const net::URLRequest& request, + int64_t bytes_read) { +} + +void NetworkDelegate::OnNetworkBytesSent(const net::URLRequest& request, + int64_t bytes_sent) { } void NetworkDelegate::OnCompleted(net::URLRequest* request, bool started) { diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index f281f663ffa..b10cabadd22 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -43,8 +43,11 @@ class NetworkDelegate : public net::NetworkDelegate { void OnBeforeRedirect(net::URLRequest* request, const GURL& new_location) override; void OnResponseStarted(net::URLRequest* request) override; - void OnRawBytesRead(const net::URLRequest& request, - int bytes_read) override; + void OnURLRequestJobOrphaned(net::URLRequest* request) override; + void OnNetworkBytesReceived(const net::URLRequest& request, + int64_t bytes_read) override; + void OnNetworkBytesSent(const net::URLRequest& request, + int64_t bytes_sent) override; void OnCompleted(net::URLRequest* request, bool started) override; void OnURLRequestDestroyed(net::URLRequest* request) override; void OnPACScriptError(int line_number, diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc index 24795ac279e..c5d1ac9a9cd 100644 --- a/brightray/browser/permission_manager.cc +++ b/brightray/browser/permission_manager.cc @@ -18,10 +18,9 @@ PermissionManager::PermissionManager() { PermissionManager::~PermissionManager() { } -void PermissionManager::RequestPermission( +int PermissionManager::RequestPermission( content::PermissionType permission, content::RenderFrameHost* render_frame_host, - int request_id, const GURL& requesting_origin, bool user_gesture, const base::Callback& callback) { @@ -30,13 +29,10 @@ void PermissionManager::RequestPermission( GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID()); } callback.Run(content::PERMISSION_STATUS_GRANTED); + return kNoPendingOperation; } -void PermissionManager::CancelPermissionRequest( - content::PermissionType permission, - content::RenderFrameHost* render_frame_host, - int request_id, - const GURL& requesting_origin) { +void PermissionManager::CancelPermissionRequest(int request_id) { } void PermissionManager::ResetPermission( diff --git a/brightray/browser/permission_manager.h b/brightray/browser/permission_manager.h index a0860dd39bd..778605c51ec 100644 --- a/brightray/browser/permission_manager.h +++ b/brightray/browser/permission_manager.h @@ -17,17 +17,13 @@ class PermissionManager : public content::PermissionManager { ~PermissionManager() override; // content::PermissionManager: - void RequestPermission( + int RequestPermission( content::PermissionType permission, content::RenderFrameHost* render_frame_host, - int request_id, const GURL& requesting_origin, bool user_gesture, const base::Callback& callback) override; - void CancelPermissionRequest(content::PermissionType permission, - content::RenderFrameHost* render_frame_host, - int request_id, - const GURL& requesting_origin) override; + void CancelPermissionRequest(int request_id) override; void ResetPermission(content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) override; diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service_impl.cc index e93408ebe10..98c41b3bae1 100644 --- a/brightray/browser/platform_notification_service_impl.cc +++ b/brightray/browser/platform_notification_service_impl.cc @@ -17,7 +17,7 @@ namespace brightray { // static PlatformNotificationServiceImpl* PlatformNotificationServiceImpl::GetInstance() { - return Singleton::get(); + return base::Singleton::get(); } PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {} diff --git a/brightray/browser/platform_notification_service_impl.h b/brightray/browser/platform_notification_service_impl.h index da1e2ad81eb..9b657d5395e 100644 --- a/brightray/browser/platform_notification_service_impl.h +++ b/brightray/browser/platform_notification_service_impl.h @@ -22,7 +22,7 @@ class PlatformNotificationServiceImpl NotificationPresenter* notification_presenter(); private: - friend struct DefaultSingletonTraits; + friend struct base::DefaultSingletonTraits; PlatformNotificationServiceImpl(); ~PlatformNotificationServiceImpl() override; diff --git a/brightray/browser/special_storage_policy.cc b/brightray/browser/special_storage_policy.cc index f28e8e5caf3..77a302bb1f8 100644 --- a/brightray/browser/special_storage_policy.cc +++ b/brightray/browser/special_storage_policy.cc @@ -20,6 +20,10 @@ bool SpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { return true; } +bool SpecialStoragePolicy::IsStorageDurable(const GURL& origin) { + return true; +} + bool SpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { return false; } diff --git a/brightray/browser/special_storage_policy.h b/brightray/browser/special_storage_policy.h index 9e02a4ac28c..265df536cf2 100644 --- a/brightray/browser/special_storage_policy.h +++ b/brightray/browser/special_storage_policy.h @@ -16,6 +16,7 @@ class SpecialStoragePolicy : public storage::SpecialStoragePolicy { // storage::SpecialStoragePolicy implementation. bool IsStorageProtected(const GURL& origin) override; bool IsStorageUnlimited(const GURL& origin) override; + bool IsStorageDurable(const GURL& origin) override; bool IsStorageSessionOnly(const GURL& origin) override; bool CanQueryDiskSize(const GURL& origin) override; bool HasIsolatedStorage(const GURL& origin) override; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 7962b7a1b4a..1165ecf2f55 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -111,19 +111,24 @@ std::string URLRequestContextGetter::Delegate::GetUserAgent() { return base::EmptyString(); } -net::URLRequestJobFactory* URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( +scoped_ptr +URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector* protocol_interceptors) { scoped_ptr job_factory(new net::URLRequestJobFactoryImpl); for (auto it = protocol_handlers->begin(); it != protocol_handlers->end(); ++it) - job_factory->SetProtocolHandler(it->first, it->second.release()); + job_factory->SetProtocolHandler( + it->first, make_scoped_ptr(it->second.release())); protocol_handlers->clear(); - job_factory->SetProtocolHandler(url::kDataScheme, new net::DataProtocolHandler); - job_factory->SetProtocolHandler(url::kFileScheme, new net::FileProtocolHandler( - BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( - base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); + job_factory->SetProtocolHandler( + url::kDataScheme, make_scoped_ptr(new net::DataProtocolHandler)); + job_factory->SetProtocolHandler( + url::kFileScheme, + make_scoped_ptr(new net::FileProtocolHandler( + BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( + base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); // Set up interceptors in the reverse order. scoped_ptr top_job_factory = job_factory.Pass(); @@ -133,7 +138,7 @@ net::URLRequestJobFactory* URLRequestContextGetter::Delegate::CreateURLRequestJo top_job_factory.Pass(), make_scoped_ptr(*i))); protocol_interceptors->weak_clear(); - return top_job_factory.release(); + return top_job_factory.Pass(); } net::HttpCache::BackendFactory* @@ -147,7 +152,8 @@ URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(const base::Fil BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); } -net::CertVerifier* URLRequestContextGetter::Delegate::CreateCertVerifier() { +scoped_ptr +URLRequestContextGetter::Delegate::CreateCertVerifier() { return net::CertVerifier::CreateDefault(); } @@ -191,8 +197,8 @@ URLRequestContextGetter::URLRequestContextGetter( // 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 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). - proxy_config_service_.reset(net::ProxyService::CreateSystemProxyConfigService( - io_loop_->task_runner(), file_loop_->task_runner())); + proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( + io_loop_->task_runner(), file_loop_->task_runner()); } URLRequestContextGetter::~URLRequestContextGetter() { @@ -241,8 +247,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { base::WorkerPool::GetTaskRunner(true)))); std::string accept_lang = l10n_util::GetApplicationLocale(""); - storage_->set_http_user_agent_settings(new net::StaticHttpUserAgentSettings( - net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang), delegate_->GetUserAgent())); + storage_->set_http_user_agent_settings(make_scoped_ptr( + new net::StaticHttpUserAgentSettings( + net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang), + delegate_->GetUserAgent()))); scoped_ptr host_resolver(net::HostResolver::CreateDefaultResolver(nullptr)); @@ -275,7 +283,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } else { storage_->set_proxy_service( net::CreateProxyServiceUsingV8ProxyResolver( - proxy_config_service_.release(), + proxy_config_service_.Pass(), new net::ProxyScriptFetcherImpl(url_request_context_.get()), dhcp_factory.Create(url_request_context_.get()), host_resolver.get(), @@ -289,7 +297,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { schemes.push_back(std::string("ntlm")); schemes.push_back(std::string("negotiate")); - auto auth_handler_factory = + auto auth_handler_factory = make_scoped_ptr( net::HttpAuthHandlerRegistryFactory::Create( schemes, url_sec_mgr_.get(), @@ -297,12 +305,13 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { std::string(), // gssapi_library_name std::string(), // gssapi_library_nam false, // auth_android_negotiate_account_type - true); // negotiate_enable_port + true)); // negotiate_enable_port storage_->set_cert_verifier(delegate_->CreateCertVerifier()); - storage_->set_transport_security_state(new net::TransportSecurityState); + storage_->set_transport_security_state( + make_scoped_ptr(new net::TransportSecurityState)); storage_->set_ssl_config_service(delegate_->CreateSSLConfigService()); - storage_->set_http_auth_handler_factory(auth_handler_factory); + storage_->set_http_auth_handler_factory(auth_handler_factory.Pass()); scoped_ptr server_properties( new net::HttpServerPropertiesImpl); storage_->set_http_server_properties(server_properties.Pass()); @@ -344,10 +353,11 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } else { backend = delegate_->CreateHttpCacheBackendFactory(base_path_); } - storage_->set_http_transaction_factory(new net::HttpCache( - new DevToolsNetworkTransactionFactory(controller_, session), - url_request_context_->net_log(), - backend)); + storage_->set_http_transaction_factory(make_scoped_ptr( + new net::HttpCache( + new DevToolsNetworkTransactionFactory(controller_, session), + url_request_context_->net_log(), + backend))); storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( &protocol_handlers_, &protocol_interceptors_)); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index c4e0f9208a1..cf647cf7b51 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -39,12 +39,12 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; } virtual std::string GetUserAgent(); - virtual net::URLRequestJobFactory* CreateURLRequestJobFactory( + virtual scoped_ptr CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector* protocol_interceptors); virtual net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory( const base::FilePath& base_path); - virtual net::CertVerifier* CreateCertVerifier(); + virtual scoped_ptr CreateCertVerifier(); virtual net::SSLConfigService* CreateSSLConfigService(); virtual bool AllowNTLMCredentialsForDomain(const GURL& auth_origin); virtual bool CanDelegateURLSecurity(const GURL& auth_origin); diff --git a/brightray/browser/web_ui_controller_factory.cc b/brightray/browser/web_ui_controller_factory.cc index cacc2f8dc28..3313d3a6c63 100644 --- a/brightray/browser/web_ui_controller_factory.cc +++ b/brightray/browser/web_ui_controller_factory.cc @@ -20,7 +20,7 @@ const char kChromeUIDevToolsBundledHost[] = "devtools"; // static WebUIControllerFactory* WebUIControllerFactory::GetInstance() { - return Singleton::get(); + return base::Singleton::get(); } WebUIControllerFactory::WebUIControllerFactory() { diff --git a/brightray/browser/web_ui_controller_factory.h b/brightray/browser/web_ui_controller_factory.h index 3367255bba3..44a77da5f1e 100644 --- a/brightray/browser/web_ui_controller_factory.h +++ b/brightray/browser/web_ui_controller_factory.h @@ -9,7 +9,9 @@ #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_controller_factory.h" +namespace base { template struct DefaultSingletonTraits; +} namespace brightray { @@ -33,7 +35,7 @@ class WebUIControllerFactory : public content::WebUIControllerFactory { const GURL& url) const override; private: - friend struct DefaultSingletonTraits; + friend struct base::DefaultSingletonTraits; DISALLOW_COPY_AND_ASSIGN(WebUIControllerFactory); }; From cbd4a25ea628b064f4987de507b9cc0d536921ec Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 7 Dec 2015 22:44:15 +0800 Subject: [PATCH 0724/1195] Link with libsandbox --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 62bcb8c2828..7a120831af4 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -153,6 +153,8 @@ '$(SDKROOT)/System/Library/Frameworks/IOKit.framework', # content_browser.gypi: '-lbsm', + # content_common.gypi: + '-lsandbox', # bluetooth.gyp: '$(SDKROOT)/System/Library/Frameworks/IOBluetooth.framework', ], From b50d23feff17ae8b34fcb9bff811fef1dda44acb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Dec 2015 12:06:17 +0800 Subject: [PATCH 0725/1195] Update libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index f202592f932..d0192f9809a 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit f202592f932cfb8494cc6fa211f9b917f2457f3b +Subproject commit d0192f9809a2eec42f66f51b0f85e38e08a2dc8e From 46677e3a36ed0dee5e86f41677ebc5d4bd319ad6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Dec 2015 14:48:46 +0800 Subject: [PATCH 0726/1195] Link with libdesktop_capture_differ_sse2 on darwin --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 074c5d45733..eedf8f2e091 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -131,6 +131,7 @@ '<(libchromiumcontent_dir)/libdevtools_http_handler.a', '<(libchromiumcontent_dir)/libhttp_server.a', '<(libchromiumcontent_dir)/libdesktop_capture.a', + '<(libchromiumcontent_dir)/libdesktop_capture_differ_sse2.a', '<(libchromiumcontent_dir)/librtc_base.a', '<(libchromiumcontent_dir)/librtc_base_approved.a', '<(libchromiumcontent_dir)/libsystem_wrappers.a', From 43add44f097f2988e2536d539cdb93120599ae45 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 8 Dec 2015 03:39:05 -0500 Subject: [PATCH 0727/1195] add list of next_protos to use --- brightray/browser/url_request_context_getter.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 1165ecf2f55..5c0d7828a96 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -330,6 +330,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.http_auth_handler_factory = url_request_context_->http_auth_handler_factory(); network_session_params.net_log = url_request_context_->net_log(); + net::NextProtoVector next_protos; + next_protos.push_back(net::kProtoHTTP2); + next_protos.push_back(net::kProtoHTTP11); + network_session_params.next_protos = next_protos; // --ignore-certificate-errors if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) From c33c0459642e28ae5ff5a5a857360440e3c89375 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Dec 2015 16:40:49 +0800 Subject: [PATCH 0728/1195] There is no libdesktop_capture_differ_sse2 no arm --- brightray/brightray.gyp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index eedf8f2e091..b0697cba241 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -113,6 +113,13 @@ ], }, }], + ['target_arch=="arm"', { + 'link_settings': { + 'libraries!': [ + '<(libchromiumcontent_dir)/libdesktop_capture_differ_sse2.a', + ], + }, + }], ], }], # OS=="linux" ['OS=="mac"', { From 161147fa1a14be04e242515fcd3e89c814492426 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Dec 2015 16:52:38 +0800 Subject: [PATCH 0729/1195] webrtc requires IOKit --- brightray/brightray.gyp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b0697cba241..c0c60c97dfd 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -126,7 +126,9 @@ 'link_settings': { 'libraries': [ '$(SDKROOT)/System/Library/Frameworks/AppKit.framework', + # Required by webrtc: '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', + '$(SDKROOT)/System/Library/Frameworks/IOKit.framework', ], }, 'conditions': [ @@ -163,7 +165,6 @@ '$(SDKROOT)/System/Library/Frameworks/CoreAudio.framework', '$(SDKROOT)/System/Library/Frameworks/CoreMIDI.framework', '$(SDKROOT)/System/Library/Frameworks/CoreVideo.framework', - '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', # surface.gyp: '$(SDKROOT)/System/Library/Frameworks/IOSurface.framework', # content_common.gypi: @@ -172,7 +173,6 @@ '$(SDKROOT)/System/Library/Frameworks/ApplicationServices.framework', '$(SDKROOT)/System/Library/Frameworks/Carbon.framework', '$(SDKROOT)/System/Library/Frameworks/CoreFoundation.framework', - '$(SDKROOT)/System/Library/Frameworks/IOKit.framework', # content_browser.gypi: '-lbsm', # content_common.gypi: From c9376142ca44657c0420d7eb7a68f397f186c850 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Dec 2015 16:55:59 +0800 Subject: [PATCH 0730/1195] Xcomposite is needed for ia32 build --- brightray/brightray.gyp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index c0c60c97dfd..ba54dd5980b 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -1,7 +1,7 @@ { 'variables': { # The libraries brightray will be compiled to. - 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xi xrandr xext gconf-2.0 gmodule-2.0 nss' + 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xi xrandr xcomposite xext gconf-2.0 gmodule-2.0 nss' }, 'includes': [ 'filenames.gypi', @@ -108,7 +108,7 @@ '-lresolv', '-lfontconfig', '-lfreetype', - '-lX11 -lXcursor -lXext -lXfixes -lXrender -lXcomposite -lXdamage -lXtst -lXrandr', + '-lXcursor -lXfixes -lXrender -lXdamage -lXtst', '-lexpat', ], }, From e0b6dd9171e56702b2082e50aec877b1c26fe08e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Dec 2015 17:02:41 +0800 Subject: [PATCH 0731/1195] Link a few more X libraries --- brightray/brightray.gyp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index ba54dd5980b..0f16122de5a 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -1,7 +1,7 @@ { 'variables': { # The libraries brightray will be compiled to. - 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xi xrandr xcomposite xext gconf-2.0 gmodule-2.0 nss' + 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xi xcursor xdamage xrandr xcomposite xext xfixes xrender xtst gconf-2.0 gmodule-2.0 nss' }, 'includes': [ 'filenames.gypi', @@ -108,7 +108,6 @@ '-lresolv', '-lfontconfig', '-lfreetype', - '-lXcursor -lXfixes -lXrender -lXdamage -lXtst', '-lexpat', ], }, From e0719f52bf130c3bfa7a80d47421b73b1aadfd41 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Dec 2015 18:12:11 +0800 Subject: [PATCH 0732/1195] Link with libyuv_neon.a on ARM --- brightray/brightray.gyp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 0f16122de5a..6bfcdb0434e 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -114,6 +114,9 @@ }], ['target_arch=="arm"', { 'link_settings': { + 'libraries': [ + '<(libchromiumcontent_dir)/libyuv_neon.a', + ], 'libraries!': [ '<(libchromiumcontent_dir)/libdesktop_capture_differ_sse2.a', ], From 975a47825b9333b81974fde1875754fae4603756 Mon Sep 17 00:00:00 2001 From: Cyrille Lebeaupin Date: Mon, 16 Nov 2015 09:03:30 +0100 Subject: [PATCH 0733/1195] Add widevine third party --- brightray/brightray.gyp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 6bfcdb0434e..b8f99ba8798 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -94,6 +94,8 @@ '<(libchromiumcontent_dir)/librtc_base_approved.a', '<(libchromiumcontent_dir)/libwebrtc_common.a', '<(libchromiumcontent_dir)/libyuv.a', + '<(libchromiumcontent_dir)/libcdm_renderer.a', + '<(libchromiumcontent_dir)/libcomponent_updater.a', ], }, }, { @@ -148,6 +150,8 @@ '<(libchromiumcontent_dir)/libsystem_wrappers.a', '<(libchromiumcontent_dir)/libwebrtc_common.a', '<(libchromiumcontent_dir)/libyuv.a', + '<(libchromiumcontent_dir)/libcdm_renderer.a', + '<(libchromiumcontent_dir)/libcomponent_updater.a', ], }, }, { @@ -205,6 +209,8 @@ '<(libchromiumcontent_dir)/system_wrappers.lib', '<(libchromiumcontent_dir)/webrtc_common.lib', '<(libchromiumcontent_dir)/libyuv.lib', + '<(libchromiumcontent_dir)/cdm_renderer.lib', + '<(libchromiumcontent_dir)/component_updater.lib', ], }, }, { From a3f85a93a0480677d547c7ea5f343018ee0fb03a Mon Sep 17 00:00:00 2001 From: Robo Date: Sat, 12 Dec 2015 10:56:47 +0530 Subject: [PATCH 0734/1195] fix value of IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE --- brightray/browser/devtools_manager_delegate.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index 4e36d204bf7..fdd0a0225ff 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -38,7 +38,7 @@ namespace { // A hack here: // Copy from grit/shell_resources.h of chromium repository // since libcontentchromium doesn't expose content_shell resources. -const int kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE = 25500; +const int kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE = 25150; class TCPServerSocketFactory : public devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory { From d12787303ca114af8f92dd9be05d4839f90c4ebd Mon Sep 17 00:00:00 2001 From: Robo Date: Sat, 12 Dec 2015 23:31:00 +0530 Subject: [PATCH 0735/1195] use value from shell_resources.h --- brightray/browser/devtools_manager_delegate.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index fdd0a0225ff..ca8f1cf2d84 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -18,6 +18,7 @@ #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/grit/shell_resources.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/favicon_status.h" @@ -35,11 +36,6 @@ namespace brightray { namespace { -// A hack here: -// Copy from grit/shell_resources.h of chromium repository -// since libcontentchromium doesn't expose content_shell resources. -const int kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE = 25150; - class TCPServerSocketFactory : public devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory { public: @@ -113,8 +109,9 @@ DevToolsDelegate::~DevToolsDelegate() { } std::string DevToolsDelegate::GetDiscoveryPageHTML() { + LOG(WARNING) << IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE; return ResourceBundle::GetSharedInstance().GetRawDataResource( - kIDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); + IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); } From 9b88fd40219cbd1149db0b7e35a164b0dfdde545 Mon Sep 17 00:00:00 2001 From: Robo Date: Sat, 19 Dec 2015 02:29:39 +0530 Subject: [PATCH 0736/1195] devtools: exclude devtools related http header from serviceworker context --- brightray/browser/net/devtools_network_transaction.cc | 10 ++++------ brightray/browser/net/devtools_network_transaction.h | 2 ++ .../net/devtools_network_transaction_factory.cc | 5 +++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc index 27e55f757c6..fa3343ef987 100644 --- a/brightray/browser/net/devtools_network_transaction.cc +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -15,12 +15,10 @@ namespace brightray { -namespace { - -const char kDevToolsEmulateNetworkConditionsClientId[] = - "X-DevTools-Emulate-Network-Conditions-Client-Id"; - -} // namespace +// static +const char + DevToolsNetworkTransaction::kDevToolsEmulateNetworkConditionsClientId[] = + "X-DevTools-Emulate-Network-Conditions-Client-Id"; DevToolsNetworkTransaction::DevToolsNetworkTransaction( DevToolsNetworkController* controller, diff --git a/brightray/browser/net/devtools_network_transaction.h b/brightray/browser/net/devtools_network_transaction.h index a03fe5106a4..3e16db0f2c2 100644 --- a/brightray/browser/net/devtools_network_transaction.h +++ b/brightray/browser/net/devtools_network_transaction.h @@ -22,6 +22,8 @@ class DevToolsNetworkInterceptor; class DevToolsNetworkTransaction : public net::HttpTransaction { public: + static const char kDevToolsEmulateNetworkConditionsClientId[]; + DevToolsNetworkTransaction( DevToolsNetworkController* controller, scoped_ptr network_transaction); diff --git a/brightray/browser/net/devtools_network_transaction_factory.cc b/brightray/browser/net/devtools_network_transaction_factory.cc index 72367112f8f..d1676a34d56 100644 --- a/brightray/browser/net/devtools_network_transaction_factory.cc +++ b/brightray/browser/net/devtools_network_transaction_factory.cc @@ -7,6 +7,7 @@ #include "browser/net/devtools_network_controller.h" #include "browser/net/devtools_network_transaction.h" +#include "content/public/browser/service_worker_context.h" #include "net/base/net_errors.h" #include "net/http/http_network_layer.h" #include "net/http/http_network_transaction.h" @@ -18,6 +19,10 @@ DevToolsNetworkTransactionFactory::DevToolsNetworkTransactionFactory( net::HttpNetworkSession* session) : controller_(controller), network_layer_(new net::HttpNetworkLayer(session)) { + std::set headers; + headers.insert( + DevToolsNetworkTransaction::kDevToolsEmulateNetworkConditionsClientId); + content::ServiceWorkerContext::AddExcludedHeadersForFetchEvent(headers); } DevToolsNetworkTransactionFactory::~DevToolsNetworkTransactionFactory() { From 862f3c21f60c3ae257b9c1361987382d9c189178 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 24 Dec 2015 10:46:08 +0800 Subject: [PATCH 0737/1195] Load libnotify dynamically --- brightray/browser/linux/libnotify_loader.cc | 113 ++++++++++++++++++ brightray/browser/linux/libnotify_loader.h | 41 +++++++ .../linux/notification_presenter_linux.cc | 43 +++++-- .../linux/notification_presenter_linux.h | 6 +- brightray/filenames.gypi | 2 + 5 files changed, 190 insertions(+), 15 deletions(-) create mode 100644 brightray/browser/linux/libnotify_loader.cc create mode 100644 brightray/browser/linux/libnotify_loader.h diff --git a/brightray/browser/linux/libnotify_loader.cc b/brightray/browser/linux/libnotify_loader.cc new file mode 100644 index 00000000000..ede4eeec670 --- /dev/null +++ b/brightray/browser/linux/libnotify_loader.cc @@ -0,0 +1,113 @@ +// This is generated file. Do not modify directly. +// Path to the code generator: tools/generate_library_loader/generate_library_loader.py . + +#include "browser/linux/libnotify_loader.h" + +#include + +LibNotifyLoader::LibNotifyLoader() : loaded_(false) { +} + +LibNotifyLoader::~LibNotifyLoader() { + CleanUp(loaded_); +} + +bool LibNotifyLoader::Load(const std::string& library_name) { + if (loaded_) + return false; + + library_ = dlopen(library_name.c_str(), RTLD_LAZY); + if (!library_) + return false; + + notify_is_initted = + reinterpret_castnotify_is_initted)>( + dlsym(library_, "notify_is_initted")); + notify_is_initted = &::notify_is_initted; + if (!notify_is_initted) { + CleanUp(true); + return false; + } + + notify_init = + reinterpret_castnotify_init)>( + dlsym(library_, "notify_init")); + notify_init = &::notify_init; + if (!notify_init) { + CleanUp(true); + return false; + } + + notify_notification_new = + reinterpret_castnotify_notification_new)>( + dlsym(library_, "notify_notification_new")); + notify_notification_new = &::notify_notification_new; + if (!notify_notification_new) { + CleanUp(true); + return false; + } + + notify_notification_add_action = + reinterpret_castnotify_notification_add_action)>( + dlsym(library_, "notify_notification_add_action")); + notify_notification_add_action = &::notify_notification_add_action; + if (!notify_notification_add_action) { + CleanUp(true); + return false; + } + + notify_notification_set_image_from_pixbuf = + reinterpret_castnotify_notification_set_image_from_pixbuf)>( + dlsym(library_, "notify_notification_set_image_from_pixbuf")); + notify_notification_set_image_from_pixbuf = &::notify_notification_set_image_from_pixbuf; + if (!notify_notification_set_image_from_pixbuf) { + CleanUp(true); + return false; + } + + notify_notification_set_timeout = + reinterpret_castnotify_notification_set_timeout)>( + dlsym(library_, "notify_notification_set_timeout")); + notify_notification_set_timeout = &::notify_notification_set_timeout; + if (!notify_notification_set_timeout) { + CleanUp(true); + return false; + } + + notify_notification_show = + reinterpret_castnotify_notification_show)>( + dlsym(library_, "notify_notification_show")); + notify_notification_show = &::notify_notification_show; + if (!notify_notification_show) { + CleanUp(true); + return false; + } + + notify_notification_close = + reinterpret_castnotify_notification_close)>( + dlsym(library_, "notify_notification_close")); + notify_notification_close = &::notify_notification_close; + if (!notify_notification_close) { + CleanUp(true); + return false; + } + + loaded_ = true; + return true; +} + +void LibNotifyLoader::CleanUp(bool unload) { + if (unload) { + dlclose(library_); + library_ = NULL; + } + loaded_ = false; + notify_is_initted = NULL; + notify_init = NULL; + notify_notification_new = NULL; + notify_notification_add_action = NULL; + notify_notification_set_image_from_pixbuf = NULL; + notify_notification_set_timeout = NULL; + notify_notification_show = NULL; + notify_notification_close = NULL; +} diff --git a/brightray/browser/linux/libnotify_loader.h b/brightray/browser/linux/libnotify_loader.h new file mode 100644 index 00000000000..6cf2853af2c --- /dev/null +++ b/brightray/browser/linux/libnotify_loader.h @@ -0,0 +1,41 @@ +// This is generated file. Do not modify directly. +// Path to the code generator: tools/generate_library_loader/generate_library_loader.py . + +#ifndef BRIGHTRAY_BROWSER_LINUX_LIBNOTIFY_LOADER_H_ +#define BRIGHTRAY_BROWSER_LINUX_LIBNOTIFY_LOADER_H_ + +#include + +#include + +class LibNotifyLoader { + public: + LibNotifyLoader(); + ~LibNotifyLoader(); + + bool Load(const std::string& library_name) + __attribute__((warn_unused_result)); + + bool loaded() const { return loaded_; } + + decltype(&::notify_is_initted) notify_is_initted; + decltype(&::notify_init) notify_init; + decltype(&::notify_notification_new) notify_notification_new; + decltype(&::notify_notification_add_action) notify_notification_add_action; + decltype(&::notify_notification_set_image_from_pixbuf) notify_notification_set_image_from_pixbuf; + decltype(&::notify_notification_set_timeout) notify_notification_set_timeout; + decltype(&::notify_notification_show) notify_notification_show; + decltype(&::notify_notification_close) notify_notification_close; + + private: + void CleanUp(bool unload); + + void* library_; + bool loaded_; + + // Disallow copy constructor and assignment operator. + LibNotifyLoader(const LibNotifyLoader&); + void operator=(const LibNotifyLoader&); +}; + +#endif // BRIGHTRAY_BROWSER_LINUX_LIBNOTIFY_LOADER_H_ diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 10e8dec765f..253ec26fe0c 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -10,11 +10,10 @@ #include "base/files/file_enumerator.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" -#include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" +#include "common/application_info.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" -#include "common/application_info.h" -#include +#include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" #include "third_party/skia/include/core/SkBitmap.h" namespace brightray { @@ -65,10 +64,12 @@ content::DesktopNotificationDelegate* GetDelegateFromNotification( // static NotificationPresenter* NotificationPresenter::Create() { - if (!notify_is_initted()) { - notify_init(GetApplicationName().c_str()); - } - return new NotificationPresenterLinux; + scoped_ptr presenter( + new NotificationPresenterLinux); + if (presenter->Init()) + return presenter.release(); + else + return nullptr; } NotificationPresenterLinux::NotificationPresenterLinux() @@ -81,6 +82,19 @@ NotificationPresenterLinux::~NotificationPresenterLinux() { g_list_free_full(notifications_, g_object_unref); } +bool NotificationPresenterLinux::Init() { + if (!libnotify_loader_.Load("libnotify.so.4") && + !libnotify_loader_.Load("libnotify.so.1") && + !libnotify_loader_.Load("libnotify.so")) { + return false; + } + if (!libnotify_loader_.notify_is_initted() && + !libnotify_loader_.notify_init(GetApplicationName().c_str())) { + return false; + } + return true; +} + void NotificationPresenterLinux::ShowNotification( const content::PlatformNotificationData& data, const SkBitmap& icon, @@ -88,7 +102,8 @@ void NotificationPresenterLinux::ShowNotification( base::Closure* cancel_callback) { std::string title = base::UTF16ToUTF8(data.title); std::string body = base::UTF16ToUTF8(data.body); - NotifyNotification* notification = notify_notification_new(title.c_str(), body.c_str(), nullptr); + NotifyNotification* notification = libnotify_loader_.notify_notification_new( + title.c_str(), body.c_str(), nullptr); content::DesktopNotificationDelegate* delegate = delegate_ptr.release(); @@ -100,19 +115,21 @@ void NotificationPresenterLinux::ShowNotification( // Zen Nature" is difficult, we will test for the presence of the indicate // dbus service if (!UnityIsRunning()) { - notify_notification_add_action( + libnotify_loader_.notify_notification_add_action( notification, "default", "View", OnNotificationViewThunk, this, nullptr); } if (!icon.drawsNothing()) { GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon); - notify_notification_set_image_from_pixbuf(notification, pixbuf); - notify_notification_set_timeout(notification, NOTIFY_EXPIRES_DEFAULT); + libnotify_loader_.notify_notification_set_image_from_pixbuf( + notification, pixbuf); + libnotify_loader_.notify_notification_set_timeout( + notification, NOTIFY_EXPIRES_DEFAULT); g_object_unref(pixbuf); } GError* error = nullptr; - notify_notification_show(notification, &error); + libnotify_loader_.notify_notification_show(notification, &error); if (error) { log_and_clear_error(error, "notify_notification_show"); g_object_unref(notification); @@ -131,7 +148,7 @@ void NotificationPresenterLinux::ShowNotification( void NotificationPresenterLinux::CancelNotification(NotifyNotification* notification) { GError* error = nullptr; - notify_notification_close(notification, &error); + libnotify_loader_.notify_notification_close(notification, &error); if (error) log_and_clear_error(error, "notify_notification_close"); diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index ddd79e4c2e8..d70d1c468a0 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -6,11 +6,10 @@ #ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_LINUX_H_ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_LINUX_H_ -#include - #include #include "base/compiler_specific.h" +#include "browser/linux/libnotify_loader.h" #include "browser/notification_presenter.h" #include "ui/base/glib/glib_signal.h" @@ -21,6 +20,7 @@ class NotificationPresenterLinux : public NotificationPresenter { NotificationPresenterLinux(); ~NotificationPresenterLinux(); + bool Init(); void RemoveNotification(NotifyNotification *notification); private: @@ -38,6 +38,8 @@ class NotificationPresenterLinux : public NotificationPresenter { CHROMEG_CALLBACK_1(NotificationPresenterLinux, void, OnNotificationView, NotifyNotification*, char*); + LibNotifyLoader libnotify_loader_; + // A list of all open NotifyNotification objects. // We do lookups here both by NotifyNotification object (when the user // clicks a notification) and by the ID diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 5b0fd733c99..91cb88876cc 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -61,6 +61,8 @@ 'browser/permission_manager.h', 'browser/platform_notification_service_impl.cc', 'browser/platform_notification_service_impl.h', + 'browser/linux/libnotify_loader.h', + 'browser/linux/libnotify_loader.cc', 'browser/linux/notification_presenter_linux.h', 'browser/linux/notification_presenter_linux.cc', 'browser/win/notification_presenter_win.h', From 513b6ae0d66e08dea6c0e46f9052e79037a46c33 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 24 Dec 2015 20:03:54 +0800 Subject: [PATCH 0738/1195] Do not use icon url when showing notification --- .../browser/win/notification_presenter_win.cc | 40 +++++++++++++++++-- .../browser/win/notification_presenter_win.h | 11 +++++ .../browser/win/windows_toast_notification.cc | 8 ++-- .../browser/win/windows_toast_notification.h | 6 +-- 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 447125f3911..29534d94bee 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -5,11 +5,15 @@ #include "browser/win/notification_presenter_win.h" +#include "base/files/file_util.h" +#include "base/md5.h" +#include "base/strings/utf_string_conversions.h" #include "base/win/windows_version.h" #include "browser/win/windows_toast_notification.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "ui/gfx/codec/png_codec.h" #pragma comment(lib, "runtimeobject.lib") @@ -17,6 +21,16 @@ namespace brightray { namespace { +bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) { + std::vector png_data; + if (!gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &png_data)) + return false; + + char* data = reinterpret_cast(&png_data[0]); + int size = static_cast(png_data.size()); + return base::WriteFile(path, data, size) == size; +} + void RemoveNotification(base::WeakPtr notification) { if (notification) notification->DismissNotification(); @@ -26,10 +40,12 @@ void RemoveNotification(base::WeakPtr notification) { // static NotificationPresenter* NotificationPresenter::Create() { - if (WindowsToastNotification::Initialize()) - return new NotificationPresenterWin; - else + if (!WindowsToastNotification::Initialize()) return nullptr; + scoped_ptr presenter(new NotificationPresenterWin); + if (!presenter->Init()) + return nullptr; + return presenter.release(); } NotificationPresenterWin::NotificationPresenterWin() { @@ -38,6 +54,10 @@ NotificationPresenterWin::NotificationPresenterWin() { NotificationPresenterWin::~NotificationPresenterWin() { } +bool NotificationPresenterWin::Init() { + return temp_dir_.CreateUniqueTempDir(); +} + void NotificationPresenterWin::ShowNotification( const content::PlatformNotificationData& data, const SkBitmap& icon, @@ -45,7 +65,8 @@ void NotificationPresenterWin::ShowNotification( base::Closure* cancel_callback) { // This class manages itself. auto notification = new WindowsToastNotification(delegate.Pass()); - notification->ShowNotification(data.title, data.body, data.icon.spec()); + notification->ShowNotification( + data.title, data.body, SaveIconToFilesystem(icon, data.icon)); if (cancel_callback) { *cancel_callback = base::Bind( @@ -53,4 +74,15 @@ void NotificationPresenterWin::ShowNotification( } } +std::wstring NotificationPresenterWin::SaveIconToFilesystem( + const SkBitmap& icon, const GURL& origin) { + std::string filename = base::MD5String(origin.spec()) + ".png"; + base::FilePath path = temp_dir_.path().Append(base::UTF8ToUTF16(filename)); + if (base::PathExists(path)) + return path.value(); + if (SaveIconToPath(icon, path)) + return path.value(); + return base::UTF8ToUTF16(origin.spec()); +} + } // namespace brightray diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index 5bc84feb92a..21152c9cab9 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -16,8 +16,13 @@ #ifndef BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ #define BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ +#include + +#include "base/files/scoped_temp_dir.h" #include "browser/notification_presenter.h" +class GURL; + namespace brightray { class NotificationPresenterWin : public NotificationPresenter { @@ -25,6 +30,8 @@ class NotificationPresenterWin : public NotificationPresenter { NotificationPresenterWin(); ~NotificationPresenterWin(); + bool Init(); + void ShowNotification( const content::PlatformNotificationData&, const SkBitmap& icon, @@ -32,6 +39,10 @@ class NotificationPresenterWin : public NotificationPresenter { base::Closure* cancel_callback) override; private: + std::wstring SaveIconToFilesystem(const SkBitmap& icon, const GURL& origin); + + base::ScopedTempDir temp_dir_; + DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin); }; diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 58b4756fed9..f2d77edf677 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -72,7 +72,7 @@ WindowsToastNotification::~WindowsToastNotification() { void WindowsToastNotification::ShowNotification( const std::wstring& title, const std::wstring& msg, - std::string icon_path) { + const std::wstring& icon_path) { ComPtr toast_xml; if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, &toast_xml))) return; @@ -122,7 +122,7 @@ bool WindowsToastNotification::GetToastXml( ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager, const std::wstring& title, const std::wstring& msg, - std::string icon_path, + const std::wstring& icon_path, IXmlDocument** toast_xml) { ABI::Windows::UI::Notifications::ToastTemplateType template_type; if (title.empty() || msg.empty()) { @@ -185,7 +185,7 @@ bool WindowsToastNotification::SetXmlText( } bool WindowsToastNotification::SetXmlImage( - IXmlDocument* doc, std::string icon_path) { + IXmlDocument* doc, const std::wstring& icon_path) { ScopedHString tag(L"image"); if (!tag.success()) return false; @@ -210,7 +210,7 @@ bool WindowsToastNotification::SetXmlImage( if (FAILED(attrs->GetNamedItem(src, &src_attr))) return false; - ScopedHString img_path(base::UTF8ToUTF16(icon_path).c_str()); + ScopedHString img_path(icon_path.c_str()); if (!img_path.success()) return false; diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index acae591bc47..a5c0a3d1d24 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -42,7 +42,7 @@ class WindowsToastNotification { void ShowNotification(const std::wstring& title, const std::wstring& msg, - std::string icon_path); + const std::wstring& icon_path); void DismissNotification(); base::WeakPtr GetWeakPtr() { @@ -59,7 +59,7 @@ class WindowsToastNotification { bool GetToastXml(ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager, const std::wstring& title, const std::wstring& msg, - std::string icon_path, + const std::wstring& icon_path, ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); bool SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const std::wstring& text); @@ -67,7 +67,7 @@ class WindowsToastNotification { const std::wstring& title, const std::wstring& body); bool SetXmlImage(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, - std::string icon_path); + const std::wstring& icon_path); bool GetTextNodeList(ScopedHString* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, From 41084883cfe9206f3d2f716df387d7e79a4d2641 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 24 Dec 2015 21:55:18 +0800 Subject: [PATCH 0739/1195] Refactor the notification code --- brightray/browser/mac/cocoa_notification.h | 59 ++++++++ brightray/browser/mac/cocoa_notification.mm | 92 ++++++++++++ brightray/browser/mac/notification_delegate.h | 14 ++ .../browser/mac/notification_delegate.mm | 31 ++++ .../browser/mac/notification_presenter_mac.h | 31 ++++ .../browser/mac/notification_presenter_mac.mm | 48 +++++++ .../browser/notification_presenter_mac.h | 56 -------- .../browser/notification_presenter_mac.mm | 133 ------------------ brightray/filenames.gypi | 8 +- 9 files changed, 281 insertions(+), 191 deletions(-) create mode 100644 brightray/browser/mac/cocoa_notification.h create mode 100644 brightray/browser/mac/cocoa_notification.mm create mode 100644 brightray/browser/mac/notification_delegate.h create mode 100644 brightray/browser/mac/notification_delegate.mm create mode 100644 brightray/browser/mac/notification_presenter_mac.h create mode 100644 brightray/browser/mac/notification_presenter_mac.mm delete mode 100644 brightray/browser/notification_presenter_mac.h delete mode 100644 brightray/browser/notification_presenter_mac.mm diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h new file mode 100644 index 00000000000..c1a54678e24 --- /dev/null +++ b/brightray/browser/mac/cocoa_notification.h @@ -0,0 +1,59 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef BROWSER_MAC_COCOA_NOTIFICATION_H_ +#define BROWSER_MAC_COCOA_NOTIFICATION_H_ + +#include + +#import + +#include "base/mac/scoped_nsobject.h" +#include "base/memory/weak_ptr.h" +#include "base/strings/string16.h" +#include "content/public/browser/desktop_notification_delegate.h" + +@class NotificationDelegate; +class SkBitmap; + +namespace brightray { + +class CocoaNotification { + public: + static CocoaNotification* FromNSNotification( + NSUserNotification* notification); + + CocoaNotification( + scoped_ptr delegate); + ~CocoaNotification(); + + void ShowNotification(const base::string16& title, + const base::string16& msg, + const SkBitmap& icon); + void DismissNotification(); + + void NotifyDisplayed(); + void NotifyClick(); + + base::WeakPtr GetWeakPtr() { + return weak_factory_.GetWeakPtr(); + } + + private: + static void Cleanup(); + + scoped_ptr delegate_; + base::scoped_nsobject notification_; + + base::WeakPtrFactory weak_factory_; + + static base::scoped_nsobject notification_delegate_; + static std::set notifications_; + + DISALLOW_COPY_AND_ASSIGN(CocoaNotification); +}; + +} // namespace brightray + +#endif // BROWSER_MAC_COCOA_NOTIFICATION_H_ diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm new file mode 100644 index 00000000000..5983cc48a08 --- /dev/null +++ b/brightray/browser/mac/cocoa_notification.mm @@ -0,0 +1,92 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "browser/mac/cocoa_notification.h" + +#include "base/at_exit.h" +#include "base/bind.h" +#include "base/mac/mac_util.h" +#include "base/stl_util.h" +#include "base/strings/sys_string_conversions.h" +#include "browser/mac/notification_delegate.h" +#include "skia/ext/skia_utils_mac.h" + +namespace brightray { + +// static +base::scoped_nsobject +CocoaNotification::notification_delegate_; + +// static +std::set CocoaNotification::notifications_; + +// static +CocoaNotification* CocoaNotification::FromNSNotification( + NSUserNotification* ns_notification) { + for (CocoaNotification* notification : notifications_) { + if ([notification->notification_ isEqual:ns_notification]) + return notification; + } + return nullptr; +} + +// static +void CocoaNotification::Cleanup() { + NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil; + notification_delegate_.reset(); + STLDeleteElements(¬ifications_); +} + +CocoaNotification::CocoaNotification( + scoped_ptr delegate) + : delegate_(delegate.Pass()), + weak_factory_(this) { + if (!notification_delegate_) { + notification_delegate_.reset([[NotificationDelegate alloc] init]); + NSUserNotificationCenter.defaultUserNotificationCenter.delegate = + notification_delegate_; + base::AtExitManager::RegisterTask(base::Bind(Cleanup)); + } + + notifications_.insert(this); +} + +CocoaNotification::~CocoaNotification() { + [NSUserNotificationCenter.defaultUserNotificationCenter + removeDeliveredNotification:notification_]; + notifications_.erase(this); +} + +void CocoaNotification::ShowNotification(const base::string16& title, + const base::string16& body, + const SkBitmap& icon) { + notification_.reset([[NSUserNotification alloc] init]); + [notification_ setTitle:base::SysUTF16ToNSString(title)]; + [notification_ setInformativeText:base::SysUTF16ToNSString(body)]; + + if ([notification_ respondsToSelector:@selector(setContentImage:)] && + !icon.drawsNothing()) { + NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( + icon, base::mac::GetGenericRGBColorSpace()); + [notification_ setContentImage:image]; + } + + [NSUserNotificationCenter.defaultUserNotificationCenter + deliverNotification:notification_]; +} + +void CocoaNotification::DismissNotification() { + delete this; +} + +void CocoaNotification::NotifyDisplayed() { + delegate_->NotificationDisplayed(); +} + +void CocoaNotification::NotifyClick() { + delegate_->NotificationClick(); + delete this; +} + +} // namespace brightray diff --git a/brightray/browser/mac/notification_delegate.h b/brightray/browser/mac/notification_delegate.h new file mode 100644 index 00000000000..41acead8b11 --- /dev/null +++ b/brightray/browser/mac/notification_delegate.h @@ -0,0 +1,14 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef BROWSER_MAC_NOTIFICATION_DELEGATE_H_ +#define BROWSER_MAC_NOTIFICATION_DELEGATE_H_ + +#import + +@interface NotificationDelegate : NSObject { +} +@end + +#endif // BROWSER_MAC_NOTIFICATION_DELEGATE_H_ diff --git a/brightray/browser/mac/notification_delegate.mm b/brightray/browser/mac/notification_delegate.mm new file mode 100644 index 00000000000..6479eeb91dc --- /dev/null +++ b/brightray/browser/mac/notification_delegate.mm @@ -0,0 +1,31 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "browser/mac/notification_delegate.h" + +#include "browser/mac/cocoa_notification.h" + +@implementation NotificationDelegate + +- (void)userNotificationCenter:(NSUserNotificationCenter*)center + didDeliverNotification:(NSUserNotification*)notif { + auto notification = brightray::CocoaNotification::FromNSNotification(notif); + if (notification) + notification->NotifyDisplayed(); +} + +- (void)userNotificationCenter:(NSUserNotificationCenter*)center + didActivateNotification:(NSUserNotification *)notif { + auto notification = brightray::CocoaNotification::FromNSNotification(notif); + if (notification) + notification->NotifyClick(); +} + +- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center + shouldPresentNotification:(NSUserNotification*)notification { + // Display notifications even if the app is active. + return YES; +} + +@end diff --git a/brightray/browser/mac/notification_presenter_mac.h b/brightray/browser/mac/notification_presenter_mac.h new file mode 100644 index 00000000000..9b2f61b7f03 --- /dev/null +++ b/brightray/browser/mac/notification_presenter_mac.h @@ -0,0 +1,31 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Adam Roben . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ +#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ + +#include "browser/notification_presenter.h" + +namespace brightray { + +class NotificationPresenterMac : public NotificationPresenter { + public: + NotificationPresenterMac(); + ~NotificationPresenterMac(); + + // NotificationPresenter: + void ShowNotification( + const content::PlatformNotificationData&, + const SkBitmap& icon, + scoped_ptr delegate, + base::Closure* cancel_callback) override; + + private: + DISALLOW_COPY_AND_ASSIGN(NotificationPresenterMac); +}; + +} // namespace brightray + +#endif diff --git a/brightray/browser/mac/notification_presenter_mac.mm b/brightray/browser/mac/notification_presenter_mac.mm new file mode 100644 index 00000000000..ead663bcbf8 --- /dev/null +++ b/brightray/browser/mac/notification_presenter_mac.mm @@ -0,0 +1,48 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Adam Roben . All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#import "browser/mac/notification_presenter_mac.h" + +#include "base/bind.h" +#include "browser/mac/cocoa_notification.h" +#include "content/public/common/platform_notification_data.h" + +namespace brightray { + +namespace { + +void RemoveNotification(base::WeakPtr notification) { + if (notification) + notification->DismissNotification(); +} + +} // namespace + +NotificationPresenter* NotificationPresenter::Create() { + return new NotificationPresenterMac; +} + +NotificationPresenterMac::NotificationPresenterMac() { +} + +NotificationPresenterMac::~NotificationPresenterMac() { +} + +void NotificationPresenterMac::ShowNotification( + const content::PlatformNotificationData& data, + const SkBitmap& icon, + scoped_ptr delegate, + base::Closure* cancel_callback) { + // This class manages itself. + auto notification = new CocoaNotification(delegate.Pass()); + notification->ShowNotification(data.title, data.body, icon); + + if (cancel_callback) { + *cancel_callback = base::Bind( + &RemoveNotification, notification->GetWeakPtr()); + } +} + +} // namespace brightray diff --git a/brightray/browser/notification_presenter_mac.h b/brightray/browser/notification_presenter_mac.h deleted file mode 100644 index 768bf2b6f1a..00000000000 --- a/brightray/browser/notification_presenter_mac.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2013 Adam Roben . All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE-CHROMIUM file. - -#ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ -#define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ - -#include "browser/notification_presenter.h" - -#include - -#import - -#include "base/mac/scoped_nsobject.h" - -@class BRYUserNotificationCenterDelegate; - -namespace brightray { - -class NotificationPresenterMac : public NotificationPresenter { - public: - NotificationPresenterMac(); - ~NotificationPresenterMac(); - - // NotificationPresenter: - void ShowNotification( - const content::PlatformNotificationData&, - const SkBitmap& icon, - scoped_ptr delegate, - base::Closure* cancel_callback) override; - - // Get the delegate accroding from the notification object. - content::DesktopNotificationDelegate* GetDelegateFromNotification( - NSUserNotification* notification); - - // Remove the notification object accroding to its delegate. - void RemoveNotification(content::DesktopNotificationDelegate* delegate); - - private: - void CancelNotification(content::DesktopNotificationDelegate* delegate); - - // The userInfo of NSUserNotification can not store pointers (because they are - // not in property list), so we have to track them in a C++ map. - // Also notice that the delegate acts as "ID" or "Key", because it is certain - // that each notification has a unique delegate. - typedef std::map> - NotificationsMap; - NotificationsMap notifications_map_; - - base::scoped_nsobject delegate_; -}; - -} // namespace brightray - -#endif diff --git a/brightray/browser/notification_presenter_mac.mm b/brightray/browser/notification_presenter_mac.mm deleted file mode 100644 index d7dfe015663..00000000000 --- a/brightray/browser/notification_presenter_mac.mm +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2013 Adam Roben . All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE-CHROMIUM file. - -#import "browser/notification_presenter_mac.h" - -#include "base/bind.h" -#include "base/stl_util.h" -#include "base/mac/mac_util.h" -#include "base/strings/sys_string_conversions.h" -#include "content/public/common/platform_notification_data.h" -#include "content/public/browser/desktop_notification_delegate.h" -#include "skia/ext/skia_utils_mac.h" - -@interface BRYUserNotificationCenterDelegate : NSObject { - @private - brightray::NotificationPresenterMac* presenter_; -} -- (instancetype)initWithNotificationPresenter:(brightray::NotificationPresenterMac*)presenter; -@end - -namespace brightray { - -namespace { - -} // namespace - -NotificationPresenter* NotificationPresenter::Create() { - return new NotificationPresenterMac; -} - -NotificationPresenterMac::NotificationPresenterMac() - : delegate_([[BRYUserNotificationCenterDelegate alloc] initWithNotificationPresenter:this]) { - NSUserNotificationCenter.defaultUserNotificationCenter.delegate = delegate_; -} - -NotificationPresenterMac::~NotificationPresenterMac() { - NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil; -} - -void NotificationPresenterMac::ShowNotification( - const content::PlatformNotificationData& data, - const SkBitmap& icon, - scoped_ptr delegate, - base::Closure* cancel_callback) { - auto notification = [[NSUserNotification alloc] init]; - notification.title = base::SysUTF16ToNSString(data.title); - notification.informativeText = base::SysUTF16ToNSString(data.body); - - if ([notification respondsToSelector:@selector(setContentImage:)] && !icon.drawsNothing()) - notification.contentImage = gfx::SkBitmapToNSImageWithColorSpace(icon, base::mac::GetGenericRGBColorSpace()); - - notifications_map_[delegate.get()].reset(notification); - [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification]; - - if (cancel_callback) - *cancel_callback = base::Bind( - &NotificationPresenterMac::CancelNotification, - base::Unretained(this), - delegate.release()); -} - -content::DesktopNotificationDelegate* NotificationPresenterMac::GetDelegateFromNotification( - NSUserNotification* notification) { - for (NotificationsMap::const_iterator it = notifications_map_.begin(); - it != notifications_map_.end(); ++it) - if ([it->second isEqual:notification]) - return it->first; - return NULL; -} - -void NotificationPresenterMac::RemoveNotification(content::DesktopNotificationDelegate* delegate) { - if (ContainsKey(notifications_map_, delegate)) { - delete delegate; - notifications_map_.erase(delegate); - } -} - -void NotificationPresenterMac::CancelNotification(content::DesktopNotificationDelegate* delegate) { - if (!ContainsKey(notifications_map_, delegate)) - return; - - // Notifications in -deliveredNotifications aren't the same objects we passed to - // -deliverNotification:, but they will respond YES to -isEqual:. - auto notification = notifications_map_[delegate]; - auto center = NSUserNotificationCenter.defaultUserNotificationCenter; - for (NSUserNotification* deliveredNotification in center.deliveredNotifications) - if ([notification isEqual:deliveredNotification]) { - [center removeDeliveredNotification:deliveredNotification]; - delegate->NotificationClosed(); - break; - } - - RemoveNotification(delegate); -} - -} // namespace brightray - -@implementation BRYUserNotificationCenterDelegate - -- (instancetype)initWithNotificationPresenter:(brightray::NotificationPresenterMac*)presenter { - self = [super init]; - if (!self) - return nil; - - presenter_ = presenter; - return self; -} - -- (void)userNotificationCenter:(NSUserNotificationCenter*)center - didDeliverNotification:(NSUserNotification*)notification { - auto delegate = presenter_->GetDelegateFromNotification(notification); - if (delegate) - delegate->NotificationDisplayed(); -} - -- (void)userNotificationCenter:(NSUserNotificationCenter*)center - didActivateNotification:(NSUserNotification *)notification { - auto delegate = presenter_->GetDelegateFromNotification(notification); - if (delegate) { - delegate->NotificationClick(); - presenter_->RemoveNotification(delegate); - } -} - -- (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center - shouldPresentNotification:(NSUserNotification*)notification { - // Display notifications even if the app is active. - return YES; -} - -@end diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 91cb88876cc..2f7ed8d3680 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -34,6 +34,12 @@ 'browser/mac/bry_application.mm', 'browser/mac/bry_inspectable_web_contents_view.h', 'browser/mac/bry_inspectable_web_contents_view.mm', + 'browser/mac/cocoa_notification.h', + 'browser/mac/cocoa_notification.mm', + 'browser/mac/notification_delegate.h', + 'browser/mac/notification_delegate.mm', + 'browser/mac/notification_presenter_mac.h', + 'browser/mac/notification_presenter_mac.mm', 'browser/media/media_capture_devices_dispatcher.cc', 'browser/media/media_capture_devices_dispatcher.h', 'browser/media/media_stream_devices_controller.cc', @@ -55,8 +61,6 @@ 'browser/network_delegate.cc', 'browser/network_delegate.h', 'browser/notification_presenter.h', - 'browser/notification_presenter_mac.h', - 'browser/notification_presenter_mac.mm', 'browser/permission_manager.cc', 'browser/permission_manager.h', 'browser/platform_notification_service_impl.cc', From 9897f3aab04b5caa003e3fc19da5123a76eb6c88 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 24 Dec 2015 22:06:41 +0800 Subject: [PATCH 0740/1195] Add an abstract Notification class --- brightray/browser/mac/cocoa_notification.h | 17 +++----- brightray/browser/mac/cocoa_notification.mm | 3 +- .../browser/mac/notification_presenter_mac.mm | 2 +- brightray/browser/notification.h | 39 +++++++++++++++++++ brightray/filenames.gypi | 1 + 5 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 brightray/browser/notification.h diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index c1a54678e24..3fefaa51712 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -10,16 +10,15 @@ #import #include "base/mac/scoped_nsobject.h" -#include "base/memory/weak_ptr.h" -#include "base/strings/string16.h" +#include "base/memory/scoped_ptr.h" +#include "browser/notification.h" #include "content/public/browser/desktop_notification_delegate.h" @class NotificationDelegate; -class SkBitmap; namespace brightray { -class CocoaNotification { +class CocoaNotification : public Notification { public: static CocoaNotification* FromNSNotification( NSUserNotification* notification); @@ -30,24 +29,18 @@ class CocoaNotification { void ShowNotification(const base::string16& title, const base::string16& msg, - const SkBitmap& icon); - void DismissNotification(); + const SkBitmap& icon) override; + void DismissNotification() override; void NotifyDisplayed(); void NotifyClick(); - base::WeakPtr GetWeakPtr() { - return weak_factory_.GetWeakPtr(); - } - private: static void Cleanup(); scoped_ptr delegate_; base::scoped_nsobject notification_; - base::WeakPtrFactory weak_factory_; - static base::scoped_nsobject notification_delegate_; static std::set notifications_; diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index 5983cc48a08..ceaf1f0d4cf 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -40,8 +40,7 @@ void CocoaNotification::Cleanup() { CocoaNotification::CocoaNotification( scoped_ptr delegate) - : delegate_(delegate.Pass()), - weak_factory_(this) { + : delegate_(delegate.Pass()) { if (!notification_delegate_) { notification_delegate_.reset([[NotificationDelegate alloc] init]); NSUserNotificationCenter.defaultUserNotificationCenter.delegate = diff --git a/brightray/browser/mac/notification_presenter_mac.mm b/brightray/browser/mac/notification_presenter_mac.mm index ead663bcbf8..fafde993a9f 100644 --- a/brightray/browser/mac/notification_presenter_mac.mm +++ b/brightray/browser/mac/notification_presenter_mac.mm @@ -13,7 +13,7 @@ namespace brightray { namespace { -void RemoveNotification(base::WeakPtr notification) { +void RemoveNotification(base::WeakPtr notification) { if (notification) notification->DismissNotification(); } diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h new file mode 100644 index 00000000000..b629eda8fde --- /dev/null +++ b/brightray/browser/notification.h @@ -0,0 +1,39 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef BROWSER_NOTIFICATION_H_ +#define BROWSER_NOTIFICATION_H_ + +#include "base/memory/weak_ptr.h" +#include "base/strings/string16.h" + +class SkBitmap; + +namespace brightray { + +class Notification { + public: + Notification() : weak_factory_(this) {} + + virtual void ShowNotification(const base::string16& title, + const base::string16& msg, + const SkBitmap& icon) = 0; + virtual void DismissNotification() = 0; + + base::WeakPtr GetWeakPtr() { + return weak_factory_.GetWeakPtr(); + } + + protected: + virtual ~Notification() {} + + private: + base::WeakPtrFactory weak_factory_; + + DISALLOW_COPY_AND_ASSIGN(Notification); +}; + +} // namespace brightray + +#endif // BROWSER_NOTIFICATION_H_ diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 2f7ed8d3680..e8d3b180091 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -61,6 +61,7 @@ 'browser/network_delegate.cc', 'browser/network_delegate.h', 'browser/notification_presenter.h', + 'browser/notification.h', 'browser/permission_manager.cc', 'browser/permission_manager.h', 'browser/platform_notification_service_impl.cc', From 6f81d1e29fca788f0f92c9d71a79c07d75d7d9ae Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 24 Dec 2015 22:20:47 +0800 Subject: [PATCH 0741/1195] Expose NotificationPresenter to public --- brightray/browser/browser_client.cc | 28 +++++++++-- brightray/browser/browser_client.h | 7 +++ ...pl.cc => platform_notification_service.cc} | 46 ++++++------------- ...impl.h => platform_notification_service.h} | 30 +++++------- brightray/filenames.gypi | 4 +- 5 files changed, 57 insertions(+), 58 deletions(-) rename brightray/browser/{platform_notification_service_impl.cc => platform_notification_service.cc} (50%) rename brightray/browser/{platform_notification_service_impl.h => platform_notification_service.h} (67%) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 18b5fd855e2..465cbce4390 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -4,15 +4,19 @@ #include "browser/browser_client.h" +#include "base/path_service.h" #include "browser/browser_context.h" #include "browser/browser_main_parts.h" #include "browser/devtools_manager_delegate.h" #include "browser/media/media_capture_devices_dispatcher.h" -#include "browser/platform_notification_service_impl.h" - -#include "base/path_service.h" +#include "browser/notification_presenter.h" +#include "browser/platform_notification_service.h" #include "content/public/common/url_constants.h" +#if defined(OS_WIN) +#include "base/win/windows_version.h" +#endif + namespace brightray { namespace { @@ -38,6 +42,20 @@ BrowserContext* BrowserClient::browser_context() { return browser_main_parts_->browser_context(); } +NotificationPresenter* BrowserClient::GetNotificationPresenter() { + #if defined(OS_WIN) + // Bail out if on Windows 7 or even lower, no operating will follow + if (base::win::GetVersion() < base::win::VERSION_WIN8) + return nullptr; + #endif + + if (!notification_presenter_) { + // Create a new presenter if on OS X, Linux, or Windows 8+ + notification_presenter_.reset(NotificationPresenter::Create()); + } + return notification_presenter_.get(); +} + BrowserMainParts* BrowserClient::OverrideCreateBrowserMainParts( const content::MainFunctionParams&) { return new BrowserMainParts; @@ -65,7 +83,9 @@ content::MediaObserver* BrowserClient::GetMediaObserver() { } content::PlatformNotificationService* BrowserClient::GetPlatformNotificationService() { - return PlatformNotificationServiceImpl::GetInstance(); + if (!notification_service_) + notification_service_.reset(new PlatformNotificationService(this)); + return notification_service_.get(); } void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 0612e56d255..bb6575c9b2b 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -13,6 +13,8 @@ namespace brightray { class BrowserContext; class BrowserMainParts; class NetLog; +class NotificationPresenter; +class PlatformNotificationService; class BrowserClient : public content::ContentBrowserClient { public: @@ -24,6 +26,8 @@ class BrowserClient : public content::ContentBrowserClient { BrowserContext* browser_context(); BrowserMainParts* browser_main_parts() { return browser_main_parts_; } + NotificationPresenter* GetNotificationPresenter(); + protected: // Subclasses should override this to provide their own BrowserMainParts // implementation. The lifetime of the returned instance is managed by the @@ -51,6 +55,9 @@ class BrowserClient : public content::ContentBrowserClient { NetLog net_log_; private: + scoped_ptr notification_service_; + scoped_ptr notification_presenter_; + DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; diff --git a/brightray/browser/platform_notification_service_impl.cc b/brightray/browser/platform_notification_service.cc similarity index 50% rename from brightray/browser/platform_notification_service_impl.cc rename to brightray/browser/platform_notification_service.cc index 98c41b3bae1..a480771e8c8 100644 --- a/brightray/browser/platform_notification_service_impl.cc +++ b/brightray/browser/platform_notification_service.cc @@ -2,68 +2,48 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include "browser/platform_notification_service_impl.h" +#include "browser/platform_notification_service.h" +#include "browser/browser_client.h" #include "browser/notification_presenter.h" - #include "content/public/browser/desktop_notification_delegate.h" -#if defined(OS_WIN) -#include "base/win/windows_version.h" -#endif - namespace brightray { -// static -PlatformNotificationServiceImpl* -PlatformNotificationServiceImpl::GetInstance() { - return base::Singleton::get(); +PlatformNotificationService::PlatformNotificationService( + BrowserClient* browser_client) + : browser_client_(browser_client) { } -PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() {} -PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} +PlatformNotificationService::~PlatformNotificationService() {} -NotificationPresenter* PlatformNotificationServiceImpl::notification_presenter() { - #if defined(OS_WIN) - // Bail out if on Windows 7 or even lower, no operating will follow - if (base::win::GetVersion() < base::win::VERSION_WIN8) - return nullptr; - #endif - - if (!notification_presenter_) { - // Create a new presenter if on OS X, Linux, or Windows 8+ - notification_presenter_.reset(NotificationPresenter::Create()); - } - return notification_presenter_.get(); -} - -blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermissionOnUIThread( +blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnUIThread( content::BrowserContext* browser_context, const GURL& origin, int render_process_id) { return blink::WebNotificationPermissionAllowed; } -blink::WebNotificationPermission PlatformNotificationServiceImpl::CheckPermissionOnIOThread( +blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnIOThread( content::ResourceContext* resource_context, const GURL& origin, int render_process_id) { return blink::WebNotificationPermissionAllowed; } -void PlatformNotificationServiceImpl::DisplayNotification( +void PlatformNotificationService::DisplayNotification( content::BrowserContext* browser_context, const GURL& origin, const SkBitmap& icon, const content::PlatformNotificationData& notification_data, scoped_ptr delegate, base::Closure* cancel_callback) { - auto presenter = notification_presenter(); + auto presenter = browser_client_->GetNotificationPresenter(); if (presenter) presenter->ShowNotification(notification_data, icon, delegate.Pass(), cancel_callback); } -void PlatformNotificationServiceImpl::DisplayPersistentNotification( +void PlatformNotificationService::DisplayPersistentNotification( content::BrowserContext* browser_context, int64_t service_worker_registration_id, const GURL& origin, @@ -71,12 +51,12 @@ void PlatformNotificationServiceImpl::DisplayPersistentNotification( const content::PlatformNotificationData& notification_data) { } -void PlatformNotificationServiceImpl::ClosePersistentNotification( +void PlatformNotificationService::ClosePersistentNotification( content::BrowserContext* browser_context, int64_t persistent_notification_id) { } -bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( +bool PlatformNotificationService::GetDisplayedPersistentNotifications( content::BrowserContext* browser_context, std::set* displayed_notifications) { return false; diff --git a/brightray/browser/platform_notification_service_impl.h b/brightray/browser/platform_notification_service.h similarity index 67% rename from brightray/browser/platform_notification_service_impl.h rename to brightray/browser/platform_notification_service.h index 9b657d5395e..0c598965df4 100644 --- a/brightray/browser/platform_notification_service_impl.h +++ b/brightray/browser/platform_notification_service.h @@ -2,31 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#ifndef BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ -#define BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ +#ifndef BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ +#define BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ -#include "base/memory/singleton.h" #include "content/public/browser/platform_notification_service.h" namespace brightray { -class NotificationPresenter; +class BrowserClient; -class PlatformNotificationServiceImpl +class PlatformNotificationService : public content::PlatformNotificationService { public: - // Returns the active instance of the service in the browser process. Safe to - // be called from any thread. - static PlatformNotificationServiceImpl* GetInstance(); - - NotificationPresenter* notification_presenter(); - - private: - friend struct base::DefaultSingletonTraits; - - PlatformNotificationServiceImpl(); - ~PlatformNotificationServiceImpl() override; + explicit PlatformNotificationService(BrowserClient* browser_client); + ~PlatformNotificationService() override; + protected: // content::PlatformNotificationService: blink::WebNotificationPermission CheckPermissionOnUIThread( content::BrowserContext* browser_context, @@ -56,11 +47,12 @@ class PlatformNotificationServiceImpl content::BrowserContext* browser_context, std::set* displayed_notifications) override; - scoped_ptr notification_presenter_; + private: + BrowserClient* browser_client_; - DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); + DISALLOW_COPY_AND_ASSIGN(PlatformNotificationService); }; } // namespace brightray -#endif // BROWSER_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ +#endif // BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index e8d3b180091..1e4868b7922 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -64,8 +64,8 @@ 'browser/notification.h', 'browser/permission_manager.cc', 'browser/permission_manager.h', - 'browser/platform_notification_service_impl.cc', - 'browser/platform_notification_service_impl.h', + 'browser/platform_notification_service.cc', + 'browser/platform_notification_service.h', 'browser/linux/libnotify_loader.h', 'browser/linux/libnotify_loader.cc', 'browser/linux/notification_presenter_linux.h', From 5b7c7be80440762e55f0c11759c197cf1e58d026 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 25 Dec 2015 10:16:07 +0800 Subject: [PATCH 0742/1195] Decouple notification code from content module --- brightray/browser/mac/cocoa_notification.h | 29 +++----- brightray/browser/mac/cocoa_notification.mm | 67 ++++++------------- ...egate.h => notification_center_delegate.h} | 10 ++- ...ate.mm => notification_center_delegate.mm} | 18 +++-- .../browser/mac/notification_presenter_mac.h | 16 +++-- .../browser/mac/notification_presenter_mac.mm | 54 ++++++--------- brightray/browser/notification.cc | 27 ++++++++ brightray/browser/notification.h | 36 ++++++++-- brightray/browser/notification_delegate.h | 20 ++++++ .../browser/notification_delegate_adapter.cc | 33 +++++++++ .../browser/notification_delegate_adapter.h | 36 ++++++++++ brightray/browser/notification_presenter.cc | 31 +++++++++ brightray/browser/notification_presenter.h | 42 +++++++----- .../browser/platform_notification_service.cc | 27 ++++++-- brightray/filenames.gypi | 9 ++- 15 files changed, 316 insertions(+), 139 deletions(-) rename brightray/browser/mac/{notification_delegate.h => notification_center_delegate.h} (52%) rename brightray/browser/mac/{notification_delegate.mm => notification_center_delegate.mm} (62%) create mode 100644 brightray/browser/notification.cc create mode 100644 brightray/browser/notification_delegate.h create mode 100644 brightray/browser/notification_delegate_adapter.cc create mode 100644 brightray/browser/notification_delegate_adapter.h create mode 100644 brightray/browser/notification_presenter.cc diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index 3fefaa51712..027e8373de1 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -5,45 +5,34 @@ #ifndef BROWSER_MAC_COCOA_NOTIFICATION_H_ #define BROWSER_MAC_COCOA_NOTIFICATION_H_ -#include - #import #include "base/mac/scoped_nsobject.h" #include "base/memory/scoped_ptr.h" #include "browser/notification.h" -#include "content/public/browser/desktop_notification_delegate.h" - -@class NotificationDelegate; namespace brightray { class CocoaNotification : public Notification { public: - static CocoaNotification* FromNSNotification( - NSUserNotification* notification); - - CocoaNotification( - scoped_ptr delegate); + CocoaNotification(NotificationDelegate* delegate, + NotificationPresenter* presenter); ~CocoaNotification(); - void ShowNotification(const base::string16& title, - const base::string16& msg, - const SkBitmap& icon) override; - void DismissNotification() override; + void Show(const base::string16& title, + const base::string16& msg, + const SkBitmap& icon) override; + void Dismiss() override; void NotifyDisplayed(); void NotifyClick(); + NSUserNotification* notification() const { return notification_; } + private: - static void Cleanup(); - - scoped_ptr delegate_; + NotificationDelegate* delegate_; base::scoped_nsobject notification_; - static base::scoped_nsobject notification_delegate_; - static std::set notifications_; - DISALLOW_COPY_AND_ASSIGN(CocoaNotification); }; diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index ceaf1f0d4cf..317211db049 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -4,62 +4,35 @@ #include "browser/mac/cocoa_notification.h" -#include "base/at_exit.h" -#include "base/bind.h" #include "base/mac/mac_util.h" -#include "base/stl_util.h" #include "base/strings/sys_string_conversions.h" -#include "browser/mac/notification_delegate.h" +#include "browser/notification_delegate.h" +#include "browser/notification_presenter.h" #include "skia/ext/skia_utils_mac.h" namespace brightray { // static -base::scoped_nsobject -CocoaNotification::notification_delegate_; - -// static -std::set CocoaNotification::notifications_; - -// static -CocoaNotification* CocoaNotification::FromNSNotification( - NSUserNotification* ns_notification) { - for (CocoaNotification* notification : notifications_) { - if ([notification->notification_ isEqual:ns_notification]) - return notification; - } - return nullptr; +Notification* Notification::Create(NotificationDelegate* delegate, + NotificationPresenter* presenter) { + return new CocoaNotification(delegate, presenter); } -// static -void CocoaNotification::Cleanup() { - NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil; - notification_delegate_.reset(); - STLDeleteElements(¬ifications_); -} - -CocoaNotification::CocoaNotification( - scoped_ptr delegate) - : delegate_(delegate.Pass()) { - if (!notification_delegate_) { - notification_delegate_.reset([[NotificationDelegate alloc] init]); - NSUserNotificationCenter.defaultUserNotificationCenter.delegate = - notification_delegate_; - base::AtExitManager::RegisterTask(base::Bind(Cleanup)); - } - - notifications_.insert(this); +CocoaNotification::CocoaNotification(NotificationDelegate* delegate, + NotificationPresenter* presenter) + : Notification(delegate, presenter) { } CocoaNotification::~CocoaNotification() { - [NSUserNotificationCenter.defaultUserNotificationCenter - removeDeliveredNotification:notification_]; - notifications_.erase(this); + if (notification_) { + [NSUserNotificationCenter.defaultUserNotificationCenter + removeDeliveredNotification:notification_]; + } } -void CocoaNotification::ShowNotification(const base::string16& title, - const base::string16& body, - const SkBitmap& icon) { +void CocoaNotification::Show(const base::string16& title, + const base::string16& body, + const SkBitmap& icon) { notification_.reset([[NSUserNotification alloc] init]); [notification_ setTitle:base::SysUTF16ToNSString(title)]; [notification_ setInformativeText:base::SysUTF16ToNSString(body)]; @@ -75,17 +48,17 @@ void CocoaNotification::ShowNotification(const base::string16& title, deliverNotification:notification_]; } -void CocoaNotification::DismissNotification() { - delete this; +void CocoaNotification::Dismiss() { + Destroy(); } void CocoaNotification::NotifyDisplayed() { - delegate_->NotificationDisplayed(); + delegate()->NotificationDisplayed(); } void CocoaNotification::NotifyClick() { - delegate_->NotificationClick(); - delete this; + delegate()->NotificationClick(); + Destroy(); } } // namespace brightray diff --git a/brightray/browser/mac/notification_delegate.h b/brightray/browser/mac/notification_center_delegate.h similarity index 52% rename from brightray/browser/mac/notification_delegate.h rename to brightray/browser/mac/notification_center_delegate.h index 41acead8b11..6bee83d411b 100644 --- a/brightray/browser/mac/notification_delegate.h +++ b/brightray/browser/mac/notification_center_delegate.h @@ -7,8 +7,16 @@ #import -@interface NotificationDelegate : NSObject { +namespace brightray { +class NotificationPresenterMac; } + +@interface NotificationCenterDelegate : + NSObject { + @private + brightray::NotificationPresenterMac* presenter_; +} +- (instancetype)initWithPresenter:(brightray::NotificationPresenterMac*)presenter; @end #endif // BROWSER_MAC_NOTIFICATION_DELEGATE_H_ diff --git a/brightray/browser/mac/notification_delegate.mm b/brightray/browser/mac/notification_center_delegate.mm similarity index 62% rename from brightray/browser/mac/notification_delegate.mm rename to brightray/browser/mac/notification_center_delegate.mm index 6479eeb91dc..53537bdc311 100644 --- a/brightray/browser/mac/notification_delegate.mm +++ b/brightray/browser/mac/notification_center_delegate.mm @@ -2,22 +2,32 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#include "browser/mac/notification_delegate.h" +#include "browser/mac/notification_center_delegate.h" #include "browser/mac/cocoa_notification.h" +#include "browser/mac/notification_presenter_mac.h" -@implementation NotificationDelegate +@implementation NotificationCenterDelegate + +- (instancetype)initWithPresenter:(brightray::NotificationPresenterMac*)presenter { + self = [super init]; + if (!self) + return nil; + + presenter_ = presenter; + return self; +} - (void)userNotificationCenter:(NSUserNotificationCenter*)center didDeliverNotification:(NSUserNotification*)notif { - auto notification = brightray::CocoaNotification::FromNSNotification(notif); + auto notification = presenter_->GetNotification(notif); if (notification) notification->NotifyDisplayed(); } - (void)userNotificationCenter:(NSUserNotificationCenter*)center didActivateNotification:(NSUserNotification *)notif { - auto notification = brightray::CocoaNotification::FromNSNotification(notif); + auto notification = presenter_->GetNotification(notif); if (notification) notification->NotifyClick(); } diff --git a/brightray/browser/mac/notification_presenter_mac.h b/brightray/browser/mac/notification_presenter_mac.h index 9b2f61b7f03..825a1dada23 100644 --- a/brightray/browser/mac/notification_presenter_mac.h +++ b/brightray/browser/mac/notification_presenter_mac.h @@ -6,23 +6,25 @@ #ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_MAC_H_ +#include "base/mac/scoped_nsobject.h" +#include "browser/mac/notification_center_delegate.h" #include "browser/notification_presenter.h" namespace brightray { +class CocoaNotification; + class NotificationPresenterMac : public NotificationPresenter { public: + CocoaNotification* GetNotification(NSUserNotification* notif); + NotificationPresenterMac(); ~NotificationPresenterMac(); - // NotificationPresenter: - void ShowNotification( - const content::PlatformNotificationData&, - const SkBitmap& icon, - scoped_ptr delegate, - base::Closure* cancel_callback) override; - private: + base::scoped_nsobject + notification_center_delegate_; + DISALLOW_COPY_AND_ASSIGN(NotificationPresenterMac); }; diff --git a/brightray/browser/mac/notification_presenter_mac.mm b/brightray/browser/mac/notification_presenter_mac.mm index fafde993a9f..a37e9182fc6 100644 --- a/brightray/browser/mac/notification_presenter_mac.mm +++ b/brightray/browser/mac/notification_presenter_mac.mm @@ -1,48 +1,38 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2013 Adam Roben . All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE-CHROMIUM file. +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. -#import "browser/mac/notification_presenter_mac.h" +#include "browser/mac/notification_presenter_mac.h" -#include "base/bind.h" #include "browser/mac/cocoa_notification.h" -#include "content/public/common/platform_notification_data.h" +#include "browser/mac/notification_center_delegate.h" namespace brightray { -namespace { - -void RemoveNotification(base::WeakPtr notification) { - if (notification) - notification->DismissNotification(); -} - -} // namespace - +// static NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterMac; } -NotificationPresenterMac::NotificationPresenterMac() { +CocoaNotification* NotificationPresenterMac::GetNotification( + NSUserNotification* ns_notification) { + for (Notification* notification : notifications()) { + auto native_notification = static_cast(notification); + if ([native_notification->notification() isEqual:ns_notification]) + return native_notification; + } + return nullptr; +} + +NotificationPresenterMac::NotificationPresenterMac() + : notification_center_delegate_( + [[NotificationCenterDelegate alloc] initWithPresenter:this]) { + NSUserNotificationCenter.defaultUserNotificationCenter.delegate = + notification_center_delegate_; } NotificationPresenterMac::~NotificationPresenterMac() { -} - -void NotificationPresenterMac::ShowNotification( - const content::PlatformNotificationData& data, - const SkBitmap& icon, - scoped_ptr delegate, - base::Closure* cancel_callback) { - // This class manages itself. - auto notification = new CocoaNotification(delegate.Pass()); - notification->ShowNotification(data.title, data.body, icon); - - if (cancel_callback) { - *cancel_callback = base::Bind( - &RemoveNotification, notification->GetWeakPtr()); - } + NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil; } } // namespace brightray diff --git a/brightray/browser/notification.cc b/brightray/browser/notification.cc new file mode 100644 index 00000000000..6384737c21b --- /dev/null +++ b/brightray/browser/notification.cc @@ -0,0 +1,27 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "browser/notification.h" + +#include "browser/notification_delegate.h" +#include "browser/notification_presenter.h" + +namespace brightray { + +Notification::Notification(NotificationDelegate* delegate, + NotificationPresenter* presenter) + : delegate_(delegate), + presenter_(presenter), + weak_factory_(this) { +} + +Notification::~Notification() { + delegate()->NotificationDestroyed(); +} + +void Notification::Destroy() { + presenter()->RemoveNotification(this); +} + +} // namespace brightray diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index b629eda8fde..9bc4ac44225 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -12,23 +12,45 @@ class SkBitmap; namespace brightray { +class NotificationDelegate; +class NotificationPresenter; + class Notification { public: - Notification() : weak_factory_(this) {} - - virtual void ShowNotification(const base::string16& title, - const base::string16& msg, - const SkBitmap& icon) = 0; - virtual void DismissNotification() = 0; + // Shows the notification. + virtual void Show(const base::string16& title, + const base::string16& msg, + const SkBitmap& icon) = 0; + // Closes the notification, this instance will be destroyed after the + // notification gets closed. + virtual void Dismiss() = 0; base::WeakPtr GetWeakPtr() { return weak_factory_.GetWeakPtr(); } + NotificationDelegate* delegate() const { return delegate_; } + NotificationPresenter* presenter() const { return presenter_; } + protected: - virtual ~Notification() {} + Notification(NotificationDelegate* delegate, + NotificationPresenter* presenter); + virtual ~Notification(); + + // delete this. + void Destroy(); private: + friend class NotificationPresenter; + + // Can only be called by NotificationPresenter, the caller is responsible of + // freeing the returned instance. + static Notification* Create(NotificationDelegate* delegate, + NotificationPresenter* presenter); + + NotificationDelegate* delegate_; + NotificationPresenter* presenter_; + base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(Notification); diff --git a/brightray/browser/notification_delegate.h b/brightray/browser/notification_delegate.h new file mode 100644 index 00000000000..efecaa54010 --- /dev/null +++ b/brightray/browser/notification_delegate.h @@ -0,0 +1,20 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef BROWSER_NOTIFICATION_DELEGATE_H_ +#define BROWSER_NOTIFICATION_DELEGATE_H_ + +#include "content/public/browser/desktop_notification_delegate.h" + +namespace brightray { + +class NotificationDelegate : public content::DesktopNotificationDelegate { + public: + // The native Notification object is destroyed. + virtual void NotificationDestroyed() {} +}; + +} // namespace brightray + +#endif // BROWSER_NOTIFICATION_DELEGATE_H_ diff --git a/brightray/browser/notification_delegate_adapter.cc b/brightray/browser/notification_delegate_adapter.cc new file mode 100644 index 00000000000..da9a70aab39 --- /dev/null +++ b/brightray/browser/notification_delegate_adapter.cc @@ -0,0 +1,33 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "browser/notification_delegate_adapter.h" + +namespace brightray { + +NotificationDelegateAdapter::NotificationDelegateAdapter( + scoped_ptr delegate) + : delegate_(delegate.Pass()) { +} + +NotificationDelegateAdapter::~NotificationDelegateAdapter() { +} + +void NotificationDelegateAdapter::NotificationDestroyed() { + delete this; +} + +void NotificationDelegateAdapter::NotificationDisplayed() { + delegate_->NotificationDisplayed(); +} + +void NotificationDelegateAdapter::NotificationClosed() { + delegate_->NotificationClosed(); +} + +void NotificationDelegateAdapter::NotificationClick() { + delegate_->NotificationClick(); +} + +} // namespace brightray diff --git a/brightray/browser/notification_delegate_adapter.h b/brightray/browser/notification_delegate_adapter.h new file mode 100644 index 00000000000..b48c7376cb0 --- /dev/null +++ b/brightray/browser/notification_delegate_adapter.h @@ -0,0 +1,36 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef BROWSER_NOTIFICATION_DELEGATE_ADAPTER_H_ +#define BROWSER_NOTIFICATION_DELEGATE_ADAPTER_H_ + +#include "base/memory/scoped_ptr.h" +#include "browser/notification_delegate.h" + +namespace brightray { + +// Adapt the content::DesktopNotificationDelegate to NotificationDelegate. +class NotificationDelegateAdapter : public NotificationDelegate { + public: + explicit NotificationDelegateAdapter( + scoped_ptr delegate); + ~NotificationDelegateAdapter() override; + + // NotificationDelegate: + void NotificationDestroyed() override; + + // content::DesktopNotificationDelegate: + void NotificationDisplayed() override; + void NotificationClosed() override; + void NotificationClick() override; + + private: + scoped_ptr delegate_; + + DISALLOW_COPY_AND_ASSIGN(NotificationDelegateAdapter); +}; + +} // namespace brightray + +#endif // BROWSER_NOTIFICATION_DELEGATE_ADAPTER_H_ diff --git a/brightray/browser/notification_presenter.cc b/brightray/browser/notification_presenter.cc new file mode 100644 index 00000000000..ad46e292a27 --- /dev/null +++ b/brightray/browser/notification_presenter.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "browser/notification_presenter.h" + +#include "browser/notification.h" + +namespace brightray { + +NotificationPresenter::NotificationPresenter() { +} + +NotificationPresenter::~NotificationPresenter() { + for (Notification* notification : notifications_) + delete notification; +} + +base::WeakPtr NotificationPresenter::CreateNotification( + NotificationDelegate* delegate) { + Notification* notification = Notification::Create(delegate, this); + notifications_.insert(notification); + return notification->GetWeakPtr(); +} + +void NotificationPresenter::RemoveNotification(Notification* notification) { + notifications_.erase(notification); + delete notification; +} + +} // namespace brightray diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index 6c1a66fc593..b3dac3005dc 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -1,29 +1,41 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + #ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_H_ -#include "base/callback_forward.h" -#include "base/memory/scoped_ptr.h" +#include -class SkBitmap; - -namespace content { -class DesktopNotificationDelegate; -struct PlatformNotificationData; -} +#include "base/memory/weak_ptr.h" namespace brightray { +class Notification; +class NotificationDelegate; + class NotificationPresenter { public: - virtual ~NotificationPresenter() {} - static NotificationPresenter* Create(); - virtual void ShowNotification( - const content::PlatformNotificationData&, - const SkBitmap& icon, - scoped_ptr delegate, - base::Closure* cancel_callback) = 0; + virtual ~NotificationPresenter(); + + base::WeakPtr CreateNotification( + NotificationDelegate* delegate); + + std::set notifications() const { return notifications_; } + + protected: + NotificationPresenter(); + + private: + friend class Notification; + + void RemoveNotification(Notification* notification); + + std::set notifications_; + + DISALLOW_COPY_AND_ASSIGN(NotificationPresenter); }; } // namespace brightray diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index a480771e8c8..0d3ecfc180b 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -5,11 +5,22 @@ #include "browser/platform_notification_service.h" #include "browser/browser_client.h" +#include "browser/notification.h" +#include "browser/notification_delegate_adapter.h" #include "browser/notification_presenter.h" -#include "content/public/browser/desktop_notification_delegate.h" +#include "content/public/common/platform_notification_data.h" namespace brightray { +namespace { + +void RemoveNotification(base::WeakPtr notification) { + if (notification) + notification->Dismiss(); +} + +} // namespace + PlatformNotificationService::PlatformNotificationService( BrowserClient* browser_client) : browser_client_(browser_client) { @@ -35,12 +46,20 @@ void PlatformNotificationService::DisplayNotification( content::BrowserContext* browser_context, const GURL& origin, const SkBitmap& icon, - const content::PlatformNotificationData& notification_data, + const content::PlatformNotificationData& data, scoped_ptr delegate, base::Closure* cancel_callback) { auto presenter = browser_client_->GetNotificationPresenter(); - if (presenter) - presenter->ShowNotification(notification_data, icon, delegate.Pass(), cancel_callback); + if (!presenter) + return; + scoped_ptr adapter( + new NotificationDelegateAdapter(delegate.Pass())); + auto notification = presenter->CreateNotification(adapter.get()); + if (notification) { + ignore_result(adapter.release()); // it will release itself automatically. + notification->Show(data.title, data.body, icon); + *cancel_callback = base::Bind(&RemoveNotification, notification); + } } void PlatformNotificationService::DisplayPersistentNotification( diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 1e4868b7922..4dc441d4b9e 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -36,8 +36,8 @@ 'browser/mac/bry_inspectable_web_contents_view.mm', 'browser/mac/cocoa_notification.h', 'browser/mac/cocoa_notification.mm', - 'browser/mac/notification_delegate.h', - 'browser/mac/notification_delegate.mm', + 'browser/mac/notification_center_delegate.h', + 'browser/mac/notification_center_delegate.mm', 'browser/mac/notification_presenter_mac.h', 'browser/mac/notification_presenter_mac.mm', 'browser/media/media_capture_devices_dispatcher.cc', @@ -60,7 +60,12 @@ 'browser/net_log.h', 'browser/network_delegate.cc', 'browser/network_delegate.h', + 'browser/notification_delegate.h', + 'browser/notification_delegate_adapter.cc', + 'browser/notification_delegate_adapter.h', + 'browser/notification_presenter.cc', 'browser/notification_presenter.h', + 'browser/notification.cc', 'browser/notification.h', 'browser/permission_manager.cc', 'browser/permission_manager.h', From b091f27abfc2d280c667f512ce42ab2e17423217 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 25 Dec 2015 11:05:48 +0800 Subject: [PATCH 0743/1195] win: Adapt to new Notification style --- brightray/browser/mac/cocoa_notification.h | 2 + brightray/browser/mac/cocoa_notification.mm | 1 + brightray/browser/notification.h | 2 + .../browser/platform_notification_service.cc | 2 +- .../browser/win/notification_presenter_win.cc | 23 +------ .../browser/win/notification_presenter_win.h | 12 +--- .../browser/win/windows_toast_notification.cc | 65 +++++++++++++------ .../browser/win/windows_toast_notification.h | 36 +++++----- 8 files changed, 72 insertions(+), 71 deletions(-) diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index 027e8373de1..9f967a5e5f9 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -19,8 +19,10 @@ class CocoaNotification : public Notification { NotificationPresenter* presenter); ~CocoaNotification(); + // Notification: void Show(const base::string16& title, const base::string16& msg, + const GURL& icon_url, const SkBitmap& icon) override; void Dismiss() override; diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index 317211db049..4b24e10f52b 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -32,6 +32,7 @@ CocoaNotification::~CocoaNotification() { void CocoaNotification::Show(const base::string16& title, const base::string16& body, + const GURL& icon_url, const SkBitmap& icon) { notification_.reset([[NSUserNotification alloc] init]); [notification_ setTitle:base::SysUTF16ToNSString(title)]; diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index 9bc4ac44225..9d0deccbf45 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -8,6 +8,7 @@ #include "base/memory/weak_ptr.h" #include "base/strings/string16.h" +class GURL; class SkBitmap; namespace brightray { @@ -20,6 +21,7 @@ class Notification { // Shows the notification. virtual void Show(const base::string16& title, const base::string16& msg, + const GURL& icon_url, const SkBitmap& icon) = 0; // Closes the notification, this instance will be destroyed after the // notification gets closed. diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 0d3ecfc180b..7d91ce5f2e4 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -57,7 +57,7 @@ void PlatformNotificationService::DisplayNotification( auto notification = presenter->CreateNotification(adapter.get()); if (notification) { ignore_result(adapter.release()); // it will release itself automatically. - notification->Show(data.title, data.body, icon); + notification->Show(data.title, data.body, data.icon, icon); *cancel_callback = base::Bind(&RemoveNotification, notification); } } diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 29534d94bee..d3d4f7dc243 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -31,11 +31,6 @@ bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) { return base::WriteFile(path, data, size) == size; } -void RemoveNotification(base::WeakPtr notification) { - if (notification) - notification->DismissNotification(); -} - } // namespace // static @@ -58,23 +53,7 @@ bool NotificationPresenterWin::Init() { return temp_dir_.CreateUniqueTempDir(); } -void NotificationPresenterWin::ShowNotification( - const content::PlatformNotificationData& data, - const SkBitmap& icon, - scoped_ptr delegate, - base::Closure* cancel_callback) { - // This class manages itself. - auto notification = new WindowsToastNotification(delegate.Pass()); - notification->ShowNotification( - data.title, data.body, SaveIconToFilesystem(icon, data.icon)); - - if (cancel_callback) { - *cancel_callback = base::Bind( - &RemoveNotification, notification->GetWeakPtr()); - } -} - -std::wstring NotificationPresenterWin::SaveIconToFilesystem( +base::string16 NotificationPresenterWin::SaveIconToFilesystem( const SkBitmap& icon, const GURL& origin) { std::string filename = base::MD5String(origin.spec()) + ".png"; base::FilePath path = temp_dir_.path().Append(base::UTF8ToUTF16(filename)); diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index 21152c9cab9..7bcf1a9909d 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -16,12 +16,12 @@ #ifndef BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ #define BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ -#include - #include "base/files/scoped_temp_dir.h" +#include "base/strings/string16.h" #include "browser/notification_presenter.h" class GURL; +class SkBitmap; namespace brightray { @@ -32,15 +32,9 @@ class NotificationPresenterWin : public NotificationPresenter { bool Init(); - void ShowNotification( - const content::PlatformNotificationData&, - const SkBitmap& icon, - scoped_ptr delegate, - base::Closure* cancel_callback) override; + base::string16 SaveIconToFilesystem(const SkBitmap& icon, const GURL& origin); private: - std::wstring SaveIconToFilesystem(const SkBitmap& icon, const GURL& origin); - base::ScopedTempDir temp_dir_; DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin); diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index f2d77edf677..050dff56935 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -8,9 +8,10 @@ #include #include "base/strings/utf_string_conversions.h" +#include "browser/notification_delegate.h" #include "browser/win/scoped_hstring.h" +#include "browser/win/notification_presenter_win.h" #include "common/application_info.h" -#include "content/public/browser/desktop_notification_delegate.h" using namespace ABI::Windows::Data::Xml::Dom; @@ -31,6 +32,12 @@ bool GetAppUserModelId(ScopedHString* app_id) { } // namespace +// static +Notification* Notification::Create(NotificationDelegate* delegate, + NotificationPresenter* presenter) { + return new WindowsToastNotification(delegate, presenter); +} + // static ComPtr WindowsToastNotification::toast_manager_; @@ -61,18 +68,25 @@ bool WindowsToastNotification::Initialize() { } WindowsToastNotification::WindowsToastNotification( - scoped_ptr delegate) - : delegate_(delegate.Pass()), - weak_factory_(this) { + NotificationDelegate* delegate, + NotificationPresenter* presenter) + : Notification(delegate, presenter) { } WindowsToastNotification::~WindowsToastNotification() { + // Remove the notification on exit, regardless whether it succeeds. + RemoveCallbacks(toast_notification_.Get()); + Dismiss(); } -void WindowsToastNotification::ShowNotification( - const std::wstring& title, - const std::wstring& msg, - const std::wstring& icon_path) { +void WindowsToastNotification::Show( + const base::string16& title, + const base::string16& msg, + const GURL& icon_url, + const SkBitmap& icon) { + auto presenter_win = static_cast(presenter()); + std::wstring icon_path = presenter_win->SaveIconToFilesystem(icon, icon_url); + ComPtr toast_xml; if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, &toast_xml))) return; @@ -97,25 +111,25 @@ void WindowsToastNotification::ShowNotification( if (FAILED(toast_notifier_->Show(toast_notification_.Get()))) return; - delegate_->NotificationDisplayed(); + delegate()->NotificationDisplayed(); } -void WindowsToastNotification::DismissNotification() { +void WindowsToastNotification::Dismiss() { toast_notifier_->Hide(toast_notification_.Get()); } void WindowsToastNotification::NotificationClicked() { - delegate_->NotificationClick(); - delete this; + delegate()->NotificationClick(); + Destroy(); } void WindowsToastNotification::NotificationDismissed() { - delegate_->NotificationClosed(); - delete this; + delegate()->NotificationClosed(); + Destroy(); } void WindowsToastNotification::NotificationFailed() { - delete this; + Destroy(); } bool WindowsToastNotification::GetToastXml( @@ -263,16 +277,27 @@ bool WindowsToastNotification::AppendTextToXml( return SUCCEEDED(node->AppendChild(text_node.Get(), &append_node)); } -bool WindowsToastNotification::SetupCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast) { - EventRegistrationToken activatedToken, dismissedToken, failedToken; +bool WindowsToastNotification::SetupCallbacks( + ABI::Windows::UI::Notifications::IToastNotification* toast) { event_handler_ = Make(this); - if (FAILED(toast->add_Activated(event_handler_.Get(), &activatedToken))) + if (FAILED(toast->add_Activated(event_handler_.Get(), &activated_token_))) return false; - if (FAILED(toast->add_Dismissed(event_handler_.Get(), &dismissedToken))) + if (FAILED(toast->add_Dismissed(event_handler_.Get(), &dismissed_token_))) return false; - return SUCCEEDED(toast->add_Failed(event_handler_.Get(), &failedToken)); + return SUCCEEDED(toast->add_Failed(event_handler_.Get(), &failed_token_)); +} + +bool WindowsToastNotification::RemoveCallbacks( + ABI::Windows::UI::Notifications::IToastNotification* toast) { + if (FAILED(toast->remove_Activated(activated_token_))) + return false; + + if (FAILED(toast->remove_Dismissed(dismissed_token_))) + return false; + + return SUCCEEDED(toast->remove_Failed(failed_token_)); } /* diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index a5c0a3d1d24..02e05666992 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -10,10 +10,7 @@ #include #include -#include "base/bind.h" -#include "base/memory/weak_ptr.h" -#include "content/public/browser/desktop_notification_delegate.h" -#include "content/public/common/platform_notification_data.h" +#include "browser/notification.h" using namespace Microsoft::WRL; @@ -31,23 +28,22 @@ using DesktopToastFailedEventHandler = ABI::Windows::Foundation::ITypedEventHandler; -class WindowsToastNotification { +class WindowsToastNotification : public Notification { public: - // Should be called before using this class. + // Should only be called by NotificationPresenterWin. static bool Initialize(); - WindowsToastNotification( - scoped_ptr delegate); + WindowsToastNotification(NotificationDelegate* delegate, + NotificationPresenter* presenter); ~WindowsToastNotification(); - void ShowNotification(const std::wstring& title, - const std::wstring& msg, - const std::wstring& icon_path); - void DismissNotification(); - - base::WeakPtr GetWeakPtr() { - return weak_factory_.GetWeakPtr(); - } + protected: + // Notification: + void Show(const base::string16& title, + const base::string16& msg, + const GURL& icon_url, + const SkBitmap& icon) override; + void Dismiss() override; private: friend class ToastEventHandler; @@ -76,16 +72,18 @@ class WindowsToastNotification { ABI::Windows::Data::Xml::Dom::IXmlNode* node, const std::wstring& text); bool SetupCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast); + bool RemoveCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast); static ComPtr toast_manager_; static ComPtr toast_notifier_; - scoped_ptr delegate_; + EventRegistrationToken activated_token_; + EventRegistrationToken dismissed_token_; + EventRegistrationToken failed_token_; + ComPtr event_handler_; ComPtr toast_notification_; - base::WeakPtrFactory weak_factory_; - DISALLOW_COPY_AND_ASSIGN(WindowsToastNotification); }; From c81bacc840a70009f50c2bf57d35b7e8b461bd1d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 25 Dec 2015 11:12:25 +0800 Subject: [PATCH 0744/1195] mac: Emit closed when notification is dismissed --- brightray/browser/mac/cocoa_notification.mm | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index 4b24e10f52b..24174e226a9 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -24,10 +24,8 @@ CocoaNotification::CocoaNotification(NotificationDelegate* delegate, } CocoaNotification::~CocoaNotification() { - if (notification_) { - [NSUserNotificationCenter.defaultUserNotificationCenter - removeDeliveredNotification:notification_]; - } + [NSUserNotificationCenter.defaultUserNotificationCenter + removeDeliveredNotification:notification_]; } void CocoaNotification::Show(const base::string16& title, @@ -50,6 +48,9 @@ void CocoaNotification::Show(const base::string16& title, } void CocoaNotification::Dismiss() { + [NSUserNotificationCenter.defaultUserNotificationCenter + removeDeliveredNotification:notification_]; + delegate()->NotificationClosed(); Destroy(); } From 82cef446231a7b8fe5ed03690ce493954403db39 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 25 Dec 2015 11:17:35 +0800 Subject: [PATCH 0745/1195] win: Fire NotificationFailed when failed to show notification --- brightray/browser/notification_delegate.h | 3 ++ .../browser/win/windows_toast_notification.cc | 33 ++++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/brightray/browser/notification_delegate.h b/brightray/browser/notification_delegate.h index efecaa54010..93512f71753 100644 --- a/brightray/browser/notification_delegate.h +++ b/brightray/browser/notification_delegate.h @@ -13,6 +13,9 @@ class NotificationDelegate : public content::DesktopNotificationDelegate { public: // The native Notification object is destroyed. virtual void NotificationDestroyed() {} + + // Failed to send the notification. + virtual void NotificationFailed() {} }; } // namespace brightray diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 050dff56935..d08b888e4a8 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -74,9 +74,11 @@ WindowsToastNotification::WindowsToastNotification( } WindowsToastNotification::~WindowsToastNotification() { - // Remove the notification on exit, regardless whether it succeeds. - RemoveCallbacks(toast_notification_.Get()); - Dismiss(); + // Remove the notification on exit. + if (toast_notification_) { + RemoveCallbacks(toast_notification_.Get()); + Dismiss(); + } } void WindowsToastNotification::Show( @@ -88,28 +90,40 @@ void WindowsToastNotification::Show( std::wstring icon_path = presenter_win->SaveIconToFilesystem(icon, icon_url); ComPtr toast_xml; - if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, &toast_xml))) + if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, &toast_xml))) { + NotificationFailed(); return; + } ScopedHString toast_str( RuntimeClass_Windows_UI_Notifications_ToastNotification); - if (!toast_str.success()) + if (!toast_str.success()) { + NotificationFailed(); return; + } ComPtr toast_factory; if (FAILED(Windows::Foundation::GetActivationFactory(toast_str, - &toast_factory))) + &toast_factory))) { + NotificationFailed(); return; + } if (FAILED(toast_factory->CreateToastNotification(toast_xml.Get(), - &toast_notification_))) + &toast_notification_))) { + NotificationFailed(); return; + } - if (FAILED(SetupCallbacks(toast_notification_.Get()))) + if (FAILED(SetupCallbacks(toast_notification_.Get()))) { + NotificationFailed(); return; + } - if (FAILED(toast_notifier_->Show(toast_notification_.Get()))) + if (FAILED(toast_notifier_->Show(toast_notification_.Get()))) { + NotificationFailed(); return; + } delegate()->NotificationDisplayed(); } @@ -129,6 +143,7 @@ void WindowsToastNotification::NotificationDismissed() { } void WindowsToastNotification::NotificationFailed() { + delegate()->NotificationFailed(); Destroy(); } From 870e6a6f896318136e7c9e7b62c08e90e38c42a4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 25 Dec 2015 11:52:19 +0800 Subject: [PATCH 0746/1195] linux: Adapt to new Notification style --- .../browser/linux/libnotify_notification.cc | 157 +++++++++++++++++ .../browser/linux/libnotify_notification.h | 46 +++++ .../linux/notification_presenter_linux.cc | 162 +----------------- .../linux/notification_presenter_linux.h | 33 +--- brightray/browser/mac/cocoa_notification.h | 1 - brightray/filenames.gypi | 2 + 6 files changed, 210 insertions(+), 191 deletions(-) create mode 100644 brightray/browser/linux/libnotify_notification.cc create mode 100644 brightray/browser/linux/libnotify_notification.h diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc new file mode 100644 index 00000000000..98aa3ffd8a7 --- /dev/null +++ b/brightray/browser/linux/libnotify_notification.cc @@ -0,0 +1,157 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "browser/linux/libnotify_notification.h" + +#include "base/files/file_enumerator.h" +#include "base/strings/string_util.h" +#include "base/strings/utf_string_conversions.h" +#include "browser/notification_delegate.h" +#include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" +#include "common/application_info.h" +#include "third_party/skia/include/core/SkBitmap.h" + +namespace brightray { + +namespace { + +bool unity_has_result = false; +bool unity_result = false; + +bool UnityIsRunning() { + if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER")) + return true; + + if (unity_has_result) + return unity_result; + + unity_has_result = true; + + // Look for the presence of libunity as our hint that we're under Ubuntu. + base::FileEnumerator enumerator(base::FilePath("/usr/lib"), + false, base::FileEnumerator::FILES); + base::FilePath haystack; + while (!((haystack = enumerator.Next()).empty())) { + if (base::StartsWith(haystack.value(), "/usr/lib/libunity-", + base::CompareCase::SENSITIVE)) { + unity_result = true; + break; + } + } + + return unity_result; +} + +void log_and_clear_error(GError* error, const char* context) { + LOG(ERROR) << context + << ": domain=" << error->domain + << " code=" << error->code + << " message=\"" << error->message << '"'; + g_error_free(error); +} + +} // namespace + +// static +Notification* Notification::Create(NotificationDelegate* delegate, + NotificationPresenter* presenter) { + return new LibnotifyNotification(delegate, presenter); +} + +// static +LibNotifyLoader LibnotifyNotification::libnotify_loader_; + +// static +bool LibnotifyNotification::Initialize() { + if (!libnotify_loader_.Load("libnotify.so.4") && + !libnotify_loader_.Load("libnotify.so.1") && + !libnotify_loader_.Load("libnotify.so")) { + return false; + } + if (!libnotify_loader_.notify_is_initted() && + !libnotify_loader_.notify_init(GetApplicationName().c_str())) { + return false; + } + return true; +} + +LibnotifyNotification::LibnotifyNotification(NotificationDelegate* delegate, + NotificationPresenter* presenter) + : Notification(delegate, presenter), + notification_(nullptr) { +} + +LibnotifyNotification::~LibnotifyNotification() { + g_object_unref(notification_); +} + +void LibnotifyNotification::Show(const base::string16& title, + const base::string16& body, + const GURL& icon_url, + const SkBitmap& icon) { + notification_ = libnotify_loader_.notify_notification_new( + base::UTF16ToUTF8(title).c_str(), + base::UTF16ToUTF8(body).c_str(), + nullptr); + + g_signal_connect( + notification_, "closed", G_CALLBACK(OnNotificationClosedThunk), this); + + // NB: On Unity, adding a notification action will cause the notification + // to display as a modal dialog box. Testing for distros that have "Unity + // Zen Nature" is difficult, we will test for the presence of the indicate + // dbus service + if (!UnityIsRunning()) { + libnotify_loader_.notify_notification_add_action( + notification_, "default", "View", OnNotificationViewThunk, this, + nullptr); + } + + if (!icon.drawsNothing()) { + GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon); + libnotify_loader_.notify_notification_set_image_from_pixbuf( + notification_, pixbuf); + libnotify_loader_.notify_notification_set_timeout( + notification_, NOTIFY_EXPIRES_DEFAULT); + g_object_unref(pixbuf); + } + + GError* error = nullptr; + libnotify_loader_.notify_notification_show(notification_, &error); + if (error) { + log_and_clear_error(error, "notify_notification_show"); + NotificationFailed(); + return; + } + + delegate()->NotificationDisplayed(); +} + +void LibnotifyNotification::Dismiss() { + GError* error = nullptr; + libnotify_loader_.notify_notification_close(notification_, &error); + if (error) { + log_and_clear_error(error, "notify_notification_close"); + Destroy(); + } +} + +void LibnotifyNotification::OnNotificationClosed( + NotifyNotification* notification) { + delegate()->NotificationClosed(); + Destroy(); +} + +void LibnotifyNotification::OnNotificationView( + NotifyNotification* notification, char* action) { + delegate()->NotificationClick(); + Destroy(); +} + +void LibnotifyNotification::NotificationFailed() { + delegate()->NotificationFailed(); + Destroy(); +} + +} // namespace brightray diff --git a/brightray/browser/linux/libnotify_notification.h b/brightray/browser/linux/libnotify_notification.h new file mode 100644 index 00000000000..be2f4280bc4 --- /dev/null +++ b/brightray/browser/linux/libnotify_notification.h @@ -0,0 +1,46 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef BROWSER_LINUX_LIBNOTIFY_NOTIFICATION_H_ +#define BROWSER_LINUX_LIBNOTIFY_NOTIFICATION_H_ + +#include "browser/linux/libnotify_loader.h" +#include "browser/notification.h" +#include "ui/base/glib/glib_signal.h" + +namespace brightray { + +class LibnotifyNotification : public Notification { + public: + LibnotifyNotification(NotificationDelegate* delegate, + NotificationPresenter* presenter); + virtual ~LibnotifyNotification(); + + static bool Initialize(); + + // Notification: + void Show(const base::string16& title, + const base::string16& msg, + const GURL& icon_url, + const SkBitmap& icon) override; + void Dismiss() override; + + private: + CHROMEG_CALLBACK_0(LibnotifyNotification, void, OnNotificationClosed, + NotifyNotification*); + CHROMEG_CALLBACK_1(LibnotifyNotification, void, OnNotificationView, + NotifyNotification*, char*); + + void NotificationFailed(); + + static LibNotifyLoader libnotify_loader_; + + NotifyNotification* notification_; + + DISALLOW_COPY_AND_ASSIGN(LibnotifyNotification); +}; + +} // namespace brightray + +#endif // BROWSER_LINUX_LIBNOTIFY_NOTIFICATION_H_ diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 253ec26fe0c..c846fca6659 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -5,175 +5,21 @@ #include "browser/linux/notification_presenter_linux.h" -#include "base/bind.h" -#include "base/logging.h" -#include "base/files/file_enumerator.h" -#include "base/strings/string_util.h" -#include "base/strings/utf_string_conversions.h" -#include "common/application_info.h" -#include "content/public/browser/desktop_notification_delegate.h" -#include "content/public/common/platform_notification_data.h" -#include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" -#include "third_party/skia/include/core/SkBitmap.h" +#include "browser/linux/libnotify_notification.h" namespace brightray { -namespace { - -bool unity_has_result = false; -bool unity_result = false; - -bool UnityIsRunning() { - if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER")) - return true; - - if (unity_has_result) - return unity_result; - - unity_has_result = true; - - // Look for the presence of libunity as our hint that we're under Ubuntu. - base::FileEnumerator enumerator(base::FilePath("/usr/lib"), - false, base::FileEnumerator::FILES); - base::FilePath haystack; - while (!((haystack = enumerator.Next()).empty())) { - if (base::StartsWith(haystack.value(), "/usr/lib/libunity-", base::CompareCase::SENSITIVE)) { - unity_result = true; - break; - } - } - - return unity_result; -} - -void log_and_clear_error(GError* error, const char* context) { - LOG(ERROR) << context - << ": domain=" << error->domain - << " code=" << error->code - << " message=\"" << error->message << '"'; - g_error_free(error); -} - -content::DesktopNotificationDelegate* GetDelegateFromNotification( - NotifyNotification* notification) { - return static_cast( - g_object_get_data(G_OBJECT(notification), "delegate")); -} - -} // namespace - // static NotificationPresenter* NotificationPresenter::Create() { - scoped_ptr presenter( - new NotificationPresenterLinux); - if (presenter->Init()) - return presenter.release(); - else + if (!LibnotifyNotification::Initialize()) return nullptr; + return new NotificationPresenterLinux; } -NotificationPresenterLinux::NotificationPresenterLinux() - : notifications_(nullptr) { +NotificationPresenterLinux::NotificationPresenterLinux() { } NotificationPresenterLinux::~NotificationPresenterLinux() { - // unref any outstanding notifications, and then free the list. - if (notifications_) - g_list_free_full(notifications_, g_object_unref); -} - -bool NotificationPresenterLinux::Init() { - if (!libnotify_loader_.Load("libnotify.so.4") && - !libnotify_loader_.Load("libnotify.so.1") && - !libnotify_loader_.Load("libnotify.so")) { - return false; - } - if (!libnotify_loader_.notify_is_initted() && - !libnotify_loader_.notify_init(GetApplicationName().c_str())) { - return false; - } - return true; -} - -void NotificationPresenterLinux::ShowNotification( - const content::PlatformNotificationData& data, - const SkBitmap& icon, - scoped_ptr delegate_ptr, - base::Closure* cancel_callback) { - std::string title = base::UTF16ToUTF8(data.title); - std::string body = base::UTF16ToUTF8(data.body); - NotifyNotification* notification = libnotify_loader_.notify_notification_new( - title.c_str(), body.c_str(), nullptr); - - content::DesktopNotificationDelegate* delegate = delegate_ptr.release(); - - g_object_set_data_full(G_OBJECT(notification), "delegate", delegate, operator delete); - g_signal_connect(notification, "closed", G_CALLBACK(OnNotificationClosedThunk), this); - - // NB: On Unity, adding a notification action will cause the notification - // to display as a modal dialog box. Testing for distros that have "Unity - // Zen Nature" is difficult, we will test for the presence of the indicate - // dbus service - if (!UnityIsRunning()) { - libnotify_loader_.notify_notification_add_action( - notification, "default", "View", OnNotificationViewThunk, this, nullptr); - } - - if (!icon.drawsNothing()) { - GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon); - libnotify_loader_.notify_notification_set_image_from_pixbuf( - notification, pixbuf); - libnotify_loader_.notify_notification_set_timeout( - notification, NOTIFY_EXPIRES_DEFAULT); - g_object_unref(pixbuf); - } - - GError* error = nullptr; - libnotify_loader_.notify_notification_show(notification, &error); - if (error) { - log_and_clear_error(error, "notify_notification_show"); - g_object_unref(notification); - return; - } - - notifications_ = g_list_append(notifications_, notification); - delegate->NotificationDisplayed(); - - if (cancel_callback) - *cancel_callback = base::Bind( - &NotificationPresenterLinux::CancelNotification, - base::Unretained(this), - notification); -} - -void NotificationPresenterLinux::CancelNotification(NotifyNotification* notification) { - GError* error = nullptr; - libnotify_loader_.notify_notification_close(notification, &error); - if (error) - log_and_clear_error(error, "notify_notification_close"); - - GetDelegateFromNotification(notification)->NotificationClosed(); - DeleteNotification(notification); -} - -void NotificationPresenterLinux::DeleteNotification(NotifyNotification* notification) { - notifications_ = g_list_remove(notifications_, notification); - g_object_unref(notification); -} - -void NotificationPresenterLinux::OnNotificationClosed(NotifyNotification* notification) { - if (!notification) - return; - GetDelegateFromNotification(notification)->NotificationClosed(); - DeleteNotification(notification); -} - -void NotificationPresenterLinux::OnNotificationView( - NotifyNotification* notification, char* action) { - if (!notification) - return; - GetDelegateFromNotification(notification)->NotificationClick(); - DeleteNotification(notification); } } // namespace brightray diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index d70d1c468a0..ef436799484 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -6,12 +6,7 @@ #ifndef BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_LINUX_H_ #define BRIGHTRAY_BROWSER_NOTIFICATION_PRESENTER_LINUX_H_ -#include - -#include "base/compiler_specific.h" -#include "browser/linux/libnotify_loader.h" #include "browser/notification_presenter.h" -#include "ui/base/glib/glib_signal.h" namespace brightray { @@ -20,34 +15,8 @@ class NotificationPresenterLinux : public NotificationPresenter { NotificationPresenterLinux(); ~NotificationPresenterLinux(); - bool Init(); - void RemoveNotification(NotifyNotification *notification); - private: - // NotificationPresenter: - void ShowNotification( - const content::PlatformNotificationData&, - const SkBitmap& icon, - scoped_ptr delegate, - base::Closure* cancel_callback) override; - - void CancelNotification(NotifyNotification* notification); - void DeleteNotification(NotifyNotification* notification); - - CHROMEG_CALLBACK_0(NotificationPresenterLinux, void, OnNotificationClosed, NotifyNotification*); - CHROMEG_CALLBACK_1(NotificationPresenterLinux, void, OnNotificationView, NotifyNotification*, - char*); - - LibNotifyLoader libnotify_loader_; - - // A list of all open NotifyNotification objects. - // We do lookups here both by NotifyNotification object (when the user - // clicks a notification) and by the ID - // tuple (when the browser asks to dismiss a notification). So it's not - // a map. - // Entries in this list count as refs, so removal from this list should - // always go with g_object_unref(). - GList* notifications_; + DISALLOW_COPY_AND_ASSIGN(NotificationPresenterLinux); }; } // namespace brightray diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index 9f967a5e5f9..b1709568210 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -32,7 +32,6 @@ class CocoaNotification : public Notification { NSUserNotification* notification() const { return notification_; } private: - NotificationDelegate* delegate_; base::scoped_nsobject notification_; DISALLOW_COPY_AND_ASSIGN(CocoaNotification); diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 4dc441d4b9e..26c02679c05 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -73,6 +73,8 @@ 'browser/platform_notification_service.h', 'browser/linux/libnotify_loader.h', 'browser/linux/libnotify_loader.cc', + 'browser/linux/libnotify_notification.h', + 'browser/linux/libnotify_notification.cc', 'browser/linux/notification_presenter_linux.h', 'browser/linux/notification_presenter_linux.cc', 'browser/win/notification_presenter_win.h', From cd95e7b9ceff71d0c0a3d466925246ad12d457be Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 29 Dec 2015 15:45:02 +0800 Subject: [PATCH 0747/1195] Update libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index d0192f9809a..ae1b1395d80 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit d0192f9809a2eec42f66f51b0f85e38e08a2dc8e +Subproject commit ae1b1395d809df1c5bf3ff74257dcfecf69a91bd From 8f26c0d849a82c68e44e5a228b972bb6bee2f8bc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 30 Dec 2015 11:39:43 +0800 Subject: [PATCH 0748/1195] Update libchromiumcontent with widevine support --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index ae1b1395d80..389d11b3bba 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit ae1b1395d809df1c5bf3ff74257dcfecf69a91bd +Subproject commit 389d11b3bba3bdd536075c4743dec9ff4e0965ff From 5990acf51bac0d0a90193a4340fe4bd9485b999a Mon Sep 17 00:00:00 2001 From: Robo Date: Wed, 30 Dec 2015 10:49:45 +0530 Subject: [PATCH 0749/1195] initialize resource bundle with application locale awareness --- brightray/common/main_delegate.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index cf0a16fb273..218422f4110 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -48,7 +48,9 @@ void MainDelegate::InitializeResourceBundle() { path = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); #endif - ui::ResourceBundle::InitSharedInstanceWithPakPath(path); + ui::ResourceBundle::InitSharedInstanceWithLocale("", NULL, + ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); + ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(path, ui::SCALE_FACTOR_100P); AddDataPackFromPath(&ui::ResourceBundle::GetSharedInstance(), path.DirName()); } From cf93f6fd58185afb41e894285b3864d113c55d51 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 30 Dec 2015 16:14:14 +0800 Subject: [PATCH 0750/1195] componenet_updater is not needed --- brightray/brightray.gyp | 3 --- 1 file changed, 3 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b8f99ba8798..a332a5a379b 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -95,7 +95,6 @@ '<(libchromiumcontent_dir)/libwebrtc_common.a', '<(libchromiumcontent_dir)/libyuv.a', '<(libchromiumcontent_dir)/libcdm_renderer.a', - '<(libchromiumcontent_dir)/libcomponent_updater.a', ], }, }, { @@ -151,7 +150,6 @@ '<(libchromiumcontent_dir)/libwebrtc_common.a', '<(libchromiumcontent_dir)/libyuv.a', '<(libchromiumcontent_dir)/libcdm_renderer.a', - '<(libchromiumcontent_dir)/libcomponent_updater.a', ], }, }, { @@ -210,7 +208,6 @@ '<(libchromiumcontent_dir)/webrtc_common.lib', '<(libchromiumcontent_dir)/libyuv.lib', '<(libchromiumcontent_dir)/cdm_renderer.lib', - '<(libchromiumcontent_dir)/component_updater.lib', ], }, }, { From ae1482947256bfa013ce008aa733bf5771c58021 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 5 Jan 2016 10:20:02 +0800 Subject: [PATCH 0751/1195] Load content_shell.pak for current scale factor --- brightray/common/main_delegate.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 218422f4110..d97d5b63b5a 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -48,9 +48,10 @@ void MainDelegate::InitializeResourceBundle() { path = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); #endif - ui::ResourceBundle::InitSharedInstanceWithLocale("", NULL, + ui::ResourceBundle::InitSharedInstanceWithLocale("", nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); - ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(path, ui::SCALE_FACTOR_100P); + ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( + path, ui::GetSupportedScaleFactors()[0]); AddDataPackFromPath(&ui::ResourceBundle::GetSharedInstance(), path.DirName()); } From 2374149b186b423309ad19c74f5222247896ab53 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 8 Jan 2016 11:29:00 +0800 Subject: [PATCH 0752/1195] Load cocoa locale before initializing resources --- brightray/common/main_delegate.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index d97d5b63b5a..000e3a530e5 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -10,6 +10,7 @@ #include "base/command_line.h" #include "base/path_service.h" #include "content/public/common/content_switches.h" +#include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" namespace brightray { @@ -35,6 +36,9 @@ bool MainDelegate::BasicStartupComplete(int* exit_code) { } void MainDelegate::PreSandboxStartup() { +#if defined(OS_MACOSX) + l10n_util::OverrideLocaleWithCocoaLocale(); +#endif InitializeResourceBundle(); } From d6051e95802af35d4ea68121b7624733756e702b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 8 Jan 2016 12:04:23 +0800 Subject: [PATCH 0753/1195] Initialize resource bundle on browser process separately --- brightray/brightray.gypi | 2 + brightray/browser/browser_main_parts.cc | 7 +- brightray/common/main_delegate.cc | 90 +++++++++++++++++++------ brightray/common/main_delegate.h | 11 +-- brightray/common/main_delegate_mac.mm | 2 +- 5 files changed, 81 insertions(+), 31 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index f9ea898085e..4513fa95db6 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -131,6 +131,8 @@ 'SK_SUPPORT_LEGACY_SETCONFIG', 'SK_IGNORE_ETC1_SUPPORT', 'SK_IGNORE_GPU_DITHER', + # NACL is not enabled: + 'DISABLE_NACL', ], 'conditions': [ ['OS!="mac"', { diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index b0a7e72b5f2..279eff9b818 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -7,6 +7,7 @@ #include "browser/browser_context.h" #include "browser/devtools_manager_delegate.h" #include "browser/web_ui_controller_factory.h" +#include "common/main_delegate.h" #include "base/command_line.h" #include "base/strings/string_number_conversions.h" @@ -14,6 +15,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" #include "net/proxy/proxy_resolver_v8.h" +#include "ui/base/l10n/l10n_util.h" #if defined(USE_AURA) #include "ui/gfx/screen.h" @@ -39,7 +41,6 @@ #if defined(OS_WIN) #include "ui/base/cursor/cursor_loader_win.h" -#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util_win.h" #include "ui/gfx/platform_font_win.h" #endif @@ -169,6 +170,10 @@ void BrowserMainParts::ToolkitInitialized() { } void BrowserMainParts::PreMainMessageLoopStart() { +#if defined(OS_MACOSX) + l10n_util::OverrideLocaleWithCocoaLocale(); +#endif + InitializeResourceBundle(""); #if defined(OS_MACOSX) InitializeMainNib(); #endif diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 000e3a530e5..74ec88791b9 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -10,11 +10,70 @@ #include "base/command_line.h" #include "base/path_service.h" #include "content/public/common/content_switches.h" -#include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" +#include "ui/base/ui_base_switches.h" namespace brightray { +namespace { + +// Returns true if this subprocess type needs the ResourceBundle initialized +// and resources loaded. +bool SubprocessNeedsResourceBundle(const std::string& process_type) { + return +#if defined(OS_WIN) || defined(OS_MACOSX) + // Windows needs resources for the default/null plugin. + // Mac needs them for the plugin process name. + process_type == switches::kPluginProcess || +#endif +#if defined(OS_POSIX) && !defined(OS_MACOSX) + // The zygote process opens the resources for the renderers. + process_type == switches::kZygoteProcess || +#endif +#if defined(OS_MACOSX) + // Mac needs them too for scrollbar related images and for sandbox + // profiles. +#if !defined(DISABLE_NACL) + process_type == switches::kNaClLoaderProcess || +#endif + process_type == switches::kPpapiPluginProcess || + process_type == switches::kPpapiBrokerProcess || + process_type == switches::kGpuProcess || +#endif + process_type == switches::kRendererProcess || + process_type == switches::kUtilityProcess; +} + +} // namespace + +void InitializeResourceBundle(const std::string& locale) { + // Load locales. + ui::ResourceBundle::InitSharedInstanceWithLocale( + locale, nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); + + // Load other resource files. + base::FilePath path; +#if defined(OS_MACOSX) + path = GetResourcesPakFilePath(); +#else + base::FilePath pak_dir; + PathService::Get(base::DIR_MODULE, &pak_dir); + path = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); +#endif + + ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); + bundle.AddDataPackFromPath(path, ui::GetSupportedScaleFactors()[0]); +#if defined(OS_WIN) + bundle.AddDataPackFromPath( + pak_dir.Append(FILE_PATH_LITERAL("ui_resources_200_percent.pak")), + ui::SCALE_FACTOR_200P); + bundle.AddDataPackFromPath( + pak_dir.Append(FILE_PATH_LITERAL("content_resources_200_percent.pak")), + ui::SCALE_FACTOR_200P); +#endif +} + + MainDelegate::MainDelegate() { } @@ -36,27 +95,16 @@ bool MainDelegate::BasicStartupComplete(int* exit_code) { } void MainDelegate::PreSandboxStartup() { -#if defined(OS_MACOSX) - l10n_util::OverrideLocaleWithCocoaLocale(); -#endif - InitializeResourceBundle(); -} + auto cmd = *base::CommandLine::ForCurrentProcess(); + std::string process_type = cmd.GetSwitchValueASCII(switches::kProcessType); -void MainDelegate::InitializeResourceBundle() { - base::FilePath path; -#if defined(OS_MACOSX) - path = GetResourcesPakFilePath(); -#else - base::FilePath pak_dir; - PathService::Get(base::DIR_MODULE, &pak_dir); - path = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); -#endif - - ui::ResourceBundle::InitSharedInstanceWithLocale("", nullptr, - ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); - ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( - path, ui::GetSupportedScaleFactors()[0]); - AddDataPackFromPath(&ui::ResourceBundle::GetSharedInstance(), path.DirName()); + // Initialize ResourceBundle which handles files loaded from external + // sources. The language should have been passed in to us from the + // browser process as a command line flag. + if (SubprocessNeedsResourceBundle(process_type)) { + std::string locale = cmd.GetSwitchValueASCII(switches::kLang); + InitializeResourceBundle(locale); + } } content::ContentBrowserClient* MainDelegate::CreateContentBrowserClient() { diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 58349944746..2082a522882 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -22,6 +22,9 @@ namespace brightray { class BrowserClient; class ContentClient; +void InitializeResourceBundle(const std::string& locale); +base::FilePath GetResourcesPakFilePath(); + class MainDelegate : public content::ContentMainDelegate { public: MainDelegate(); @@ -36,15 +39,9 @@ class MainDelegate : public content::ContentMainDelegate { // implementation. virtual scoped_ptr CreateBrowserClient(); - // Subclasses can override this to provide additional .pak files to be - // included in the ui::ResourceBundle. - virtual void AddDataPackFromPath( - ui::ResourceBundle* bundle, const base::FilePath& pak_dir) {} - #if defined(OS_MACOSX) // Subclasses can override this to custom the paths of child process and // framework bundle. - virtual base::FilePath GetResourcesPakFilePath(); virtual void OverrideChildProcessPath(); virtual void OverrideFrameworkBundlePath(); #endif @@ -55,8 +52,6 @@ class MainDelegate : public content::ContentMainDelegate { private: content::ContentBrowserClient* CreateContentBrowserClient() override; - void InitializeResourceBundle(); - scoped_ptr content_client_; scoped_ptr browser_client_; diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index 42f6e818e17..464cf68b50f 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -27,7 +27,7 @@ base::FilePath GetFrameworksPath() { } -base::FilePath MainDelegate::GetResourcesPakFilePath() { +base::FilePath GetResourcesPakFilePath() { auto path = [base::mac::FrameworkBundle() pathForResource:@"content_shell" ofType:@"pak"]; return base::mac::NSStringToFilePath(path); } From f5bb23124aeeaa17faab8248ca6467bb614d8449 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 11 Jan 2016 10:40:20 +0800 Subject: [PATCH 0754/1195] Change our PATH_START to 11000 --- brightray/browser/brightray_paths.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/brightray_paths.h b/brightray/browser/brightray_paths.h index 91e95f9791b..14c51ca8f22 100644 --- a/brightray/browser/brightray_paths.h +++ b/brightray/browser/brightray_paths.h @@ -20,7 +20,7 @@ namespace brightray { enum { - PATH_START = 1000, + PATH_START = 11000, DIR_USER_DATA = PATH_START, // Directory where user data can be written. DIR_USER_CACHE, // Directory where user cache can be written. From f6ebf83513b75ad796015c9eae87a53826fe819c Mon Sep 17 00:00:00 2001 From: Eran Tiktin Date: Fri, 15 Jan 2016 22:39:20 +0200 Subject: [PATCH 0755/1195] update libchromiumcontent 47.0.2526.110 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 389d11b3bba..ad63d8ba890 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 389d11b3bba3bdd536075c4743dec9ff4e0965ff +Subproject commit ad63d8ba890bcaad2f1b7e6de148b7992f4d3af7 From 728f0f985b550abb9d8b353b9ac3545c1dc96155 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Wed, 20 Jan 2016 16:36:41 -0800 Subject: [PATCH 0756/1195] :checkered_flag: :apple: Add Silent Notification Support * Implements support for silent notifications on Windows and OS X * Exposes bool `silent` to Linux notification presenters --- .../browser/linux/libnotify_notification.cc | 3 +- .../browser/linux/libnotify_notification.h | 3 +- brightray/browser/mac/cocoa_notification.h | 3 +- brightray/browser/mac/cocoa_notification.mm | 9 ++- brightray/browser/notification.h | 3 +- .../browser/platform_notification_service.cc | 2 +- .../browser/win/windows_toast_notification.cc | 77 ++++++++++++++++++- .../browser/win/windows_toast_notification.h | 5 +- 8 files changed, 95 insertions(+), 10 deletions(-) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index 98aa3ffd8a7..a903007b523 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -89,7 +89,8 @@ LibnotifyNotification::~LibnotifyNotification() { void LibnotifyNotification::Show(const base::string16& title, const base::string16& body, const GURL& icon_url, - const SkBitmap& icon) { + const SkBitmap& icon, + const bool silent) { notification_ = libnotify_loader_.notify_notification_new( base::UTF16ToUTF8(title).c_str(), base::UTF16ToUTF8(body).c_str(), diff --git a/brightray/browser/linux/libnotify_notification.h b/brightray/browser/linux/libnotify_notification.h index be2f4280bc4..17fb427bcf4 100644 --- a/brightray/browser/linux/libnotify_notification.h +++ b/brightray/browser/linux/libnotify_notification.h @@ -23,7 +23,8 @@ class LibnotifyNotification : public Notification { void Show(const base::string16& title, const base::string16& msg, const GURL& icon_url, - const SkBitmap& icon) override; + const SkBitmap& icon, + const bool silent) override; void Dismiss() override; private: diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index b1709568210..8cefb3a59b7 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -23,7 +23,8 @@ class CocoaNotification : public Notification { void Show(const base::string16& title, const base::string16& msg, const GURL& icon_url, - const SkBitmap& icon) override; + const SkBitmap& icon, + const bool silent) override; void Dismiss() override; void NotifyDisplayed(); diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index 24174e226a9..68f22d33637 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -31,7 +31,8 @@ CocoaNotification::~CocoaNotification() { void CocoaNotification::Show(const base::string16& title, const base::string16& body, const GURL& icon_url, - const SkBitmap& icon) { + const SkBitmap& icon, + const bool silent) { notification_.reset([[NSUserNotification alloc] init]); [notification_ setTitle:base::SysUTF16ToNSString(title)]; [notification_ setInformativeText:base::SysUTF16ToNSString(body)]; @@ -42,6 +43,12 @@ void CocoaNotification::Show(const base::string16& title, icon, base::mac::GetGenericRGBColorSpace()); [notification_ setContentImage:image]; } + + if (silent) { + [notification_ setSoundName:nil]; + } else { + [notification_ setSoundName:NSUserNotificationDefaultSoundName]; + } [NSUserNotificationCenter.defaultUserNotificationCenter deliverNotification:notification_]; diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index 9d0deccbf45..5f1396c8e3e 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -22,7 +22,8 @@ class Notification { virtual void Show(const base::string16& title, const base::string16& msg, const GURL& icon_url, - const SkBitmap& icon) = 0; + const SkBitmap& icon, + const bool silent) = 0; // Closes the notification, this instance will be destroyed after the // notification gets closed. virtual void Dismiss() = 0; diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 7d91ce5f2e4..e4658f35ffb 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -57,7 +57,7 @@ void PlatformNotificationService::DisplayNotification( auto notification = presenter->CreateNotification(adapter.get()); if (notification) { ignore_result(adapter.release()); // it will release itself automatically. - notification->Show(data.title, data.body, data.icon, icon); + notification->Show(data.title, data.body, data.icon, icon, data.silent); *cancel_callback = base::Bind(&RemoveNotification, notification); } } diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index d08b888e4a8..c1be87223cd 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -85,12 +85,13 @@ void WindowsToastNotification::Show( const base::string16& title, const base::string16& msg, const GURL& icon_url, - const SkBitmap& icon) { + const SkBitmap& icon, + const bool silent) { auto presenter_win = static_cast(presenter()); std::wstring icon_path = presenter_win->SaveIconToFilesystem(icon, icon_url); ComPtr toast_xml; - if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, &toast_xml))) { + if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, silent, &toast_xml))) { NotificationFailed(); return; } @@ -152,6 +153,7 @@ bool WindowsToastNotification::GetToastXml( const std::wstring& title, const std::wstring& msg, const std::wstring& icon_path, + const bool silent, IXmlDocument** toast_xml) { ABI::Windows::UI::Notifications::ToastTemplateType template_type; if (title.empty() || msg.empty()) { @@ -171,14 +173,83 @@ bool WindowsToastNotification::GetToastXml( if (!SetXmlText(*toast_xml, title, msg)) return false; } + + // Configure the toast's notification sound + if (silent) { + if (FAILED(SetXmlAudioSilent(*toast_xml))) + return false; + } - // Toast has image + // Configure the toast's image if (!icon_path.empty()) return SetXmlImage(*toast_xml, icon_path); return true; } +bool WindowsToastNotification::SetXmlAudioSilent( + IXmlDocument* doc) { + ScopedHString tag(L"toast"); + if (!tag.success()) + return false; + + ComPtr node_list; + if (FAILED(doc->GetElementsByTagName(tag, &node_list))) + return false; + + ComPtr root; + if (FAILED(node_list->Item(0, &root))) + return false; + + ComPtr audio_element; + ScopedHString audio_str(L"audio"); + if (FAILED(doc->CreateElement(audio_str, &audio_element))) + return false; + + ComPtr audio_node_tmp; + if (FAILED(audio_element.As(&audio_node_tmp))) + return false; + + // Append audio node to toast xml + ComPtr audio_node; + if (FAILED(root->AppendChild(audio_node_tmp.Get(), &audio_node))) + return false; + + // Create silent attribute + ComPtr attributes; + if (FAILED(audio_node->get_Attributes(&attributes))) + return false; + + ComPtr silent_attribute; + ScopedHString silent_str(L"silent"); + if (FAILED(doc->CreateAttribute(silent_str, &silent_attribute))) + return false; + + ComPtr silent_attribute_node; + if (FAILED(silent_attribute.As(&silent_attribute_node))) + return false; + + // Set silent attribute to true + ScopedHString silent_value(L"true"); + if (!silent_value.success()) + return false; + + ComPtr silent_text; + if (FAILED(doc->CreateTextNode(silent_value, &silent_text))) + return false; + + ComPtr silent_node; + if (FAILED(silent_text.As(&silent_node))) + return false; + + ComPtr child_node; + if (FAILED(silent_attribute_node->AppendChild(silent_node.Get(), &child_node))) + return false; + + ComPtr silent_attribute_pnode; + return SUCCEEDED(attributes.Get()->SetNamedItem(silent_attribute_node.Get(), &silent_attribute_pnode)); +} + bool WindowsToastNotification::SetXmlText( IXmlDocument* doc, const std::wstring& text) { ScopedHString tag; diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index 02e05666992..cb69d3da2a1 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -42,7 +42,8 @@ class WindowsToastNotification : public Notification { void Show(const base::string16& title, const base::string16& msg, const GURL& icon_url, - const SkBitmap& icon) override; + const SkBitmap& icon, + const bool silent) override; void Dismiss() override; private: @@ -56,7 +57,9 @@ class WindowsToastNotification : public Notification { const std::wstring& title, const std::wstring& msg, const std::wstring& icon_path, + const bool silent, ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); + bool SetXmlAudioSilent(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc); bool SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const std::wstring& text); bool SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, From 3b09c370d4ca5af9a05c92f753519c0f2a43eeab Mon Sep 17 00:00:00 2001 From: Robo Date: Sat, 23 Jan 2016 19:02:30 +0530 Subject: [PATCH 0757/1195] allow client to decide displaying web notifications --- brightray/browser/browser_client.h | 6 +++ .../browser/platform_notification_service.cc | 44 ++++++++++++++----- .../browser/platform_notification_service.h | 1 + 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index bb6575c9b2b..9b7cff7fe4c 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -28,6 +28,12 @@ class BrowserClient : public content::ContentBrowserClient { NotificationPresenter* GetNotificationPresenter(); + // Subclasses should override this to enable or disable WebNotification. + virtual void WebNotificationAllowed(int render_process_id, + const base::Callback& callback) { + callback.Run(true); + } + protected: // Subclasses should override this to provide their own BrowserMainParts // implementation. The lifetime of the returned instance is managed by the diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index e4658f35ffb..53b94242c80 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -9,6 +9,7 @@ #include "browser/notification_delegate_adapter.h" #include "browser/notification_presenter.h" #include "content/public/common/platform_notification_data.h" +#include "third_party/skia/include/core/SkBitmap.h" namespace brightray { @@ -19,11 +20,34 @@ void RemoveNotification(base::WeakPtr notification) { notification->Dismiss(); } +void OnWebNotificationAllowed( + brightray::BrowserClient* browser_client, + const SkBitmap& icon, + const content::PlatformNotificationData& data, + scoped_ptr delegate, + base::Closure* cancel_callback, + bool allowed) { + if (!allowed) + return; + auto presenter = browser_client->GetNotificationPresenter(); + if (!presenter) + return; + scoped_ptr adapter( + new NotificationDelegateAdapter(delegate.Pass())); + auto notification = presenter->CreateNotification(adapter.get()); + if (notification) { + ignore_result(adapter.release()); // it will release itself automatically. + notification->Show(data.title, data.body, data.icon, icon, data.silent); + *cancel_callback = base::Bind(&RemoveNotification, notification); + } +} + } // namespace PlatformNotificationService::PlatformNotificationService( BrowserClient* browser_client) - : browser_client_(browser_client) { + : browser_client_(browser_client), + render_process_id_(0) { } PlatformNotificationService::~PlatformNotificationService() {} @@ -32,6 +56,7 @@ blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnU content::BrowserContext* browser_context, const GURL& origin, int render_process_id) { + render_process_id_ = render_process_id; return blink::WebNotificationPermissionAllowed; } @@ -49,17 +74,12 @@ void PlatformNotificationService::DisplayNotification( const content::PlatformNotificationData& data, scoped_ptr delegate, base::Closure* cancel_callback) { - auto presenter = browser_client_->GetNotificationPresenter(); - if (!presenter) - return; - scoped_ptr adapter( - new NotificationDelegateAdapter(delegate.Pass())); - auto notification = presenter->CreateNotification(adapter.get()); - if (notification) { - ignore_result(adapter.release()); // it will release itself automatically. - notification->Show(data.title, data.body, data.icon, icon, data.silent); - *cancel_callback = base::Bind(&RemoveNotification, notification); - } + browser_client_->WebNotificationAllowed( + render_process_id_, + base::Bind(&OnWebNotificationAllowed, + browser_client_, icon, data, + base::Passed(&delegate), + cancel_callback)); } void PlatformNotificationService::DisplayPersistentNotification( diff --git a/brightray/browser/platform_notification_service.h b/brightray/browser/platform_notification_service.h index 0c598965df4..c84a02aa02e 100644 --- a/brightray/browser/platform_notification_service.h +++ b/brightray/browser/platform_notification_service.h @@ -48,6 +48,7 @@ class PlatformNotificationService std::set* displayed_notifications) override; private: + int render_process_id_; BrowserClient* browser_client_; DISALLOW_COPY_AND_ASSIGN(PlatformNotificationService); From 7cfc9fad839a19f64500427adcc45f55e5f6e242 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 27 Jan 2016 23:18:42 +0800 Subject: [PATCH 0758/1195] Fix compilation error --- brightray/browser/platform_notification_service.cc | 2 +- brightray/browser/platform_notification_service.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 53b94242c80..5ce66762508 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -47,7 +47,7 @@ void OnWebNotificationAllowed( PlatformNotificationService::PlatformNotificationService( BrowserClient* browser_client) : browser_client_(browser_client), - render_process_id_(0) { + render_process_id_(-1) { } PlatformNotificationService::~PlatformNotificationService() {} diff --git a/brightray/browser/platform_notification_service.h b/brightray/browser/platform_notification_service.h index c84a02aa02e..ebbb6bae1de 100644 --- a/brightray/browser/platform_notification_service.h +++ b/brightray/browser/platform_notification_service.h @@ -48,8 +48,8 @@ class PlatformNotificationService std::set* displayed_notifications) override; private: - int render_process_id_; BrowserClient* browser_client_; + int render_process_id_; DISALLOW_COPY_AND_ASSIGN(PlatformNotificationService); }; From c61e6f3f170197851ba07f595b54ef60127e9275 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 1 Feb 2016 21:08:52 +0800 Subject: [PATCH 0759/1195] Remove DefaultWebContentsDelegate --- .../browser/default_web_contents_delegate.cc | 28 ----------------- .../browser/default_web_contents_delegate.h | 31 ------------------- .../default_web_contents_delegate_mac.mm | 15 --------- brightray/filenames.gypi | 3 -- 4 files changed, 77 deletions(-) delete mode 100644 brightray/browser/default_web_contents_delegate.cc delete mode 100644 brightray/browser/default_web_contents_delegate.h delete mode 100644 brightray/browser/default_web_contents_delegate_mac.mm diff --git a/brightray/browser/default_web_contents_delegate.cc b/brightray/browser/default_web_contents_delegate.cc deleted file mode 100644 index 4c7051ba182..00000000000 --- a/brightray/browser/default_web_contents_delegate.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include "browser/default_web_contents_delegate.h" - -#include "browser/media/media_stream_devices_controller.h" - -namespace brightray { - -DefaultWebContentsDelegate::DefaultWebContentsDelegate() { -} - -DefaultWebContentsDelegate::~DefaultWebContentsDelegate() { -} - -bool DefaultWebContentsDelegate::CheckMediaAccessPermission( - content::WebContents* web_contents, - const GURL& security_origin, - content::MediaStreamType type) { - return true; -} - -void DefaultWebContentsDelegate::RequestMediaAccessPermission( - content::WebContents*, - const content::MediaStreamRequest& request, - const content::MediaResponseCallback& callback) { - MediaStreamDevicesController controller(request, callback); - controller.TakeAction(); -} - -} // namespace brightray diff --git a/brightray/browser/default_web_contents_delegate.h b/brightray/browser/default_web_contents_delegate.h deleted file mode 100644 index 2e1ce681a7c..00000000000 --- a/brightray/browser/default_web_contents_delegate.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef BRIGHTRAY_BROWSER_DEFAULT_WEB_CONTENTS_DELEGATE_H_ -#define BRIGHTRAY_BROWSER_DEFAULT_WEB_CONTENTS_DELEGATE_H_ - -#include "content/public/browser/web_contents_delegate.h" - -namespace brightray { - -// This class provides some sane default behaviors to any content::WebContents -// instance (e.g., keyboard shortcut handling on Mac). -class DefaultWebContentsDelegate : public content::WebContentsDelegate { - public: - DefaultWebContentsDelegate(); - ~DefaultWebContentsDelegate(); - - protected: - bool CheckMediaAccessPermission(content::WebContents* web_contents, - const GURL& security_origin, - content::MediaStreamType type) override; - void RequestMediaAccessPermission( - content::WebContents*, - const content::MediaStreamRequest&, - const content::MediaResponseCallback&) override; -#if defined(OS_MACOSX) - void HandleKeyboardEvent( - content::WebContents*, const content::NativeWebKeyboardEvent&) override; -#endif -}; - -} // namespace brightray - -#endif diff --git a/brightray/browser/default_web_contents_delegate_mac.mm b/brightray/browser/default_web_contents_delegate_mac.mm deleted file mode 100644 index 78760614cbf..00000000000 --- a/brightray/browser/default_web_contents_delegate_mac.mm +++ /dev/null @@ -1,15 +0,0 @@ -#import "browser/default_web_contents_delegate.h" - -#import "content/public/browser/native_web_keyboard_event.h" -#import - -namespace brightray { - -void DefaultWebContentsDelegate::HandleKeyboardEvent(content::WebContents*, const content::NativeWebKeyboardEvent& event) { - if (event.skip_in_browser) - return; - - [[NSApp mainMenu] performKeyEquivalent:event.os_event]; -} - -} \ No newline at end of file diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 26c02679c05..c61af39748b 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -9,9 +9,6 @@ 'browser/browser_main_parts.cc', 'browser/browser_main_parts.h', 'browser/browser_main_parts_mac.mm', - 'browser/default_web_contents_delegate.cc', - 'browser/default_web_contents_delegate.h', - 'browser/default_web_contents_delegate_mac.mm', 'browser/devtools_contents_resizing_strategy.cc', 'browser/devtools_contents_resizing_strategy.h', 'browser/devtools_embedder_message_dispatcher.cc', From 93c7126bc72683e9a6b8b1e68fd8671756361c87 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 17 Feb 2016 22:20:40 +0800 Subject: [PATCH 0760/1195] Link with ffmpeg --- brightray/brightray.gyp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index a332a5a379b..d7120ea98f8 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -100,6 +100,8 @@ }, { 'link_settings': { 'libraries': [ + # Link with ffmpeg. + '<(libchromiumcontent_dir)/libffmpeg.so', # Following libraries are required by libchromiumcontent: '-lasound', '-lcap', @@ -155,6 +157,8 @@ }, { 'link_settings': { 'libraries': [ + # Link with ffmpeg. + '<(libchromiumcontent_dir)/libffmpeg.dylib', # Link with system frameworks. # ui_base.gypi: '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', @@ -214,6 +218,8 @@ # Link with system libraries. 'link_settings': { 'libraries': [ + # Link with ffmpeg. + '<(libchromiumcontent_dir)/ffmpeg.dll', # content_browser.gypi: '-lsensorsapi.lib', '-lportabledeviceguids.lib', From 9fd88e9bb7efa2bed6fe65cdc5b34673b5aca5be Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Mar 2016 10:04:06 +0900 Subject: [PATCH 0761/1195] Update to Chrome 49 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index ad63d8ba890..881cf10e525 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit ad63d8ba890bcaad2f1b7e6de148b7992f4d3af7 +Subproject commit 881cf10e5255c3037d5624616fd7544c1e7252ae From c72c89bd75dbaf3d22d9242b04b0c23482836130 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Mar 2016 10:14:16 +0900 Subject: [PATCH 0762/1195] No more basictypes.h --- brightray/browser/devtools_contents_resizing_strategy.h | 2 +- brightray/browser/devtools_manager_delegate.h | 2 +- brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- brightray/browser/inspectable_web_contents_impl.h | 4 ++-- brightray/browser/web_ui_controller_factory.h | 2 +- brightray/browser/win/scoped_hstring.h | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/brightray/browser/devtools_contents_resizing_strategy.h b/brightray/browser/devtools_contents_resizing_strategy.h index 9c82c060b1e..c48272f7977 100644 --- a/brightray/browser/devtools_contents_resizing_strategy.h +++ b/brightray/browser/devtools_contents_resizing_strategy.h @@ -5,7 +5,7 @@ #ifndef BRIGHTRAY_BROWSER_DEVTOOLS_CONTENTS_RESIZING_STRATEGY_H_ #define BRIGHTRAY_BROWSER_DEVTOOLS_CONTENTS_RESIZING_STRATEGY_H_ -#include "base/basictypes.h" +#include "base/macros.h" #include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h index ed8e357482b..12eedc66082 100644 --- a/brightray/browser/devtools_manager_delegate.h +++ b/brightray/browser/devtools_manager_delegate.h @@ -5,7 +5,7 @@ #ifndef BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_ #define BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_ -#include "base/basictypes.h" +#include "base/macros.h" #include "base/compiler_specific.h" #include "components/devtools_http_handler/devtools_http_handler_delegate.h" #include "content/public/browser/devtools_manager_delegate.h" diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 1ff21b694a0..b876ef86288 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -592,9 +592,9 @@ void InspectableWebContentsImpl::WebContentsDestroyed() { bool InspectableWebContentsImpl::AddMessageToConsole( content::WebContents* source, - int32 level, + int32_t level, const base::string16& message, - int32 line_no, + int32_t line_no, const base::string16& source_id) { logging::LogMessage("CONSOLE", line_no, level).stream() << "\"" << message << "\", source: " << source_id << " (" << line_no << ")"; diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 9b985bbc6c9..8543f5e99e7 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -134,9 +134,9 @@ class InspectableWebContentsImpl : // content::WebContentsDelegate: bool AddMessageToConsole(content::WebContents* source, - int32 level, + int32_t level, const base::string16& message, - int32 line_no, + int32_t line_no, const base::string16& source_id) override; bool ShouldCreateWebContents( content::WebContents* web_contents, diff --git a/brightray/browser/web_ui_controller_factory.h b/brightray/browser/web_ui_controller_factory.h index 44a77da5f1e..ca86de6baa6 100644 --- a/brightray/browser/web_ui_controller_factory.h +++ b/brightray/browser/web_ui_controller_factory.h @@ -5,7 +5,7 @@ #ifndef BRIGHTRAY_BROWSER_WEB_UI_CONTROLLER_FACTORY_H_ #define BRIGHTRAY_BROWSER_WEB_UI_CONTROLLER_FACTORY_H_ -#include "base/basictypes.h" +#include "base/macros.h" #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_controller_factory.h" diff --git a/brightray/browser/win/scoped_hstring.h b/brightray/browser/win/scoped_hstring.h index 5494df2fc5c..67e4fe67fd0 100644 --- a/brightray/browser/win/scoped_hstring.h +++ b/brightray/browser/win/scoped_hstring.h @@ -10,7 +10,7 @@ #include #include -#include "base/basictypes.h" +#include "base/macros.h" class ScopedHString { public: From da59c0f58b044b0b13aa0a522272489ada2a60fe Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 7 Mar 2016 21:38:56 -0800 Subject: [PATCH 0763/1195] basictypes.h => macros.h --- brightray/browser/devtools_contents_resizing_strategy.h | 2 +- brightray/browser/devtools_manager_delegate.h | 2 +- brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- brightray/browser/inspectable_web_contents_impl.h | 4 ++-- brightray/browser/net/devtools_network_interceptor.cc | 2 +- brightray/browser/web_ui_controller_factory.h | 2 +- brightray/browser/win/scoped_hstring.h | 2 +- brightray/browser/win/windows_toast_notification.cc | 4 ++-- brightray/browser/win/windows_toast_notification.h | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/brightray/browser/devtools_contents_resizing_strategy.h b/brightray/browser/devtools_contents_resizing_strategy.h index 9c82c060b1e..c48272f7977 100644 --- a/brightray/browser/devtools_contents_resizing_strategy.h +++ b/brightray/browser/devtools_contents_resizing_strategy.h @@ -5,7 +5,7 @@ #ifndef BRIGHTRAY_BROWSER_DEVTOOLS_CONTENTS_RESIZING_STRATEGY_H_ #define BRIGHTRAY_BROWSER_DEVTOOLS_CONTENTS_RESIZING_STRATEGY_H_ -#include "base/basictypes.h" +#include "base/macros.h" #include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h index ed8e357482b..12eedc66082 100644 --- a/brightray/browser/devtools_manager_delegate.h +++ b/brightray/browser/devtools_manager_delegate.h @@ -5,7 +5,7 @@ #ifndef BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_ #define BROWSER_DEVTOOLS_MANAGER_DELEGATE_H_ -#include "base/basictypes.h" +#include "base/macros.h" #include "base/compiler_specific.h" #include "components/devtools_http_handler/devtools_http_handler_delegate.h" #include "content/public/browser/devtools_manager_delegate.h" diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 1ff21b694a0..b876ef86288 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -592,9 +592,9 @@ void InspectableWebContentsImpl::WebContentsDestroyed() { bool InspectableWebContentsImpl::AddMessageToConsole( content::WebContents* source, - int32 level, + int32_t level, const base::string16& message, - int32 line_no, + int32_t line_no, const base::string16& source_id) { logging::LogMessage("CONSOLE", line_no, level).stream() << "\"" << message << "\", source: " << source_id << " (" << line_no << ")"; diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 9b985bbc6c9..8543f5e99e7 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -134,9 +134,9 @@ class InspectableWebContentsImpl : // content::WebContentsDelegate: bool AddMessageToConsole(content::WebContents* source, - int32 level, + int32_t level, const base::string16& message, - int32 line_no, + int32_t line_no, const base::string16& source_id) override; bool ShouldCreateWebContents( content::WebContents* web_contents, diff --git a/brightray/browser/net/devtools_network_interceptor.cc b/brightray/browser/net/devtools_network_interceptor.cc index 78afb00a09a..2535ed74bd3 100644 --- a/brightray/browser/net/devtools_network_interceptor.cc +++ b/brightray/browser/net/devtools_network_interceptor.cc @@ -207,7 +207,7 @@ void DevToolsNetworkInterceptor::ArmTimer(base::TimeTicks now) { base::TimeTicks desired_time = offset_ + tick_length_ * (last_tick_ + min_ticks_left); - int64_t min_baseline = std::numeric_limits::max(); + int64_t min_baseline = std::numeric_limits::max(); for (size_t i = 0; i < suspend_count; ++i) { if (suspended_transactions_[i].second < min_baseline) min_baseline = suspended_transactions_[i].second; diff --git a/brightray/browser/web_ui_controller_factory.h b/brightray/browser/web_ui_controller_factory.h index 44a77da5f1e..ca86de6baa6 100644 --- a/brightray/browser/web_ui_controller_factory.h +++ b/brightray/browser/web_ui_controller_factory.h @@ -5,7 +5,7 @@ #ifndef BRIGHTRAY_BROWSER_WEB_UI_CONTROLLER_FACTORY_H_ #define BRIGHTRAY_BROWSER_WEB_UI_CONTROLLER_FACTORY_H_ -#include "base/basictypes.h" +#include "base/macros.h" #include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui_controller_factory.h" diff --git a/brightray/browser/win/scoped_hstring.h b/brightray/browser/win/scoped_hstring.h index 5494df2fc5c..67e4fe67fd0 100644 --- a/brightray/browser/win/scoped_hstring.h +++ b/brightray/browser/win/scoped_hstring.h @@ -10,7 +10,7 @@ #include #include -#include "base/basictypes.h" +#include "base/macros.h" class ScopedHString { public: diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index c1be87223cd..badd4f2254b 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -330,7 +330,7 @@ bool WindowsToastNotification::GetTextNodeList( ScopedHString* tag, IXmlDocument* doc, IXmlNodeList** node_list, - UINT32 req_length) { + Uint32_t req_length) { tag->Reset(L"text"); if (!tag->success()) return false; @@ -338,7 +338,7 @@ bool WindowsToastNotification::GetTextNodeList( if (FAILED(doc->GetElementsByTagName(*tag, node_list))) return false; - UINT32 node_length; + Uint32_t node_length; if (FAILED((*node_list)->get_Length(&node_length))) return false; diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index cb69d3da2a1..6cd7bafe876 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -70,7 +70,7 @@ class WindowsToastNotification : public Notification { bool GetTextNodeList(ScopedHString* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, - UINT32 reqLength); + Uint32_t reqLength); bool AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const std::wstring& text); From e901b1c6caae54144805a1add9453a4636d8283e Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 7 Mar 2016 21:59:14 -0800 Subject: [PATCH 0764/1195] Update NetworkDelegate --- brightray/browser/network_delegate.cc | 13 +++++++------ brightray/browser/network_delegate.h | 9 +++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index 8a1f8ee828c..e03adba65a1 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -92,14 +92,11 @@ void NetworkDelegate::OnBeforeRedirect(net::URLRequest* request, void NetworkDelegate::OnResponseStarted(net::URLRequest* request) { } -void NetworkDelegate::OnURLRequestJobOrphaned(net::URLRequest* request) { -} - -void NetworkDelegate::OnNetworkBytesReceived(const net::URLRequest& request, +void NetworkDelegate::OnNetworkBytesReceived(net::URLRequest* request, int64_t bytes_read) { } -void NetworkDelegate::OnNetworkBytesSent(const net::URLRequest& request, +void NetworkDelegate::OnNetworkBytesSent(net::URLRequest* request, int64_t bytes_sent) { } @@ -143,7 +140,11 @@ bool NetworkDelegate::OnCanEnablePrivacyMode( return false; } -bool NetworkDelegate::OnFirstPartyOnlyCookieExperimentEnabled() const { +bool OnAreStrictSecureCookiesEnabled() { + return true; +} + +bool OnAreExperimentalCookieFeaturesEnabled() { return true; } diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index b10cabadd22..11358754008 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -43,10 +43,9 @@ class NetworkDelegate : public net::NetworkDelegate { void OnBeforeRedirect(net::URLRequest* request, const GURL& new_location) override; void OnResponseStarted(net::URLRequest* request) override; - void OnURLRequestJobOrphaned(net::URLRequest* request) override; - void OnNetworkBytesReceived(const net::URLRequest& request, + void OnNetworkBytesReceived(net::URLRequest* request, int64_t bytes_read) override; - void OnNetworkBytesSent(const net::URLRequest& request, + void OnNetworkBytesSent(net::URLRequest* request, int64_t bytes_sent) override; void OnCompleted(net::URLRequest* request, bool started) override; void OnURLRequestDestroyed(net::URLRequest* request) override; @@ -67,7 +66,9 @@ class NetworkDelegate : public net::NetworkDelegate { bool OnCanEnablePrivacyMode( const GURL& url, const GURL& first_party_for_cookies) const override; - bool OnFirstPartyOnlyCookieExperimentEnabled() const override; + + virtual bool OnAreStrictSecureCookiesEnabled() const override; + virtual bool OnAreExperimentalCookieFeaturesEnabled() const override; bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( const net::URLRequest& request, const GURL& target_url, From 157f3abe64a7845f5ccba34435e77dbd4e7ebc29 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 7 Mar 2016 22:02:42 -0800 Subject: [PATCH 0765/1195] Not quite sure how this ever worked --- .../browser/win/windows_toast_notification.cc | 28 +++++++++---------- .../browser/win/windows_toast_notification.h | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index badd4f2254b..74cd74ecebd 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -173,10 +173,10 @@ bool WindowsToastNotification::GetToastXml( if (!SetXmlText(*toast_xml, title, msg)) return false; } - + // Configure the toast's notification sound if (silent) { - if (FAILED(SetXmlAudioSilent(*toast_xml))) + if (FAILED(SetXmlAudioSilent(*toast_xml))) return false; } @@ -200,40 +200,40 @@ bool WindowsToastNotification::SetXmlAudioSilent( ComPtr root; if (FAILED(node_list->Item(0, &root))) return false; - + ComPtr audio_element; ScopedHString audio_str(L"audio"); if (FAILED(doc->CreateElement(audio_str, &audio_element))) return false; - + ComPtr audio_node_tmp; if (FAILED(audio_element.As(&audio_node_tmp))) return false; - + // Append audio node to toast xml ComPtr audio_node; if (FAILED(root->AppendChild(audio_node_tmp.Get(), &audio_node))) return false; - + // Create silent attribute ComPtr attributes; if (FAILED(audio_node->get_Attributes(&attributes))) return false; - + ComPtr silent_attribute; ScopedHString silent_str(L"silent"); if (FAILED(doc->CreateAttribute(silent_str, &silent_attribute))) return false; - + ComPtr silent_attribute_node; if (FAILED(silent_attribute.As(&silent_attribute_node))) return false; - + // Set silent attribute to true ScopedHString silent_value(L"true"); if (!silent_value.success()) return false; - + ComPtr silent_text; if (FAILED(doc->CreateTextNode(silent_value, &silent_text))) return false; @@ -241,11 +241,11 @@ bool WindowsToastNotification::SetXmlAudioSilent( ComPtr silent_node; if (FAILED(silent_text.As(&silent_node))) return false; - + ComPtr child_node; if (FAILED(silent_attribute_node->AppendChild(silent_node.Get(), &child_node))) return false; - + ComPtr silent_attribute_pnode; return SUCCEEDED(attributes.Get()->SetNamedItem(silent_attribute_node.Get(), &silent_attribute_pnode)); } @@ -330,7 +330,7 @@ bool WindowsToastNotification::GetTextNodeList( ScopedHString* tag, IXmlDocument* doc, IXmlNodeList** node_list, - Uint32_t req_length) { + uint32_t req_length) { tag->Reset(L"text"); if (!tag->success()) return false; @@ -338,7 +338,7 @@ bool WindowsToastNotification::GetTextNodeList( if (FAILED(doc->GetElementsByTagName(*tag, node_list))) return false; - Uint32_t node_length; + uint32_t node_length; if (FAILED((*node_list)->get_Length(&node_length))) return false; diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index 6cd7bafe876..d5e5f2a82cf 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -70,7 +70,7 @@ class WindowsToastNotification : public Notification { bool GetTextNodeList(ScopedHString* tag, ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNodeList** nodeList, - Uint32_t reqLength); + uint32_t reqLength); bool AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const std::wstring& text); From 40c98381abbb6792f9ba0986127b4ece603968e8 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 7 Mar 2016 22:18:16 -0800 Subject: [PATCH 0766/1195] Update headers for InspectableWebContentsImpl --- brightray/browser/inspectable_web_contents_impl.cc | 7 ++++--- brightray/browser/inspectable_web_contents_impl.h | 13 ++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index b876ef86288..76972b654e9 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -573,7 +573,7 @@ void InspectableWebContentsImpl::AgentHostClosed( content::DevToolsAgentHost* agent_host, bool replaced) { } -void InspectableWebContentsImpl::AboutToNavigateRenderFrame( +void InspectableWebContentsImpl::RenderFrameHostChanged( content::RenderFrameHost* old_host, content::RenderFrameHost* new_host) { if (new_host->GetParent()) @@ -603,8 +603,9 @@ bool InspectableWebContentsImpl::AddMessageToConsole( bool InspectableWebContentsImpl::ShouldCreateWebContents( content::WebContents* web_contents, - int route_id, - int main_frame_route_id, + int32_t route_id, + int32_t main_frame_route_id, + int32_t main_frame_widget_route_id, WindowContainerType window_container_type, const std::string& frame_name, const GURL& target_url, diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 8543f5e99e7..7edf9ce96e8 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -33,7 +33,6 @@ class InspectableWebContentsView; class InspectableWebContentsImpl : public InspectableWebContents, - public content::DevToolsFrontendHost::Delegate, public content::DevToolsAgentHostClient, public content::WebContentsObserver, public content::WebContentsDelegate, @@ -117,8 +116,7 @@ class InspectableWebContentsImpl : void ClearPreferences() override; // content::DevToolsFrontendHostDelegate: - void HandleMessageFromDevToolsFrontend(const std::string& message) override; - void HandleMessageFromDevToolsFrontendToBackend(const std::string& message) override; + void HandleMessageFromDevToolsFrontend(const std::string& message); // content::DevToolsAgentHostClient: void DispatchProtocolMessage(content::DevToolsAgentHost* agent_host, @@ -127,8 +125,8 @@ class InspectableWebContentsImpl : bool replaced) override; // content::WebContentsObserver: - void AboutToNavigateRenderFrame(content::RenderFrameHost* old_host, - content::RenderFrameHost* new_host) override; + void RenderFrameHostChanged(content::RenderFrameHost* old_host, + content::RenderFrameHost* new_host) override; void WebContentsDestroyed() override; void OnWebContentsFocused() override; @@ -140,8 +138,9 @@ class InspectableWebContentsImpl : const base::string16& source_id) override; bool ShouldCreateWebContents( content::WebContents* web_contents, - int route_id, - int main_frame_route_id, + int32_t route_id, + int32_t main_frame_route_id, + int32_t main_frame_widget_route_id, WindowContainerType window_container_type, const std::string& frame_name, const GURL& target_url, From d204febecfc1546b49e343eecb2b6161117a6ccf Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 7 Mar 2016 22:29:23 -0800 Subject: [PATCH 0767/1195] Update DevtoolsNetworkTransaction --- brightray/browser/net/devtools_network_transaction.cc | 8 +++++++- brightray/browser/net/devtools_network_transaction.h | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc index fa3343ef987..c65230d6f5a 100644 --- a/brightray/browser/net/devtools_network_transaction.cc +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -106,10 +106,11 @@ int DevToolsNetworkTransaction::RestartIgnoringLastError( int DevToolsNetworkTransaction::RestartWithCertificate( net::X509Certificate* client_certificate, + net::SSLPrivateKey* client_private_key, const net::CompletionCallback& callback) { if (failed_) return net::ERR_INTERNET_DISCONNECTED; - int rv = transaction_->RestartWithCertificate(client_certificate, proxy_callback_); + int rv = transaction_->RestartWithCertificate(client_certificate, client_private_key, proxy_callback_); return SetupCallback(callback, rv, RESTART_WITH_CERTIFICATE); } @@ -185,6 +186,11 @@ bool DevToolsNetworkTransaction::GetRemoteEndpoint( return transaction_->GetRemoteEndpoint(endpoint); } +void DevToolsNetworkTransaction::PopulateNetErrorDetails( + net::NetErrorDetails* details) const { + return transaction_->PopulateNetErrorDetails(details); +} + void DevToolsNetworkTransaction::SetPriority(net::RequestPriority priority) { transaction_->SetPriority(priority); } diff --git a/brightray/browser/net/devtools_network_transaction.h b/brightray/browser/net/devtools_network_transaction.h index 3e16db0f2c2..f8e54e67775 100644 --- a/brightray/browser/net/devtools_network_transaction.h +++ b/brightray/browser/net/devtools_network_transaction.h @@ -46,6 +46,7 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { int RestartIgnoringLastError( const net::CompletionCallback& callback) override; int RestartWithCertificate(net::X509Certificate* client_cert, + net::SSLPrivateKey* client_private_key, const net::CompletionCallback& callback) override; int RestartWithAuth(const net::AuthCredentials& credentials, const net::CompletionCallback& callback) override; @@ -65,6 +66,7 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { void SetQuicServerInfo(net::QuicServerInfo* quic_server_info) override; bool GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override; bool GetRemoteEndpoint(net::IPEndPoint* endpoint) const override; + void PopulateNetErrorDetails(net::NetErrorDetails* details) const override; void SetPriority(net::RequestPriority priority) override; void SetWebSocketHandshakeStreamCreateHelper( net::WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; From 18a75b5124a0d6eb26aa9c54691be771fdb9c6dc Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 7 Mar 2016 22:38:48 -0800 Subject: [PATCH 0768/1195] Renamed enum in MediaStreamDeviceRequest --- brightray/browser/devtools_manager_delegate.cc | 2 +- brightray/browser/media/media_stream_devices_controller.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index ca8f1cf2d84..cf266f01811 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -55,7 +55,7 @@ class TCPServerSocketFactory } std::string address_; - uint16 port_; + uint16_t port_; DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); }; diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index 3d4f4cc3328..1a205f1ed77 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -33,10 +33,10 @@ MediaStreamDevicesController::MediaStreamDevicesController( // and microphone to avoid popping two infobars. microphone_requested_( request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || - request.request_type == content::MEDIA_OPEN_DEVICE), + request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY), webcam_requested_( request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE || - request.request_type == content::MEDIA_OPEN_DEVICE) { + request.request_type == content::MEDIA_OPEN_DEVICE_PEPPER_ONLY) { } MediaStreamDevicesController::~MediaStreamDevicesController() { @@ -72,7 +72,7 @@ void MediaStreamDevicesController::Accept() { content::MediaStreamDevices devices; if (microphone_requested_ || webcam_requested_) { switch (request_.request_type) { - case content::MEDIA_OPEN_DEVICE: { + case content::MEDIA_OPEN_DEVICE_PEPPER_ONLY: { const content::MediaStreamDevice* device = NULL; // For open device request pick the desired device or fall back to the // first available of the given type. From 6517dffa04f3f9c052762774fa6113b986654572 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 7 Mar 2016 22:58:25 -0800 Subject: [PATCH 0769/1195] Start to update UrlRequestContextGetter --- brightray/browser/url_request_context_getter.cc | 10 +++++++++- brightray/browser/url_request_context_getter.h | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 5c0d7828a96..d585b1d12b7 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -104,8 +104,16 @@ bool URLRequestContextGetter::DelegateURLSecurityManager::CanDelegate return delegate_->CanDelegateURLSecurity(auth_origin); } +void URLRequestContextGetter::DelegateURLSecurityManager::SetDefaultWhitelist( + scoped_ptr whitelist_default) { +} + +void URLRequestContextGetter::DelegateURLSecurityManager::SetDelegateWhitelist( + scoped_ptr whitelist_delegate) { +} + URLRequestContextGetter::Delegate::Delegate() : - orig_url_sec_mgr_(net::URLSecurityManager::Create(NULL, NULL)) {} + orig_url_sec_mgr_(net::URLSecurityManager::Create()) {} std::string URLRequestContextGetter::Delegate::GetUserAgent() { return base::EmptyString(); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index cf647cf7b51..cb9af8c6f7f 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -59,6 +59,10 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { bool CanUseDefaultCredentials(const GURL& auth_origin) const override; bool CanDelegate(const GURL& auth_origin) const override; + void SetDefaultWhitelist( + scoped_ptr whitelist_default) override; + void SetDelegateWhitelist( + scoped_ptr whitelist_delegate) override; private: URLRequestContextGetter::Delegate* delegate_; From dba668057816743533891019e35b0966f06ef552 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Mon, 7 Mar 2016 23:09:25 -0800 Subject: [PATCH 0770/1195] Everyone gets permission --- brightray/browser/permission_manager.cc | 21 +++++++++++++++++++++ brightray/browser/permission_manager.h | 7 +++++++ 2 files changed, 28 insertions(+) diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc index c5d1ac9a9cd..eff85ddc120 100644 --- a/brightray/browser/permission_manager.cc +++ b/brightray/browser/permission_manager.cc @@ -32,6 +32,27 @@ int PermissionManager::RequestPermission( return kNoPendingOperation; } +int PermissionManager::RequestPermissions( + const std::vector& permissions, + content::RenderFrameHost* render_frame_host, + const GURL& requesting_origin, + bool user_gesture, + const base::Callback&)>& callback) { + std::vector permissionStatuses; + + for (auto permission : permissions) { + if (permission == content::PermissionType::MIDI_SYSEX) { + content::ChildProcessSecurityPolicy::GetInstance()-> + GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID()); + } + + permissionStatuses.push_back(content::PERMISSION_STATUS_GRANTED); + } + + callback.Run(permissionStatuses); + return kNoPendingOperation; +} void PermissionManager::CancelPermissionRequest(int request_id) { } diff --git a/brightray/browser/permission_manager.h b/brightray/browser/permission_manager.h index 778605c51ec..f3ed51d3c1a 100644 --- a/brightray/browser/permission_manager.h +++ b/brightray/browser/permission_manager.h @@ -23,6 +23,13 @@ class PermissionManager : public content::PermissionManager { const GURL& requesting_origin, bool user_gesture, const base::Callback& callback) override; + int RequestPermissions( + const std::vector& permissions, + content::RenderFrameHost* render_frame_host, + const GURL& requesting_origin, + bool user_gesture, + const base::Callback&)>& callback) override; void CancelPermissionRequest(int request_id) override; void ResetPermission(content::PermissionType permission, const GURL& requesting_origin, From 948e7c4055ec03452b0ea6d29044ec8395186287 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Mar 2016 17:51:16 +0900 Subject: [PATCH 0771/1195] virutal should not be used together with override --- brightray/browser/network_delegate.h | 5 ++--- brightray/browser/permission_manager.cc | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 11358754008..a561fc05902 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -66,9 +66,8 @@ class NetworkDelegate : public net::NetworkDelegate { bool OnCanEnablePrivacyMode( const GURL& url, const GURL& first_party_for_cookies) const override; - - virtual bool OnAreStrictSecureCookiesEnabled() const override; - virtual bool OnAreExperimentalCookieFeaturesEnabled() const override; + bool OnAreStrictSecureCookiesEnabled() const override; + bool OnAreExperimentalCookieFeaturesEnabled() const override; bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( const net::URLRequest& request, const GURL& target_url, diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc index eff85ddc120..4492e749c8a 100644 --- a/brightray/browser/permission_manager.cc +++ b/brightray/browser/permission_manager.cc @@ -53,6 +53,7 @@ int PermissionManager::RequestPermissions( callback.Run(permissionStatuses); return kNoPendingOperation; } + void PermissionManager::CancelPermissionRequest(int request_id) { } From baf5f384cd48d70382127c7e5ece0ace5c872f02 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Mar 2016 20:59:29 +0900 Subject: [PATCH 0772/1195] Pass() is deprecated for std::move --- brightray/browser/browser_client.cc | 2 +- brightray/browser/browser_context.cc | 2 +- brightray/browser/mac/cocoa_notification.mm | 4 +- .../net/devtools_network_controller.cc | 10 ++-- .../net/devtools_network_interceptor.cc | 2 +- .../net/devtools_network_protocol_handler.cc | 10 ++-- .../net/devtools_network_transaction.cc | 2 +- .../devtools_network_transaction_factory.cc | 3 +- brightray/browser/net_log.cc | 2 +- .../browser/notification_delegate_adapter.cc | 2 +- .../browser/platform_notification_service.cc | 2 +- .../browser/url_request_context_getter.cc | 47 ++++++++++--------- .../browser/url_request_context_getter.h | 4 +- brightray/common/main_delegate.cc | 8 ++-- 14 files changed, 52 insertions(+), 48 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 465cbce4390..88c41957ae9 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -75,7 +75,7 @@ net::URLRequestContextGetter* BrowserClient::CreateRequestContext( auto context = static_cast(browser_context); return context->CreateRequestContext(static_cast(GetNetLog()), protocol_handlers, - protocol_interceptors.Pass()); + std::move(protocol_interceptors)); } content::MediaObserver* BrowserClient::GetMediaObserver() { diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 67ad5c8d540..e082b4ac5c1 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -148,7 +148,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), protocol_handlers, - protocol_interceptors.Pass()); + std::move(protocol_interceptors)); resource_context_->set_url_request_context_getter(url_request_getter_.get()); return url_request_getter_.get(); } diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index 68f22d33637..fefae397880 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -39,11 +39,11 @@ void CocoaNotification::Show(const base::string16& title, if ([notification_ respondsToSelector:@selector(setContentImage:)] && !icon.drawsNothing()) { - NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( + NSImage* image = skia::SkBitmapToNSImageWithColorSpace( icon, base::mac::GetGenericRGBColorSpace()); [notification_ setContentImage:image]; } - + if (silent) { [notification_ setSoundName:nil]; } else { diff --git a/brightray/browser/net/devtools_network_controller.cc b/brightray/browser/net/devtools_network_controller.cc index 42ebf06471f..71eae70af3c 100644 --- a/brightray/browser/net/devtools_network_controller.cc +++ b/brightray/browser/net/devtools_network_controller.cc @@ -30,7 +30,7 @@ void DevToolsNetworkController::SetNetworkState( if (client_id.empty()) { if (!conditions) return; - default_interceptor_->UpdateConditions(conditions.Pass()); + default_interceptor_->UpdateConditions(std::move(conditions)); return; } @@ -40,16 +40,16 @@ void DevToolsNetworkController::SetNetworkState( return; scoped_ptr new_interceptor( new DevToolsNetworkInterceptor); - new_interceptor->UpdateConditions(conditions.Pass()); - interceptors_.set(client_id, new_interceptor.Pass()); + new_interceptor->UpdateConditions(std::move(conditions)); + interceptors_.set(client_id, std::move(new_interceptor)); } else { if (!conditions) { scoped_ptr online_conditions( new DevToolsNetworkConditions(false)); - interceptor->UpdateConditions(online_conditions.Pass()); + interceptor->UpdateConditions(std::move(online_conditions)); interceptors_.erase(client_id); } else { - interceptor->UpdateConditions(conditions.Pass()); + interceptor->UpdateConditions(std::move(conditions)); } } } diff --git a/brightray/browser/net/devtools_network_interceptor.cc b/brightray/browser/net/devtools_network_interceptor.cc index 2535ed74bd3..ed89fc1b54c 100644 --- a/brightray/browser/net/devtools_network_interceptor.cc +++ b/brightray/browser/net/devtools_network_interceptor.cc @@ -40,7 +40,7 @@ void DevToolsNetworkInterceptor::UpdateConditions( if (conditions_->IsThrottling()) UpdateThrottledTransactions(now); - conditions_ = conditions.Pass(); + conditions_ = std::move(conditions); if (conditions_->offline()) { timer_.Stop(); diff --git a/brightray/browser/net/devtools_network_protocol_handler.cc b/brightray/browser/net/devtools_network_protocol_handler.cc index b94a0413289..b06678fe92d 100644 --- a/brightray/browser/net/devtools_network_protocol_handler.cc +++ b/brightray/browser/net/devtools_network_protocol_handler.cc @@ -64,7 +64,7 @@ CreateSuccessResponse(int id, scoped_ptr result) { scoped_ptr response(new base::DictionaryValue); response->SetInteger(kId, id); response->Set(params::kResult, result.release()); - return response.Pass(); + return response; } scoped_ptr @@ -75,14 +75,14 @@ CreateFailureResponse(int id, const std::string& param) { error_object->SetInteger(params::kErrorCode, kErrorInvalidParams); error_object->SetString(params::kErrorMessage, base::StringPrintf("Missing or Invalid '%s' parameter", param.c_str())); - return response.Pass(); + return response; } void UpdateNetworkStateInIO(brightray::DevToolsNetworkController* controller, const std::string& client_id, scoped_ptr conditions) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - controller->SetNetworkState(client_id, conditions.Pass()); + controller->SetNetworkState(client_id, std::move(conditions)); } } // namespace @@ -119,7 +119,7 @@ DevToolsNetworkProtocolHandler::CanEmulateNetworkConditions( const base::DictionaryValue* params) { scoped_ptr result(new base::DictionaryValue); result->SetBoolean(params::kResult, true); - return CreateSuccessResponse(id, result.Pass()); + return CreateSuccessResponse(id, std::move(result)); } scoped_ptr @@ -154,7 +154,7 @@ DevToolsNetworkProtocolHandler::EmulateNetworkConditions( latency, download_throughput, upload_throughput)); - UpdateNetworkState(agent_host, conditions.Pass()); + UpdateNetworkState(agent_host, std::move(conditions)); return scoped_ptr(); } diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc index c65230d6f5a..f0d66a047bb 100644 --- a/brightray/browser/net/devtools_network_transaction.cc +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -24,7 +24,7 @@ DevToolsNetworkTransaction::DevToolsNetworkTransaction( DevToolsNetworkController* controller, scoped_ptr transaction) : controller_(controller), - transaction_(transaction.Pass()), + transaction_(std::move(transaction)), request_(nullptr), failed_(false), throttled_byte_count_(0), diff --git a/brightray/browser/net/devtools_network_transaction_factory.cc b/brightray/browser/net/devtools_network_transaction_factory.cc index d1676a34d56..d3fb4cfb08b 100644 --- a/brightray/browser/net/devtools_network_transaction_factory.cc +++ b/brightray/browser/net/devtools_network_transaction_factory.cc @@ -35,7 +35,8 @@ int DevToolsNetworkTransactionFactory::CreateTransaction( int rv = network_layer_->CreateTransaction(priority, &new_transaction); if (rv != net::OK) return rv; - transaction->reset(new DevToolsNetworkTransaction(controller_, new_transaction.Pass())); + transaction->reset( + new DevToolsNetworkTransaction(controller_, std::move(new_transaction))); return net::OK; } diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index 7d781a22e7b..b0b06483f9b 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -55,7 +55,7 @@ void NetLog::StartLogging(net::URLRequestContext* url_request_context) { scoped_ptr constants(GetConstants()); write_to_file_observer_.StartObserving(this, - log_file_.Pass(), + std::move(log_file_), constants.get(), url_request_context); } diff --git a/brightray/browser/notification_delegate_adapter.cc b/brightray/browser/notification_delegate_adapter.cc index da9a70aab39..1a4853723b5 100644 --- a/brightray/browser/notification_delegate_adapter.cc +++ b/brightray/browser/notification_delegate_adapter.cc @@ -8,7 +8,7 @@ namespace brightray { NotificationDelegateAdapter::NotificationDelegateAdapter( scoped_ptr delegate) - : delegate_(delegate.Pass()) { + : delegate_(std::move(delegate)) { } NotificationDelegateAdapter::~NotificationDelegateAdapter() { diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 5ce66762508..7971f281001 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -33,7 +33,7 @@ void OnWebNotificationAllowed( if (!presenter) return; scoped_ptr adapter( - new NotificationDelegateAdapter(delegate.Pass())); + new NotificationDelegateAdapter(std::move(delegate))); auto notification = presenter->CreateNotification(adapter.get()); if (notification) { ignore_result(adapter.release()); // it will release itself automatically. diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index d585b1d12b7..1779170136e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -23,6 +23,7 @@ #include "net/cookies/cookie_monster.h" #include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_handler_factory.h" +#include "net/http/http_auth_preferences.h" #include "net/http/http_server_properties_impl.h" #include "net/log/net_log.h" #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" @@ -139,14 +140,14 @@ URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); // Set up interceptors in the reverse order. - scoped_ptr top_job_factory = job_factory.Pass(); + scoped_ptr top_job_factory = std::move(job_factory); content::URLRequestInterceptorScopedVector::reverse_iterator i; for (i = protocol_interceptors->rbegin(); i != protocol_interceptors->rend(); ++i) top_job_factory.reset(new net::URLRequestInterceptingJobFactory( - top_job_factory.Pass(), make_scoped_ptr(*i))); + std::move(top_job_factory), make_scoped_ptr(*i))); protocol_interceptors->weak_clear(); - return top_job_factory.Pass(); + return top_job_factory; } net::HttpCache::BackendFactory* @@ -195,8 +196,7 @@ URLRequestContextGetter::URLRequestContextGetter( in_memory_(in_memory), io_loop_(io_loop), file_loop_(file_loop), - url_sec_mgr_(new URLRequestContextGetter::DelegateURLSecurityManager(delegate)), - protocol_interceptors_(protocol_interceptors.Pass()) { + protocol_interceptors_(std::move(protocol_interceptors)) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -265,10 +265,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { // --host-resolver-rules if (command_line.HasSwitch(switches::kHostResolverRules)) { scoped_ptr remapped_resolver( - new net::MappedHostResolver(host_resolver.Pass())); + new net::MappedHostResolver(std::move(host_resolver))); remapped_resolver->SetRulesFromString( command_line.GetSwitchValueASCII(switches::kHostResolverRules)); - host_resolver = remapped_resolver.Pass(); + host_resolver = std::move(remapped_resolver); } // --proxy-server @@ -291,7 +291,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } else { storage_->set_proxy_service( net::CreateProxyServiceUsingV8ProxyResolver( - proxy_config_service_.Pass(), + std::move(proxy_config_service_), new net::ProxyScriptFetcherImpl(url_request_context_.get()), dhcp_factory.Create(url_request_context_.get()), host_resolver.get(), @@ -304,16 +304,15 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { schemes.push_back(std::string("digest")); schemes.push_back(std::string("ntlm")); schemes.push_back(std::string("negotiate")); - +#if defined(OS_POSIX) + http_auth_preferences_.reset(new net::HttpAuthPreferences(schemes, + std::string())); +#else + http_auth_preferences_.reset(new net::HttpAuthPreferences(schemes)); +#endif auto auth_handler_factory = make_scoped_ptr( net::HttpAuthHandlerRegistryFactory::Create( - schemes, - url_sec_mgr_.get(), - host_resolver.get(), - std::string(), // gssapi_library_name - std::string(), // gssapi_library_nam - false, // auth_android_negotiate_account_type - true)); // negotiate_enable_port + http_auth_preferences_.get(), host_resolver.get())); storage_->set_cert_verifier(delegate_->CreateCertVerifier()); storage_->set_transport_security_state( @@ -322,7 +321,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_http_auth_handler_factory(auth_handler_factory.Pass()); scoped_ptr server_properties( new net::HttpServerPropertiesImpl); - storage_->set_http_server_properties(server_properties.Pass()); + storage_->set_http_server_properties(std::move(server_properties)); net::HttpNetworkSession::Params network_session_params; network_session_params.cert_verifier = url_request_context_->cert_verifier(); @@ -355,21 +354,23 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } // Give |storage_| ownership at the end in case it's |mapped_host_resolver|. - storage_->set_host_resolver(host_resolver.Pass()); + storage_->set_host_resolver(std::move(host_resolver)); network_session_params.host_resolver = url_request_context_->host_resolver(); - net::HttpNetworkSession* session = new net::HttpNetworkSession(network_session_params); - net::HttpCache::BackendFactory* backend = nullptr; + http_network_session_.reset( + new net::HttpNetworkSession(network_session_params)); + scoped_ptr backend; if (in_memory_) { backend = net::HttpCache::DefaultBackend::InMemory(0); } else { - backend = delegate_->CreateHttpCacheBackendFactory(base_path_); + backend.reset(delegate_->CreateHttpCacheBackendFactory(base_path_)); } storage_->set_http_transaction_factory(make_scoped_ptr( new net::HttpCache( - new DevToolsNetworkTransactionFactory(controller_, session), + new DevToolsNetworkTransactionFactory(controller_, + http_network_session_.get()), url_request_context_->net_log(), - backend))); + std::move(backend)))); storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( &protocol_handlers_, &protocol_interceptors_)); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index cb9af8c6f7f..aaf9855d2a5 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -19,6 +19,7 @@ class MessageLoop; namespace net { class HostMappingRules; class HostResolver; +class HttpAuthPreferences; class NetworkDelegate; class ProxyConfigService; class URLRequestContextStorage; @@ -103,7 +104,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr storage_; scoped_ptr url_request_context_; scoped_ptr host_mapping_rules_; - scoped_ptr url_sec_mgr_; + scoped_ptr http_auth_preferences_; + scoped_ptr http_network_session_; content::ProtocolHandlerMap protocol_handlers_; content::URLRequestInterceptorScopedVector protocol_interceptors_; diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 74ec88791b9..6516111aedd 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -81,11 +81,11 @@ MainDelegate::~MainDelegate() { } scoped_ptr MainDelegate::CreateContentClient() { - return make_scoped_ptr(new ContentClient).Pass(); + return make_scoped_ptr(new ContentClient); } bool MainDelegate::BasicStartupComplete(int* exit_code) { - content_client_ = CreateContentClient().Pass(); + content_client_ = CreateContentClient(); SetContentClient(content_client_.get()); #if defined(OS_MACOSX) OverrideChildProcessPath(); @@ -108,12 +108,12 @@ void MainDelegate::PreSandboxStartup() { } content::ContentBrowserClient* MainDelegate::CreateContentBrowserClient() { - browser_client_ = CreateBrowserClient().Pass(); + browser_client_ = CreateBrowserClient(); return browser_client_.get(); } scoped_ptr MainDelegate::CreateBrowserClient() { - return make_scoped_ptr(new BrowserClient).Pass(); + return make_scoped_ptr(new BrowserClient); } } // namespace brightray From d3a39540b5a67a70a80aa930a2aff033266f4602 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 8 Mar 2016 23:28:28 +0900 Subject: [PATCH 0773/1195] Fix compilation errors on OS X --- brightray/browser/browser_context.cc | 4 ++++ brightray/browser/browser_context.h | 1 + .../devtools_embedder_message_dispatcher.cc | 5 +++-- .../devtools_embedder_message_dispatcher.h | 3 ++- .../browser/inspectable_web_contents_impl.cc | 19 ++++++++++--------- .../browser/inspectable_web_contents_impl.h | 3 ++- brightray/browser/network_delegate.cc | 4 ++-- .../browser/url_request_context_getter.cc | 14 +++++++------- 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index e082b4ac5c1..6181f8ec632 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -232,4 +232,8 @@ content::PermissionManager* BrowserContext::GetPermissionManager() { return permission_manager_.get(); } +content::BackgroundSyncController* BrowserContext::GetBackgroundSyncController() { + return nullptr; +} + } // namespace brightray diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 3c9b68d8838..9866732cbcb 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -57,6 +57,7 @@ class BrowserContext : public base::RefCounted, content::PushMessagingService* GetPushMessagingService() override; content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; content::PermissionManager* GetPermissionManager() override; + content::BackgroundSyncController* GetBackgroundSyncController() override; net::URLRequestContextGetter* CreateRequestContext( NetLog* net_log, diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index 2a4b3817659..f45d90d753f 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -190,8 +190,9 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend( d->RegisterHandler("resetZoom", &Delegate::ResetZoom, delegate); d->RegisterHandler("setDevicesUpdatesEnabled", &Delegate::SetDevicesUpdatesEnabled, delegate); - d->RegisterHandler("sendMessageToBrowser", - &Delegate::SendMessageToBrowser, delegate); + d->RegisterHandler("dispatchProtocolMessage", + &Delegate::DispatchProtocolMessageFromDevToolsFrontend, + delegate); d->RegisterHandler("recordActionUMA", &Delegate::RecordActionUMA, delegate); d->RegisterHandlerWithCallback("sendJsonRequest", &Delegate::SendJsonRequest, delegate); diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index 46f54dfbf2c..eb3dc389786 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -68,7 +68,8 @@ class DevToolsEmbedderMessageDispatcher { virtual void ZoomOut() = 0; virtual void ResetZoom() = 0; virtual void SetDevicesUpdatesEnabled(bool enabled) = 0; - virtual void SendMessageToBrowser(const std::string& message) = 0; + virtual void DispatchProtocolMessageFromDevToolsFrontend( + const std::string& message) = 0; virtual void RecordActionUMA(const std::string& name, int action) = 0; virtual void SendJsonRequest(const DispatchCallback& callback, const std::string& browser_id, diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 76972b654e9..5afff01ff6b 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -26,6 +26,7 @@ #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/common/user_agent.h" +#include "ipc/ipc_channel.h" #include "net/http/http_response_headers.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher_response_writer.h" @@ -251,7 +252,9 @@ void InspectableWebContentsImpl::ShowDevTools() { agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()); frontend_host_.reset(content::DevToolsFrontendHost::Create( - web_contents_->GetMainFrame(), this)); + web_contents_->GetMainFrame(), + base::Bind(&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend, + base::Unretained(this)))); agent_host_->AttachClient(this); GURL devtools_url(base::StringPrintf(kChromeUIDevToolsURL, @@ -477,7 +480,8 @@ void InspectableWebContentsImpl::ResetZoom() { void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) { } -void InspectableWebContentsImpl::SendMessageToBrowser(const std::string& message) { +void InspectableWebContentsImpl::DispatchProtocolMessageFromDevToolsFrontend( + const std::string& message) { if (agent_host_.get()) agent_host_->DispatchProtocolMessage(message); } @@ -543,12 +547,6 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::st params); } -void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontendToBackend( - const std::string& message) { - if (agent_host_.get()) - agent_host_->DispatchProtocolMessage(message); -} - void InspectableWebContentsImpl::DispatchProtocolMessage( content::DevToolsAgentHost* agent_host, const std::string& message) { if (!frontend_loaded_) @@ -578,7 +576,10 @@ void InspectableWebContentsImpl::RenderFrameHostChanged( content::RenderFrameHost* new_host) { if (new_host->GetParent()) return; - frontend_host_.reset(content::DevToolsFrontendHost::Create(new_host, this)); + frontend_host_.reset(content::DevToolsFrontendHost::Create( + web_contents_->GetMainFrame(), + base::Bind(&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend, + base::Unretained(this)))); } void InspectableWebContentsImpl::WebContentsDestroyed() { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 7edf9ce96e8..e4a964adf07 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -104,7 +104,8 @@ class InspectableWebContentsImpl : void ZoomOut() override; void ResetZoom() override; void SetDevicesUpdatesEnabled(bool enabled) override; - void SendMessageToBrowser(const std::string& message) override; + void DispatchProtocolMessageFromDevToolsFrontend( + const std::string& message) override; void RecordActionUMA(const std::string& name, int action) override; void SendJsonRequest(const DispatchCallback& callback, const std::string& browser_id, diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index e03adba65a1..a1795605562 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -140,11 +140,11 @@ bool NetworkDelegate::OnCanEnablePrivacyMode( return false; } -bool OnAreStrictSecureCookiesEnabled() { +bool NetworkDelegate::OnAreStrictSecureCookiesEnabled() const { return true; } -bool OnAreExperimentalCookieFeaturesEnabled() { +bool NetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const { return true; } diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 1779170136e..6e516edef5c 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -310,15 +310,15 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { #else http_auth_preferences_.reset(new net::HttpAuthPreferences(schemes)); #endif - auto auth_handler_factory = make_scoped_ptr( + auto auth_handler_factory = net::HttpAuthHandlerRegistryFactory::Create( - http_auth_preferences_.get(), host_resolver.get())); + http_auth_preferences_.get(), host_resolver.get()); storage_->set_cert_verifier(delegate_->CreateCertVerifier()); storage_->set_transport_security_state( make_scoped_ptr(new net::TransportSecurityState)); storage_->set_ssl_config_service(delegate_->CreateSSLConfigService()); - storage_->set_http_auth_handler_factory(auth_handler_factory.Pass()); + storage_->set_http_auth_handler_factory(std::move(auth_handler_factory)); scoped_ptr server_properties( new net::HttpServerPropertiesImpl); storage_->set_http_server_properties(std::move(server_properties)); @@ -367,10 +367,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } storage_->set_http_transaction_factory(make_scoped_ptr( new net::HttpCache( - new DevToolsNetworkTransactionFactory(controller_, - http_network_session_.get()), - url_request_context_->net_log(), - std::move(backend)))); + make_scoped_ptr(new DevToolsNetworkTransactionFactory( + controller_, http_network_session_.get())), + std::move(backend), + false))); storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( &protocol_handlers_, &protocol_interceptors_)); From ead0bb0cfc1ce7c2a10c598840408c65e41e3045 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Mar 2016 14:55:46 +0900 Subject: [PATCH 0774/1195] Fix devtools not working --- brightray/browser/devtools_manager_delegate.cc | 1 - brightray/browser/inspectable_web_contents_impl.cc | 14 ++++++++++---- brightray/browser/inspectable_web_contents_impl.h | 3 +++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index cf266f01811..155f35728df 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -109,7 +109,6 @@ DevToolsDelegate::~DevToolsDelegate() { } std::string DevToolsDelegate::GetDiscoveryPageHTML() { - LOG(WARNING) << IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE; return ResourceBundle::GetSharedInstance().GetRawDataResource( IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); } diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 5afff01ff6b..4065053b1ae 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -251,10 +251,6 @@ void InspectableWebContentsImpl::ShowDevTools() { devtools_web_contents_->SetDelegate(this); agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()); - frontend_host_.reset(content::DevToolsFrontendHost::Create( - web_contents_->GetMainFrame(), - base::Bind(&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend, - base::Unretained(this)))); agent_host_->AttachClient(this); GURL devtools_url(base::StringPrintf(kChromeUIDevToolsURL, @@ -634,6 +630,16 @@ void InspectableWebContentsImpl::OnWebContentsFocused() { #endif } +void InspectableWebContentsImpl::DidStartNavigationToPendingEntry( + const GURL& url, + content::NavigationController::ReloadType reload_type) { + frontend_host_.reset( + content::DevToolsFrontendHost::Create( + web_contents()->GetMainFrame(), + base::Bind(&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend, + base::Unretained(this)))); +} + void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) { DCHECK(source); PendingRequestsMap::iterator it = pending_requests_.find(source); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index e4a964adf07..1e2bab8a26c 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -130,6 +130,9 @@ class InspectableWebContentsImpl : content::RenderFrameHost* new_host) override; void WebContentsDestroyed() override; void OnWebContentsFocused() override; + void DidStartNavigationToPendingEntry( + const GURL& url, + content::NavigationController::ReloadType reload_type) override; // content::WebContentsDelegate: bool AddMessageToConsole(content::WebContents* source, From 82c30ef9b992179db1a4655afab74b274a4ff7c3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Mar 2016 18:47:11 +0900 Subject: [PATCH 0775/1195] Fix RenderFrameHostChanged --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 4065053b1ae..8217812b58c 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -573,7 +573,7 @@ void InspectableWebContentsImpl::RenderFrameHostChanged( if (new_host->GetParent()) return; frontend_host_.reset(content::DevToolsFrontendHost::Create( - web_contents_->GetMainFrame(), + new_host, base::Bind(&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend, base::Unretained(this)))); } From f70ece16696c955523ba61a23e3f1d8026620e46 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 9 Mar 2016 22:24:25 +0900 Subject: [PATCH 0776/1195] No more libyuv_neon --- brightray/brightray.gyp | 3 --- 1 file changed, 3 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index d7120ea98f8..85af875c48b 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -117,9 +117,6 @@ }], ['target_arch=="arm"', { 'link_settings': { - 'libraries': [ - '<(libchromiumcontent_dir)/libyuv_neon.a', - ], 'libraries!': [ '<(libchromiumcontent_dir)/libdesktop_capture_differ_sse2.a', ], From 3983566fa316e9da44c79af87038c27903667e56 Mon Sep 17 00:00:00 2001 From: Robo Date: Wed, 9 Mar 2016 19:43:33 +0530 Subject: [PATCH 0777/1195] allow setting pkg-config variable --- brightray/brightray.gyp | 8 ++++---- brightray/brightray.gypi | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 85af875c48b..87604fb49f8 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -55,15 +55,15 @@ ['OS=="linux"', { 'link_settings': { 'ldflags': [ - ' Date: Thu, 10 Mar 2016 14:39:07 +0900 Subject: [PATCH 0778/1195] Handle nullptr in RequestConextGetter --- .../browser/url_request_context_getter.cc | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 6e516edef5c..976a779484e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -200,7 +200,8 @@ URLRequestContextGetter::URLRequestContextGetter( // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - std::swap(protocol_handlers_, *protocol_handlers); + if (protocol_handlers) + std::swap(protocol_handlers_, *protocol_handlers); // 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 @@ -231,8 +232,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { #endif // --log-net-log - net_log_->StartLogging(url_request_context_.get()); - url_request_context_->set_net_log(net_log_); + if (net_log_) { + 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()); @@ -365,12 +368,20 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } else { backend.reset(delegate_->CreateHttpCacheBackendFactory(base_path_)); } - storage_->set_http_transaction_factory(make_scoped_ptr( - new net::HttpCache( - make_scoped_ptr(new DevToolsNetworkTransactionFactory( - controller_, http_network_session_.get())), - std::move(backend), - false))); + + if (controller_) { + storage_->set_http_transaction_factory(make_scoped_ptr( + new net::HttpCache( + make_scoped_ptr(new DevToolsNetworkTransactionFactory( + controller_, http_network_session_.get())), + std::move(backend), + false))); + } else { + storage_->set_http_transaction_factory(make_scoped_ptr( + new net::HttpCache(http_network_session_.get(), + std::move(backend), + false))); + } storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( &protocol_handlers_, &protocol_interceptors_)); From b68d2ba8b5ec95d3fb16996e5a63fbf9b6059fdf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 10 Mar 2016 15:56:13 +0900 Subject: [PATCH 0779/1195] Fix compilation error on Windows --- brightray/browser/url_request_context_getter.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 976a779484e..dffc106ede5 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -22,6 +22,7 @@ #include "net/cert/cert_verifier.h" #include "net/cookies/cookie_monster.h" #include "net/dns/mapped_host_resolver.h" +#include "net/http/http_auth_filter.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_auth_preferences.h" #include "net/http/http_server_properties_impl.h" From 6b79926cc7f63678971c0d8e4f66e564d671dc0b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 10 Mar 2016 16:11:38 +0900 Subject: [PATCH 0780/1195] Link with sandbox_helper_win.lib --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 85af875c48b..05a63c7aeed 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -198,6 +198,7 @@ 'libraries': [ '<(libchromiumcontent_dir)/base_static.lib', '<(libchromiumcontent_dir)/sandbox.lib', + '<(libchromiumcontent_dir)/sandbox_helper_win.lib', '<(libchromiumcontent_dir)/devtools_discovery.lib', '<(libchromiumcontent_dir)/devtools_http_handler.lib', '<(libchromiumcontent_dir)/http_server.lib', From deb1abe15257d482d91b3363ee184afd280d2b09 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 10 Mar 2016 21:00:49 +0900 Subject: [PATCH 0781/1195] Fix linking error for Release build --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 881cf10e525..217af424022 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 881cf10e5255c3037d5624616fd7544c1e7252ae +Subproject commit 217af424022afea696510146cd0d3e6bba453771 From 6b3d4fdc61d4b49a23567b1fcbaa9c6c074bfdb9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 11 Mar 2016 10:41:22 +0900 Subject: [PATCH 0782/1195] Update to lastest master of libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 217af424022..b06d4c307b8 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 217af424022afea696510146cd0d3e6bba453771 +Subproject commit b06d4c307b861cdb091f4ba26b1a185333889033 From 95e63f6b8ee04c7f3ed3cf8f5950b9ae01ddba36 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 13 Mar 2016 10:10:56 +0900 Subject: [PATCH 0783/1195] Dealy loading powrprof.dll --- brightray/brightray.gyp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index a2e95fbcbe9..f3e0a54bd17 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -242,11 +242,12 @@ 'gdi32.lib', 'netapi32.lib', 'oleacc.lib', - 'powrprof.lib', 'user32.lib', 'usp10.lib', 'version.lib', 'winspool.lib', + # base.gyp: + 'powrprof.lib', ], 'DelayLoadDLLs': [ # content_common.gypi: @@ -260,6 +261,8 @@ 'BluetoothApis.dll', 'Bthprops.cpl', 'setupapi.dll', + # base.gyp: + 'powrprof.dll', # windows runtime 'API-MS-WIN-CORE-WINRT-L1-1-0.DLL', 'API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL', From 215a81d0e66eb6dcb48a5892cf5426ca828cb9fd Mon Sep 17 00:00:00 2001 From: Robo Date: Mon, 14 Mar 2016 02:35:22 +0530 Subject: [PATCH 0784/1195] update devtools network interceptor to throttle uploads --- .../browser/devtools_manager_delegate.cc | 6 + brightray/browser/devtools_manager_delegate.h | 2 +- .../net/devtools_network_controller.cc | 44 ++- .../browser/net/devtools_network_controller.h | 7 +- .../net/devtools_network_interceptor.cc | 357 ++++++++++-------- .../net/devtools_network_interceptor.h | 80 ++-- .../net/devtools_network_protocol_handler.cc | 9 + .../net/devtools_network_protocol_handler.h | 2 + .../net/devtools_network_transaction.cc | 271 ++++++------- .../net/devtools_network_transaction.h | 65 +--- .../devtools_network_upload_data_stream.cc | 94 +++++ .../net/devtools_network_upload_data_stream.h | 51 +++ brightray/filenames.gypi | 2 + 13 files changed, 598 insertions(+), 392 deletions(-) create mode 100644 brightray/browser/net/devtools_network_upload_data_stream.cc create mode 100644 brightray/browser/net/devtools_network_upload_data_stream.h diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index 155f35728df..b79c94f8140 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -158,6 +158,12 @@ DevToolsManagerDelegate::DevToolsManagerDelegate() DevToolsManagerDelegate::~DevToolsManagerDelegate() { } +void DevToolsManagerDelegate::DevToolsAgentStateChanged( + content::DevToolsAgentHost* agent_host, + bool attached) { + handler_->DevToolsAgentStateChanged(agent_host, attached); +} + base::DictionaryValue* DevToolsManagerDelegate::HandleCommand( content::DevToolsAgentHost* agent_host, base::DictionaryValue* command) { diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h index 12eedc66082..34e6a6bd704 100644 --- a/brightray/browser/devtools_manager_delegate.h +++ b/brightray/browser/devtools_manager_delegate.h @@ -29,7 +29,7 @@ class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { void Inspect(content::BrowserContext* browser_context, content::DevToolsAgentHost* agent_host) override {} void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host, - bool attached) override {} + bool attached) override; base::DictionaryValue* HandleCommand(content::DevToolsAgentHost* agent_host, base::DictionaryValue* command) override; diff --git a/brightray/browser/net/devtools_network_controller.cc b/brightray/browser/net/devtools_network_controller.cc index 71eae70af3c..7313a378432 100644 --- a/brightray/browser/net/devtools_network_controller.cc +++ b/brightray/browser/net/devtools_network_controller.cc @@ -16,7 +16,7 @@ using content::BrowserThread; namespace brightray { DevToolsNetworkController::DevToolsNetworkController() - : default_interceptor_(new DevToolsNetworkInterceptor) { + : appcache_interceptor_(new DevToolsNetworkInterceptor) { } DevToolsNetworkController::~DevToolsNetworkController() { @@ -27,14 +27,7 @@ void DevToolsNetworkController::SetNetworkState( scoped_ptr conditions) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - if (client_id.empty()) { - if (!conditions) - return; - default_interceptor_->UpdateConditions(std::move(conditions)); - return; - } - - auto interceptor = interceptors_.get(client_id); + DevToolsNetworkInterceptor* interceptor = interceptors_.get(client_id); if (!interceptor) { if (!conditions) return; @@ -52,23 +45,36 @@ void DevToolsNetworkController::SetNetworkState( interceptor->UpdateConditions(std::move(conditions)); } } + + bool has_offline_interceptors = false; + InterceptorMap::iterator it = interceptors_.begin(); + for (; it != interceptors_.end(); ++it) { + if (it->second->IsOffline()) { + has_offline_interceptors = true; + break; + } + } + + bool is_appcache_offline = appcache_interceptor_->IsOffline(); + if (is_appcache_offline != has_offline_interceptors) { + scoped_ptr appcache_conditions( + new DevToolsNetworkConditions(has_offline_interceptors)); + appcache_interceptor_->UpdateConditions(std::move(appcache_conditions)); + } } -base::WeakPtr -DevToolsNetworkController::GetInterceptor(DevToolsNetworkTransaction* transaction) { +DevToolsNetworkInterceptor* +DevToolsNetworkController::GetInterceptor(const std::string& client_id) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - DCHECK(transaction->request()); - if (!interceptors_.size()) - return default_interceptor_->GetWeakPtr(); + if (!interceptors_.size() || client_id.empty()) + return nullptr; - transaction->ProcessRequest(); - auto& client_id = transaction->client_id(); - auto interceptor = interceptors_.get(client_id); + DevToolsNetworkInterceptor* interceptor = interceptors_.get(client_id); if (!interceptor) - return default_interceptor_->GetWeakPtr(); + return nullptr; - return interceptor->GetWeakPtr(); + return interceptor; } } // namespace brightray diff --git a/brightray/browser/net/devtools_network_controller.h b/brightray/browser/net/devtools_network_controller.h index a73268f798f..2e3ab419da4 100644 --- a/brightray/browser/net/devtools_network_controller.h +++ b/brightray/browser/net/devtools_network_controller.h @@ -8,7 +8,6 @@ #include "base/containers/scoped_ptr_hash_map.h" #include "base/macros.h" #include "base/memory/scoped_ptr.h" -#include "base/memory/weak_ptr.h" namespace brightray { @@ -23,13 +22,13 @@ class DevToolsNetworkController { void SetNetworkState(const std::string& client_id, scoped_ptr conditions); - base::WeakPtr GetInterceptor( - DevToolsNetworkTransaction* transaction); + DevToolsNetworkInterceptor* GetInterceptor(const std::string& client_id); private: using InterceptorMap = base::ScopedPtrHashMap>; - scoped_ptr default_interceptor_; + + scoped_ptr appcache_interceptor_; InterceptorMap interceptors_; DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController); diff --git a/brightray/browser/net/devtools_network_interceptor.cc b/brightray/browser/net/devtools_network_interceptor.cc index ed89fc1b54c..126077c5f72 100644 --- a/brightray/browser/net/devtools_network_interceptor.cc +++ b/brightray/browser/net/devtools_network_interceptor.cc @@ -4,13 +4,12 @@ #include "browser/net/devtools_network_interceptor.h" +#include #include -#include "browser/net/devtools_network_conditions.h" -#include "browser/net/devtools_network_transaction.h" - #include "base/time/time.h" -#include "net/base/load_timing_info.h" +#include "browser/net/devtools_network_conditions.h" +#include "net/base/net_errors.h" namespace brightray { @@ -18,10 +17,31 @@ namespace { int64_t kPacketSize = 1500; +base::TimeDelta CalculateTickLength(double throughput) { + if (!throughput) + return base::TimeDelta(); + + int64_t us_tick_length = (1000000L * kPacketSize) / throughput; + if (us_tick_length == 0) + us_tick_length = 1; + return base::TimeDelta::FromMicroseconds(us_tick_length); +} + } // namespace +DevToolsNetworkInterceptor::ThrottleRecord::ThrottleRecord() { +} + +DevToolsNetworkInterceptor::ThrottleRecord::ThrottleRecord( + const ThrottleRecord& other) = default; + +DevToolsNetworkInterceptor::ThrottleRecord::~ThrottleRecord() { +} + DevToolsNetworkInterceptor::DevToolsNetworkInterceptor() : conditions_(new DevToolsNetworkConditions(false)), + download_last_tick_(0), + upload_last_tick_(0), weak_ptr_factory_(this) { } @@ -33,186 +53,164 @@ DevToolsNetworkInterceptor::GetWeakPtr() { return weak_ptr_factory_.GetWeakPtr(); } +void DevToolsNetworkInterceptor::FinishRecords( + ThrottleRecords* records, bool offline) { + ThrottleRecords temp; + temp.swap(*records); + for (const ThrottleRecord& record : temp) { + bool failed = offline && !record.is_upload; + record.callback.Run( + failed ? net::ERR_INTERNET_DISCONNECTED : record.result, + record.bytes); + } +} + void DevToolsNetworkInterceptor::UpdateConditions( scoped_ptr conditions) { DCHECK(conditions); base::TimeTicks now = base::TimeTicks::Now(); if (conditions_->IsThrottling()) - UpdateThrottledTransactions(now); + UpdateThrottled(now); conditions_ = std::move(conditions); - if (conditions_->offline()) { + bool offline = conditions_->offline(); + if (offline || conditions_->IsThrottling()) { timer_.Stop(); - throttled_transactions_.clear(); - suspended_transactions_.clear(); - Transactions old_transactions(transactions_); - Transactions::iterator it = old_transactions.begin(); - for (; it != old_transactions.end(); ++it) { - if (transactions_.find(*it) == transactions_.end()) - continue; - if (!(*it)->request() || (*it)->failed()) - continue; - if (ShouldFail(*it)) - (*it)->Fail(); - } + FinishRecords(&download_, offline); + FinishRecords(&upload_, offline); + FinishRecords(&suspended_, offline); return; } - if (conditions_->IsThrottling()) { - DCHECK_NE(conditions_->download_throughput(), 0); - offset_ = now; - last_tick_ = 0; - int64_t us_tick_length = - (1000000L * kPacketSize) / conditions_->download_throughput(); - DCHECK_NE(us_tick_length, 0); - if (us_tick_length == 0) - us_tick_length = 1; - tick_length_ = base::TimeDelta::FromMicroseconds(us_tick_length); - latency_length_ = base::TimeDelta(); - double latency = conditions_->latency(); - if (latency > 0) - latency_length_ = base::TimeDelta::FromMillisecondsD(latency); - ArmTimer(now); - } else { - timer_.Stop(); + // Throttling. + DCHECK(conditions_->download_throughput() != 0 || + conditions_->upload_throughput() != 0); + offset_ = now; - std::vector throttled_transactions; - throttled_transactions.swap(throttled_transactions_); - for (auto& throttled_transaction : throttled_transactions) - FireThrottledCallback(throttled_transaction); + download_last_tick_ = 0; + download_tick_length_ = CalculateTickLength( + conditions_->download_throughput()); - SuspendedTransactions suspended_transactions; - suspended_transactions.swap(suspended_transactions_); - for (auto& suspended_transaction : suspended_transactions) - FireThrottledCallback(suspended_transaction.first); - } -} - -void DevToolsNetworkInterceptor::AddTransaction( - DevToolsNetworkTransaction* transaction) { - DCHECK(transactions_.find(transaction) == transactions_.end()); - transactions_.insert(transaction); -} - -void DevToolsNetworkInterceptor::RemoveTransaction( - DevToolsNetworkTransaction* transaction) { - DCHECK(transactions_.find(transaction) != transactions_.end()); - transactions_.erase(transaction); - - if (!conditions_->IsThrottling()) - return; - - base::TimeTicks now = base::TimeTicks::Now(); - UpdateThrottledTransactions(now); - throttled_transactions_.erase(std::remove(throttled_transactions_.begin(), - throttled_transactions_.end(), transaction), - throttled_transactions_.end()); - - SuspendedTransactions::iterator it = suspended_transactions_.begin(); - for (; it != suspended_transactions_.end(); ++it) { - if (it->first == transaction) { - suspended_transactions_.erase(it); - break; - } - } + upload_last_tick_ = 0; + upload_tick_length_ = CalculateTickLength(conditions_->upload_throughput()); + latency_length_ = base::TimeDelta(); + double latency = conditions_->latency(); + if (latency > 0) + latency_length_ = base::TimeDelta::FromMilliseconds(latency); ArmTimer(now); } -bool DevToolsNetworkInterceptor::ShouldFail( - const DevToolsNetworkTransaction* transaction) { - return conditions_->offline(); -} - -bool DevToolsNetworkInterceptor::ShouldThrottle( - const DevToolsNetworkTransaction* transaction) { - return conditions_->IsThrottling(); -} - -void DevToolsNetworkInterceptor::ThrottleTransaction( - DevToolsNetworkTransaction* transaction, bool start) { - base::TimeTicks now = base::TimeTicks::Now(); - UpdateThrottledTransactions(now); - if (start && latency_length_ != base::TimeDelta()) { - net::LoadTimingInfo load_timing_info; - base::TimeTicks send_end; - if (transaction->GetLoadTimingInfo(&load_timing_info)) - send_end = load_timing_info.send_end; - if (send_end.is_null()) - send_end = now; - int64_t us_send_end = (send_end - base::TimeTicks()).InMicroseconds(); - suspended_transactions_.push_back( - SuspendedTransaction(transaction, us_send_end)); - UpdateSuspendedTransactions(now); - } else { - throttled_transactions_.push_back(transaction); +uint64_t DevToolsNetworkInterceptor::UpdateThrottledRecords( + base::TimeTicks now, + ThrottleRecords* records, + uint64_t last_tick, + base::TimeDelta tick_length) { + if (tick_length.is_zero()) { + DCHECK(!records->size()); + return last_tick; } - ArmTimer(now); -} -void DevToolsNetworkInterceptor::UpdateThrottledTransactions( - base::TimeTicks now) { - int64_t last_tick = (now - offset_) / tick_length_; - int64_t ticks = last_tick - last_tick_; - last_tick_ = last_tick; + int64_t new_tick = (now - offset_) / tick_length; + int64_t ticks = new_tick - last_tick; - int64_t length = throttled_transactions_.size(); - if (!length) { - UpdateSuspendedTransactions(now); - return; - } + int64_t length = records->size(); + if (!length) + return new_tick; int64_t shift = ticks % length; for (int64_t i = 0; i < length; ++i) { - throttled_transactions_[i]->DecreaseThrottledByteCount( - (ticks / length) * kPacketSize + (i < shift ? kPacketSize : 0)); + (*records)[i].bytes -= + (ticks / length) * kPacketSize + (i < shift ? kPacketSize : 0); } - std::rotate(throttled_transactions_.begin(), - throttled_transactions_.begin() + shift, throttled_transactions_.end()); - - UpdateSuspendedTransactions(now); + std::rotate(records->begin(), records->end() + shift, records->end()); + return new_tick; } -void DevToolsNetworkInterceptor::UpdateSuspendedTransactions( - base::TimeTicks now) { +void DevToolsNetworkInterceptor::UpdateThrottled(base::TimeTicks now) { + download_last_tick_ = UpdateThrottledRecords( + now, &download_, download_last_tick_, download_tick_length_); + upload_last_tick_ = UpdateThrottledRecords( + now, &upload_, upload_last_tick_, upload_tick_length_); + UpdateSuspended(now); +} + +void DevToolsNetworkInterceptor::UpdateSuspended(base::TimeTicks now) { int64_t activation_baseline = - (now - latency_length_ - base::TimeTicks()).InMicroseconds(); - SuspendedTransactions suspended_transactions; - SuspendedTransactions::iterator it = suspended_transactions_.begin(); - for (; it != suspended_transactions_.end(); ++it) { - if (it->second <= activation_baseline) - throttled_transactions_.push_back(it->first); - else - suspended_transactions.push_back(*it); + (now - latency_length_ - base::TimeTicks::Now()).InMicroseconds(); + ThrottleRecords suspended; + for (const ThrottleRecord& record : suspended_) { + if (record.send_end <= activation_baseline) { + if (record.is_upload) + upload_.push_back(record); + else + download_.push_back(record); + } else { + suspended.push_back(record); + } } - suspended_transactions_.swap(suspended_transactions); + suspended_.swap(suspended); } -void DevToolsNetworkInterceptor::ArmTimer(base::TimeTicks now) { - size_t throttle_count = throttled_transactions_.size(); - size_t suspend_count = suspended_transactions_.size(); - if (!throttle_count && !suspend_count) - return; +void DevToolsNetworkInterceptor::CollectFinished( + ThrottleRecords* records, ThrottleRecords* finished) { + ThrottleRecords active; + for (const ThrottleRecord& record : *records) { + if (record.bytes < 0) + finished->push_back(record); + else + active.push_back(record); + } + records->swap(active); +} +void DevToolsNetworkInterceptor::OnTimer() { + base::TimeTicks now = base::TimeTicks::Now(); + UpdateThrottled(now); + + ThrottleRecords finished; + CollectFinished(&download_, &finished); + CollectFinished(&upload_, &finished); + for (const ThrottleRecord& record : finished) + record.callback.Run(record.result, record.bytes); + + ArmTimer(now); +} + +base::TimeTicks DevToolsNetworkInterceptor::CalculateDesiredTime( + const ThrottleRecords& records, + uint64_t last_tick, + base::TimeDelta tick_length) { int64_t min_ticks_left = 0x10000L; - for (size_t i = 0; i < throttle_count; ++i) { - int64_t packets_left = (throttled_transactions_[i]->throttled_byte_count() + - kPacketSize - 1) / kPacketSize; - int64_t ticks_left = (i + 1) + throttle_count * (packets_left - 1); + size_t count = records.size(); + for (size_t i = 0; i < count; ++i) { + int64_t packets_left = (records[i].bytes + kPacketSize - 1) / kPacketSize; + int64_t ticks_left = (i + 1) + count * (packets_left - 1); if (i == 0 || ticks_left < min_ticks_left) min_ticks_left = ticks_left; } + return offset_ + tick_length * (last_tick + min_ticks_left); +} - base::TimeTicks desired_time = - offset_ + tick_length_ * (last_tick_ + min_ticks_left); +void DevToolsNetworkInterceptor::ArmTimer(base::TimeTicks now) { + size_t suspend_count = suspended_.size(); + if (!download_.size() && !upload_.size() && !suspend_count) + return; + + base::TimeTicks desired_time = CalculateDesiredTime( + download_, download_last_tick_, download_tick_length_); + + base::TimeTicks upload_time = CalculateDesiredTime( + upload_, upload_last_tick_, upload_tick_length_); + if (upload_time < desired_time) + desired_time = upload_time; int64_t min_baseline = std::numeric_limits::max(); for (size_t i = 0; i < suspend_count; ++i) { - if (suspended_transactions_[i].second < min_baseline) - min_baseline = suspended_transactions_[i].second; + if (suspended_[i].send_end < min_baseline) + min_baseline = suspended_[i].send_end; } - if (suspend_count) { base::TimeTicks activation_time = base::TimeTicks() + base::TimeDelta::FromMicroseconds(min_baseline) + latency_length_; @@ -222,34 +220,69 @@ void DevToolsNetworkInterceptor::ArmTimer(base::TimeTicks now) { timer_.Start(FROM_HERE, desired_time - now, base::Bind(&DevToolsNetworkInterceptor::OnTimer, - base::Unretained(this))); + base::Unretained(this))); } -void DevToolsNetworkInterceptor::OnTimer() { - base::TimeTicks now = base::TimeTicks::Now(); - UpdateThrottledTransactions(now); +int DevToolsNetworkInterceptor::StartThrottle( + int result, + int64_t bytes, + base::TimeTicks send_end, + bool start, + bool is_upload, + const ThrottleCallback& callback) { + if (result < 0) + return result; - std::vector active_transactions; - std::vector finished_transactions; - size_t length = throttled_transactions_.size(); - for (size_t i = 0; i < length; ++i) { - if (throttled_transactions_[i]->throttled_byte_count() < 0) - finished_transactions.push_back(throttled_transactions_[i]); - else - active_transactions.push_back(throttled_transactions_[i]); + if (conditions_->offline()) + return is_upload ? result : net::ERR_INTERNET_DISCONNECTED; + + if ((is_upload && !conditions_->upload_throughput()) || + (!is_upload && !conditions_->download_throughput())) { + return result; } - throttled_transactions_.swap(active_transactions); - for (auto& transaction : finished_transactions) - FireThrottledCallback(transaction); + ThrottleRecord record; + record.result = result; + record.bytes = bytes; + record.callback = callback; + record.is_upload = is_upload; + base::TimeTicks now = base::TimeTicks::Now(); + UpdateThrottled(now); + if (start && latency_length_ != base::TimeDelta()) { + record.send_end = (send_end - base::TimeTicks()).InMicroseconds(); + suspended_.push_back(record); + UpdateSuspended(now); + } else { + if (is_upload) + upload_.push_back(record); + else + download_.push_back(record); + } ArmTimer(now); + + return net::ERR_IO_PENDING; } -void DevToolsNetworkInterceptor::FireThrottledCallback( - DevToolsNetworkTransaction* transaction) { - if (transactions_.find(transaction) != transactions_.end()) - transaction->FireThrottledCallback(); +void DevToolsNetworkInterceptor::StopThrottle( + const ThrottleCallback& callback) { + RemoveRecord(&download_, callback); + RemoveRecord(&upload_, callback); + RemoveRecord(&suspended_, callback); +} + +void DevToolsNetworkInterceptor::RemoveRecord( + ThrottleRecords* records, const ThrottleCallback& callback) { + records->erase( + std::remove_if(records->begin(), records->end(), + [&callback](const ThrottleRecord& record){ + return record.callback.Equals(callback); + }), + records->end()); +} + +bool DevToolsNetworkInterceptor::IsOffline() { + return conditions_->offline(); } } // namespace brightray diff --git a/brightray/browser/net/devtools_network_interceptor.h b/brightray/browser/net/devtools_network_interceptor.h index 60093d0ad63..d1293e41acc 100644 --- a/brightray/browser/net/devtools_network_interceptor.h +++ b/brightray/browser/net/devtools_network_interceptor.h @@ -5,7 +5,6 @@ #ifndef BROWSER_DEVTOOLS_NETWORK_INTERCEPTOR_H_ #define BROWSER_DEVTOOLS_NETWORK_INTERCEPTOR_H_ -#include #include #include #include @@ -26,6 +25,8 @@ class DevToolsNetworkTransaction; class DevToolsNetworkInterceptor { public: + using ThrottleCallback = base::Callback; + DevToolsNetworkInterceptor(); virtual ~DevToolsNetworkInterceptor(); @@ -34,45 +35,68 @@ class DevToolsNetworkInterceptor { // Applies network emulation configuration. void UpdateConditions(scoped_ptr conditions); - void AddTransaction(DevToolsNetworkTransaction* transaction); - void RemoveTransaction(DevToolsNetworkTransaction* transaction); + // Throttles with |is_upload == true| always succeed, even in offline mode. + int StartThrottle(int result, + int64_t bytes, + base::TimeTicks send_end, + bool start, + bool is_upload, + const ThrottleCallback& callback); + void StopThrottle(const ThrottleCallback& callback); - // Returns whether transaction should fail with |net::ERR_INTERNET_DISCONNECTED| - bool ShouldFail(const DevToolsNetworkTransaction* transaction); - // Returns whether transaction should be throttled. - bool ShouldThrottle(const DevToolsNetworkTransaction* transaction); - - void ThrottleTransaction(DevToolsNetworkTransaction* transaction, bool start); - - const DevToolsNetworkConditions* conditions() const { - return conditions_.get(); - } + bool IsOffline(); private: - void UpdateThrottledTransactions(base::TimeTicks now); - void UpdateSuspendedTransactions(base::TimeTicks now); - void ArmTimer(base::TimeTicks now); + struct ThrottleRecord { + public: + ThrottleRecord(); + ThrottleRecord(const ThrottleRecord& other); + ~ThrottleRecord(); + + int result; + int64_t bytes; + int64_t send_end; + bool is_upload; + ThrottleCallback callback; + }; + + using ThrottleRecords = std::vector; + + void FinishRecords(ThrottleRecords* records, bool offline); + + uint64_t UpdateThrottledRecords(base::TimeTicks now, + ThrottleRecords* records, + uint64_t last_tick, + base::TimeDelta tick_length); + void UpdateThrottled(base::TimeTicks now); + void UpdateSuspended(base::TimeTicks now); + + void CollectFinished(ThrottleRecords* records, ThrottleRecords* finished); void OnTimer(); - void FireThrottledCallback(DevToolsNetworkTransaction* transaction); + + base::TimeTicks CalculateDesiredTime(const ThrottleRecords& records, + uint64_t last_tick, + base::TimeDelta tick_length); + void ArmTimer(base::TimeTicks now); + + void RemoveRecord(ThrottleRecords* records, const ThrottleCallback& callback); scoped_ptr conditions_; - using Transactions = std::set; - Transactions transactions_; + // Throttables suspended for a "latency" period. + ThrottleRecords suspended_; - // Transactions suspended for a latency period. - using SuspendedTransaction = std::pair; - using SuspendedTransactions = std::vector; - SuspendedTransactions suspended_transactions_; - - // Transactions waiting certain amount of transfer to be accounted. - std::vector throttled_transactions_; + // Throttables waiting for certain amount of transfer to be "accounted". + ThrottleRecords download_; + ThrottleRecords upload_; base::OneShotTimer timer_; base::TimeTicks offset_; - base::TimeDelta tick_length_; + base::TimeDelta download_tick_length_; + base::TimeDelta upload_tick_length_; base::TimeDelta latency_length_; - uint64_t last_tick_; + uint64_t download_last_tick_; + uint64_t upload_last_tick_; base::WeakPtrFactory weak_ptr_factory_; diff --git a/brightray/browser/net/devtools_network_protocol_handler.cc b/brightray/browser/net/devtools_network_protocol_handler.cc index b06678fe92d..9febb2a677d 100644 --- a/brightray/browser/net/devtools_network_protocol_handler.cc +++ b/brightray/browser/net/devtools_network_protocol_handler.cc @@ -112,6 +112,15 @@ base::DictionaryValue* DevToolsNetworkProtocolHandler::HandleCommand( return nullptr; } +void DevToolsNetworkProtocolHandler::DevToolsAgentStateChanged( + content::DevToolsAgentHost* agent_host, + bool attached) { + scoped_ptr conditions; + if (attached) + conditions.reset(new DevToolsNetworkConditions(false)); + UpdateNetworkState(agent_host, std::move(conditions)); +} + scoped_ptr DevToolsNetworkProtocolHandler::CanEmulateNetworkConditions( content::DevToolsAgentHost* agent_host, diff --git a/brightray/browser/net/devtools_network_protocol_handler.h b/brightray/browser/net/devtools_network_protocol_handler.h index 4fba01b74d3..fd9c996cdc1 100644 --- a/brightray/browser/net/devtools_network_protocol_handler.h +++ b/brightray/browser/net/devtools_network_protocol_handler.h @@ -25,6 +25,8 @@ class DevToolsNetworkProtocolHandler { base::DictionaryValue* HandleCommand( content::DevToolsAgentHost* agent_host, base::DictionaryValue* command); + void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host, + bool attached); private: scoped_ptr CanEmulateNetworkConditions( diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc index f0d66a047bb..5e6bd59e866 100644 --- a/brightray/browser/net/devtools_network_transaction.cc +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -5,8 +5,8 @@ #include "browser/net/devtools_network_transaction.h" #include "browser/net/devtools_network_controller.h" -#include "browser/net/devtools_network_interceptor.h" - +#include "browser/net/devtools_network_upload_data_stream.h" +#include "net/base/load_timing_info.h" #include "net/base/net_errors.h" #include "net/base/upload_progress.h" #include "net/http/http_network_transaction.h" @@ -23,58 +23,84 @@ const char DevToolsNetworkTransaction::DevToolsNetworkTransaction( DevToolsNetworkController* controller, scoped_ptr transaction) - : controller_(controller), + : throttled_byte_count_(0), + controller_(controller), transaction_(std::move(transaction)), request_(nullptr), - failed_(false), - throttled_byte_count_(0), - callback_type_(NONE) { - proxy_callback_ = base::Bind(&DevToolsNetworkTransaction::OnCallback, - base::Unretained(this)); + failed_(false) { + DCHECK(controller); } DevToolsNetworkTransaction::~DevToolsNetworkTransaction() { - if (interceptor_) - interceptor_->RemoveTransaction(this); + if (interceptor_ && !throttle_callback_.is_null()) + interceptor_->StopThrottle(throttle_callback_); } -void DevToolsNetworkTransaction::ProcessRequest() { - DCHECK(request_); +void DevToolsNetworkTransaction::IOCallback( + const net::CompletionCallback& callback, bool start, int result) { + result = Throttle(callback, start, result); + if (result != net::ERR_IO_PENDING) + callback.Run(result); +} - bool has_devtools_client_id = request_->extra_headers.HasHeader( - kDevToolsEmulateNetworkConditionsClientId); - if (!has_devtools_client_id) - return; +int DevToolsNetworkTransaction::Throttle( + const net::CompletionCallback& callback, bool start, int result) { + if (failed_) + return net::ERR_INTERNET_DISCONNECTED; + if (!interceptor_ || result < 0) + return result; - custom_request_.reset(new net::HttpRequestInfo(*request_)); - custom_request_->extra_headers.GetHeader( - kDevToolsEmulateNetworkConditionsClientId, &client_id_); - custom_request_->extra_headers.RemoveHeader( - kDevToolsEmulateNetworkConditionsClientId); + base::TimeTicks send_end; + if (start) { + throttled_byte_count_ += transaction_->GetTotalReceivedBytes(); + net::LoadTimingInfo load_timing_info; + if (GetLoadTimingInfo(&load_timing_info)) + send_end = load_timing_info.send_end; + if (send_end.is_null()) + send_end = base::TimeTicks::Now(); + } + if (result > 0) + throttled_byte_count_ += result; - request_ = custom_request_.get(); + throttle_callback_ = base::Bind(&DevToolsNetworkTransaction::ThrottleCallback, + base::Unretained(this), + callback); + int rv = interceptor_->StartThrottle(result, throttled_byte_count_, send_end, + start, false, throttle_callback_); + if (rv != net::ERR_IO_PENDING) + throttle_callback_.Reset(); + if (rv == net::ERR_INTERNET_DISCONNECTED) + Fail(); + return rv; +} + +void DevToolsNetworkTransaction::ThrottleCallback( + const net::CompletionCallback& callback, int result, int64_t bytes) { + DCHECK(!throttle_callback_.is_null()); + throttle_callback_.Reset(); + if (result == net::ERR_INTERNET_DISCONNECTED) + Fail(); + throttled_byte_count_ = bytes; + callback.Run(result); } void DevToolsNetworkTransaction::Fail() { DCHECK(request_); DCHECK(!failed_); - failed_ = true; - transaction_->SetBeforeNetworkStartCallback( - BeforeNetworkStartCallback()); - - if (callback_.is_null()) - return; - - net::CompletionCallback original_callback = callback_; - callback_.Reset(); - callback_type_ = NONE; - original_callback.Run(net::ERR_INTERNET_DISCONNECTED); + transaction_->SetBeforeNetworkStartCallback(BeforeNetworkStartCallback()); + if (interceptor_) + interceptor_.reset(); } -void DevToolsNetworkTransaction::DecreaseThrottledByteCount( - int64_t delta) { - throttled_byte_count_ -= delta; +bool DevToolsNetworkTransaction::CheckFailed() { + if (failed_) + return true; + if (interceptor_ && interceptor_->IsOffline()) { + Fail(); + return true; + } + return false; } int DevToolsNetworkTransaction::Start( @@ -82,45 +108,90 @@ int DevToolsNetworkTransaction::Start( const net::CompletionCallback& callback, const net::BoundNetLog& net_log) { DCHECK(request); - request_ = request; - interceptor_ = controller_->GetInterceptor(this); - interceptor_->AddTransaction(this); - if (interceptor_->ShouldFail(this)) { - failed_ = true; - transaction_->SetBeforeNetworkStartCallback(BeforeNetworkStartCallback()); - return net::ERR_INTERNET_DISCONNECTED; + std::string client_id; + bool has_devtools_client_id = request_->extra_headers.HasHeader( + kDevToolsEmulateNetworkConditionsClientId); + if (has_devtools_client_id) { + custom_request_.reset(new net::HttpRequestInfo(*request_)); + custom_request_->extra_headers.GetHeader( + kDevToolsEmulateNetworkConditionsClientId, &client_id); + custom_request_->extra_headers.RemoveHeader( + kDevToolsEmulateNetworkConditionsClientId); + + if (request_->upload_data_stream) { + custom_upload_data_stream_.reset( + new DevToolsNetworkUploadDataStream(request_->upload_data_stream)); + custom_request_->upload_data_stream = custom_upload_data_stream_.get(); + } + + request_ = custom_request_.get(); } - int rv = transaction_->Start(request_, proxy_callback_, net_log); - return SetupCallback(callback, rv, START); + + DevToolsNetworkInterceptor* interceptor = controller_->GetInterceptor(client_id); + if (interceptor) { + interceptor_ = interceptor->GetWeakPtr(); + if (custom_upload_data_stream_) + custom_upload_data_stream_->SetInterceptor(interceptor); + } + + if (CheckFailed()) + return net::ERR_INTERNET_DISCONNECTED; + + if (!interceptor_) + return transaction_->Start(request_, callback, net_log); + + int result = transaction_->Start(request_, + base::Bind(&DevToolsNetworkTransaction::IOCallback, + base::Unretained(this), callback, true), + net_log); + return Throttle(callback, true, result); } int DevToolsNetworkTransaction::RestartIgnoringLastError( const net::CompletionCallback& callback) { - if (failed_) + if (CheckFailed()) return net::ERR_INTERNET_DISCONNECTED; - int rv = transaction_->RestartIgnoringLastError(proxy_callback_); - return SetupCallback(callback, rv, RESTART_IGNORING_LAST_ERROR); + if (!interceptor_) + return transaction_->RestartIgnoringLastError(callback); + + int result = transaction_->RestartIgnoringLastError( + base::Bind(&DevToolsNetworkTransaction::IOCallback, + base::Unretained(this), callback, true)); + return Throttle(callback, true, result); } int DevToolsNetworkTransaction::RestartWithCertificate( - net::X509Certificate* client_certificate, + net::X509Certificate* client_cert, net::SSLPrivateKey* client_private_key, const net::CompletionCallback& callback) { - if (failed_) + if (CheckFailed()) return net::ERR_INTERNET_DISCONNECTED; - int rv = transaction_->RestartWithCertificate(client_certificate, client_private_key, proxy_callback_); - return SetupCallback(callback, rv, RESTART_WITH_CERTIFICATE); + if (!interceptor_) { + return transaction_->RestartWithCertificate( + client_cert, client_private_key, callback); + } + + int result = transaction_->RestartWithCertificate( + client_cert, client_private_key, + base::Bind(&DevToolsNetworkTransaction::IOCallback, + base::Unretained(this), callback, true)); + return Throttle(callback, true, result); } int DevToolsNetworkTransaction::RestartWithAuth( const net::AuthCredentials& credentials, const net::CompletionCallback& callback) { - if (failed_) + if (CheckFailed()) return net::ERR_INTERNET_DISCONNECTED; - int rv = transaction_->RestartWithAuth(credentials, proxy_callback_); - return SetupCallback(callback, rv, RESTART_WITH_AUTH); + if (!interceptor_) + return transaction_->RestartWithAuth(credentials, callback); + + int result = transaction_->RestartWithAuth(credentials, + base::Bind(&DevToolsNetworkTransaction::IOCallback, + base::Unretained(this), callback, true)); + return Throttle(callback, true, result); } bool DevToolsNetworkTransaction::IsReadyToRestartForAuth() { @@ -128,13 +199,21 @@ bool DevToolsNetworkTransaction::IsReadyToRestartForAuth() { } int DevToolsNetworkTransaction::Read( - net::IOBuffer* buffer, - int length, + net::IOBuffer* buf, + int buf_len, const net::CompletionCallback& callback) { - if (failed_) + if (CheckFailed()) return net::ERR_INTERNET_DISCONNECTED; - int rv = transaction_->Read(buffer, length, proxy_callback_); - return SetupCallback(callback, rv, READ); + if (!interceptor_) + return transaction_->Read(buf, buf_len, callback); + + int result = transaction_->Read(buf, buf_len, + base::Bind(&DevToolsNetworkTransaction::IOCallback, + base::Unretained(this), callback, false)); + // URLRequestJob relies on synchronous end-of-stream notification. + if (result == 0) + return result; + return Throttle(callback, false, result); } void DevToolsNetworkTransaction::StopCaching() { @@ -221,76 +300,4 @@ void DevToolsNetworkTransaction::GetConnectionAttempts( transaction_->GetConnectionAttempts(out); } -void DevToolsNetworkTransaction::OnCallback(int rv) { - if (failed_ || callback_.is_null()) - return; - - if (callback_type_ == START || callback_type_ == READ) { - if (interceptor_ && interceptor_->ShouldThrottle(this)) { - Throttle(rv); - return; - } - } - - net::CompletionCallback original_callback = callback_; - callback_.Reset(); - callback_type_ = NONE; - original_callback.Run(rv); -} - -int DevToolsNetworkTransaction::SetupCallback( - net::CompletionCallback callback, - int result, - CallbackType callback_type) { - DCHECK(callback_type_ == NONE); - - if (result == net::ERR_IO_PENDING) { - callback_type_ = callback_type; - callback_ = callback; - return result; - } - - if (!interceptor_ || !interceptor_->ShouldThrottle(this)) - return result; - - // Only START and READ operation throttling is supported. - if (callback_type != START && callback_type != READ) - return result; - - // In case of error |throttled_byte_count_| is unknown. - if (result < 0) - return result; - - // URLRequestJob relies on synchronous end-of-stream notification. - if (callback_type == READ && result == 0) - return result; - - callback_type_ = callback_type; - callback_ = callback; - Throttle(result); - return net::ERR_IO_PENDING; -} - -void DevToolsNetworkTransaction::Throttle(int result) { - throttled_result_ = result; - - if (callback_type_ == START) - throttled_byte_count_ += transaction_->GetTotalReceivedBytes(); - if (result > 0) - throttled_byte_count_ += result; - - if (interceptor_) - interceptor_->ThrottleTransaction(this, callback_type_ == START); -} - -void DevToolsNetworkTransaction::FireThrottledCallback() { - DCHECK(!callback_.is_null()); - DCHECK(callback_type_ == READ || callback_type_ == START); - - net::CompletionCallback original_callback = callback_; - callback_.Reset(); - callback_type_ = NONE; - original_callback.Run(throttled_result_); -} - } // namespace brightray diff --git a/brightray/browser/net/devtools_network_transaction.h b/brightray/browser/net/devtools_network_transaction.h index f8e54e67775..a7f08651f65 100644 --- a/brightray/browser/net/devtools_network_transaction.h +++ b/brightray/browser/net/devtools_network_transaction.h @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" +#include "browser/net/devtools_network_interceptor.h" #include "net/base/completion_callback.h" #include "net/base/load_states.h" #include "net/base/request_priority.h" @@ -18,7 +19,7 @@ namespace brightray { class DevToolsNetworkController; -class DevToolsNetworkInterceptor; +class DevToolsNetworkUploadDataStream; class DevToolsNetworkTransaction : public net::HttpTransaction { public: @@ -29,16 +30,6 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { scoped_ptr network_transaction); ~DevToolsNetworkTransaction() override; - // Checks if request contains DevTools specific headers. Found values are - // remembered and corresponding keys are removed from headers. - void ProcessRequest(); - - // Runs callback with net::ERR_INTERNET_DISCONNECTED result. - void Fail(); - - void DecreaseThrottledByteCount(int64_t delta); - void FireThrottledCallback(); - // HttpTransaction methods: int Start(const net::HttpRequestInfo* request, const net::CompletionCallback& callback, @@ -77,39 +68,30 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { int ResumeNetworkStart() override; void GetConnectionAttempts(net::ConnectionAttempts* out) const override; - bool failed() const { return failed_; } - - const net::HttpRequestInfo* request() const { return request_; } - - int64_t throttled_byte_count() const { return throttled_byte_count_; } - - const std::string& client_id() const { - return client_id_; - } - private: - enum CallbackType { - NONE, - READ, - RESTART_IGNORING_LAST_ERROR, - RESTART_WITH_AUTH, - RESTART_WITH_CERTIFICATE, - START - }; + void Fail(); + bool CheckFailed(); - // Proxy callback handler. Runs saved callback. - void OnCallback(int result); + void IOCallback(const net::CompletionCallback& callback, + bool start, + int result); + int Throttle(const net::CompletionCallback& callback, + bool start, + int result); + void ThrottleCallback(const net::CompletionCallback& callback, + int result, + int64_t bytes); - int SetupCallback( - net::CompletionCallback callback, - int result, - CallbackType callback_type); - void Throttle(int result); + DevToolsNetworkInterceptor::ThrottleCallback throttle_callback_; + int64_t throttled_byte_count_; DevToolsNetworkController* controller_; base::WeakPtr interceptor_; - // Modified request. Should be destructed after |transaction_| + // Modified upload data stream. Should be destructed after |custom_request_|. + scoped_ptr custom_upload_data_stream_; + + // Modified request. Should be destructed after |transaction_|. scoped_ptr custom_request_; // Original network transaction. @@ -120,15 +102,6 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { // True if Fail was already invoked. bool failed_; - // Value of "X-DevTools-Emulate-Network-Conditions-Client-Id" request header. - std::string client_id_; - - int throttled_result_; - int64_t throttled_byte_count_; - CallbackType callback_type_; - net::CompletionCallback proxy_callback_; - net::CompletionCallback callback_; - DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkTransaction); }; diff --git a/brightray/browser/net/devtools_network_upload_data_stream.cc b/brightray/browser/net/devtools_network_upload_data_stream.cc new file mode 100644 index 00000000000..31bd8f38199 --- /dev/null +++ b/brightray/browser/net/devtools_network_upload_data_stream.cc @@ -0,0 +1,94 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "browser/net/devtools_network_upload_data_stream.h" + +#include "net/base/net_errors.h" + +namespace brightray { + +DevToolsNetworkUploadDataStream::DevToolsNetworkUploadDataStream( + net::UploadDataStream* upload_data_stream) + : net::UploadDataStream(upload_data_stream->is_chunked(), + upload_data_stream->identifier()), + throttle_callback_( + base::Bind(&DevToolsNetworkUploadDataStream::ThrottleCallback, + base::Unretained(this))), + throttled_byte_count_(0), + upload_data_stream_(upload_data_stream) { +} + +DevToolsNetworkUploadDataStream::~DevToolsNetworkUploadDataStream() { + if (interceptor_) + interceptor_->StopThrottle(throttle_callback_); +} + +void DevToolsNetworkUploadDataStream::SetInterceptor( + DevToolsNetworkInterceptor* interceptor) { + DCHECK(!interceptor_); + if (interceptor) + interceptor_ = interceptor->GetWeakPtr(); +} + +bool DevToolsNetworkUploadDataStream::IsInMemory() const { + return false; +} + +int DevToolsNetworkUploadDataStream::InitInternal() { + throttled_byte_count_ = 0; + int result = upload_data_stream_->Init( + base::Bind(&DevToolsNetworkUploadDataStream::StreamInitCallback, + base::Unretained(this))); + if (result == net::OK && !is_chunked()) + SetSize(upload_data_stream_->size()); + return result; +} + +void DevToolsNetworkUploadDataStream::StreamInitCallback(int result) { + if (!is_chunked()) + SetSize(upload_data_stream_->size()); + OnInitCompleted(result); +} + +int DevToolsNetworkUploadDataStream::ReadInternal( + net::IOBuffer* buf, int buf_len) { + int result = upload_data_stream_->Read(buf, buf_len, + base::Bind(&DevToolsNetworkUploadDataStream::StreamReadCallback, + base::Unretained(this))); + return ThrottleRead(result); +} + +void DevToolsNetworkUploadDataStream::StreamReadCallback(int result) { + result = ThrottleRead(result); + if (result != net::ERR_IO_PENDING) + OnReadCompleted(result); +} + +int DevToolsNetworkUploadDataStream::ThrottleRead(int result) { + if (is_chunked() && upload_data_stream_->IsEOF()) + SetIsFinalChunk(); + + if (!interceptor_ || result < 0) + return result; + + if (result > 0) + throttled_byte_count_ += result; + return interceptor_->StartThrottle(result, throttled_byte_count_, + base::TimeTicks(), false, true, throttle_callback_); +} + +void DevToolsNetworkUploadDataStream::ThrottleCallback( + int result, int64_t bytes) { + throttled_byte_count_ = bytes; + OnReadCompleted(result); +} + +void DevToolsNetworkUploadDataStream::ResetInternal() { + upload_data_stream_->Reset(); + throttled_byte_count_ = 0; + if (interceptor_) + interceptor_->StopThrottle(throttle_callback_); +} + +} // namespace brightray diff --git a/brightray/browser/net/devtools_network_upload_data_stream.h b/brightray/browser/net/devtools_network_upload_data_stream.h new file mode 100644 index 00000000000..e297836f8c5 --- /dev/null +++ b/brightray/browser/net/devtools_network_upload_data_stream.h @@ -0,0 +1,51 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BROWSER_DEVTOOLS_NETWORK_UPLOAD_DATA_STREAM_H_ +#define BROWSER_DEVTOOLS_NETWORK_UPLOAD_DATA_STREAM_H_ + +#include + +#include "base/macros.h" +#include "base/memory/weak_ptr.h" +#include "browser/net/devtools_network_interceptor.h" +#include "net/base/completion_callback.h" +#include "net/base/upload_data_stream.h" + +namespace brightray { + +class DevToolsNetworkUploadDataStream : public net::UploadDataStream { + public: + // Supplied |upload_data_stream| must outlive this object. + explicit DevToolsNetworkUploadDataStream( + net::UploadDataStream* upload_data_stream); + ~DevToolsNetworkUploadDataStream() override; + + void SetInterceptor(DevToolsNetworkInterceptor* interceptor); + + private: + // net::UploadDataStream implementation. + bool IsInMemory() const override; + int InitInternal() override; + int ReadInternal(net::IOBuffer* buf, int buf_len) override; + void ResetInternal() override; + + void StreamInitCallback(int result); + void StreamReadCallback(int result); + + int ThrottleRead(int result); + void ThrottleCallback(int result, int64_t bytes); + + DevToolsNetworkInterceptor::ThrottleCallback throttle_callback_; + int64_t throttled_byte_count_; + + net::UploadDataStream* upload_data_stream_; + base::WeakPtr interceptor_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkUploadDataStream); +}; + +} // namespace brightray + +#endif // BROWSER_DEVTOOLS_NETWORK_UPLOAD_DATA_STREAM_H_ diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index c61af39748b..e65e87307c3 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -53,6 +53,8 @@ 'browser/net/devtools_network_transaction_factory.h', 'browser/net/devtools_network_transaction.cc', 'browser/net/devtools_network_transaction.h', + 'browser/net/devtools_network_upload_data_stream.cc', + 'browser/net/devtools_network_upload_data_stream.h', 'browser/net_log.cc', 'browser/net_log.h', 'browser/network_delegate.cc', From c25264113f41892f29df4fb4622759bfd79cee76 Mon Sep 17 00:00:00 2001 From: Robo Date: Tue, 15 Mar 2016 07:53:40 +0530 Subject: [PATCH 0785/1195] fix devtools filesystem api and allow delegate to request stored filesystem paths --- .../browser/devtools_embedder_message_dispatcher.h | 2 +- brightray/browser/inspectable_web_contents_delegate.h | 1 + brightray/browser/inspectable_web_contents_impl.cc | 10 ++++++---- brightray/browser/inspectable_web_contents_impl.h | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index eb3dc389786..4401bd5ab85 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -49,7 +49,7 @@ class DevToolsEmbedderMessageDispatcher { virtual void AppendToFile(const std::string& url, const std::string& content) = 0; virtual void RequestFileSystems() = 0; - virtual void AddFileSystem() = 0; + virtual void AddFileSystem(const std::string& file_system_path) = 0; virtual void RemoveFileSystem(const std::string& file_system_path) = 0; virtual void UpgradeDraggedFileSystemPermissions( const std::string& file_system_url) = 0; diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index 9c4ee722c2a..e9f071cb4d0 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -14,6 +14,7 @@ class InspectableWebContentsDelegate { const std::string& url, const std::string& content, bool save_as) {} virtual void DevToolsAppendToFile( const std::string& url, const std::string& content) {} + virtual void DevToolsRequestFileSystems() {} virtual void DevToolsAddFileSystem( const base::FilePath& file_system_path) {} virtual void DevToolsRemoveFileSystem( diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 8217812b58c..9484593de47 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -420,13 +420,15 @@ void InspectableWebContentsImpl::AppendToFile( } void InspectableWebContentsImpl::RequestFileSystems() { - GetDevToolsWebContents()->GetMainFrame()->ExecuteJavaScript( - base::ASCIIToUTF16("DevToolsAPI.fileSystemsLoaded([])")); + if (delegate_) + delegate_->DevToolsRequestFileSystems(); } -void InspectableWebContentsImpl::AddFileSystem() { +void InspectableWebContentsImpl::AddFileSystem( + const std::string& file_system_path) { if (delegate_) - delegate_->DevToolsAddFileSystem(base::FilePath()); + delegate_->DevToolsAddFileSystem( + base::FilePath::FromUTF8Unsafe(file_system_path)); } void InspectableWebContentsImpl::RemoveFileSystem( diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 1e2bab8a26c..518fc853cb1 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -89,7 +89,7 @@ class InspectableWebContentsImpl : void AppendToFile(const std::string& url, const std::string& content) override; void RequestFileSystems() override; - void AddFileSystem() override; + void AddFileSystem(const std::string& file_system_path) override; void RemoveFileSystem(const std::string& file_system_path) override; void UpgradeDraggedFileSystemPermissions( const std::string& file_system_url) override; From b68be5c583e7f8ec956f3c91cfa464c8b00162c5 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Tue, 15 Mar 2016 17:10:24 -0700 Subject: [PATCH 0786/1195] :checkered_flag: Notify only when enabled - Previously, we'd attempt to create a notification no matter what the user's configuration was. Microsoft advises against that, because it can create race conditions if notifications are disabled. - This fixes the issue. Closes https://github.com/atom/electron/issues/4681 --- brightray/browser/win/windows_toast_notification.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 74cd74ecebd..a744c888154 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -89,7 +89,16 @@ void WindowsToastNotification::Show( const bool silent) { auto presenter_win = static_cast(presenter()); std::wstring icon_path = presenter_win->SaveIconToFilesystem(icon, icon_url); - + + // Ask Windows for the current notification settings + // If not allowed, we return here (0 = enabled) + ABI::Windows::UI::Notifications::NotificationSetting setting; + toast_notifier_->get_Setting(&setting); + if (setting != 0) { + NotificationFailed(); + return; + } + ComPtr toast_xml; if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, silent, &toast_xml))) { NotificationFailed(); From b6312ce63c658736874d243bc2fe290e63f7197c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 4 Apr 2016 12:55:40 -0700 Subject: [PATCH 0787/1195] Update urls for new GitHub org --- brightray/.gitmodules | 2 +- brightray/README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/brightray/.gitmodules b/brightray/.gitmodules index b1e57ad74f0..e7b61d62c5b 100644 --- a/brightray/.gitmodules +++ b/brightray/.gitmodules @@ -1,6 +1,6 @@ [submodule "vendor/libchromiumcontent"] path = vendor/libchromiumcontent - url = https://github.com/atom/libchromiumcontent + url = https://github.com/electron/libchromiumcontent [submodule "vendor/gyp"] path = vendor/gyp url = https://github.com/svn2github/gyp diff --git a/brightray/README.md b/brightray/README.md index 2c118f5cabc..eba0f515c9a 100644 --- a/brightray/README.md +++ b/brightray/README.md @@ -1,12 +1,12 @@ # Brightray Brightray is a static library that makes -[libchromiumcontent](https://github.com/atom/libchromiumcontent) easier to +[libchromiumcontent](https://github.com/electron/libchromiumcontent) easier to use in applications. ## Using it in your app -See [brightray_example](https://github.com/atom/brightray_example) for a +See [brightray_example](https://github.com/electron/brightray_example) for a sample application written using Brightray. ## Development @@ -34,7 +34,7 @@ You must previously have built and uploaded libchromiumcontent using its Building Brightray on its own isn’t all that interesting, since it’s just a static library. Building it into an application (like -[brightray_example](https://github.com/atom/brightray_example)) is the only +[brightray_example](https://github.com/electron/brightray_example)) is the only way to test it. ## License From 2b3813135ccbfc0e725b842a33d17b0c785941eb Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 7 Apr 2016 16:25:30 +0530 Subject: [PATCH 0788/1195] register localized media strings --- brightray/browser/browser_main_parts.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 279eff9b818..888a1c52956 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -11,9 +11,11 @@ #include "base/command_line.h" #include "base/strings/string_number_conversions.h" +#include "base/strings/utf_string_conversions.h" #include "components/devtools_http_handler/devtools_http_handler.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" +#include "media/base/media_resources.h" #include "net/proxy/proxy_resolver_v8.h" #include "ui/base/l10n/l10n_util.h" @@ -129,6 +131,19 @@ int X11EmptyIOErrorHandler(Display* d) { } #endif +base::string16 MediaStringProvider(media::MessageId id) { + switch (id) { + case media::DEFAULT_AUDIO_DEVICE_NAME: + return base::ASCIIToUTF16("Default"); +#if defined(OS_WIN) + case media::COMMUNICATIONS_AUDIO_DEVICE_NAME: + return base::ASCIIToUTF16("Communications"); +#endif + default: + return base::string16(); + } +} + } // namespace BrowserMainParts::BrowserMainParts() { @@ -177,6 +192,7 @@ void BrowserMainParts::PreMainMessageLoopStart() { #if defined(OS_MACOSX) InitializeMainNib(); #endif + media::SetLocalizedStringProvider(MediaStringProvider); } void BrowserMainParts::PreMainMessageLoopRun() { From 13a5dd4800276ad67244fb76f473deff1a0bccd7 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 11 Apr 2016 15:08:15 +0530 Subject: [PATCH 0789/1195] link libsecurity_state for providing security style --- brightray/brightray.gyp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index f3e0a54bd17..a0a2cdc0ea8 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -95,6 +95,7 @@ '<(libchromiumcontent_dir)/libwebrtc_common.a', '<(libchromiumcontent_dir)/libyuv.a', '<(libchromiumcontent_dir)/libcdm_renderer.a', + '<(libchromiumcontent_dir)/libsecurity_state.a', ], }, }, { @@ -149,6 +150,7 @@ '<(libchromiumcontent_dir)/libwebrtc_common.a', '<(libchromiumcontent_dir)/libyuv.a', '<(libchromiumcontent_dir)/libcdm_renderer.a', + '<(libchromiumcontent_dir)/libsecurity_state.a', ], }, }, { @@ -210,6 +212,7 @@ '<(libchromiumcontent_dir)/webrtc_common.lib', '<(libchromiumcontent_dir)/libyuv.lib', '<(libchromiumcontent_dir)/cdm_renderer.lib', + '<(libchromiumcontent_dir)/security_state.lib', ], }, }, { From 11685faffa9c7664198cbdeb16c37fafba3a0428 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 12 Apr 2016 16:35:35 +0900 Subject: [PATCH 0790/1195] Hijack the Page.reload command --- brightray/browser/inspectable_web_contents_delegate.h | 1 + brightray/browser/inspectable_web_contents_impl.cc | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index e9f071cb4d0..7f004dd4fbd 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -10,6 +10,7 @@ class InspectableWebContentsDelegate { virtual ~InspectableWebContentsDelegate() {} // Requested by WebContents of devtools. + virtual void DevToolsReloadPage() {} virtual void DevToolsSaveToFile( const std::string& url, const std::string& content, bool save_as) {} virtual void DevToolsAppendToFile( diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 9484593de47..64544058951 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -18,6 +18,7 @@ #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/prefs/scoped_user_pref_update.h" +#include "base/strings/pattern.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" @@ -480,6 +481,16 @@ void InspectableWebContentsImpl::SetDevicesUpdatesEnabled(bool enabled) { void InspectableWebContentsImpl::DispatchProtocolMessageFromDevToolsFrontend( const std::string& message) { + // If the devtools wants to reload the page, hijack the message and handle it + // to the delegate. + if (base::MatchPattern(message, "{\"id\":*," + "\"method\":\"Page.reload\"," + "\"params\":*}")) { + if (delegate_) + delegate_->DevToolsReloadPage(); + return; + } + if (agent_host_.get()) agent_host_->DispatchProtocolMessage(message); } From 4e7f478d1e512cf20509b79ba07c7d91655e0c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 13 Apr 2016 04:02:23 +0200 Subject: [PATCH 0791/1195] LibnotifyLoader: add notify_get_server_info support --- brightray/browser/linux/libnotify_loader.cc | 10 ++++++++++ brightray/browser/linux/libnotify_loader.h | 1 + 2 files changed, 11 insertions(+) diff --git a/brightray/browser/linux/libnotify_loader.cc b/brightray/browser/linux/libnotify_loader.cc index ede4eeec670..61d74226895 100644 --- a/brightray/browser/linux/libnotify_loader.cc +++ b/brightray/browser/linux/libnotify_loader.cc @@ -38,6 +38,15 @@ bool LibNotifyLoader::Load(const std::string& library_name) { return false; } + notify_get_server_info = + reinterpret_castnotify_get_server_info)>( + dlsym(library_, "notify_get_server_info")); + notify_get_server_info = &::notify_get_server_info; + if (!notify_get_server_info) { + CleanUp(true); + return false; + } + notify_notification_new = reinterpret_castnotify_notification_new)>( dlsym(library_, "notify_notification_new")); @@ -104,6 +113,7 @@ void LibNotifyLoader::CleanUp(bool unload) { loaded_ = false; notify_is_initted = NULL; notify_init = NULL; + notify_get_server_info = NULL; notify_notification_new = NULL; notify_notification_add_action = NULL; notify_notification_set_image_from_pixbuf = NULL; diff --git a/brightray/browser/linux/libnotify_loader.h b/brightray/browser/linux/libnotify_loader.h index 6cf2853af2c..32b01cf4332 100644 --- a/brightray/browser/linux/libnotify_loader.h +++ b/brightray/browser/linux/libnotify_loader.h @@ -20,6 +20,7 @@ class LibNotifyLoader { decltype(&::notify_is_initted) notify_is_initted; decltype(&::notify_init) notify_init; + decltype(&::notify_get_server_info) notify_get_server_info; decltype(&::notify_notification_new) notify_notification_new; decltype(&::notify_notification_add_action) notify_notification_add_action; decltype(&::notify_notification_set_image_from_pixbuf) notify_notification_set_image_from_pixbuf; From a22dc8676f24899e01a18d85b430ff53df2b739c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 13 Apr 2016 04:42:01 +0200 Subject: [PATCH 0792/1195] LibnotifyLoader: add notify_get_server_caps support --- brightray/browser/linux/libnotify_loader.cc | 10 ++++++++++ brightray/browser/linux/libnotify_loader.h | 1 + 2 files changed, 11 insertions(+) diff --git a/brightray/browser/linux/libnotify_loader.cc b/brightray/browser/linux/libnotify_loader.cc index 61d74226895..f5c384db567 100644 --- a/brightray/browser/linux/libnotify_loader.cc +++ b/brightray/browser/linux/libnotify_loader.cc @@ -47,6 +47,15 @@ bool LibNotifyLoader::Load(const std::string& library_name) { return false; } + notify_get_server_caps = + reinterpret_castnotify_get_server_caps)>( + dlsym(library_, "notify_get_server_caps")); + notify_get_server_caps = &::notify_get_server_caps; + if (!notify_get_server_caps) { + CleanUp(true); + return false; + } + notify_notification_new = reinterpret_castnotify_notification_new)>( dlsym(library_, "notify_notification_new")); @@ -114,6 +123,7 @@ void LibNotifyLoader::CleanUp(bool unload) { notify_is_initted = NULL; notify_init = NULL; notify_get_server_info = NULL; + notify_get_server_caps = NULL; notify_notification_new = NULL; notify_notification_add_action = NULL; notify_notification_set_image_from_pixbuf = NULL; diff --git a/brightray/browser/linux/libnotify_loader.h b/brightray/browser/linux/libnotify_loader.h index 32b01cf4332..818b0ddae07 100644 --- a/brightray/browser/linux/libnotify_loader.h +++ b/brightray/browser/linux/libnotify_loader.h @@ -20,6 +20,7 @@ class LibNotifyLoader { decltype(&::notify_is_initted) notify_is_initted; decltype(&::notify_init) notify_init; + decltype(&::notify_get_server_caps) notify_get_server_caps; decltype(&::notify_get_server_info) notify_get_server_info; decltype(&::notify_notification_new) notify_notification_new; decltype(&::notify_notification_add_action) notify_notification_add_action; From 743ceed7802f5a9e533a8763e13732cfb38c2ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 13 Apr 2016 04:43:22 +0200 Subject: [PATCH 0793/1195] LibnotifyNotification: verify if the "actions" capability is supported before adding actions This would prevent to add actions to notifier such as Ubuntu's Notify-OSD which doesn't support them. --- .../browser/linux/libnotify_notification.cc | 46 ++++++++----------- .../browser/linux/libnotify_notification.h | 2 - 2 files changed, 18 insertions(+), 30 deletions(-) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index a903007b523..3d9fec263ee 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -15,32 +15,26 @@ namespace brightray { namespace { +LibNotifyLoader libnotify_loader_; -bool unity_has_result = false; -bool unity_result = false; - -bool UnityIsRunning() { +bool NotifierSupportsActions() { if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER")) - return true; + return false; - if (unity_has_result) - return unity_result; + static bool notify_has_result = false; + static bool notify_result = false; + GList *capabilities = NULL; - unity_has_result = true; + if (notify_has_result) + return notify_result; - // Look for the presence of libunity as our hint that we're under Ubuntu. - base::FileEnumerator enumerator(base::FilePath("/usr/lib"), - false, base::FileEnumerator::FILES); - base::FilePath haystack; - while (!((haystack = enumerator.Next()).empty())) { - if (base::StartsWith(haystack.value(), "/usr/lib/libunity-", - base::CompareCase::SENSITIVE)) { - unity_result = true; - break; - } - } + capabilities = libnotify_loader_.notify_get_server_caps(); - return unity_result; + if (g_list_find_custom(capabilities, "actions", (GCompareFunc) g_strcmp0) != NULL) + notify_result = true; + + g_list_free_full(capabilities, g_free); + return notify_result; } void log_and_clear_error(GError* error, const char* context) { @@ -59,9 +53,6 @@ Notification* Notification::Create(NotificationDelegate* delegate, return new LibnotifyNotification(delegate, presenter); } -// static -LibNotifyLoader LibnotifyNotification::libnotify_loader_; - // static bool LibnotifyNotification::Initialize() { if (!libnotify_loader_.Load("libnotify.so.4") && @@ -83,6 +74,7 @@ LibnotifyNotification::LibnotifyNotification(NotificationDelegate* delegate, } LibnotifyNotification::~LibnotifyNotification() { + g_signal_handlers_disconnect_by_data(notification_, this); g_object_unref(notification_); } @@ -99,11 +91,9 @@ void LibnotifyNotification::Show(const base::string16& title, g_signal_connect( notification_, "closed", G_CALLBACK(OnNotificationClosedThunk), this); - // NB: On Unity, adding a notification action will cause the notification - // to display as a modal dialog box. Testing for distros that have "Unity - // Zen Nature" is difficult, we will test for the presence of the indicate - // dbus service - if (!UnityIsRunning()) { + // 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. + if (NotifierSupportsActions()) { libnotify_loader_.notify_notification_add_action( notification_, "default", "View", OnNotificationViewThunk, this, nullptr); diff --git a/brightray/browser/linux/libnotify_notification.h b/brightray/browser/linux/libnotify_notification.h index 17fb427bcf4..24a4debada4 100644 --- a/brightray/browser/linux/libnotify_notification.h +++ b/brightray/browser/linux/libnotify_notification.h @@ -35,8 +35,6 @@ class LibnotifyNotification : public Notification { void NotificationFailed(); - static LibNotifyLoader libnotify_loader_; - NotifyNotification* notification_; DISALLOW_COPY_AND_ASSIGN(LibnotifyNotification); From 59ed6ad41366c29087fba7bcda65f1efcad098e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 13 Apr 2016 05:31:56 +0200 Subject: [PATCH 0794/1195] Notification: pass tag to Show method --- brightray/browser/linux/libnotify_notification.cc | 1 + brightray/browser/linux/libnotify_notification.h | 1 + brightray/browser/mac/cocoa_notification.h | 1 + brightray/browser/mac/cocoa_notification.mm | 1 + brightray/browser/notification.h | 1 + brightray/browser/platform_notification_service.cc | 2 +- brightray/browser/win/windows_toast_notification.cc | 1 + brightray/browser/win/windows_toast_notification.h | 1 + 8 files changed, 8 insertions(+), 1 deletion(-) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index a903007b523..bd94ef35a67 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -88,6 +88,7 @@ LibnotifyNotification::~LibnotifyNotification() { void LibnotifyNotification::Show(const base::string16& title, const base::string16& body, + const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) { diff --git a/brightray/browser/linux/libnotify_notification.h b/brightray/browser/linux/libnotify_notification.h index 17fb427bcf4..505816ae35b 100644 --- a/brightray/browser/linux/libnotify_notification.h +++ b/brightray/browser/linux/libnotify_notification.h @@ -22,6 +22,7 @@ class LibnotifyNotification : public Notification { // Notification: void Show(const base::string16& title, const base::string16& msg, + const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) override; diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index 8cefb3a59b7..dd7d3cae4b0 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -22,6 +22,7 @@ class CocoaNotification : public Notification { // Notification: void Show(const base::string16& title, const base::string16& msg, + const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) override; diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index fefae397880..febd2af4c94 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -30,6 +30,7 @@ CocoaNotification::~CocoaNotification() { void CocoaNotification::Show(const base::string16& title, const base::string16& body, + const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) { diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index 5f1396c8e3e..30ac680d25f 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -21,6 +21,7 @@ class Notification { // Shows the notification. virtual void Show(const base::string16& title, const base::string16& msg, + const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) = 0; diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 7971f281001..146cd968c9b 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -37,7 +37,7 @@ void OnWebNotificationAllowed( auto notification = presenter->CreateNotification(adapter.get()); if (notification) { ignore_result(adapter.release()); // it will release itself automatically. - notification->Show(data.title, data.body, data.icon, icon, data.silent); + notification->Show(data.title, data.body, data.tag, data.icon, icon, data.silent); *cancel_callback = base::Bind(&RemoveNotification, notification); } } diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index a744c888154..401473b9c3e 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -84,6 +84,7 @@ WindowsToastNotification::~WindowsToastNotification() { void WindowsToastNotification::Show( const base::string16& title, const base::string16& msg, + const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) { diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index d5e5f2a82cf..c603ce3d796 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -41,6 +41,7 @@ class WindowsToastNotification : public Notification { // Notification: void Show(const base::string16& title, const base::string16& msg, + const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) override; From 1ce34fb8d276037c48da3121291a97d9501cc96b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 13 Apr 2016 06:08:35 +0200 Subject: [PATCH 0795/1195] LibnotifyNotification: add support for notification tag We set the id of the notification if tag is provided. As per the protocol, this should cause the old notification with same ID to be replaced. --- brightray/browser/linux/libnotify_notification.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index bd94ef35a67..37aef607136 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -119,6 +119,11 @@ void LibnotifyNotification::Show(const base::string16& title, g_object_unref(pixbuf); } + if (!tag.empty()) { + GQuark id = g_quark_from_string(tag.c_str()); + g_object_set(G_OBJECT(notification_), "id", id, NULL); + } + GError* error = nullptr; libnotify_loader_.notify_notification_show(notification_, &error); if (error) { From de60acbfdeb98531c6057f714adc931c44e4c887 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 14 Apr 2016 06:59:14 +0530 Subject: [PATCH 0796/1195] Fix race initialising DevtoolsNetworkController --- brightray/browser/browser_context.cc | 8 +-- brightray/browser/browser_context.h | 11 +++- .../net/devtools_network_controller_handle.cc | 60 +++++++++++++++++++ .../net/devtools_network_controller_handle.h | 44 ++++++++++++++ .../net/devtools_network_interceptor.cc | 8 +-- .../net/devtools_network_protocol_handler.cc | 14 +---- .../net/devtools_network_transaction.cc | 2 +- .../browser/url_request_context_getter.cc | 10 ++-- .../browser/url_request_context_getter.h | 6 +- brightray/filenames.gypi | 2 + 10 files changed, 130 insertions(+), 35 deletions(-) create mode 100644 brightray/browser/net/devtools_network_controller_handle.cc create mode 100644 brightray/browser/net/devtools_network_controller_handle.h diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 6181f8ec632..11214bd38ab 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -141,7 +141,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( DCHECK(!url_request_getter_.get()); url_request_getter_ = new URLRequestContextGetter( this, - GetDevToolsNetworkController(), + network_controller_handle(), net_log, GetPath(), in_memory_, @@ -153,12 +153,6 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( return url_request_getter_.get(); } -DevToolsNetworkController* BrowserContext::GetDevToolsNetworkController() { - if (!controller_) - controller_.reset(new DevToolsNetworkController); - return controller_.get(); -} - net::NetworkDelegate* BrowserContext::CreateNetworkDelegate() { return new NetworkDelegate; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 9866732cbcb..5ec2b2bcede 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -7,7 +7,7 @@ #include -#include "browser/net/devtools_network_controller.h" +#include "browser/net/devtools_network_controller_handle.h" #include "browser/permission_manager.h" #include "browser/url_request_context_getter.h" @@ -63,12 +63,15 @@ class BrowserContext : public base::RefCounted, NetLog* net_log, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors); - DevToolsNetworkController* GetDevToolsNetworkController(); net::URLRequestContextGetter* url_request_context_getter() const { return url_request_getter_.get(); } + DevToolsNetworkControllerHandle* network_controller_handle() { + return &network_controller_handle_; + } + void InitPrefs(); PrefService* prefs() { return prefs_.get(); } @@ -114,8 +117,10 @@ class BrowserContext : public base::RefCounted, base::FilePath path_; bool in_memory_; + + DevToolsNetworkControllerHandle network_controller_handle_; + scoped_ptr resource_context_; - scoped_ptr controller_; scoped_refptr url_request_getter_; scoped_refptr storage_policy_; scoped_ptr prefs_; diff --git a/brightray/browser/net/devtools_network_controller_handle.cc b/brightray/browser/net/devtools_network_controller_handle.cc new file mode 100644 index 00000000000..efc53a23a17 --- /dev/null +++ b/brightray/browser/net/devtools_network_controller_handle.cc @@ -0,0 +1,60 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#include "browser/net/devtools_network_controller_handle.h" + +#include "base/bind.h" +#include "browser/net/devtools_network_conditions.h" +#include "browser/net/devtools_network_controller.h" +#include "content/public/browser/browser_thread.h" + +using content::BrowserThread; + +namespace brightray { + +DevToolsNetworkControllerHandle::DevToolsNetworkControllerHandle() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); +} + +DevToolsNetworkControllerHandle::~DevToolsNetworkControllerHandle() { + BrowserThread::DeleteSoon(BrowserThread::IO, + FROM_HERE, + controller_.release()); +} + +void DevToolsNetworkControllerHandle::SetNetworkState( + const std::string& client_id, + scoped_ptr conditions) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&DevToolsNetworkControllerHandle::SetNetworkStateOnIO, + base::Unretained(this), client_id, base::Passed(&conditions))); +} + +DevToolsNetworkController* DevToolsNetworkControllerHandle::GetController() { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + + LazyInitialize(); + return controller_.get(); +} + +void DevToolsNetworkControllerHandle::LazyInitialize() { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + + if (!controller_) + controller_.reset(new DevToolsNetworkController); +} + +void DevToolsNetworkControllerHandle::SetNetworkStateOnIO( + const std::string& client_id, + scoped_ptr conditions) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + + LazyInitialize(); + controller_->SetNetworkState(client_id, std::move(conditions)); +} + +} // namespace brightray diff --git a/brightray/browser/net/devtools_network_controller_handle.h b/brightray/browser/net/devtools_network_controller_handle.h new file mode 100644 index 00000000000..f009d273268 --- /dev/null +++ b/brightray/browser/net/devtools_network_controller_handle.h @@ -0,0 +1,44 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE-CHROMIUM file. + +#ifndef BROWSER_DEVTOOLS_NETWORK_CONTROLLER_HANDLE_H_ +#define BROWSER_DEVTOOLS_NETWORK_CONTROLLER_HANDLE_H_ + +#include + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" + +namespace brightray { + +class DevToolsNetworkConditions; +class DevToolsNetworkController; + +// A handle to manage an IO-thread DevToolsNetworkController on the IO thread +// while allowing SetNetworkState to be called from the UI thread. +class DevToolsNetworkControllerHandle { + public: + DevToolsNetworkControllerHandle(); + ~DevToolsNetworkControllerHandle(); + + // Called on the UI thread. + void SetNetworkState(const std::string& client_id, + scoped_ptr conditions); + + // Called on the IO thread. + DevToolsNetworkController* GetController(); + + private: + void LazyInitialize(); + void SetNetworkStateOnIO(const std::string& client_id, + scoped_ptr conditions); + + scoped_ptr controller_; + + DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkControllerHandle); +}; + +} // namespace brightray + +#endif // BROWSER_DEVTOOLS_NETWORK_CONTROLLER_HANDLE_H_ diff --git a/brightray/browser/net/devtools_network_interceptor.cc b/brightray/browser/net/devtools_network_interceptor.cc index 126077c5f72..f1f8c63ae55 100644 --- a/brightray/browser/net/devtools_network_interceptor.cc +++ b/brightray/browser/net/devtools_network_interceptor.cc @@ -75,7 +75,7 @@ void DevToolsNetworkInterceptor::UpdateConditions( conditions_ = std::move(conditions); bool offline = conditions_->offline(); - if (offline || conditions_->IsThrottling()) { + if (offline || !conditions_->IsThrottling()) { timer_.Stop(); FinishRecords(&download_, offline); FinishRecords(&upload_, offline); @@ -98,7 +98,7 @@ void DevToolsNetworkInterceptor::UpdateConditions( latency_length_ = base::TimeDelta(); double latency = conditions_->latency(); if (latency > 0) - latency_length_ = base::TimeDelta::FromMilliseconds(latency); + latency_length_ = base::TimeDelta::FromMillisecondsD(latency); ArmTimer(now); } @@ -124,7 +124,7 @@ uint64_t DevToolsNetworkInterceptor::UpdateThrottledRecords( (*records)[i].bytes -= (ticks / length) * kPacketSize + (i < shift ? kPacketSize : 0); } - std::rotate(records->begin(), records->end() + shift, records->end()); + std::rotate(records->begin(), records->begin() + shift, records->end()); return new_tick; } @@ -138,7 +138,7 @@ void DevToolsNetworkInterceptor::UpdateThrottled(base::TimeTicks now) { void DevToolsNetworkInterceptor::UpdateSuspended(base::TimeTicks now) { int64_t activation_baseline = - (now - latency_length_ - base::TimeTicks::Now()).InMicroseconds(); + (now - latency_length_ - base::TimeTicks()).InMicroseconds(); ThrottleRecords suspended; for (const ThrottleRecord& record : suspended_) { if (record.send_end <= activation_baseline) { diff --git a/brightray/browser/net/devtools_network_protocol_handler.cc b/brightray/browser/net/devtools_network_protocol_handler.cc index 9febb2a677d..b5e723d06a6 100644 --- a/brightray/browser/net/devtools_network_protocol_handler.cc +++ b/brightray/browser/net/devtools_network_protocol_handler.cc @@ -78,13 +78,6 @@ CreateFailureResponse(int id, const std::string& param) { return response; } -void UpdateNetworkStateInIO(brightray::DevToolsNetworkController* controller, - const std::string& client_id, - scoped_ptr conditions) { - DCHECK_CURRENTLY_ON(BrowserThread::IO); - controller->SetNetworkState(client_id, std::move(conditions)); -} - } // namespace DevToolsNetworkProtocolHandler::DevToolsNetworkProtocolHandler() { @@ -172,11 +165,8 @@ void DevToolsNetworkProtocolHandler::UpdateNetworkState( scoped_ptr conditions) { auto browser_context = static_cast(agent_host->GetBrowserContext()); - BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, - base::Bind(&UpdateNetworkStateInIO, - browser_context->GetDevToolsNetworkController(), - agent_host->GetId(), - base::Passed(&conditions))); + browser_context->network_controller_handle()->SetNetworkState( + agent_host->GetId(), std::move(conditions)); } } // namespace brightray diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc index 5e6bd59e866..48ed4232db8 100644 --- a/brightray/browser/net/devtools_network_transaction.cc +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -290,7 +290,7 @@ void DevToolsNetworkTransaction::SetBeforeProxyHeadersSentCallback( } int DevToolsNetworkTransaction::ResumeNetworkStart() { - if (failed_) + if (CheckFailed()) return net::ERR_INTERNET_DISCONNECTED; return transaction_->ResumeNetworkStart(); } diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index dffc106ede5..ae0771974b0 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -6,7 +6,7 @@ #include -#include "browser/net/devtools_network_controller.h" +#include "browser/net/devtools_network_controller_handle.h" #include "browser/net/devtools_network_transaction_factory.h" #include "browser/net_log.h" #include "browser/network_delegate.h" @@ -182,7 +182,7 @@ bool URLRequestContextGetter::Delegate::CanDelegateURLSecurity(const GURL& auth_ URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, - DevToolsNetworkController* controller, + DevToolsNetworkControllerHandle* handle, NetLog* net_log, const base::FilePath& base_path, bool in_memory, @@ -191,7 +191,7 @@ URLRequestContextGetter::URLRequestContextGetter( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors) : delegate_(delegate), - controller_(controller), + network_controller_handle_(handle), net_log_(net_log), base_path_(base_path), in_memory_(in_memory), @@ -370,11 +370,11 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { backend.reset(delegate_->CreateHttpCacheBackendFactory(base_path_)); } - if (controller_) { + if (network_controller_handle_) { storage_->set_http_transaction_factory(make_scoped_ptr( new net::HttpCache( make_scoped_ptr(new DevToolsNetworkTransactionFactory( - controller_, http_network_session_.get())), + network_controller_handle_->GetController(), http_network_session_.get())), std::move(backend), false))); } else { diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index aaf9855d2a5..3f06ba78ba2 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -28,7 +28,7 @@ class URLRequestJobFactory; namespace brightray { -class DevToolsNetworkController; +class DevToolsNetworkControllerHandle; class NetLog; class URLRequestContextGetter : public net::URLRequestContextGetter { @@ -73,7 +73,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { URLRequestContextGetter( Delegate* delegate, - DevToolsNetworkController* controller, + DevToolsNetworkControllerHandle* handle, NetLog* net_log, const base::FilePath& base_path, bool in_memory, @@ -92,7 +92,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { private: Delegate* delegate_; - DevToolsNetworkController* controller_; + DevToolsNetworkControllerHandle* network_controller_handle_; NetLog* net_log_; base::FilePath base_path_; bool in_memory_; diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index e65e87307c3..566c6972e29 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -45,6 +45,8 @@ 'browser/net/devtools_network_conditions.h', 'browser/net/devtools_network_controller.cc', 'browser/net/devtools_network_controller.h', + 'browser/net/devtools_network_controller_handle.cc', + 'browser/net/devtools_network_controller_handle.h', 'browser/net/devtools_network_interceptor.cc', 'browser/net/devtools_network_interceptor.h', 'browser/net/devtools_network_protocol_handler.cc', From 0b681178221cd77e020f23e71a9f10628a30fae2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 14 Apr 2016 16:29:54 +0900 Subject: [PATCH 0797/1195] Link with pdf.dll --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index a0a2cdc0ea8..8826341afd1 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -206,6 +206,7 @@ '<(libchromiumcontent_dir)/http_server.lib', '<(libchromiumcontent_dir)/desktop_capture.lib', '<(libchromiumcontent_dir)/desktop_capture_differ_sse2.lib', + '<(libchromiumcontent_dir)/pdf.lib', '<(libchromiumcontent_dir)/rtc_base.lib', '<(libchromiumcontent_dir)/rtc_base_approved.lib', '<(libchromiumcontent_dir)/system_wrappers.lib', From 4c42fe2bb048b1ae7c586d7636e1e299f122eff4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 14 Apr 2016 17:09:09 +0900 Subject: [PATCH 0798/1195] Link with other dependencies of pdf.lib --- brightray/brightray.gyp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 8826341afd1..68aa0314112 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -206,7 +206,6 @@ '<(libchromiumcontent_dir)/http_server.lib', '<(libchromiumcontent_dir)/desktop_capture.lib', '<(libchromiumcontent_dir)/desktop_capture_differ_sse2.lib', - '<(libchromiumcontent_dir)/pdf.lib', '<(libchromiumcontent_dir)/rtc_base.lib', '<(libchromiumcontent_dir)/rtc_base_approved.lib', '<(libchromiumcontent_dir)/system_wrappers.lib', @@ -214,6 +213,31 @@ '<(libchromiumcontent_dir)/libyuv.lib', '<(libchromiumcontent_dir)/cdm_renderer.lib', '<(libchromiumcontent_dir)/security_state.lib', + # Friends of pdf.lib: + '<(libchromiumcontent_dir)/pdf.lib', + '<(libchromiumcontent_dir)/ppapi_cpp_objects.lib', + '<(libchromiumcontent_dir)/ppapi_cpp.lib', + '<(libchromiumcontent_dir)/ppapi_internal_module.lib', + '<(libchromiumcontent_dir)/libjpeg.lib', + '<(libchromiumcontent_dir)/pdfium.lib', + '<(libchromiumcontent_dir)/fdrm.lib', + '<(libchromiumcontent_dir)/formfiller.lib', + '<(libchromiumcontent_dir)/fpdfapi.lib', + '<(libchromiumcontent_dir)/fpdfdoc.lib', + '<(libchromiumcontent_dir)/fpdftext.lib', + '<(libchromiumcontent_dir)/fpdftext.lib', + '<(libchromiumcontent_dir)/fxcodec.lib', + '<(libchromiumcontent_dir)/fxcrt.lib', + '<(libchromiumcontent_dir)/fxedit.lib', + '<(libchromiumcontent_dir)/fxge.lib', + '<(libchromiumcontent_dir)/javascript.lib', + '<(libchromiumcontent_dir)/pdfwindow.lib', + '<(libchromiumcontent_dir)/bigint.lib', + '<(libchromiumcontent_dir)/fx_agg.lib', + '<(libchromiumcontent_dir)/fx_freetype.lib', + '<(libchromiumcontent_dir)/fx_lcms2.lib', + '<(libchromiumcontent_dir)/fx_libopenjpeg.lib', + '<(libchromiumcontent_dir)/fx_zlib.lib', ], }, }, { From 77ca9bc76e787f3fca86aa4c410f8d65c937762f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 14 Apr 2016 18:22:05 +0900 Subject: [PATCH 0799/1195] Do not link with ppapi_cpp.lib --- brightray/brightray.gyp | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 68aa0314112..4a821d1b9f2 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -216,7 +216,6 @@ # Friends of pdf.lib: '<(libchromiumcontent_dir)/pdf.lib', '<(libchromiumcontent_dir)/ppapi_cpp_objects.lib', - '<(libchromiumcontent_dir)/ppapi_cpp.lib', '<(libchromiumcontent_dir)/ppapi_internal_module.lib', '<(libchromiumcontent_dir)/libjpeg.lib', '<(libchromiumcontent_dir)/pdfium.lib', From 8dd7a8d7fe79261c087ba1e5c0af02e422948a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Apr 2016 18:24:00 +0200 Subject: [PATCH 0800/1195] LibNotifyLoader: implement generic HasCapability --- .../browser/linux/libnotify_notification.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index 399416a5721..6772588f509 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -17,6 +17,18 @@ namespace brightray { namespace { LibNotifyLoader libnotify_loader_; +bool HasCapability(const std::string& capability) { + bool result = false; + GList* capabilities = libnotify_loader_.notify_get_server_caps(); + + if (g_list_find_custom(capabilities, capability.c_str(), (GCompareFunc) g_strcmp0) != NULL) + result = true; + + g_list_free_full(capabilities, g_free); + + return result; +} + bool NotifierSupportsActions() { if (getenv("ELECTRON_USE_UBUNTU_NOTIFIER")) return false; @@ -28,12 +40,7 @@ bool NotifierSupportsActions() { if (notify_has_result) return notify_result; - capabilities = libnotify_loader_.notify_get_server_caps(); - - if (g_list_find_custom(capabilities, "actions", (GCompareFunc) g_strcmp0) != NULL) - notify_result = true; - - g_list_free_full(capabilities, g_free); + notify_result = HasCapability("actions"); return notify_result; } From 8962da380bb73d7ebe6dc1ad033e521412002e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Apr 2016 18:29:00 +0200 Subject: [PATCH 0801/1195] LibnotifyLoader: add notify_notification_set_hint_string --- brightray/browser/linux/libnotify_loader.cc | 10 ++++++++++ brightray/browser/linux/libnotify_loader.h | 1 + 2 files changed, 11 insertions(+) diff --git a/brightray/browser/linux/libnotify_loader.cc b/brightray/browser/linux/libnotify_loader.cc index f5c384db567..9720e64d8c1 100644 --- a/brightray/browser/linux/libnotify_loader.cc +++ b/brightray/browser/linux/libnotify_loader.cc @@ -92,6 +92,15 @@ bool LibNotifyLoader::Load(const std::string& library_name) { return false; } + notify_notification_set_hint_string = + reinterpret_castnotify_notification_set_hint_string)>( + dlsym(library_, "notify_notification_set_hint_string")); + notify_notification_set_hint_string = &::notify_notification_set_hint_string; + if (!notify_notification_set_hint_string) { + CleanUp(true); + return false; + } + notify_notification_show = reinterpret_castnotify_notification_show)>( dlsym(library_, "notify_notification_show")); @@ -128,6 +137,7 @@ void LibNotifyLoader::CleanUp(bool unload) { notify_notification_add_action = NULL; notify_notification_set_image_from_pixbuf = NULL; notify_notification_set_timeout = NULL; + notify_notification_set_hint_string = NULL; notify_notification_show = NULL; notify_notification_close = NULL; } diff --git a/brightray/browser/linux/libnotify_loader.h b/brightray/browser/linux/libnotify_loader.h index 818b0ddae07..825a349b39f 100644 --- a/brightray/browser/linux/libnotify_loader.h +++ b/brightray/browser/linux/libnotify_loader.h @@ -26,6 +26,7 @@ class LibNotifyLoader { decltype(&::notify_notification_add_action) notify_notification_add_action; decltype(&::notify_notification_set_image_from_pixbuf) notify_notification_set_image_from_pixbuf; decltype(&::notify_notification_set_timeout) notify_notification_set_timeout; + decltype(&::notify_notification_set_hint_string) notify_notification_set_hint_string; decltype(&::notify_notification_show) notify_notification_show; decltype(&::notify_notification_close) notify_notification_close; From 83cbc1182d5ded13d6b00c6517a528886a694f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Apr 2016 18:31:02 +0200 Subject: [PATCH 0802/1195] LibnotifyNotification: use "append" when supported This behavior can be overridden by just providing unique tags to notifications --- brightray/browser/linux/libnotify_notification.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index 6772588f509..6314bd650f2 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -121,6 +121,16 @@ void LibnotifyNotification::Show(const base::string16& title, g_object_set(G_OBJECT(notification_), "id", id, NULL); } + // Always try to append notifications. + // Unique tags can be used to prevent this. + if (HasCapability("append")) { + libnotify_loader_.notify_notification_set_hint_string( + notification_, "append", "true"); + } else if (HasCapability("x-canonical-append")) { + libnotify_loader_.notify_notification_set_hint_string( + notification_, "x-canonical-append", "true"); + } + GError* error = nullptr; libnotify_loader_.notify_notification_show(notification_, &error); if (error) { From ddee77fae4ed1bce6e35dd2889bcdbd945015ef6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 15 Apr 2016 16:01:21 +0900 Subject: [PATCH 0803/1195] Do not use get_Setting to determine whether notification is enabled On Windows 10 get_Setting always returns DISABLED when the program has a AppUserModelID. --- brightray/browser/win/windows_toast_notification.cc | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 401473b9c3e..24e13197156 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -90,16 +90,7 @@ void WindowsToastNotification::Show( const bool silent) { auto presenter_win = static_cast(presenter()); std::wstring icon_path = presenter_win->SaveIconToFilesystem(icon, icon_url); - - // Ask Windows for the current notification settings - // If not allowed, we return here (0 = enabled) - ABI::Windows::UI::Notifications::NotificationSetting setting; - toast_notifier_->get_Setting(&setting); - if (setting != 0) { - NotificationFailed(); - return; - } - + ComPtr toast_xml; if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, silent, &toast_xml))) { NotificationFailed(); From f4c27c6d29b43784dd6579f815a14c7bd036972a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 15 Apr 2016 16:14:13 +0900 Subject: [PATCH 0804/1195] Store weak ref to Notification in ToastEventHandler --- .../browser/linux/libnotify_notification.cc | 11 ++-------- .../browser/linux/libnotify_notification.h | 2 -- brightray/browser/mac/cocoa_notification.h | 3 +-- brightray/browser/mac/cocoa_notification.mm | 10 ++------- .../mac/notification_center_delegate.mm | 4 ++-- brightray/browser/notification.cc | 15 +++++++++++++ brightray/browser/notification.h | 5 +++++ .../browser/win/windows_toast_notification.cc | 21 +++---------------- .../browser/win/windows_toast_notification.h | 8 ++----- 9 files changed, 32 insertions(+), 47 deletions(-) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index 399416a5721..e94c81619fe 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -136,19 +136,12 @@ void LibnotifyNotification::Dismiss() { void LibnotifyNotification::OnNotificationClosed( NotifyNotification* notification) { - delegate()->NotificationClosed(); - Destroy(); + NotificationDismissed(); } void LibnotifyNotification::OnNotificationView( NotifyNotification* notification, char* action) { - delegate()->NotificationClick(); - Destroy(); -} - -void LibnotifyNotification::NotificationFailed() { - delegate()->NotificationFailed(); - Destroy(); + NotificationClicked(); } } // namespace brightray diff --git a/brightray/browser/linux/libnotify_notification.h b/brightray/browser/linux/libnotify_notification.h index 40d52cac419..cb9384cb0e0 100644 --- a/brightray/browser/linux/libnotify_notification.h +++ b/brightray/browser/linux/libnotify_notification.h @@ -34,8 +34,6 @@ class LibnotifyNotification : public Notification { CHROMEG_CALLBACK_1(LibnotifyNotification, void, OnNotificationView, NotifyNotification*, char*); - void NotificationFailed(); - NotifyNotification* notification_; DISALLOW_COPY_AND_ASSIGN(LibnotifyNotification); diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index dd7d3cae4b0..7287f00f245 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -28,8 +28,7 @@ class CocoaNotification : public Notification { const bool silent) override; void Dismiss() override; - void NotifyDisplayed(); - void NotifyClick(); + void NotificationDisplayed(); NSUserNotification* notification() const { return notification_; } diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index febd2af4c94..e7ed61dbf36 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -58,17 +58,11 @@ void CocoaNotification::Show(const base::string16& title, void CocoaNotification::Dismiss() { [NSUserNotificationCenter.defaultUserNotificationCenter removeDeliveredNotification:notification_]; - delegate()->NotificationClosed(); - Destroy(); + NotificationDismissed(); } -void CocoaNotification::NotifyDisplayed() { +void CocoaNotification::NotificationDisplayed() { delegate()->NotificationDisplayed(); } -void CocoaNotification::NotifyClick() { - delegate()->NotificationClick(); - Destroy(); -} - } // namespace brightray diff --git a/brightray/browser/mac/notification_center_delegate.mm b/brightray/browser/mac/notification_center_delegate.mm index 53537bdc311..fd77e0685e4 100644 --- a/brightray/browser/mac/notification_center_delegate.mm +++ b/brightray/browser/mac/notification_center_delegate.mm @@ -22,14 +22,14 @@ didDeliverNotification:(NSUserNotification*)notif { auto notification = presenter_->GetNotification(notif); if (notification) - notification->NotifyDisplayed(); + notification->NotificationDisplayed(); } - (void)userNotificationCenter:(NSUserNotificationCenter*)center didActivateNotification:(NSUserNotification *)notif { auto notification = presenter_->GetNotification(notif); if (notification) - notification->NotifyClick(); + notification->NotificationClicked(); } - (BOOL)userNotificationCenter:(NSUserNotificationCenter*)center diff --git a/brightray/browser/notification.cc b/brightray/browser/notification.cc index 6384737c21b..ba9df5446f3 100644 --- a/brightray/browser/notification.cc +++ b/brightray/browser/notification.cc @@ -20,6 +20,21 @@ Notification::~Notification() { delegate()->NotificationDestroyed(); } +void Notification::NotificationClicked() { + delegate()->NotificationClick(); + Destroy(); +} + +void Notification::NotificationDismissed() { + delegate()->NotificationClosed(); + Destroy(); +} + +void Notification::NotificationFailed() { + delegate()->NotificationFailed(); + Destroy(); +} + void Notification::Destroy() { presenter()->RemoveNotification(this); } diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index 30ac680d25f..afacd50c193 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -29,6 +29,11 @@ class Notification { // notification gets closed. virtual void Dismiss() = 0; + // Should be called by derived classes. + void NotificationClicked(); + void NotificationDismissed(); + void NotificationFailed(); + base::WeakPtr GetWeakPtr() { return weak_factory_.GetWeakPtr(); } diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 24e13197156..efa30f2fe11 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -117,7 +117,7 @@ void WindowsToastNotification::Show( return; } - if (FAILED(SetupCallbacks(toast_notification_.Get()))) { + if (!SetupCallbacks(toast_notification_.Get())) { NotificationFailed(); return; } @@ -134,21 +134,6 @@ void WindowsToastNotification::Dismiss() { toast_notifier_->Hide(toast_notification_.Get()); } -void WindowsToastNotification::NotificationClicked() { - delegate()->NotificationClick(); - Destroy(); -} - -void WindowsToastNotification::NotificationDismissed() { - delegate()->NotificationClosed(); - Destroy(); -} - -void WindowsToastNotification::NotificationFailed() { - delegate()->NotificationFailed(); - Destroy(); -} - bool WindowsToastNotification::GetToastXml( ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager, const std::wstring& title, @@ -390,8 +375,8 @@ bool WindowsToastNotification::RemoveCallbacks( /* / Toast Event Handler */ -ToastEventHandler::ToastEventHandler(WindowsToastNotification* notification) - : notification_(notification) { +ToastEventHandler::ToastEventHandler(Notification* notification) + : notification_(notification->GetWeakPtr()) { } ToastEventHandler::~ToastEventHandler() { diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index c603ce3d796..fcbe78faa4d 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -50,10 +50,6 @@ class WindowsToastNotification : public Notification { private: friend class ToastEventHandler; - void NotificationClicked(); - void NotificationDismissed(); - void NotificationFailed(); - bool GetToastXml(ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager, const std::wstring& title, const std::wstring& msg, @@ -97,7 +93,7 @@ class ToastEventHandler : public RuntimeClass, DesktopToastDismissedEventHandler, DesktopToastFailedEventHandler> { public: - ToastEventHandler(WindowsToastNotification* notification); + ToastEventHandler(Notification* notification); ~ToastEventHandler(); IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args); @@ -105,7 +101,7 @@ class ToastEventHandler : public RuntimeClass, IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastFailedEventArgs* e); private: - WindowsToastNotification* notification_; // weak ref. + base::WeakPtr notification_; // weak ref. DISALLOW_COPY_AND_ASSIGN(ToastEventHandler); }; From 593fb8cdf06e1bb45a857a3fbf3d827d943f0d36 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 15 Apr 2016 16:20:36 +0900 Subject: [PATCH 0805/1195] Delay notification events to next tick It is possible that the events get emitted when calling Show(), which would then delete the class before Show() ends, results in using members of a deleted class. By delaying the events to next tick we can effectively avoid this. --- brightray/browser/win/windows_toast_notification.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index efa30f2fe11..4d4b5bfc341 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -12,6 +12,7 @@ #include "browser/win/scoped_hstring.h" #include "browser/win/notification_presenter_win.h" #include "common/application_info.h" +#include "content/public/browser/browser_thread.h" using namespace ABI::Windows::Data::Xml::Dom; @@ -384,21 +385,27 @@ ToastEventHandler::~ToastEventHandler() { IFACEMETHODIMP ToastEventHandler::Invoke( ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args) { - notification_->NotificationClicked(); + content::BrowserThread::PostTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&Notification::NotificationClicked, notification_)); return S_OK; } IFACEMETHODIMP ToastEventHandler::Invoke( ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e) { - notification_->NotificationDismissed(); + content::BrowserThread::PostTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&Notification::NotificationDismissed, notification_)); return S_OK; } IFACEMETHODIMP ToastEventHandler::Invoke( ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastFailedEventArgs* e) { - notification_->NotificationFailed(); + content::BrowserThread::PostTask( + content::BrowserThread::UI, FROM_HERE, + base::Bind(&Notification::NotificationFailed, notification_)); return S_OK; } From ffe88163bb56c6ec848c8ae43410964d2fce69d9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 15 Apr 2016 16:46:55 +0900 Subject: [PATCH 0806/1195] Update libchromiumcontent for printing fix --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index b06d4c307b8..60c7ec9f9bf 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit b06d4c307b861cdb091f4ba26b1a185333889033 +Subproject commit 60c7ec9f9bf465a8c9c7ccc3fcd2aa1cdf644bac From e858c0c6d223be35d9e2f0c260d50a7b08e5e21e Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 19 Apr 2016 18:13:08 +0530 Subject: [PATCH 0807/1195] pass the current dock state to devtools url when available --- brightray/browser/inspectable_web_contents.h | 2 +- .../browser/inspectable_web_contents_impl.cc | 26 ++++++++++++++----- .../browser/inspectable_web_contents_impl.h | 5 ++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index edf26ed117d..01e9c6d2741 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -34,7 +34,7 @@ class InspectableWebContents { virtual void SetDelegate(InspectableWebContentsDelegate* delegate) = 0; virtual InspectableWebContentsDelegate* GetDelegate() const = 0; - virtual void SetCanDock(bool can_dock) = 0; + virtual void SetDockState(const std::string& state) = 0; virtual void ShowDevTools() = 0; virtual void CloseDevTools() = 0; virtual bool IsDevToolsViewShowing() = 0; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 64544058951..819bdba93a5 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -116,6 +116,18 @@ GURL GetRemoteBaseURL() { content::GetWebKitRevision().c_str())); } +GURL GetDevToolsURL( + bool can_dock, + const std::string& dock_state) { + auto url_string = + base::StringPrintf(kChromeUIDevToolsURL, + GetRemoteBaseURL().spec().c_str(), + can_dock ? "true" : ""); + if (!dock_state.empty()) + url_string += "&settings={\"currentDockState\":\"\\\"" + dock_state + "\\\"\"}&"; + return GURL(url_string); +} + // ResponseWriter ------------------------------------------------------------- class ResponseWriter : public net::URLFetcherResponseWriter { @@ -234,8 +246,13 @@ InspectableWebContentsDelegate* InspectableWebContentsImpl::GetDelegate() const return delegate_; } -void InspectableWebContentsImpl::SetCanDock(bool can_dock) { - can_dock_ = can_dock; +void InspectableWebContentsImpl::SetDockState(const std::string& state) { + if (state == "detach") { + can_dock_ = false; + } else { + can_dock_ = true; + dock_state_ = state; + } } void InspectableWebContentsImpl::ShowDevTools() { @@ -254,11 +271,8 @@ void InspectableWebContentsImpl::ShowDevTools() { agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()); agent_host_->AttachClient(this); - GURL devtools_url(base::StringPrintf(kChromeUIDevToolsURL, - GetRemoteBaseURL().spec().c_str(), - can_dock_ ? "true" : "")); devtools_web_contents_->GetController().LoadURL( - devtools_url, + GetDevToolsURL(can_dock_, dock_state_), content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 518fc853cb1..b6e91a7d0f5 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -50,7 +50,7 @@ class InspectableWebContentsImpl : void SetDelegate(InspectableWebContentsDelegate* delegate) override; InspectableWebContentsDelegate* GetDelegate() const override; - void SetCanDock(bool can_dock) override; + void SetDockState(const std::string& state) override; void ShowDevTools() override; void CloseDevTools() override; bool IsDevToolsViewShowing() override; @@ -168,12 +168,13 @@ class InspectableWebContentsImpl : DevToolsContentsResizingStrategy contents_resizing_strategy_; gfx::Rect devtools_bounds_; bool can_dock_; + std::string dock_state_; using PendingRequestsMap = std::map; PendingRequestsMap pending_requests_; InspectableWebContentsDelegate* delegate_; // weak references. - PrefService* pref_service_; // weak reference. + PrefService* pref_service_; // weak reference. scoped_ptr web_contents_; scoped_ptr devtools_web_contents_; From d5d16844b52f22bba7723d0c29c47d6f079be846 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 2 May 2016 16:04:28 +0900 Subject: [PATCH 0808/1195] Update libchromiumcontent for --build-libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 60c7ec9f9bf..bb58747e7db 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 60c7ec9f9bf465a8c9c7ccc3fcd2aa1cdf644bac +Subproject commit bb58747e7db083131ff7298b9509ccf89707c9e4 From 434456e7715084e7d22b7558b6bbc6738ad24948 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 2 May 2016 16:17:20 +0900 Subject: [PATCH 0809/1195] Do not check existence of paths --- brightray/script/bootstrap | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index e0f373cecf3..e241606c2de 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -17,15 +17,7 @@ def main(): if (args.libcc_source_path != None and args.libcc_shared_library_path != None and args.libcc_static_library_path != None): - if (not os.path.isdir(args.libcc_source_path)): - print "Error: Directory does not exist:", args.libcc_source_path - sys.exit(0) - elif (not os.path.isdir(args.libcc_shared_library_path)): - print "Error: Directory does not exist:", args.libcc_shared_library_path - sys.exit(0) - elif (not os.path.isdir(args.libcc_static_library_path)): - print "Error: Directory does not exist:", args.libcc_static_library_path - sys.exit(0) + pass elif (args.libcc_source_path != None or args.libcc_shared_library_path != None or args.libcc_static_library_path != None): From 8e94d5ab0fd428589e5f2645f70ecbcbbfb245ca Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 2 May 2016 21:18:43 +0900 Subject: [PATCH 0810/1195] Update libchromiumcontent for --defines parameter --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index bb58747e7db..33cb3ff7ca0 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit bb58747e7db083131ff7298b9509ccf89707c9e4 +Subproject commit 33cb3ff7ca065375d44cac2143a8b09c4a99563e From 2db138f2dc5007acbd04566d5db037a3816c74b9 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sat, 7 May 2016 04:36:00 +0530 Subject: [PATCH 0811/1195] allow delegate to handle file system indexing requests --- brightray/browser/inspectable_web_contents_delegate.h | 7 +++++++ brightray/browser/inspectable_web_contents_impl.cc | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_delegate.h b/brightray/browser/inspectable_web_contents_delegate.h index 7f004dd4fbd..a94bcac44d5 100644 --- a/brightray/browser/inspectable_web_contents_delegate.h +++ b/brightray/browser/inspectable_web_contents_delegate.h @@ -20,6 +20,13 @@ class InspectableWebContentsDelegate { const base::FilePath& file_system_path) {} virtual void DevToolsRemoveFileSystem( const base::FilePath& file_system_path) {} + virtual void DevToolsIndexPath( + int request_id, const std::string& file_system_path) {} + virtual void DevToolsStopIndexing(int request_id) {} + virtual void DevToolsSearchInPath( + int request_id, + const std::string& file_system_path, + const std::string& query) {} }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 819bdba93a5..8353a71eb76 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -459,15 +459,21 @@ void InspectableWebContentsImpl::UpgradeDraggedFileSystemPermissions( void InspectableWebContentsImpl::IndexPath( int request_id, const std::string& file_system_path) { + if (delegate_) + delegate_->DevToolsIndexPath(request_id, file_system_path); } void InspectableWebContentsImpl::StopIndexing(int request_id) { + if (delegate_) + delegate_->DevToolsStopIndexing(request_id); } void InspectableWebContentsImpl::SearchInPath( int request_id, const std::string& file_system_path, const std::string& query) { + if (delegate_) + delegate_->DevToolsSearchInPath(request_id, file_system_path, query); } void InspectableWebContentsImpl::SetWhitelistedShortcuts(const std::string& message) { From f15940e7034ad976842af3516740fbd5c67b4234 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sat, 7 May 2016 04:36:42 +0530 Subject: [PATCH 0812/1195] port DevToolsFileSystemIndexer --- .../browser/devtools_file_system_indexer.cc | 495 ++++++++++++++++++ .../browser/devtools_file_system_indexer.h | 115 ++++ brightray/filenames.gypi | 2 + 3 files changed, 612 insertions(+) create mode 100644 brightray/browser/devtools_file_system_indexer.cc create mode 100644 brightray/browser/devtools_file_system_indexer.h diff --git a/brightray/browser/devtools_file_system_indexer.cc b/brightray/browser/devtools_file_system_indexer.cc new file mode 100644 index 00000000000..788db1fa630 --- /dev/null +++ b/brightray/browser/devtools_file_system_indexer.cc @@ -0,0 +1,495 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "browser/devtools_file_system_indexer.h" + +#include + +#include + +#include "base/bind.h" +#include "base/callback.h" +#include "base/files/file_enumerator.h" +#include "base/files/file_util.h" +#include "base/files/file_util_proxy.h" +#include "base/lazy_instance.h" +#include "base/logging.h" +#include "base/macros.h" +#include "base/stl_util.h" +#include "base/strings/string_util.h" +#include "base/strings/utf_string_conversions.h" +#include "content/public/browser/browser_thread.h" + +using base::Bind; +using base::Callback; +using base::FileEnumerator; +using base::FilePath; +using base::Time; +using base::TimeDelta; +using base::TimeTicks; +using content::BrowserThread; +using std::map; +using std::set; +using std::string; +using std::vector; + +namespace brightray { + +namespace { + +typedef int32_t Trigram; +typedef char TrigramChar; +typedef uint16_t FileId; + +const int kMinTimeoutBetweenWorkedNotification = 200; +// Trigram characters include all ASCII printable characters (32-126) except for +// the capital letters, because the index is case insensitive. +const size_t kTrigramCharacterCount = 126 - 'Z' - 1 + 'A' - ' ' + 1; +const size_t kTrigramCount = + kTrigramCharacterCount * kTrigramCharacterCount * kTrigramCharacterCount; +const int kMaxReadLength = 10 * 1024; +const TrigramChar kUndefinedTrigramChar = -1; +const TrigramChar kBinaryTrigramChar = -2; +const Trigram kUndefinedTrigram = -1; + +template +bool IsAsciiUpper(Char c) { + return c >= 'A' && c <= 'Z'; +} + +class Index { + public: + Index(); + Time LastModifiedTimeForFile(const FilePath& file_path); + void SetTrigramsForFile(const FilePath& file_path, + const vector& index, + const Time& time); + vector Search(string query); + void PrintStats(); + void NormalizeVectors(); + + private: + ~Index(); + + FileId GetFileId(const FilePath& file_path); + + typedef map FileIdsMap; + FileIdsMap file_ids_; + FileId last_file_id_; + // The index in this vector is the trigram id. + vector > index_; + typedef map IndexedFilesMap; + IndexedFilesMap index_times_; + vector is_normalized_; + + DISALLOW_COPY_AND_ASSIGN(Index); +}; + +base::LazyInstance::Leaky g_trigram_index = LAZY_INSTANCE_INITIALIZER; + +TrigramChar TrigramCharForChar(char c) { + static TrigramChar* trigram_chars = nullptr; + if (!trigram_chars) { + trigram_chars = new TrigramChar[256]; + for (size_t i = 0; i < 256; ++i) { + if (i > 127) { + trigram_chars[i] = kUndefinedTrigramChar; + continue; + } + char ch = static_cast(i); + if (ch == '\t') + ch = ' '; + if (IsAsciiUpper(ch)) + ch = ch - 'A' + 'a'; + + bool is_binary_char = ch < 9 || (ch >= 14 && ch < 32) || ch == 127; + if (is_binary_char) { + trigram_chars[i] = kBinaryTrigramChar; + continue; + } + + if (ch < ' ') { + trigram_chars[i] = kUndefinedTrigramChar; + continue; + } + + if (ch >= 'Z') + ch = ch - 'Z' - 1 + 'A'; + ch -= ' '; + char signed_trigram_count = static_cast(kTrigramCharacterCount); + CHECK(ch >= 0 && ch < signed_trigram_count); + trigram_chars[i] = ch; + } + } + unsigned char uc = static_cast(c); + return trigram_chars[uc]; +} + +Trigram TrigramAtIndex(const vector& trigram_chars, size_t index) { + static int kTrigramCharacterCountSquared = + kTrigramCharacterCount * kTrigramCharacterCount; + if (trigram_chars[index] == kUndefinedTrigramChar || + trigram_chars[index + 1] == kUndefinedTrigramChar || + trigram_chars[index + 2] == kUndefinedTrigramChar) + return kUndefinedTrigram; + Trigram trigram = kTrigramCharacterCountSquared * trigram_chars[index] + + kTrigramCharacterCount * trigram_chars[index + 1] + + trigram_chars[index + 2]; + return trigram; +} + +Index::Index() : last_file_id_(0) { + index_.resize(kTrigramCount); + is_normalized_.resize(kTrigramCount); + std::fill(is_normalized_.begin(), is_normalized_.end(), true); +} + +Index::~Index() {} + +Time Index::LastModifiedTimeForFile(const FilePath& file_path) { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + Time last_modified_time; + if (index_times_.find(file_path) != index_times_.end()) + last_modified_time = index_times_[file_path]; + return last_modified_time; +} + +void Index::SetTrigramsForFile(const FilePath& file_path, + const vector& index, + const Time& time) { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + FileId file_id = GetFileId(file_path); + vector::const_iterator it = index.begin(); + for (; it != index.end(); ++it) { + Trigram trigram = *it; + index_[trigram].push_back(file_id); + is_normalized_[trigram] = false; + } + index_times_[file_path] = time; +} + +vector Index::Search(string query) { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + const char* data = query.c_str(); + vector trigram_chars; + trigram_chars.reserve(query.size()); + for (size_t i = 0; i < query.size(); ++i) { + TrigramChar trigram_char = TrigramCharForChar(data[i]); + if (trigram_char == kBinaryTrigramChar) + trigram_char = kUndefinedTrigramChar; + trigram_chars.push_back(trigram_char); + } + vector trigrams; + for (size_t i = 0; i + 2 < query.size(); ++i) { + Trigram trigram = TrigramAtIndex(trigram_chars, i); + if (trigram != kUndefinedTrigram) + trigrams.push_back(trigram); + } + set file_ids; + bool first = true; + vector::const_iterator it = trigrams.begin(); + for (; it != trigrams.end(); ++it) { + Trigram trigram = *it; + if (first) { + std::copy(index_[trigram].begin(), + index_[trigram].end(), + std::inserter(file_ids, file_ids.begin())); + first = false; + continue; + } + set intersection = base::STLSetIntersection >( + file_ids, index_[trigram]); + file_ids.swap(intersection); + } + vector result; + FileIdsMap::const_iterator ids_it = file_ids_.begin(); + for (; ids_it != file_ids_.end(); ++ids_it) { + if (trigrams.size() == 0 || + file_ids.find(ids_it->second) != file_ids.end()) { + result.push_back(ids_it->first); + } + } + return result; +} + +FileId Index::GetFileId(const FilePath& file_path) { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + string file_path_str = file_path.AsUTF8Unsafe(); + if (file_ids_.find(file_path) != file_ids_.end()) + return file_ids_[file_path]; + file_ids_[file_path] = ++last_file_id_; + return last_file_id_; +} + +void Index::NormalizeVectors() { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + for (size_t i = 0; i < kTrigramCount; ++i) { + if (!is_normalized_[i]) { + std::sort(index_[i].begin(), index_[i].end()); + if (index_[i].capacity() > index_[i].size()) + vector(index_[i]).swap(index_[i]); + is_normalized_[i] = true; + } + } +} + +void Index::PrintStats() { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + LOG(ERROR) << "Index stats:"; + size_t size = 0; + size_t maxSize = 0; + size_t capacity = 0; + for (size_t i = 0; i < kTrigramCount; ++i) { + if (index_[i].size() > maxSize) + maxSize = index_[i].size(); + size += index_[i].size(); + capacity += index_[i].capacity(); + } + LOG(ERROR) << " - total trigram count: " << size; + LOG(ERROR) << " - max file count per trigram: " << maxSize; + LOG(ERROR) << " - total vectors capacity " << capacity; + size_t total_index_size = + capacity * sizeof(FileId) + sizeof(vector) * kTrigramCount; + LOG(ERROR) << " - estimated total index size " << total_index_size; +} + +typedef Callback&)> IndexerCallback; + +} // namespace + +DevToolsFileSystemIndexer::FileSystemIndexingJob::FileSystemIndexingJob( + const FilePath& file_system_path, + const TotalWorkCallback& total_work_callback, + const WorkedCallback& worked_callback, + const DoneCallback& done_callback) + : file_system_path_(file_system_path), + total_work_callback_(total_work_callback), + worked_callback_(worked_callback), + done_callback_(done_callback), + current_file_(BrowserThread::GetMessageLoopProxyForThread( + BrowserThread::FILE).get()), + files_indexed_(0), + stopped_(false) { + current_trigrams_set_.resize(kTrigramCount); + current_trigrams_.reserve(kTrigramCount); +} + +DevToolsFileSystemIndexer::FileSystemIndexingJob::~FileSystemIndexingJob() {} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::Start() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + BrowserThread::PostTask( + BrowserThread::FILE, + FROM_HERE, + Bind(&FileSystemIndexingJob::CollectFilesToIndex, this)); +} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::Stop() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + BrowserThread::PostTask(BrowserThread::FILE, + FROM_HERE, + Bind(&FileSystemIndexingJob::StopOnFileThread, this)); +} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::StopOnFileThread() { + stopped_ = true; +} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::CollectFilesToIndex() { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + if (stopped_) + return; + if (!file_enumerator_) { + file_enumerator_.reset( + new FileEnumerator(file_system_path_, true, FileEnumerator::FILES)); + } + FilePath file_path = file_enumerator_->Next(); + if (file_path.empty()) { + BrowserThread::PostTask( + BrowserThread::UI, + FROM_HERE, + Bind(total_work_callback_, file_path_times_.size())); + indexing_it_ = file_path_times_.begin(); + IndexFiles(); + return; + } + Time saved_last_modified_time = + g_trigram_index.Get().LastModifiedTimeForFile(file_path); + FileEnumerator::FileInfo file_info = file_enumerator_->GetInfo(); + Time current_last_modified_time = file_info.GetLastModifiedTime(); + if (current_last_modified_time > saved_last_modified_time) { + file_path_times_[file_path] = current_last_modified_time; + } + BrowserThread::PostTask( + BrowserThread::FILE, + FROM_HERE, + Bind(&FileSystemIndexingJob::CollectFilesToIndex, this)); +} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::IndexFiles() { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + if (stopped_) + return; + if (indexing_it_ == file_path_times_.end()) { + g_trigram_index.Get().NormalizeVectors(); + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, done_callback_); + return; + } + FilePath file_path = indexing_it_->first; + current_file_.CreateOrOpen( + file_path, + base::File::FLAG_OPEN | base::File::FLAG_READ, + Bind(&FileSystemIndexingJob::StartFileIndexing, this)); +} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::StartFileIndexing( + base::File::Error error) { + if (!current_file_.IsValid()) { + FinishFileIndexing(false); + return; + } + current_file_offset_ = 0; + current_trigrams_.clear(); + std::fill(current_trigrams_set_.begin(), current_trigrams_set_.end(), false); + ReadFromFile(); +} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::ReadFromFile() { + if (stopped_) { + CloseFile(); + return; + } + current_file_.Read(current_file_offset_, kMaxReadLength, + Bind(&FileSystemIndexingJob::OnRead, this)); +} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::OnRead( + base::File::Error error, + const char* data, + int bytes_read) { + if (error != base::File::FILE_OK) { + FinishFileIndexing(false); + return; + } + + if (!bytes_read || bytes_read < 3) { + FinishFileIndexing(true); + return; + } + + size_t size = static_cast(bytes_read); + vector trigram_chars; + trigram_chars.reserve(size); + for (size_t i = 0; i < size; ++i) { + TrigramChar trigram_char = TrigramCharForChar(data[i]); + if (trigram_char == kBinaryTrigramChar) { + current_trigrams_.clear(); + FinishFileIndexing(true); + return; + } + trigram_chars.push_back(trigram_char); + } + + for (size_t i = 0; i + 2 < size; ++i) { + Trigram trigram = TrigramAtIndex(trigram_chars, i); + if ((trigram != kUndefinedTrigram) && !current_trigrams_set_[trigram]) { + current_trigrams_set_[trigram] = true; + current_trigrams_.push_back(trigram); + } + } + current_file_offset_ += bytes_read - 2; + ReadFromFile(); +} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::FinishFileIndexing( + bool success) { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + CloseFile(); + if (success) { + FilePath file_path = indexing_it_->first; + g_trigram_index.Get().SetTrigramsForFile( + file_path, current_trigrams_, file_path_times_[file_path]); + } + ReportWorked(); + ++indexing_it_; + IndexFiles(); +} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::CloseFile() { + if (current_file_.IsValid()) + current_file_.Close(Bind(&FileSystemIndexingJob::CloseCallback, this)); +} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::CloseCallback( + base::File::Error error) {} + +void DevToolsFileSystemIndexer::FileSystemIndexingJob::ReportWorked() { + TimeTicks current_time = TimeTicks::Now(); + bool should_send_worked_nitification = true; + if (!last_worked_notification_time_.is_null()) { + TimeDelta delta = current_time - last_worked_notification_time_; + if (delta.InMilliseconds() < kMinTimeoutBetweenWorkedNotification) + should_send_worked_nitification = false; + } + ++files_indexed_; + if (should_send_worked_nitification) { + last_worked_notification_time_ = current_time; + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, Bind(worked_callback_, files_indexed_)); + files_indexed_ = 0; + } +} + +DevToolsFileSystemIndexer::DevToolsFileSystemIndexer() { +} + +DevToolsFileSystemIndexer::~DevToolsFileSystemIndexer() {} + +scoped_refptr +DevToolsFileSystemIndexer::IndexPath( + const string& file_system_path, + const TotalWorkCallback& total_work_callback, + const WorkedCallback& worked_callback, + const DoneCallback& done_callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + scoped_refptr indexing_job = + new FileSystemIndexingJob(FilePath::FromUTF8Unsafe(file_system_path), + total_work_callback, + worked_callback, + done_callback); + indexing_job->Start(); + return indexing_job; +} + +void DevToolsFileSystemIndexer::SearchInPath(const string& file_system_path, + const string& query, + const SearchCallback& callback) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + BrowserThread::PostTask( + BrowserThread::FILE, + FROM_HERE, + Bind(&DevToolsFileSystemIndexer::SearchInPathOnFileThread, + this, + file_system_path, + query, + callback)); +} + +void DevToolsFileSystemIndexer::SearchInPathOnFileThread( + const string& file_system_path, + const string& query, + const SearchCallback& callback) { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + vector file_paths = g_trigram_index.Get().Search(query); + vector result; + FilePath path = FilePath::FromUTF8Unsafe(file_system_path); + vector::const_iterator it = file_paths.begin(); + for (; it != file_paths.end(); ++it) { + if (path.IsParent(*it)) + result.push_back(it->AsUTF8Unsafe()); + } + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, Bind(callback, result)); +} + +} // namespace brightray diff --git a/brightray/browser/devtools_file_system_indexer.h b/brightray/browser/devtools_file_system_indexer.h new file mode 100644 index 00000000000..bb1acefab52 --- /dev/null +++ b/brightray/browser/devtools_file_system_indexer.h @@ -0,0 +1,115 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BROWSER_DEVTOOLS_FILE_SYSTEM_INDEXER_H_ +#define BROWSER_DEVTOOLS_FILE_SYSTEM_INDEXER_H_ + +#include + +#include +#include +#include +#include + +#include "base/callback.h" +#include "base/files/file_proxy.h" +#include "base/macros.h" +#include "base/memory/ref_counted.h" + +namespace base { +class FilePath; +class FileEnumerator; +class Time; +} + +namespace content { +class WebContents; +} + +namespace brightray { + +class DevToolsFileSystemIndexer + : public base::RefCountedThreadSafe { + public: + typedef base::Callback TotalWorkCallback; + typedef base::Callback WorkedCallback; + typedef base::Callback DoneCallback; + typedef base::Callback&)> SearchCallback; + + class FileSystemIndexingJob : public base::RefCounted { + public: + void Stop(); + + private: + friend class base::RefCounted; + friend class DevToolsFileSystemIndexer; + FileSystemIndexingJob(const base::FilePath& file_system_path, + const TotalWorkCallback& total_work_callback, + const WorkedCallback& worked_callback, + const DoneCallback& done_callback); + virtual ~FileSystemIndexingJob(); + + void Start(); + void StopOnFileThread(); + void CollectFilesToIndex(); + void IndexFiles(); + void StartFileIndexing(base::File::Error error); + void ReadFromFile(); + void OnRead(base::File::Error error, + const char* data, + int bytes_read); + void FinishFileIndexing(bool success); + void CloseFile(); + void CloseCallback(base::File::Error error); + void ReportWorked(); + + base::FilePath file_system_path_; + TotalWorkCallback total_work_callback_; + WorkedCallback worked_callback_; + DoneCallback done_callback_; + std::unique_ptr file_enumerator_; + typedef std::map FilePathTimesMap; + FilePathTimesMap file_path_times_; + FilePathTimesMap::const_iterator indexing_it_; + base::FileProxy current_file_; + int64_t current_file_offset_; + typedef int32_t Trigram; + std::vector current_trigrams_; + // The index in this vector is the trigram id. + std::vector current_trigrams_set_; + base::TimeTicks last_worked_notification_time_; + int files_indexed_; + bool stopped_; + }; + + DevToolsFileSystemIndexer(); + + // Performs file system indexing for given |file_system_path| and sends + // progress callbacks. + scoped_refptr IndexPath( + const std::string& file_system_path, + const TotalWorkCallback& total_work_callback, + const WorkedCallback& worked_callback, + const DoneCallback& done_callback); + + // Performs trigram search for given |query| in |file_system_path|. + void SearchInPath(const std::string& file_system_path, + const std::string& query, + const SearchCallback& callback); + + private: + friend class base::RefCountedThreadSafe; + + virtual ~DevToolsFileSystemIndexer(); + + void SearchInPathOnFileThread(const std::string& file_system_path, + const std::string& query, + const SearchCallback& callback); + + DISALLOW_COPY_AND_ASSIGN(DevToolsFileSystemIndexer); +}; + +} // namespace brightray + +#endif // BROWSER_DEVTOOLS_FILE_SYSTEM_INDEXER_H_ diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 566c6972e29..98818759d26 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -13,6 +13,8 @@ 'browser/devtools_contents_resizing_strategy.h', 'browser/devtools_embedder_message_dispatcher.cc', 'browser/devtools_embedder_message_dispatcher.h', + 'browser/devtools_file_system_indexer.cc', + 'browser/devtools_file_system_indexer.h', 'browser/devtools_manager_delegate.cc', 'browser/devtools_manager_delegate.h', 'browser/devtools_ui.cc', From db0c931d60b49ec6c71f31fbcd5fc98c5a65a69c Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 12 May 2016 07:15:49 +0530 Subject: [PATCH 0813/1195] notify delegate when devtools is loaded --- brightray/browser/inspectable_web_contents_impl.cc | 3 +++ brightray/browser/inspectable_web_contents_view_delegate.h | 1 + 2 files changed, 4 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 8353a71eb76..1648bee7049 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -368,6 +368,9 @@ void InspectableWebContentsImpl::LoadCompleted() { // If the devtools can dock, "SetIsDocked" will be called by devtools itself. if (!can_dock_) SetIsDocked(DispatchCallback(), false); + + if (view_->GetDelegate()) + view_->GetDelegate()->DevToolsLoaded(); } void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { diff --git a/brightray/browser/inspectable_web_contents_view_delegate.h b/brightray/browser/inspectable_web_contents_view_delegate.h index 900857c7a10..ce1b6e721b6 100644 --- a/brightray/browser/inspectable_web_contents_view_delegate.h +++ b/brightray/browser/inspectable_web_contents_view_delegate.h @@ -12,6 +12,7 @@ class InspectableWebContentsViewDelegate { virtual void DevToolsFocused() {} virtual void DevToolsOpened() {} virtual void DevToolsClosed() {} + virtual void DevToolsLoaded() {} // Returns the icon of devtools window. virtual gfx::ImageSkia GetDevToolsWindowIcon(); From 7e0918f95a0eb4f7ee8b7f739e6c4dfe4919b083 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 12 May 2016 18:57:54 +0530 Subject: [PATCH 0814/1195] Revert "Merge pull request #218 from deepak1556/devtools_extensions_load_patch" This reverts commit c0942cbbe67158c68ecfd9bf4cb7bdea84e0d529, reversing changes made to a370461f3420ec285838126da7e7efd6a3101640. --- brightray/browser/inspectable_web_contents_impl.cc | 3 --- brightray/browser/inspectable_web_contents_view_delegate.h | 1 - 2 files changed, 4 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 1648bee7049..8353a71eb76 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -368,9 +368,6 @@ void InspectableWebContentsImpl::LoadCompleted() { // If the devtools can dock, "SetIsDocked" will be called by devtools itself. if (!can_dock_) SetIsDocked(DispatchCallback(), false); - - if (view_->GetDelegate()) - view_->GetDelegate()->DevToolsLoaded(); } void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { diff --git a/brightray/browser/inspectable_web_contents_view_delegate.h b/brightray/browser/inspectable_web_contents_view_delegate.h index ce1b6e721b6..900857c7a10 100644 --- a/brightray/browser/inspectable_web_contents_view_delegate.h +++ b/brightray/browser/inspectable_web_contents_view_delegate.h @@ -12,7 +12,6 @@ class InspectableWebContentsViewDelegate { virtual void DevToolsFocused() {} virtual void DevToolsOpened() {} virtual void DevToolsClosed() {} - virtual void DevToolsLoaded() {} // Returns the icon of devtools window. virtual gfx::ImageSkia GetDevToolsWindowIcon(); From a01f8ba73918a14e3e09d5875763c243329083d2 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 12 May 2016 19:16:13 +0530 Subject: [PATCH 0815/1195] notify devtools opened and closed once per lifetime --- brightray/browser/inspectable_web_contents_impl.cc | 6 ++++++ brightray/browser/inspectable_web_contents_view_mac.mm | 4 ---- .../browser/views/inspectable_web_contents_view_views.cc | 4 ---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 8353a71eb76..71c981bb409 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -368,6 +368,9 @@ void InspectableWebContentsImpl::LoadCompleted() { // If the devtools can dock, "SetIsDocked" will be called by devtools itself. if (!can_dock_) SetIsDocked(DispatchCallback(), false); + + if (view_->GetDelegate()) + view_->GetDelegate()->DevToolsOpened(); } void InspectableWebContentsImpl::SetInspectedPageBounds(const gfx::Rect& rect) { @@ -618,6 +621,9 @@ void InspectableWebContentsImpl::WebContentsDestroyed() { for (const auto& pair : pending_requests_) delete pair.first; + + if (view_ && view_->GetDelegate()) + view_->GetDelegate()->DevToolsClosed(); } bool InspectableWebContentsImpl::AddMessageToConsole( diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index f4c1cd5cb8b..e708a686802 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -29,14 +29,10 @@ gfx::NativeView InspectableWebContentsViewMac::GetNativeView() const { void InspectableWebContentsViewMac::ShowDevTools() { [view_ setDevToolsVisible:YES]; - if (GetDelegate()) - GetDelegate()->DevToolsOpened(); } void InspectableWebContentsViewMac::CloseDevTools() { [view_ setDevToolsVisible:NO]; - if (GetDelegate()) - GetDelegate()->DevToolsClosed(); } bool InspectableWebContentsViewMac::IsDevToolsViewShowing() { diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 79fcc103796..09c9ab6f801 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -118,8 +118,6 @@ void InspectableWebContentsViewViews::ShowDevTools() { devtools_web_view_->RequestFocus(); Layout(); } - if (GetDelegate()) - GetDelegate()->DevToolsOpened(); } void InspectableWebContentsViewViews::CloseDevTools() { @@ -137,8 +135,6 @@ void InspectableWebContentsViewViews::CloseDevTools() { devtools_web_view_->SetWebContents(NULL); Layout(); } - if (GetDelegate()) - GetDelegate()->DevToolsClosed(); } bool InspectableWebContentsViewViews::IsDevToolsViewShowing() { From 71aa9a605a43c2a5696166d42da1feabe8fbda72 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Tue, 26 Apr 2016 22:07:58 -0400 Subject: [PATCH 0816/1195] Remove user_gesture parameter from PermissionManager::RequestPermission --- brightray/browser/permission_manager.cc | 2 -- brightray/browser/permission_manager.h | 2 -- 2 files changed, 4 deletions(-) diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc index 4492e749c8a..26e3c622cee 100644 --- a/brightray/browser/permission_manager.cc +++ b/brightray/browser/permission_manager.cc @@ -22,7 +22,6 @@ int PermissionManager::RequestPermission( content::PermissionType permission, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, - bool user_gesture, const base::Callback& callback) { if (permission == content::PermissionType::MIDI_SYSEX) { content::ChildProcessSecurityPolicy::GetInstance()-> @@ -36,7 +35,6 @@ int PermissionManager::RequestPermissions( const std::vector& permissions, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, - bool user_gesture, const base::Callback&)>& callback) { std::vector permissionStatuses; diff --git a/brightray/browser/permission_manager.h b/brightray/browser/permission_manager.h index f3ed51d3c1a..d53fe763ce5 100644 --- a/brightray/browser/permission_manager.h +++ b/brightray/browser/permission_manager.h @@ -21,13 +21,11 @@ class PermissionManager : public content::PermissionManager { content::PermissionType permission, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, - bool user_gesture, const base::Callback& callback) override; int RequestPermissions( const std::vector& permissions, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, - bool user_gesture, const base::Callback&)>& callback) override; void CancelPermissionRequest(int request_id) override; From 9d31297d2711ff6f01430fd17b4d75402ed2bca2 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Tue, 26 Apr 2016 22:24:48 -0400 Subject: [PATCH 0817/1195] Use HttpNetworkSession::Params::enable_http2 next_protos is a private member now and HTTP1.1 is always added --- brightray/browser/url_request_context_getter.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index ae0771974b0..86ebc90efdb 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -341,10 +341,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.http_auth_handler_factory = url_request_context_->http_auth_handler_factory(); network_session_params.net_log = url_request_context_->net_log(); - net::NextProtoVector next_protos; - next_protos.push_back(net::kProtoHTTP2); - next_protos.push_back(net::kProtoHTTP11); - network_session_params.next_protos = next_protos; + network_session_params.enable_http2 = true; // --ignore-certificate-errors if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) From 23eda6930a40f5a796a0196881f82c9bd39ebfbd Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Tue, 26 Apr 2016 22:52:26 -0400 Subject: [PATCH 0818/1195] Refactor for NotificationResources bitmaps SkBitmap icon moves into content::NotificationResources --- .../browser/platform_notification_service.cc | 15 +++++++++------ brightray/browser/platform_notification_service.h | 11 +++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 146cd968c9b..ce539cad8d4 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -9,6 +9,7 @@ #include "browser/notification_delegate_adapter.h" #include "browser/notification_presenter.h" #include "content/public/common/platform_notification_data.h" +#include "content/public/common/notification_resources.h" #include "third_party/skia/include/core/SkBitmap.h" namespace brightray { @@ -70,24 +71,26 @@ blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnI void PlatformNotificationService::DisplayNotification( content::BrowserContext* browser_context, const GURL& origin, - const SkBitmap& icon, - const content::PlatformNotificationData& data, + const content::PlatformNotificationData& notification_data, + const content::NotificationResources& notification_resources, scoped_ptr delegate, base::Closure* cancel_callback) { browser_client_->WebNotificationAllowed( render_process_id_, base::Bind(&OnWebNotificationAllowed, - browser_client_, icon, data, + browser_client_, + notification_resources.notification_icon, + notification_data, base::Passed(&delegate), cancel_callback)); } void PlatformNotificationService::DisplayPersistentNotification( content::BrowserContext* browser_context, - int64_t service_worker_registration_id, + int64_t persistent_notification_id, const GURL& origin, - const SkBitmap& icon, - const content::PlatformNotificationData& notification_data) { + const content::PlatformNotificationData& notification_data, + const content::NotificationResources& notification_resources) { } void PlatformNotificationService::ClosePersistentNotification( diff --git a/brightray/browser/platform_notification_service.h b/brightray/browser/platform_notification_service.h index ebbb6bae1de..2f7663d588f 100644 --- a/brightray/browser/platform_notification_service.h +++ b/brightray/browser/platform_notification_service.h @@ -27,19 +27,18 @@ class PlatformNotificationService content::ResourceContext* resource_context, const GURL& origin, int render_process_id) override; - void DisplayNotification( - content::BrowserContext* browser_context, + void DisplayNotification(content::BrowserContext* browser_context, const GURL& origin, - const SkBitmap& icon, const content::PlatformNotificationData& notification_data, + const content::NotificationResources& notification_resources, scoped_ptr delegate, base::Closure* cancel_callback) override; void DisplayPersistentNotification( content::BrowserContext* browser_context, - int64_t service_worker_registration_id, + int64_t persistent_notification_id, const GURL& origin, - const SkBitmap& icon, - const content::PlatformNotificationData& notification_data) override; + const content::PlatformNotificationData& notification_data, + const content::NotificationResources& notification_resources) override; void ClosePersistentNotification( content::BrowserContext* browser_context, int64_t persistent_notification_id) override; From 270fc41024628b3e56507692ae0162e06c53a260 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Tue, 26 Apr 2016 22:19:42 -0400 Subject: [PATCH 0819/1195] Remove NetworkDelegate::OnResolveProxy It doesn't exist anymore --- brightray/browser/network_delegate.cc | 9 --------- brightray/browser/network_delegate.h | 6 +----- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index a1795605562..5e63a0c57c0 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -50,15 +50,6 @@ int NetworkDelegate::OnBeforeURLRequest( return net::OK; } -void NetworkDelegate::OnResolveProxy(const GURL& url, - int load_flags, - const net::ProxyService& proxy_service, - net::ProxyInfo* result) { -} - -void NetworkDelegate::OnProxyFallback(const net::ProxyServer& bad_proxy, int net_error) { -} - int NetworkDelegate::OnBeforeSendHeaders( net::URLRequest* request, const net::CompletionCallback& callback, diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index a561fc05902..bc2601886ac 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -9,6 +9,7 @@ #include #include "net/base/network_delegate.h" +#include "net/proxy/proxy_server.h" namespace brightray { @@ -21,11 +22,6 @@ class NetworkDelegate : public net::NetworkDelegate { int OnBeforeURLRequest(net::URLRequest* request, const net::CompletionCallback& callback, GURL* new_url) override; - void OnResolveProxy(const GURL& url, - int load_flags, - const net::ProxyService& proxy_service, - net::ProxyInfo* result) override; - void OnProxyFallback(const net::ProxyServer& bad_proxy, int net_error) override; int OnBeforeSendHeaders(net::URLRequest* request, const net::CompletionCallback& callback, net::HttpRequestHeaders* headers) override; From f9dfa5466df635fc95a6ace5118f9ff2de7039f5 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Tue, 26 Apr 2016 23:07:11 -0400 Subject: [PATCH 0820/1195] Rename PERMISSION_STATUS enum value --- brightray/browser/permission_manager.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc index 26e3c622cee..8936678a4f7 100644 --- a/brightray/browser/permission_manager.cc +++ b/brightray/browser/permission_manager.cc @@ -27,7 +27,7 @@ int PermissionManager::RequestPermission( content::ChildProcessSecurityPolicy::GetInstance()-> GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID()); } - callback.Run(content::PERMISSION_STATUS_GRANTED); + callback.Run(content::PermissionStatus::GRANTED); return kNoPendingOperation; } @@ -45,7 +45,7 @@ int PermissionManager::RequestPermissions( GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID()); } - permissionStatuses.push_back(content::PERMISSION_STATUS_GRANTED); + permissionStatuses.push_back(content::PermissionStatus::GRANTED); } callback.Run(permissionStatuses); @@ -65,7 +65,7 @@ content::PermissionStatus PermissionManager::GetPermissionStatus( content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) { - return content::PERMISSION_STATUS_GRANTED; + return content::PermissionStatus::GRANTED; } void PermissionManager::RegisterPermissionUsage( From f8f97687dcde65645c8218464fbf95bbe620a915 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Tue, 26 Apr 2016 22:12:52 -0400 Subject: [PATCH 0821/1195] Update to new pref service location in components --- brightray/browser/browser_context.cc | 12 +++++++----- brightray/browser/inspectable_web_contents_impl.cc | 8 +++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 11214bd38ab..12d1d357741 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -13,10 +13,12 @@ #include "base/files/file_path.h" #include "base/path_service.h" -#include "base/prefs/json_pref_store.h" -#include "base/prefs/pref_registry_simple.h" -#include "base/prefs/pref_service.h" -#include "base/prefs/pref_service_factory.h" + +#include "components/prefs/json_pref_store.h" +#include "components/prefs/pref_registry_simple.h" +#include "components/prefs/pref_service.h" +#include "components/prefs/pref_service_factory.h" + #include "base/strings/string_util.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" @@ -112,7 +114,7 @@ BrowserContext::BrowserContext(const std::string& partition, bool in_memory) void BrowserContext::InitPrefs() { auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); - base::PrefServiceFactory prefs_factory; + PrefServiceFactory prefs_factory; prefs_factory.SetUserPrefsFile(prefs_path, JsonPrefStore::GetTaskRunnerForFile( prefs_path, BrowserThread::GetBlockingPool()).get()); diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 71c981bb409..09c5521c948 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -15,9 +15,11 @@ #include "base/json/json_reader.h" #include "base/json/json_writer.h" #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 "components/prefs/pref_service.h" +#include "components/prefs/scoped_user_pref_update.h" +#include "components/prefs/pref_registry_simple.h" + #include "base/strings/pattern.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" From df386f854f782c541d91034acf8b22219805f9c1 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Wed, 27 Apr 2016 11:53:33 -0400 Subject: [PATCH 0822/1195] GetNativeScreen -> GetScreen --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 09c5521c948..02cf75ffaae 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -214,7 +214,7 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( devtools_bounds_.set_height(600); devtools_bounds_.set_width(800); } - gfx::Rect display = gfx::Screen::GetNativeScreen() + gfx::Rect display = gfx::Screen::GetScreen() ->GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); if (!IsPointInRect(devtools_bounds_.origin(), display)) { devtools_bounds_.set_x(display.x() + (display.width() - devtools_bounds_.width()) / 2); From 88d8effa01401770d9ddb28f0db8c949640a32dd Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Wed, 27 Apr 2016 12:01:48 -0400 Subject: [PATCH 0823/1195] Iterator to use size_t --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 02cf75ffaae..be85d4a37d7 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -692,7 +692,7 @@ void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* sourc response.SetInteger("statusCode", rh ? rh->response_code() : 200); response.Set("headers", headers); - void* iterator = nullptr; + size_t iterator = 0; std::string name; std::string value; while (rh && rh->EnumerateHeaderLines(&iterator, &name, &value)) From c6f198a1af86b73eda42b27042a984cfd339ce82 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Sat, 30 Apr 2016 19:40:59 -0400 Subject: [PATCH 0824/1195] Update SetScreenInstance call for linux --- brightray/browser/browser_main_parts.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 888a1c52956..11bbe90c497 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -230,7 +230,7 @@ void BrowserMainParts::PostMainMessageLoopRun() { int BrowserMainParts::PreCreateThreads() { #if defined(USE_AURA) gfx::Screen* screen = views::CreateDesktopScreen(); - gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen); + gfx::Screen::SetScreenInstance(screen); #if defined(USE_X11) views::LinuxUI::instance()->UpdateDeviceScaleFactor( screen->GetPrimaryDisplay().device_scale_factor()); From 9d742d61350a4bf67bc4cc51aeac64190ba5eb15 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 13 May 2016 11:10:33 +0900 Subject: [PATCH 0825/1195] Update libchromiumcontent to chrome50 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 33cb3ff7ca0..c9e6091e670 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 33cb3ff7ca065375d44cac2143a8b09c4a99563e +Subproject commit c9e6091e670bfb7ec2cdee663300674e5727e7aa From 616fa3001998eb3b7559b1e322a516b0c64d09f8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 13 May 2016 13:39:34 +0900 Subject: [PATCH 0826/1195] Update gyp with support for CLANG_ENABLE_OBJC_WEAK --- brightray/.gitmodules | 2 +- brightray/vendor/gyp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/.gitmodules b/brightray/.gitmodules index e7b61d62c5b..719488608b5 100644 --- a/brightray/.gitmodules +++ b/brightray/.gitmodules @@ -3,7 +3,7 @@ url = https://github.com/electron/libchromiumcontent [submodule "vendor/gyp"] path = vendor/gyp - url = https://github.com/svn2github/gyp + url = https://github.com/electron/gyp [submodule "vendor/google-styleguide"] path = vendor/google-styleguide url = https://github.com/svn2github/sgss-mirror-google-styleguide diff --git a/brightray/vendor/gyp b/brightray/vendor/gyp index e0ee72ddc7f..549e55a2276 160000 --- a/brightray/vendor/gyp +++ b/brightray/vendor/gyp @@ -1 +1 @@ -Subproject commit e0ee72ddc7fb97eb33d530cf684efcbe4d27ecb3 +Subproject commit 549e55a22765ccf99e46b419b2dff6338bcac64a From 80cd5ae43b9984203973088ab8f63aa47ffca950 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 17 May 2016 20:26:19 +0900 Subject: [PATCH 0827/1195] Do not link with libnotify We are already loading it dynamically. --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 4a821d1b9f2..3978a5e368d 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -1,7 +1,7 @@ { 'variables': { # The libraries brightray will be compiled to. - 'linux_system_libraries': 'gtk+-2.0 libnotify dbus-1 x11 xi xcursor xdamage xrandr xcomposite xext xfixes xrender xtst gconf-2.0 gmodule-2.0 nss' + 'linux_system_libraries': 'gtk+-2.0 dbus-1 x11 xi xcursor xdamage xrandr xcomposite xext xfixes xrender xtst gconf-2.0 gmodule-2.0 nss' }, 'includes': [ 'filenames.gypi', From eb215c173ca32de3328773f79b8f60e7c0581dc0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 17 May 2016 20:30:53 +0900 Subject: [PATCH 0828/1195] Try linking with libnotify.so.5 --- brightray/browser/linux/libnotify_notification.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index 49c3b6ad047..a3f273c1c02 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -15,6 +15,7 @@ namespace brightray { namespace { + LibNotifyLoader libnotify_loader_; bool HasCapability(const std::string& capability) { @@ -35,7 +36,6 @@ bool NotifierSupportsActions() { static bool notify_has_result = false; static bool notify_result = false; - GList *capabilities = NULL; if (notify_has_result) return notify_result; @@ -62,7 +62,8 @@ Notification* Notification::Create(NotificationDelegate* delegate, // static bool LibnotifyNotification::Initialize() { - if (!libnotify_loader_.Load("libnotify.so.4") && + if (!libnotify_loader_.Load("libnotify.so.4") && // most common one + !libnotify_loader_.Load("libnotify.so.5") && !libnotify_loader_.Load("libnotify.so.1") && !libnotify_loader_.Load("libnotify.so")) { return false; From a45af78b15fb3beb8e0b9d8cff276794373599b5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 18 May 2016 09:42:14 +0900 Subject: [PATCH 0829/1195] Remove unneeded lines when importing code --- brightray/browser/linux/libnotify_loader.cc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/brightray/browser/linux/libnotify_loader.cc b/brightray/browser/linux/libnotify_loader.cc index 9720e64d8c1..747108529ae 100644 --- a/brightray/browser/linux/libnotify_loader.cc +++ b/brightray/browser/linux/libnotify_loader.cc @@ -23,7 +23,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_is_initted = reinterpret_castnotify_is_initted)>( dlsym(library_, "notify_is_initted")); - notify_is_initted = &::notify_is_initted; if (!notify_is_initted) { CleanUp(true); return false; @@ -32,7 +31,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_init = reinterpret_castnotify_init)>( dlsym(library_, "notify_init")); - notify_init = &::notify_init; if (!notify_init) { CleanUp(true); return false; @@ -41,7 +39,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_get_server_info = reinterpret_castnotify_get_server_info)>( dlsym(library_, "notify_get_server_info")); - notify_get_server_info = &::notify_get_server_info; if (!notify_get_server_info) { CleanUp(true); return false; @@ -50,7 +47,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_get_server_caps = reinterpret_castnotify_get_server_caps)>( dlsym(library_, "notify_get_server_caps")); - notify_get_server_caps = &::notify_get_server_caps; if (!notify_get_server_caps) { CleanUp(true); return false; @@ -59,7 +55,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_notification_new = reinterpret_castnotify_notification_new)>( dlsym(library_, "notify_notification_new")); - notify_notification_new = &::notify_notification_new; if (!notify_notification_new) { CleanUp(true); return false; @@ -68,7 +63,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_notification_add_action = reinterpret_castnotify_notification_add_action)>( dlsym(library_, "notify_notification_add_action")); - notify_notification_add_action = &::notify_notification_add_action; if (!notify_notification_add_action) { CleanUp(true); return false; @@ -77,7 +71,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_notification_set_image_from_pixbuf = reinterpret_castnotify_notification_set_image_from_pixbuf)>( dlsym(library_, "notify_notification_set_image_from_pixbuf")); - notify_notification_set_image_from_pixbuf = &::notify_notification_set_image_from_pixbuf; if (!notify_notification_set_image_from_pixbuf) { CleanUp(true); return false; @@ -86,7 +79,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_notification_set_timeout = reinterpret_castnotify_notification_set_timeout)>( dlsym(library_, "notify_notification_set_timeout")); - notify_notification_set_timeout = &::notify_notification_set_timeout; if (!notify_notification_set_timeout) { CleanUp(true); return false; @@ -95,7 +87,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_notification_set_hint_string = reinterpret_castnotify_notification_set_hint_string)>( dlsym(library_, "notify_notification_set_hint_string")); - notify_notification_set_hint_string = &::notify_notification_set_hint_string; if (!notify_notification_set_hint_string) { CleanUp(true); return false; @@ -104,7 +95,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_notification_show = reinterpret_castnotify_notification_show)>( dlsym(library_, "notify_notification_show")); - notify_notification_show = &::notify_notification_show; if (!notify_notification_show) { CleanUp(true); return false; @@ -113,7 +103,6 @@ bool LibNotifyLoader::Load(const std::string& library_name) { notify_notification_close = reinterpret_castnotify_notification_close)>( dlsym(library_, "notify_notification_close")); - notify_notification_close = &::notify_notification_close; if (!notify_notification_close) { CleanUp(true); return false; From e7168306714b8bd45a11ae5a8a9f35d6945d8450 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 17 May 2016 23:49:23 +0530 Subject: [PATCH 0830/1195] flag to disable HTTP/2 and SPDY/3.1 protocols --- brightray/browser/url_request_context_getter.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 86ebc90efdb..a2f7032f683 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -89,6 +89,9 @@ const char kProxyBypassList[] = "proxy-bypass-list"; // Uses the pac script at the given URL. const char kProxyPacUrl[] = "proxy-pac-url"; +// Disable HTTP/2 and SPDY/3.1 protocols. +const char kDisableHttp2[] = "disable-http2"; + } // namespace @@ -341,7 +344,12 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.http_auth_handler_factory = url_request_context_->http_auth_handler_factory(); network_session_params.net_log = url_request_context_->net_log(); - network_session_params.enable_http2 = true; + + // --disable-http2 + if (command_line.HasSwitch(kDisableHttp2)) { + network_session_params.enable_spdy31 = false; + network_session_params.enable_http2 = false; + } // --ignore-certificate-errors if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) From 3d019301226790dda90f61bb6ad60bed26539599 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 19 May 2016 15:05:32 +0900 Subject: [PATCH 0831/1195] Link with static runtime library for Release build --- brightray/brightray.gypi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 8bae0735b9e..d22c458ce14 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -54,7 +54,6 @@ ], 'msvs_settings': { 'VCCLCompilerTool': { - 'RuntimeLibrary': '2', # /MD (nondebug DLL) 'AdditionalOptions': ['/MP'], 'MinimalRebuild': 'false', 'BufferSecurityCheck': 'true', @@ -226,6 +225,7 @@ ], 'msvs_settings': { 'VCCLCompilerTool': { + 'RuntimeLibrary': '2', # /MD (nondebug DLL) 'Optimization': '0', # 0 = /Od # See http://msdn.microsoft.com/en-us/library/8wtf2dfz(VS.71).aspx 'BasicRuntimeChecks': '3', # 3 = all checks enabled, 0 = off @@ -236,6 +236,7 @@ 'abstract': 1, 'msvs_settings': { 'VCCLCompilerTool': { + 'RuntimeLibrary': '0', # /MT (nondebug static) # 1, optimizeMinSpace, Minimize Size (/O1) 'Optimization': '1', # 2, favorSize - Favor small code (/Os) From b8e8e08f63f3221505615c72a5ce46868f99cc65 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sat, 21 May 2016 23:40:02 +0530 Subject: [PATCH 0832/1195] flags to control iwa enabled server whitelist --- .../browser/url_request_context_getter.cc | 54 +++++++------------ .../browser/url_request_context_getter.h | 24 +-------- 2 files changed, 20 insertions(+), 58 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index a2f7032f683..7bd479e34f6 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -92,34 +92,14 @@ const char kProxyPacUrl[] = "proxy-pac-url"; // Disable HTTP/2 and SPDY/3.1 protocols. const char kDisableHttp2[] = "disable-http2"; +// Whitelist containing servers for which Integrated Authentication is enabled. +const char kAuthServerWhitelist[] = "auth-server-whitelist"; + +// Whitelist containing servers for which Kerberos delegation is allowed. +const char kAuthNegotiateDelegateWhitelist[] = "auth-negotiate-delegate-whitelist"; + } // namespace - -URLRequestContextGetter::DelegateURLSecurityManager::DelegateURLSecurityManager - (URLRequestContextGetter::Delegate* delegate) : - delegate_(delegate) {} - -bool URLRequestContextGetter::DelegateURLSecurityManager::CanUseDefaultCredentials - (const GURL& auth_origin) const { - return delegate_->AllowNTLMCredentialsForDomain(auth_origin); -} - -bool URLRequestContextGetter::DelegateURLSecurityManager::CanDelegate - (const GURL& auth_origin) const { - return delegate_->CanDelegateURLSecurity(auth_origin); -} - -void URLRequestContextGetter::DelegateURLSecurityManager::SetDefaultWhitelist( - scoped_ptr whitelist_default) { -} - -void URLRequestContextGetter::DelegateURLSecurityManager::SetDelegateWhitelist( - scoped_ptr whitelist_delegate) { -} - -URLRequestContextGetter::Delegate::Delegate() : - orig_url_sec_mgr_(net::URLSecurityManager::Create()) {} - std::string URLRequestContextGetter::Delegate::GetUserAgent() { return base::EmptyString(); } @@ -174,15 +154,6 @@ net::SSLConfigService* URLRequestContextGetter::Delegate::CreateSSLConfigService return new net::SSLConfigServiceDefaults; } -bool URLRequestContextGetter::Delegate::AllowNTLMCredentialsForDomain(const GURL& auth_origin) { - return orig_url_sec_mgr_->CanUseDefaultCredentials(auth_origin); -} - -bool URLRequestContextGetter::Delegate::CanDelegateURLSecurity(const GURL& auth_origin) { - return orig_url_sec_mgr_->CanDelegate(auth_origin); -} - - URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, DevToolsNetworkControllerHandle* handle, @@ -317,6 +288,19 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { #else http_auth_preferences_.reset(new net::HttpAuthPreferences(schemes)); #endif + + // --auth-server-whitelist + if (command_line.HasSwitch(kAuthServerWhitelist)) { + http_auth_preferences_->set_server_whitelist( + command_line.GetSwitchValueASCII(kAuthServerWhitelist)); + } + + // --auth-negotiate-delegate-whitelist + if (command_line.HasSwitch(kAuthNegotiateDelegateWhitelist)) { + http_auth_preferences_->set_delegate_whitelist( + command_line.GetSwitchValueASCII(kAuthNegotiateDelegateWhitelist)); + } + auto auth_handler_factory = net::HttpAuthHandlerRegistryFactory::Create( http_auth_preferences_.get(), host_resolver.get()); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 3f06ba78ba2..546cda9b8ac 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -35,7 +35,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { public: class Delegate { public: - Delegate(); + Delegate() {} virtual ~Delegate() {} virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; } @@ -47,28 +47,6 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { const base::FilePath& base_path); virtual scoped_ptr CreateCertVerifier(); virtual net::SSLConfigService* CreateSSLConfigService(); - virtual bool AllowNTLMCredentialsForDomain(const GURL& auth_origin); - virtual bool CanDelegateURLSecurity(const GURL& auth_origin); - - private: - scoped_ptr orig_url_sec_mgr_; - }; - - class DelegateURLSecurityManager : public net::URLSecurityManager { - public: - DelegateURLSecurityManager(URLRequestContextGetter::Delegate* delegate); - - bool CanUseDefaultCredentials(const GURL& auth_origin) const override; - bool CanDelegate(const GURL& auth_origin) const override; - void SetDefaultWhitelist( - scoped_ptr whitelist_default) override; - void SetDelegateWhitelist( - scoped_ptr whitelist_delegate) override; - - private: - URLRequestContextGetter::Delegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(DelegateURLSecurityManager); }; URLRequestContextGetter( From e7be3d0ef9025873b331006a20fbd4a57b9cc3f8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 22 May 2016 18:06:06 +0900 Subject: [PATCH 0833/1195] Update to Chrome 51 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index c9e6091e670..31ff4384348 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit c9e6091e670bfb7ec2cdee663300674e5727e7aa +Subproject commit 31ff4384348b139d9e138d4df41b85a11d1a4dbb From 851ef398fb6a423997880ee07ff6d5e2d6ede996 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 May 2016 10:59:07 +0900 Subject: [PATCH 0834/1195] Adapt to changes of Chrome 51 API changes --- brightray/browser/browser_client.cc | 14 ------ brightray/browser/browser_client.h | 13 ++---- brightray/browser/browser_context.cc | 22 ++++----- brightray/browser/browser_context.h | 17 ++++--- brightray/browser/browser_main_parts.cc | 2 +- brightray/browser/browser_main_parts.h | 7 ++- .../browser/devtools_manager_delegate.cc | 10 ++-- brightray/browser/devtools_manager_delegate.h | 2 +- .../browser/inspectable_web_contents_impl.cc | 6 +-- .../browser/inspectable_web_contents_impl.h | 10 ++-- brightray/browser/mac/cocoa_notification.h | 1 - .../media/media_capture_devices_dispatcher.h | 1 - .../media/media_stream_devices_controller.cc | 8 ++-- .../net/devtools_network_controller.cc | 8 ++-- .../browser/net/devtools_network_controller.h | 7 ++- .../net/devtools_network_controller_handle.cc | 4 +- .../net/devtools_network_controller_handle.h | 7 ++- .../net/devtools_network_interceptor.cc | 2 +- .../net/devtools_network_interceptor.h | 5 +- .../net/devtools_network_protocol_handler.cc | 24 +++++----- .../net/devtools_network_protocol_handler.h | 7 ++- .../net/devtools_network_transaction.cc | 2 +- .../net/devtools_network_transaction.h | 9 ++-- .../devtools_network_transaction_factory.cc | 4 +- .../devtools_network_transaction_factory.h | 5 +- brightray/browser/net_log.cc | 6 +-- .../browser/notification_delegate_adapter.cc | 2 +- .../browser/notification_delegate_adapter.h | 8 ++-- brightray/browser/permission_manager.cc | 16 +++---- brightray/browser/permission_manager.h | 8 ++-- .../browser/platform_notification_service.cc | 6 +-- .../browser/platform_notification_service.h | 3 +- .../browser/url_request_context_getter.cc | 46 +++++++++---------- .../browser/url_request_context_getter.h | 26 +++++------ .../inspectable_web_contents_view_views.h | 2 +- .../browser/win/notification_presenter_win.cc | 2 +- brightray/common/application_info_win.cc | 5 +- brightray/common/main_delegate.cc | 15 +++--- brightray/common/main_delegate.h | 11 ++--- 39 files changed, 157 insertions(+), 196 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 88c41957ae9..7a386c2d7ff 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -68,16 +68,6 @@ content::BrowserMainParts* BrowserClient::CreateBrowserMainParts( return browser_main_parts_; } -net::URLRequestContextGetter* BrowserClient::CreateRequestContext( - content::BrowserContext* browser_context, - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector protocol_interceptors) { - auto context = static_cast(browser_context); - return context->CreateRequestContext(static_cast(GetNetLog()), - protocol_handlers, - std::move(protocol_interceptors)); -} - content::MediaObserver* BrowserClient::GetMediaObserver() { return MediaCaptureDevicesDispatcher::GetInstance(); } @@ -94,10 +84,6 @@ void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( additional_schemes->push_back(content::kChromeUIScheme); } -net::NetLog* BrowserClient::GetNetLog() { - return &net_log_; -} - base::FilePath BrowserClient::GetDefaultDownloadDirectory() { // ~/Downloads base::FilePath path; diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 9b7cff7fe4c..b5ee8a18940 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -5,14 +5,13 @@ #ifndef BRIGHTRAY_BROWSER_BROWSER_CLIENT_H_ #define BRIGHTRAY_BROWSER_BROWSER_CLIENT_H_ -#include "browser/net_log.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" namespace brightray { class BrowserContext; class BrowserMainParts; -class NetLog; class NotificationPresenter; class PlatformNotificationService; @@ -43,26 +42,20 @@ class BrowserClient : public content::ContentBrowserClient { // Subclasses that override this (e.g., to provide their own protocol // handlers) should call this implementation after doing their own work. - net::URLRequestContextGetter* CreateRequestContext( - content::BrowserContext* browser_context, - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector protocol_interceptors) override; content::BrowserMainParts* CreateBrowserMainParts( const content::MainFunctionParams&) override; content::MediaObserver* GetMediaObserver() override; content::PlatformNotificationService* GetPlatformNotificationService() override; void GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) override; - net::NetLog* GetNetLog() override; base::FilePath GetDefaultDownloadDirectory() override; content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override; BrowserMainParts* browser_main_parts_; - NetLog net_log_; private: - scoped_ptr notification_service_; - scoped_ptr notification_presenter_; + std::unique_ptr notification_service_; + std::unique_ptr notification_presenter_; DISALLOW_COPY_AND_ASSIGN(BrowserClient); }; diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 12d1d357741..10132a7cd10 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -64,16 +64,16 @@ class BrowserContext::ResourceContext : public content::ResourceContext { return getter_->GetURLRequestContext(); } - scoped_ptr CreateClientCertStore() override { + std::unique_ptr CreateClientCertStore() override { #if defined(USE_NSS_CERTS) - return scoped_ptr(new net::ClientCertStoreNSS( + return std::unique_ptr(new net::ClientCertStoreNSS( net::ClientCertStoreNSS::PasswordDelegateFactory())); #elif defined(OS_WIN) - return scoped_ptr(new net::ClientCertStoreWin()); + return std::unique_ptr(new net::ClientCertStoreWin()); #elif defined(OS_MACOSX) - return scoped_ptr(new net::ClientCertStoreMac()); + return std::unique_ptr(new net::ClientCertStoreMac()); #elif defined(USE_OPENSSL) - return scoped_ptr(); + return std::unique_ptr(); #endif } @@ -137,14 +137,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, network_controller_handle(), - net_log, + net_log_, GetPath(), in_memory_, BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), @@ -163,9 +162,9 @@ base::FilePath BrowserContext::GetPath() const { return path_; } -scoped_ptr BrowserContext::CreateZoomLevelDelegate( +std::unique_ptr BrowserContext::CreateZoomLevelDelegate( const base::FilePath& partition_path) { - return scoped_ptr(); + return std::unique_ptr(); } bool BrowserContext::IsOffTheRecord() const { @@ -176,11 +175,6 @@ net::URLRequestContextGetter* BrowserContext::GetRequestContext() { return GetDefaultStoragePartition(this)->GetURLRequestContext(); } -net::URLRequestContextGetter* BrowserContext::GetRequestContextForRenderProcess( - int renderer_child_id) { - return GetRequestContext(); -} - net::URLRequestContextGetter* BrowserContext::GetMediaRequestContext() { return GetRequestContext(); } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 5ec2b2bcede..1604774440c 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -7,6 +7,7 @@ #include +#include "browser/net_log.h" #include "browser/net/devtools_network_controller_handle.h" #include "browser/permission_manager.h" #include "browser/url_request_context_getter.h" @@ -24,6 +25,7 @@ class SpecialStoragePolicy; namespace brightray { +class NetLog; class PermissionManager; class BrowserContext : public base::RefCounted, @@ -39,12 +41,10 @@ class BrowserContext : public base::RefCounted, const std::string& partition, bool in_memory); // content::BrowserContext: - scoped_ptr CreateZoomLevelDelegate( + std::unique_ptr CreateZoomLevelDelegate( const base::FilePath& partition_path) override; bool IsOffTheRecord() const override; net::URLRequestContextGetter* GetRequestContext() override; - net::URLRequestContextGetter* GetRequestContextForRenderProcess( - int renderer_child_id) override; net::URLRequestContextGetter* GetMediaRequestContext() override; net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( int renderer_child_id) override; @@ -58,11 +58,9 @@ class BrowserContext : public base::RefCounted, content::SSLHostStateDelegate* GetSSLHostStateDelegate() override; content::PermissionManager* GetPermissionManager() override; content::BackgroundSyncController* GetBackgroundSyncController() override; - net::URLRequestContextGetter* CreateRequestContext( - NetLog* net_log, content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector protocol_interceptors); + content::URLRequestInterceptorScopedVector request_interceptors) override; net::URLRequestContextGetter* url_request_context_getter() const { return url_request_getter_.get(); @@ -119,12 +117,13 @@ class BrowserContext : public base::RefCounted, bool in_memory_; DevToolsNetworkControllerHandle network_controller_handle_; + NetLog net_log_; - scoped_ptr resource_context_; + std::unique_ptr resource_context_; scoped_refptr url_request_getter_; scoped_refptr storage_policy_; - scoped_ptr prefs_; - scoped_ptr permission_manager_; + std::unique_ptr prefs_; + std::unique_ptr permission_manager_; base::WeakPtrFactory weak_factory_; diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 11bbe90c497..bc6ecd88dbd 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -76,7 +76,7 @@ void OverrideLinuxAppDataPath() { base::FilePath path; if (PathService::Get(DIR_APP_DATA, &path)) return; - scoped_ptr env(base::Environment::Create()); + std::unique_ptr env(base::Environment::Create()); path = base::nix::GetXDGDirectory(env.get(), base::nix::kXdgConfigHomeEnvVar, base::nix::kDotConfigDir); diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 5b50516f7cc..40adc027282 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -7,7 +7,6 @@ #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_main_parts.h" namespace devtools_http_handler { @@ -53,14 +52,14 @@ class BrowserMainParts : public content::BrowserMainParts { #endif scoped_refptr browser_context_; - scoped_ptr devtools_http_handler_; + std::unique_ptr devtools_http_handler_; #if defined(TOOLKIT_VIEWS) - scoped_ptr views_delegate_; + std::unique_ptr views_delegate_; #endif #if defined(USE_AURA) && defined(USE_X11) - scoped_ptr wm_state_; + std::unique_ptr wm_state_; #endif DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index b79c94f8140..1464362f3ad 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -45,11 +45,11 @@ class TCPServerSocketFactory private: // content::DevToolsHttpHandler::ServerSocketFactory. - scoped_ptr CreateForHttpServer() override { - scoped_ptr socket( + std::unique_ptr CreateForHttpServer() override { + std::unique_ptr socket( new net::TCPServerSocket(nullptr, net::NetLog::Source())); if (socket->ListenWithAddressAndPort(address_, port_, 10) != net::OK) - return scoped_ptr(); + return std::unique_ptr(); return socket; } @@ -60,7 +60,7 @@ class TCPServerSocketFactory DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); }; -scoped_ptr +std::unique_ptr CreateSocketFactory() { auto& command_line = *base::CommandLine::ForCurrentProcess(); // See if the user specified a port on the command line (useful for @@ -77,7 +77,7 @@ CreateSocketFactory() { DLOG(WARNING) << "Invalid http debugger port number " << temp_port; } } - return scoped_ptr< + return std::unique_ptr< devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory>( new TCPServerSocketFactory("127.0.0.1", port)); } diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h index 34e6a6bd704..23d28c74dbb 100644 --- a/brightray/browser/devtools_manager_delegate.h +++ b/brightray/browser/devtools_manager_delegate.h @@ -34,7 +34,7 @@ class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { base::DictionaryValue* command) override; private: - scoped_ptr handler_; + std::unique_ptr handler_; DISALLOW_COPY_AND_ASSIGN(DevToolsManagerDelegate); }; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index be85d4a37d7..80429a1a189 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -190,7 +190,7 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents_impl); void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { - auto bounds_dict = make_scoped_ptr(new base::DictionaryValue); + auto bounds_dict = make_std::unique_ptr(new base::DictionaryValue); RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get()); registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release()); registry->RegisterDoublePref(kDevToolsZoomPref, 0.); @@ -412,7 +412,7 @@ void InspectableWebContentsImpl::LoadNetworkResource( pending_requests_[fetcher] = callback; fetcher->SetRequestContext(browser_context->url_request_context_getter()); fetcher->SetExtraRequestHeaders(headers); - fetcher->SaveResponseWithWriter(scoped_ptr( + fetcher->SaveResponseWithWriter(std::unique_ptr( new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id))); fetcher->Start(); } @@ -562,7 +562,7 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::st base::ListValue* params = &empty_params; base::DictionaryValue* dict = nullptr; - scoped_ptr parsed_message(base::JSONReader::Read(message)); + std::unique_ptr parsed_message(base::JSONReader::Read(message)); if (!parsed_message || !parsed_message->GetAsDictionary(&dict) || !dict->GetString(kFrontendHostMethod, &method) || diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index b6e91a7d0f5..f9496a75398 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -162,8 +162,8 @@ class InspectableWebContentsImpl : bool frontend_loaded_; scoped_refptr agent_host_; - scoped_ptr frontend_host_; - scoped_ptr embedder_message_dispatcher_; + std::unique_ptr frontend_host_; + std::unique_ptr embedder_message_dispatcher_; DevToolsContentsResizingStrategy contents_resizing_strategy_; gfx::Rect devtools_bounds_; @@ -176,9 +176,9 @@ class InspectableWebContentsImpl : PrefService* pref_service_; // weak reference. - scoped_ptr web_contents_; - scoped_ptr devtools_web_contents_; - scoped_ptr view_; + std::unique_ptr web_contents_; + std::unique_ptr devtools_web_contents_; + std::unique_ptr view_; base::WeakPtrFactory weak_factory_; diff --git a/brightray/browser/mac/cocoa_notification.h b/brightray/browser/mac/cocoa_notification.h index 7287f00f245..f6ec9e9da6b 100644 --- a/brightray/browser/mac/cocoa_notification.h +++ b/brightray/browser/mac/cocoa_notification.h @@ -8,7 +8,6 @@ #import #include "base/mac/scoped_nsobject.h" -#include "base/memory/scoped_ptr.h" #include "browser/notification.h" namespace brightray { diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index c62a917572d..27fe6766469 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -6,7 +6,6 @@ #define BRIGHTRAY_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_ #include "base/callback.h" -#include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "content/public/browser/media_observer.h" #include "content/public/browser/web_contents_delegate.h" diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index 1a205f1ed77..103feea369d 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -43,7 +43,7 @@ MediaStreamDevicesController::~MediaStreamDevicesController() { if (!callback_.is_null()) { callback_.Run(content::MediaStreamDevices(), content::MEDIA_DEVICE_INVALID_STATE, - scoped_ptr()); + std::unique_ptr()); } } @@ -146,7 +146,7 @@ void MediaStreamDevicesController::Accept() { content::MediaResponseCallback cb = callback_; callback_.Reset(); - cb.Run(devices, content::MEDIA_DEVICE_OK, scoped_ptr()); + cb.Run(devices, content::MEDIA_DEVICE_OK, std::unique_ptr()); } void MediaStreamDevicesController::Deny(content::MediaStreamRequestResult result) { @@ -154,7 +154,7 @@ void MediaStreamDevicesController::Deny(content::MediaStreamRequestResult result callback_.Reset(); cb.Run(content::MediaStreamDevices(), result, - scoped_ptr()); + std::unique_ptr()); } void MediaStreamDevicesController::HandleUserMediaRequest() { @@ -194,7 +194,7 @@ void MediaStreamDevicesController::HandleUserMediaRequest() { cb.Run(devices, devices.empty() ? content::MEDIA_DEVICE_INVALID_STATE : content::MEDIA_DEVICE_OK, - scoped_ptr()); + std::unique_ptr()); } } // namespace brightray diff --git a/brightray/browser/net/devtools_network_controller.cc b/brightray/browser/net/devtools_network_controller.cc index 7313a378432..cb2f92ba222 100644 --- a/brightray/browser/net/devtools_network_controller.cc +++ b/brightray/browser/net/devtools_network_controller.cc @@ -24,20 +24,20 @@ DevToolsNetworkController::~DevToolsNetworkController() { void DevToolsNetworkController::SetNetworkState( const std::string& client_id, - scoped_ptr conditions) { + std::unique_ptr conditions) { DCHECK_CURRENTLY_ON(BrowserThread::IO); DevToolsNetworkInterceptor* interceptor = interceptors_.get(client_id); if (!interceptor) { if (!conditions) return; - scoped_ptr new_interceptor( + std::unique_ptr new_interceptor( new DevToolsNetworkInterceptor); new_interceptor->UpdateConditions(std::move(conditions)); interceptors_.set(client_id, std::move(new_interceptor)); } else { if (!conditions) { - scoped_ptr online_conditions( + std::unique_ptr online_conditions( new DevToolsNetworkConditions(false)); interceptor->UpdateConditions(std::move(online_conditions)); interceptors_.erase(client_id); @@ -57,7 +57,7 @@ void DevToolsNetworkController::SetNetworkState( bool is_appcache_offline = appcache_interceptor_->IsOffline(); if (is_appcache_offline != has_offline_interceptors) { - scoped_ptr appcache_conditions( + std::unique_ptr appcache_conditions( new DevToolsNetworkConditions(has_offline_interceptors)); appcache_interceptor_->UpdateConditions(std::move(appcache_conditions)); } diff --git a/brightray/browser/net/devtools_network_controller.h b/brightray/browser/net/devtools_network_controller.h index 2e3ab419da4..02bb6985594 100644 --- a/brightray/browser/net/devtools_network_controller.h +++ b/brightray/browser/net/devtools_network_controller.h @@ -7,7 +7,6 @@ #include "base/containers/scoped_ptr_hash_map.h" #include "base/macros.h" -#include "base/memory/scoped_ptr.h" namespace brightray { @@ -21,14 +20,14 @@ class DevToolsNetworkController { virtual ~DevToolsNetworkController(); void SetNetworkState(const std::string& client_id, - scoped_ptr conditions); + std::unique_ptr conditions); DevToolsNetworkInterceptor* GetInterceptor(const std::string& client_id); private: using InterceptorMap = base::ScopedPtrHashMap>; + std::unique_ptr>; - scoped_ptr appcache_interceptor_; + std::unique_ptr appcache_interceptor_; InterceptorMap interceptors_; DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkController); diff --git a/brightray/browser/net/devtools_network_controller_handle.cc b/brightray/browser/net/devtools_network_controller_handle.cc index efc53a23a17..44b7b9c6c14 100644 --- a/brightray/browser/net/devtools_network_controller_handle.cc +++ b/brightray/browser/net/devtools_network_controller_handle.cc @@ -25,7 +25,7 @@ DevToolsNetworkControllerHandle::~DevToolsNetworkControllerHandle() { void DevToolsNetworkControllerHandle::SetNetworkState( const std::string& client_id, - scoped_ptr conditions) { + std::unique_ptr conditions) { DCHECK_CURRENTLY_ON(BrowserThread::UI); BrowserThread::PostTask( @@ -50,7 +50,7 @@ void DevToolsNetworkControllerHandle::LazyInitialize() { void DevToolsNetworkControllerHandle::SetNetworkStateOnIO( const std::string& client_id, - scoped_ptr conditions) { + std::unique_ptr conditions) { DCHECK_CURRENTLY_ON(BrowserThread::IO); LazyInitialize(); diff --git a/brightray/browser/net/devtools_network_controller_handle.h b/brightray/browser/net/devtools_network_controller_handle.h index f009d273268..1eefa6244e5 100644 --- a/brightray/browser/net/devtools_network_controller_handle.h +++ b/brightray/browser/net/devtools_network_controller_handle.h @@ -8,7 +8,6 @@ #include #include "base/macros.h" -#include "base/memory/scoped_ptr.h" namespace brightray { @@ -24,7 +23,7 @@ class DevToolsNetworkControllerHandle { // Called on the UI thread. void SetNetworkState(const std::string& client_id, - scoped_ptr conditions); + std::unique_ptr conditions); // Called on the IO thread. DevToolsNetworkController* GetController(); @@ -32,9 +31,9 @@ class DevToolsNetworkControllerHandle { private: void LazyInitialize(); void SetNetworkStateOnIO(const std::string& client_id, - scoped_ptr conditions); + std::unique_ptr conditions); - scoped_ptr controller_; + std::unique_ptr controller_; DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkControllerHandle); }; diff --git a/brightray/browser/net/devtools_network_interceptor.cc b/brightray/browser/net/devtools_network_interceptor.cc index f1f8c63ae55..fa866b4aa12 100644 --- a/brightray/browser/net/devtools_network_interceptor.cc +++ b/brightray/browser/net/devtools_network_interceptor.cc @@ -66,7 +66,7 @@ void DevToolsNetworkInterceptor::FinishRecords( } void DevToolsNetworkInterceptor::UpdateConditions( - scoped_ptr conditions) { + std::unique_ptr conditions) { DCHECK(conditions); base::TimeTicks now = base::TimeTicks::Now(); if (conditions_->IsThrottling()) diff --git a/brightray/browser/net/devtools_network_interceptor.h b/brightray/browser/net/devtools_network_interceptor.h index d1293e41acc..4a04876b6f1 100644 --- a/brightray/browser/net/devtools_network_interceptor.h +++ b/brightray/browser/net/devtools_network_interceptor.h @@ -10,7 +10,6 @@ #include #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "base/timer/timer.h" namespace base { @@ -33,7 +32,7 @@ class DevToolsNetworkInterceptor { base::WeakPtr GetWeakPtr(); // Applies network emulation configuration. - void UpdateConditions(scoped_ptr conditions); + void UpdateConditions(std::unique_ptr conditions); // Throttles with |is_upload == true| always succeed, even in offline mode. int StartThrottle(int result, @@ -81,7 +80,7 @@ class DevToolsNetworkInterceptor { void RemoveRecord(ThrottleRecords* records, const ThrottleCallback& callback); - scoped_ptr conditions_; + std::unique_ptr conditions_; // Throttables suspended for a "latency" period. ThrottleRecords suspended_; diff --git a/brightray/browser/net/devtools_network_protocol_handler.cc b/brightray/browser/net/devtools_network_protocol_handler.cc index b5e723d06a6..60a3a15a0a3 100644 --- a/brightray/browser/net/devtools_network_protocol_handler.cc +++ b/brightray/browser/net/devtools_network_protocol_handler.cc @@ -59,17 +59,17 @@ bool ParseCommand(const base::DictionaryValue* command, return true; } -scoped_ptr -CreateSuccessResponse(int id, scoped_ptr result) { - scoped_ptr response(new base::DictionaryValue); +std::unique_ptr +CreateSuccessResponse(int id, std::unique_ptr result) { + std::unique_ptr response(new base::DictionaryValue); response->SetInteger(kId, id); response->Set(params::kResult, result.release()); return response; } -scoped_ptr +std::unique_ptr CreateFailureResponse(int id, const std::string& param) { - scoped_ptr response(new base::DictionaryValue); + std::unique_ptr response(new base::DictionaryValue); auto error_object = new base::DictionaryValue; response->Set(kError, error_object); error_object->SetInteger(params::kErrorCode, kErrorInvalidParams); @@ -108,23 +108,23 @@ base::DictionaryValue* DevToolsNetworkProtocolHandler::HandleCommand( void DevToolsNetworkProtocolHandler::DevToolsAgentStateChanged( content::DevToolsAgentHost* agent_host, bool attached) { - scoped_ptr conditions; + std::unique_ptr conditions; if (attached) conditions.reset(new DevToolsNetworkConditions(false)); UpdateNetworkState(agent_host, std::move(conditions)); } -scoped_ptr +std::unique_ptr DevToolsNetworkProtocolHandler::CanEmulateNetworkConditions( content::DevToolsAgentHost* agent_host, int id, const base::DictionaryValue* params) { - scoped_ptr result(new base::DictionaryValue); + std::unique_ptr result(new base::DictionaryValue); result->SetBoolean(params::kResult, true); return CreateSuccessResponse(id, std::move(result)); } -scoped_ptr +std::unique_ptr DevToolsNetworkProtocolHandler::EmulateNetworkConditions( content::DevToolsAgentHost* agent_host, int id, @@ -151,18 +151,18 @@ DevToolsNetworkProtocolHandler::EmulateNetworkConditions( if (upload_throughput < 0.0) upload_throughput = 0.0; - scoped_ptr conditions( + std::unique_ptr conditions( new DevToolsNetworkConditions(offline, latency, download_throughput, upload_throughput)); UpdateNetworkState(agent_host, std::move(conditions)); - return scoped_ptr(); + return std::unique_ptr(); } void DevToolsNetworkProtocolHandler::UpdateNetworkState( content::DevToolsAgentHost* agent_host, - scoped_ptr conditions) { + std::unique_ptr conditions) { auto browser_context = static_cast(agent_host->GetBrowserContext()); browser_context->network_controller_handle()->SetNetworkState( diff --git a/brightray/browser/net/devtools_network_protocol_handler.h b/brightray/browser/net/devtools_network_protocol_handler.h index fd9c996cdc1..9ec577814c3 100644 --- a/brightray/browser/net/devtools_network_protocol_handler.h +++ b/brightray/browser/net/devtools_network_protocol_handler.h @@ -6,7 +6,6 @@ #define BROWSER_DEVTOOLS_NETWORK_PROTOCOL_HANDLER_H_ #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "base/values.h" namespace content { @@ -29,17 +28,17 @@ class DevToolsNetworkProtocolHandler { bool attached); private: - scoped_ptr CanEmulateNetworkConditions( + std::unique_ptr CanEmulateNetworkConditions( content::DevToolsAgentHost* agent_host, int command_id, const base::DictionaryValue* params); - scoped_ptr EmulateNetworkConditions( + std::unique_ptr EmulateNetworkConditions( content::DevToolsAgentHost* agent_host, int command_id, const base::DictionaryValue* params); void UpdateNetworkState( content::DevToolsAgentHost* agent_host, - scoped_ptr conditions); + std::unique_ptr conditions); DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkProtocolHandler); }; diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc index 48ed4232db8..e4c057b289d 100644 --- a/brightray/browser/net/devtools_network_transaction.cc +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -22,7 +22,7 @@ const char DevToolsNetworkTransaction::DevToolsNetworkTransaction( DevToolsNetworkController* controller, - scoped_ptr transaction) + std::unique_ptr transaction) : throttled_byte_count_(0), controller_(controller), transaction_(std::move(transaction)), diff --git a/brightray/browser/net/devtools_network_transaction.h b/brightray/browser/net/devtools_network_transaction.h index a7f08651f65..3de3a158767 100644 --- a/brightray/browser/net/devtools_network_transaction.h +++ b/brightray/browser/net/devtools_network_transaction.h @@ -7,7 +7,6 @@ #include -#include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "browser/net/devtools_network_interceptor.h" #include "net/base/completion_callback.h" @@ -27,7 +26,7 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { DevToolsNetworkTransaction( DevToolsNetworkController* controller, - scoped_ptr network_transaction); + std::unique_ptr network_transaction); ~DevToolsNetworkTransaction() override; // HttpTransaction methods: @@ -89,13 +88,13 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { base::WeakPtr interceptor_; // Modified upload data stream. Should be destructed after |custom_request_|. - scoped_ptr custom_upload_data_stream_; + std::unique_ptr custom_upload_data_stream_; // Modified request. Should be destructed after |transaction_|. - scoped_ptr custom_request_; + std::unique_ptr custom_request_; // Original network transaction. - scoped_ptr transaction_; + std::unique_ptr transaction_; const net::HttpRequestInfo* request_; diff --git a/brightray/browser/net/devtools_network_transaction_factory.cc b/brightray/browser/net/devtools_network_transaction_factory.cc index d3fb4cfb08b..7373c14ddef 100644 --- a/brightray/browser/net/devtools_network_transaction_factory.cc +++ b/brightray/browser/net/devtools_network_transaction_factory.cc @@ -30,8 +30,8 @@ DevToolsNetworkTransactionFactory::~DevToolsNetworkTransactionFactory() { int DevToolsNetworkTransactionFactory::CreateTransaction( net::RequestPriority priority, - scoped_ptr* transaction) { - scoped_ptr new_transaction; + std::unique_ptr* transaction) { + std::unique_ptr new_transaction; int rv = network_layer_->CreateTransaction(priority, &new_transaction); if (rv != net::OK) return rv; diff --git a/brightray/browser/net/devtools_network_transaction_factory.h b/brightray/browser/net/devtools_network_transaction_factory.h index a14d97c1d13..a6c8f6a3c2d 100644 --- a/brightray/browser/net/devtools_network_transaction_factory.h +++ b/brightray/browser/net/devtools_network_transaction_factory.h @@ -6,7 +6,6 @@ #define BROWSER_DEVTOOLS_NETWORK_TRANSACTION_FACTORY_H_ #include "base/macros.h" -#include "base/memory/scoped_ptr.h" #include "net/base/request_priority.h" #include "net/http/http_transaction_factory.h" @@ -23,13 +22,13 @@ class DevToolsNetworkTransactionFactory : public net::HttpTransactionFactory { // net::HttpTransactionFactory: int CreateTransaction(net::RequestPriority priority, - scoped_ptr* transaction) override; + std::unique_ptr* transaction) override; net::HttpCache* GetCache() override; net::HttpNetworkSession* GetSession() override; private: DevToolsNetworkController* controller_; - scoped_ptr network_layer_; + std::unique_ptr network_layer_; DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkTransactionFactory); }; diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index b0b06483f9b..9876b49418b 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -14,8 +14,8 @@ namespace brightray { namespace { -scoped_ptr GetConstants() { - scoped_ptr constants = net::GetNetConstants(); +std::unique_ptr GetConstants() { + std::unique_ptr constants = net::GetNetConstants(); // Adding client information to constants dictionary. base::DictionaryValue* client_info = new base::DictionaryValue(); @@ -53,7 +53,7 @@ void NetLog::StartLogging(net::URLRequestContext* url_request_context) { return; } - scoped_ptr constants(GetConstants()); + std::unique_ptr constants(GetConstants()); write_to_file_observer_.StartObserving(this, std::move(log_file_), constants.get(), diff --git a/brightray/browser/notification_delegate_adapter.cc b/brightray/browser/notification_delegate_adapter.cc index 1a4853723b5..c0ad3d03f06 100644 --- a/brightray/browser/notification_delegate_adapter.cc +++ b/brightray/browser/notification_delegate_adapter.cc @@ -7,7 +7,7 @@ namespace brightray { NotificationDelegateAdapter::NotificationDelegateAdapter( - scoped_ptr delegate) + std::unique_ptr delegate) : delegate_(std::move(delegate)) { } diff --git a/brightray/browser/notification_delegate_adapter.h b/brightray/browser/notification_delegate_adapter.h index b48c7376cb0..01f3284e2b8 100644 --- a/brightray/browser/notification_delegate_adapter.h +++ b/brightray/browser/notification_delegate_adapter.h @@ -5,7 +5,9 @@ #ifndef BROWSER_NOTIFICATION_DELEGATE_ADAPTER_H_ #define BROWSER_NOTIFICATION_DELEGATE_ADAPTER_H_ -#include "base/memory/scoped_ptr.h" +#include + +#include "base/macros.h" #include "browser/notification_delegate.h" namespace brightray { @@ -14,7 +16,7 @@ namespace brightray { class NotificationDelegateAdapter : public NotificationDelegate { public: explicit NotificationDelegateAdapter( - scoped_ptr delegate); + std::unique_ptr delegate); ~NotificationDelegateAdapter() override; // NotificationDelegate: @@ -26,7 +28,7 @@ class NotificationDelegateAdapter : public NotificationDelegate { void NotificationClick() override; private: - scoped_ptr delegate_; + std::unique_ptr delegate_; DISALLOW_COPY_AND_ASSIGN(NotificationDelegateAdapter); }; diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc index 8936678a4f7..5431035561a 100644 --- a/brightray/browser/permission_manager.cc +++ b/brightray/browser/permission_manager.cc @@ -22,12 +22,12 @@ int PermissionManager::RequestPermission( content::PermissionType permission, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, - const base::Callback& callback) { + const base::Callback& callback) { if (permission == content::PermissionType::MIDI_SYSEX) { content::ChildProcessSecurityPolicy::GetInstance()-> GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID()); } - callback.Run(content::PermissionStatus::GRANTED); + callback.Run(blink::mojom::PermissionStatus::GRANTED); return kNoPendingOperation; } @@ -36,8 +36,8 @@ int PermissionManager::RequestPermissions( content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, const base::Callback&)>& callback) { - std::vector permissionStatuses; + const std::vector&)>& callback) { + std::vector permissionStatuses; for (auto permission : permissions) { if (permission == content::PermissionType::MIDI_SYSEX) { @@ -45,7 +45,7 @@ int PermissionManager::RequestPermissions( GrantSendMidiSysExMessage(render_frame_host->GetProcess()->GetID()); } - permissionStatuses.push_back(content::PermissionStatus::GRANTED); + permissionStatuses.push_back(blink::mojom::PermissionStatus::GRANTED); } callback.Run(permissionStatuses); @@ -61,11 +61,11 @@ void PermissionManager::ResetPermission( const GURL& embedding_origin) { } -content::PermissionStatus PermissionManager::GetPermissionStatus( +blink::mojom::PermissionStatus PermissionManager::GetPermissionStatus( content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) { - return content::PermissionStatus::GRANTED; + return blink::mojom::PermissionStatus::GRANTED; } void PermissionManager::RegisterPermissionUsage( @@ -78,7 +78,7 @@ int PermissionManager::SubscribePermissionStatusChange( content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin, - const base::Callback& callback) { + const base::Callback& callback) { return -1; } diff --git a/brightray/browser/permission_manager.h b/brightray/browser/permission_manager.h index d53fe763ce5..3f6001c18bf 100644 --- a/brightray/browser/permission_manager.h +++ b/brightray/browser/permission_manager.h @@ -21,18 +21,18 @@ class PermissionManager : public content::PermissionManager { content::PermissionType permission, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, - const base::Callback& callback) override; + const base::Callback& callback) override; int RequestPermissions( const std::vector& permissions, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, const base::Callback&)>& callback) override; + const std::vector&)>& callback) override; void CancelPermissionRequest(int request_id) override; void ResetPermission(content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) override; - content::PermissionStatus GetPermissionStatus( + blink::mojom::PermissionStatus GetPermissionStatus( content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) override; @@ -43,7 +43,7 @@ class PermissionManager : public content::PermissionManager { content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin, - const base::Callback& callback) override; + const base::Callback& callback) override; void UnsubscribePermissionStatusChange(int subscription_id) override; private: diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index ce539cad8d4..023f0a2a131 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -25,7 +25,7 @@ void OnWebNotificationAllowed( brightray::BrowserClient* browser_client, const SkBitmap& icon, const content::PlatformNotificationData& data, - scoped_ptr delegate, + std::unique_ptr delegate, base::Closure* cancel_callback, bool allowed) { if (!allowed) @@ -33,7 +33,7 @@ void OnWebNotificationAllowed( auto presenter = browser_client->GetNotificationPresenter(); if (!presenter) return; - scoped_ptr adapter( + std::unique_ptr adapter( new NotificationDelegateAdapter(std::move(delegate))); auto notification = presenter->CreateNotification(adapter.get()); if (notification) { @@ -73,7 +73,7 @@ void PlatformNotificationService::DisplayNotification( const GURL& origin, const content::PlatformNotificationData& notification_data, const content::NotificationResources& notification_resources, - scoped_ptr delegate, + std::unique_ptr delegate, base::Closure* cancel_callback) { browser_client_->WebNotificationAllowed( render_process_id_, diff --git a/brightray/browser/platform_notification_service.h b/brightray/browser/platform_notification_service.h index 2f7663d588f..1c4b53da94a 100644 --- a/brightray/browser/platform_notification_service.h +++ b/brightray/browser/platform_notification_service.h @@ -5,6 +5,7 @@ #ifndef BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ #define BROWSER_PLATFORM_NOTIFICATION_SERVICE_H_ +#include "content/public/browser/browser_context.h" #include "content/public/browser/platform_notification_service.h" namespace brightray { @@ -31,7 +32,7 @@ class PlatformNotificationService const GURL& origin, const content::PlatformNotificationData& notification_data, const content::NotificationResources& notification_resources, - scoped_ptr delegate, + std::unique_ptr delegate, base::Closure* cancel_callback) override; void DisplayPersistentNotification( content::BrowserContext* browser_context, diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index a2f7032f683..b547be53b1b 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -12,6 +12,7 @@ #include "browser/network_delegate.h" #include "base/command_line.h" +#include "base/memory/ptr_util.h" #include "base/strings/string_util.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" @@ -110,11 +111,11 @@ bool URLRequestContextGetter::DelegateURLSecurityManager::CanDelegate } void URLRequestContextGetter::DelegateURLSecurityManager::SetDefaultWhitelist( - scoped_ptr whitelist_default) { + std::unique_ptr whitelist_default) { } void URLRequestContextGetter::DelegateURLSecurityManager::SetDelegateWhitelist( - scoped_ptr whitelist_delegate) { + std::unique_ptr whitelist_delegate) { } URLRequestContextGetter::Delegate::Delegate() : @@ -124,31 +125,31 @@ std::string URLRequestContextGetter::Delegate::GetUserAgent() { return base::EmptyString(); } -scoped_ptr +std::unique_ptr URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector* protocol_interceptors) { - scoped_ptr job_factory(new net::URLRequestJobFactoryImpl); + std::unique_ptr job_factory(new net::URLRequestJobFactoryImpl); for (auto it = protocol_handlers->begin(); it != protocol_handlers->end(); ++it) job_factory->SetProtocolHandler( - it->first, make_scoped_ptr(it->second.release())); + it->first, base::WrapUnique(it->second.release())); protocol_handlers->clear(); job_factory->SetProtocolHandler( - url::kDataScheme, make_scoped_ptr(new net::DataProtocolHandler)); + url::kDataScheme, base::WrapUnique(new net::DataProtocolHandler)); job_factory->SetProtocolHandler( url::kFileScheme, - make_scoped_ptr(new net::FileProtocolHandler( + base::WrapUnique(new net::FileProtocolHandler( BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); // Set up interceptors in the reverse order. - scoped_ptr top_job_factory = std::move(job_factory); + std::unique_ptr top_job_factory = std::move(job_factory); content::URLRequestInterceptorScopedVector::reverse_iterator i; for (i = protocol_interceptors->rbegin(); i != protocol_interceptors->rend(); ++i) top_job_factory.reset(new net::URLRequestInterceptingJobFactory( - std::move(top_job_factory), make_scoped_ptr(*i))); + std::move(top_job_factory), base::WrapUnique(*i))); protocol_interceptors->weak_clear(); return top_job_factory; @@ -165,7 +166,7 @@ URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(const base::Fil BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); } -scoped_ptr +std::unique_ptr URLRequestContextGetter::Delegate::CreateCertVerifier() { return net::CertVerifier::CreateDefault(); } @@ -246,7 +247,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_.reset(new net::URLRequestContextStorage(url_request_context_.get())); - scoped_refptr cookie_store = nullptr; + std::unique_ptr cookie_store = nullptr; if (in_memory_) { cookie_store = content::CreateCookieStore(content::CookieStoreConfig()); } else { @@ -256,22 +257,22 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { NULL, NULL); cookie_store = content::CreateCookieStore(cookie_config); } - storage_->set_cookie_store(cookie_store.get()); - storage_->set_channel_id_service(make_scoped_ptr( + storage_->set_cookie_store(std::move(cookie_store)); + storage_->set_channel_id_service(base::WrapUnique( new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), base::WorkerPool::GetTaskRunner(true)))); std::string accept_lang = l10n_util::GetApplicationLocale(""); - storage_->set_http_user_agent_settings(make_scoped_ptr( + storage_->set_http_user_agent_settings(base::WrapUnique( new net::StaticHttpUserAgentSettings( net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang), delegate_->GetUserAgent()))); - scoped_ptr host_resolver(net::HostResolver::CreateDefaultResolver(nullptr)); + std::unique_ptr host_resolver(net::HostResolver::CreateDefaultResolver(nullptr)); // --host-resolver-rules if (command_line.HasSwitch(switches::kHostResolverRules)) { - scoped_ptr remapped_resolver( + std::unique_ptr remapped_resolver( new net::MappedHostResolver(std::move(host_resolver))); remapped_resolver->SetRulesFromString( command_line.GetSwitchValueASCII(switches::kHostResolverRules)); @@ -323,10 +324,10 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_cert_verifier(delegate_->CreateCertVerifier()); storage_->set_transport_security_state( - make_scoped_ptr(new net::TransportSecurityState)); + base::WrapUnique(new net::TransportSecurityState)); storage_->set_ssl_config_service(delegate_->CreateSSLConfigService()); storage_->set_http_auth_handler_factory(std::move(auth_handler_factory)); - scoped_ptr server_properties( + std::unique_ptr server_properties( new net::HttpServerPropertiesImpl); storage_->set_http_server_properties(std::move(server_properties)); @@ -334,7 +335,6 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.cert_verifier = url_request_context_->cert_verifier(); network_session_params.proxy_service = url_request_context_->proxy_service(); network_session_params.ssl_config_service = url_request_context_->ssl_config_service(); - network_session_params.network_delegate = url_request_context_->network_delegate(); network_session_params.http_server_properties = url_request_context_->http_server_properties(); network_session_params.ignore_certificate_errors = false; network_session_params.transport_security_state = @@ -368,7 +368,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { http_network_session_.reset( new net::HttpNetworkSession(network_session_params)); - scoped_ptr backend; + std::unique_ptr backend; if (in_memory_) { backend = net::HttpCache::DefaultBackend::InMemory(0); } else { @@ -376,14 +376,14 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } if (network_controller_handle_) { - storage_->set_http_transaction_factory(make_scoped_ptr( + storage_->set_http_transaction_factory(base::WrapUnique( new net::HttpCache( - make_scoped_ptr(new DevToolsNetworkTransactionFactory( + base::WrapUnique(new DevToolsNetworkTransactionFactory( network_controller_handle_->GetController(), http_network_session_.get())), std::move(backend), false))); } else { - storage_->set_http_transaction_factory(make_scoped_ptr( + storage_->set_http_transaction_factory(base::WrapUnique( new net::HttpCache(http_network_session_.get(), std::move(backend), false))); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 3f06ba78ba2..2643a91a70d 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -6,7 +6,7 @@ #define BRIGHTRAY_BROWSER_URL_REQUEST_CONTEXT_GETTER_H_ #include "base/files/file_path.h" -#include "base/memory/scoped_ptr.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" #include "net/http/http_cache.h" #include "net/http/url_security_manager.h" @@ -40,18 +40,18 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; } virtual std::string GetUserAgent(); - virtual scoped_ptr CreateURLRequestJobFactory( + virtual std::unique_ptr CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector* protocol_interceptors); virtual net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory( const base::FilePath& base_path); - virtual scoped_ptr CreateCertVerifier(); + virtual std::unique_ptr CreateCertVerifier(); virtual net::SSLConfigService* CreateSSLConfigService(); virtual bool AllowNTLMCredentialsForDomain(const GURL& auth_origin); virtual bool CanDelegateURLSecurity(const GURL& auth_origin); private: - scoped_ptr orig_url_sec_mgr_; + std::unique_ptr orig_url_sec_mgr_; }; class DelegateURLSecurityManager : public net::URLSecurityManager { @@ -61,9 +61,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { bool CanUseDefaultCredentials(const GURL& auth_origin) const override; bool CanDelegate(const GURL& auth_origin) const override; void SetDefaultWhitelist( - scoped_ptr whitelist_default) override; + std::unique_ptr whitelist_default) override; void SetDelegateWhitelist( - scoped_ptr whitelist_delegate) override; + std::unique_ptr whitelist_delegate) override; private: URLRequestContextGetter::Delegate* delegate_; @@ -99,13 +99,13 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { base::MessageLoop* io_loop_; base::MessageLoop* file_loop_; - scoped_ptr proxy_config_service_; - scoped_ptr network_delegate_; - scoped_ptr storage_; - scoped_ptr url_request_context_; - scoped_ptr host_mapping_rules_; - scoped_ptr http_auth_preferences_; - scoped_ptr http_network_session_; + std::unique_ptr proxy_config_service_; + std::unique_ptr network_delegate_; + std::unique_ptr storage_; + std::unique_ptr url_request_context_; + std::unique_ptr host_mapping_rules_; + std::unique_ptr http_auth_preferences_; + std::unique_ptr http_network_session_; content::ProtocolHandlerMap protocol_handlers_; content::URLRequestInterceptorScopedVector protocol_interceptors_; diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index bcdbdb9518b..e73ea187ff7 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -54,7 +54,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, // Owns us. InspectableWebContentsImpl* inspectable_web_contents_; - scoped_ptr devtools_window_; + std::unique_ptr devtools_window_; views::WebView* devtools_window_web_view_; views::WebView* contents_web_view_; views::WebView* devtools_web_view_; diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index d3d4f7dc243..107b62ea76b 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -37,7 +37,7 @@ bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) { NotificationPresenter* NotificationPresenter::Create() { if (!WindowsToastNotification::Initialize()) return nullptr; - scoped_ptr presenter(new NotificationPresenterWin); + std::unique_ptr presenter(new NotificationPresenterWin); if (!presenter->Init()) return nullptr; return presenter.release(); diff --git a/brightray/common/application_info_win.cc b/brightray/common/application_info_win.cc index fd18d54b0ca..7c04617079d 100644 --- a/brightray/common/application_info_win.cc +++ b/brightray/common/application_info_win.cc @@ -1,21 +1,20 @@ #include "common/application_info.h" #include "base/file_version_info.h" -#include "base/memory/scoped_ptr.h" #include "base/strings/utf_string_conversions.h" namespace brightray { std::string GetApplicationName() { auto module = GetModuleHandle(nullptr); - auto info = make_scoped_ptr( + auto info = make_std::unique_ptr( FileVersionInfo::CreateFileVersionInfoForModule(module)); return base::UTF16ToUTF8(info->product_name()); } std::string GetApplicationVersion() { auto module = GetModuleHandle(nullptr); - auto info = make_scoped_ptr( + auto info = make_std::unique_ptr( FileVersionInfo::CreateFileVersionInfoForModule(module)); return base::UTF16ToUTF8(info->product_version()); } diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 6516111aedd..7dd1d153f5d 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -4,6 +4,8 @@ #include "common/main_delegate.h" +#include + #include "browser/browser_client.h" #include "common/content_client.h" @@ -21,11 +23,6 @@ namespace { // and resources loaded. bool SubprocessNeedsResourceBundle(const std::string& process_type) { return -#if defined(OS_WIN) || defined(OS_MACOSX) - // Windows needs resources for the default/null plugin. - // Mac needs them for the plugin process name. - process_type == switches::kPluginProcess || -#endif #if defined(OS_POSIX) && !defined(OS_MACOSX) // The zygote process opens the resources for the renderers. process_type == switches::kZygoteProcess || @@ -80,8 +77,8 @@ MainDelegate::MainDelegate() { MainDelegate::~MainDelegate() { } -scoped_ptr MainDelegate::CreateContentClient() { - return make_scoped_ptr(new ContentClient); +std::unique_ptr MainDelegate::CreateContentClient() { + return std::unique_ptr(new ContentClient); } bool MainDelegate::BasicStartupComplete(int* exit_code) { @@ -112,8 +109,8 @@ content::ContentBrowserClient* MainDelegate::CreateContentBrowserClient() { return browser_client_.get(); } -scoped_ptr MainDelegate::CreateBrowserClient() { - return make_scoped_ptr(new BrowserClient); +std::unique_ptr MainDelegate::CreateBrowserClient() { + return std::unique_ptr(new BrowserClient); } } // namespace brightray diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 2082a522882..1eb1366f32e 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -5,8 +5,7 @@ #ifndef BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ #define BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" +#include "base/macros.h" #include "content/public/app/content_main_delegate.h" namespace base { @@ -33,11 +32,11 @@ class MainDelegate : public content::ContentMainDelegate { protected: // Subclasses can override this to provide their own ContentClient // implementation. - virtual scoped_ptr CreateContentClient(); + virtual std::unique_ptr CreateContentClient(); // Subclasses can override this to provide their own BrowserClient // implementation. - virtual scoped_ptr CreateBrowserClient(); + virtual std::unique_ptr CreateBrowserClient(); #if defined(OS_MACOSX) // Subclasses can override this to custom the paths of child process and @@ -52,8 +51,8 @@ class MainDelegate : public content::ContentMainDelegate { private: content::ContentBrowserClient* CreateContentBrowserClient() override; - scoped_ptr content_client_; - scoped_ptr browser_client_; + std::unique_ptr content_client_; + std::unique_ptr browser_client_; DISALLOW_COPY_AND_ASSIGN(MainDelegate); }; From 76d180a80dff2499380616cd7cb986e9ab446cf8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 May 2016 12:28:41 +0900 Subject: [PATCH 0835/1195] Adapt to changes of Chrome 51 API changes (Part 2) --- brightray/browser/browser_context.cc | 11 ++++++++++- brightray/browser/browser_context.h | 5 +++++ brightray/browser/inspectable_web_contents_impl.cc | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 10132a7cd10..dac47ccba6a 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -143,7 +143,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( url_request_getter_ = new URLRequestContextGetter( this, network_controller_handle(), - net_log_, + &net_log_, GetPath(), in_memory_, BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), @@ -226,4 +226,13 @@ content::BackgroundSyncController* BrowserContext::GetBackgroundSyncController() return nullptr; } +net::URLRequestContextGetter* +BrowserContext::CreateRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory, + content::ProtocolHandlerMap* protocol_handlers, + content::URLRequestInterceptorScopedVector request_interceptors) { + return nullptr; +} + } // namespace brightray diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 1604774440c..00cf4d51f4d 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -61,6 +61,11 @@ class BrowserContext : public base::RefCounted, net::URLRequestContextGetter* CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptors) override; + net::URLRequestContextGetter* CreateRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory, + content::ProtocolHandlerMap* protocol_handlers, + content::URLRequestInterceptorScopedVector request_interceptors) override; net::URLRequestContextGetter* url_request_context_getter() const { return url_request_getter_.get(); diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 80429a1a189..99efcd3984c 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -190,7 +190,7 @@ InspectableWebContentsView* CreateInspectableContentsView( InspectableWebContentsImpl* inspectable_web_contents_impl); void InspectableWebContentsImpl::RegisterPrefs(PrefRegistrySimple* registry) { - auto bounds_dict = make_std::unique_ptr(new base::DictionaryValue); + std::unique_ptr bounds_dict(new base::DictionaryValue); RectToDictionary(gfx::Rect(0, 0, 800, 600), bounds_dict.get()); registry->RegisterDictionaryPref(kDevToolsBoundsPref, bounds_dict.release()); registry->RegisterDoublePref(kDevToolsZoomPref, 0.); From 7c39075c2c4d604707aebe0b23f75343fe1346bf Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 May 2016 12:34:09 +0900 Subject: [PATCH 0836/1195] Initialize FeatureList --- brightray/browser/browser_main_parts.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index bc6ecd88dbd..43c49de8d44 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -10,6 +10,7 @@ #include "common/main_delegate.h" #include "base/command_line.h" +#include "base/feature_list.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" #include "components/devtools_http_handler/devtools_http_handler.h" @@ -153,6 +154,10 @@ BrowserMainParts::~BrowserMainParts() { } void BrowserMainParts::PreEarlyInitialization() { + std::unique_ptr feature_list(new base::FeatureList); + feature_list->InitializeFromCommandLine("", ""); + base::FeatureList::SetInstance(std::move(feature_list)); + #if defined(USE_X11) views::LinuxUI::SetInstance(BuildGtk2UI()); OverrideLinuxAppDataPath(); From 0a5c4b8ced5f6037fab6d4da81b039f411e03be0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 May 2016 12:36:34 +0900 Subject: [PATCH 0837/1195] Call BrowserContext::Initialize --- brightray/browser/browser_context.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index dac47ccba6a..9992f06eb0f 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -110,6 +110,8 @@ BrowserContext::BrowserContext(const std::string& partition, bool in_memory) if (!in_memory_ && !partition.empty()) path_ = path_.Append(FILE_PATH_LITERAL("Partitions")) .Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition))); + + content::BrowserContext::Initialize(this, path_); } void BrowserContext::InitPrefs() { From 4ccf4394d78f0e725dc18f11445727bc39bc0124 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 May 2016 15:08:20 +0900 Subject: [PATCH 0838/1195] Fix compilation errors on Linux --- brightray/browser/net/devtools_network_controller_handle.h | 1 + brightray/common/application_info_win.cc | 6 ++++-- brightray/common/main_delegate.h | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/brightray/browser/net/devtools_network_controller_handle.h b/brightray/browser/net/devtools_network_controller_handle.h index 1eefa6244e5..b5c861f5cd6 100644 --- a/brightray/browser/net/devtools_network_controller_handle.h +++ b/brightray/browser/net/devtools_network_controller_handle.h @@ -5,6 +5,7 @@ #ifndef BROWSER_DEVTOOLS_NETWORK_CONTROLLER_HANDLE_H_ #define BROWSER_DEVTOOLS_NETWORK_CONTROLLER_HANDLE_H_ +#include #include #include "base/macros.h" diff --git a/brightray/common/application_info_win.cc b/brightray/common/application_info_win.cc index 7c04617079d..22635711cb4 100644 --- a/brightray/common/application_info_win.cc +++ b/brightray/common/application_info_win.cc @@ -1,3 +1,5 @@ +#include + #include "common/application_info.h" #include "base/file_version_info.h" @@ -7,14 +9,14 @@ namespace brightray { std::string GetApplicationName() { auto module = GetModuleHandle(nullptr); - auto info = make_std::unique_ptr( + std::unique_ptr info( FileVersionInfo::CreateFileVersionInfoForModule(module)); return base::UTF16ToUTF8(info->product_name()); } std::string GetApplicationVersion() { auto module = GetModuleHandle(nullptr); - auto info = make_std::unique_ptr( + std::unique_ptr info( FileVersionInfo::CreateFileVersionInfoForModule(module)); return base::UTF16ToUTF8(info->product_version()); } diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 1eb1366f32e..058e553903c 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -5,6 +5,8 @@ #ifndef BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ #define BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ +#include + #include "base/macros.h" #include "content/public/app/content_main_delegate.h" From f5bfbada97ccbf4b6190d70989852144925f385e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 May 2016 19:02:13 +0900 Subject: [PATCH 0839/1195] NetLog should be managed by BrowserClient --- brightray/browser/browser_client.cc | 4 ++++ brightray/browser/browser_client.h | 19 +++++++++++-------- brightray/browser/browser_context.cc | 3 ++- brightray/browser/browser_context.h | 3 --- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 7a386c2d7ff..4ba0caa67d9 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -84,6 +84,10 @@ void BrowserClient::GetAdditionalAllowedSchemesForFileSystem( additional_schemes->push_back(content::kChromeUIScheme); } +net::NetLog* BrowserClient::GetNetLog() { + return &net_log_; +} + base::FilePath BrowserClient::GetDefaultDownloadDirectory() { // ~/Downloads base::FilePath path; diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index b5ee8a18940..acb12b99708 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -5,6 +5,7 @@ #ifndef BRIGHTRAY_BROWSER_BROWSER_CLIENT_H_ #define BRIGHTRAY_BROWSER_BROWSER_CLIENT_H_ +#include "browser/net_log.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" @@ -33,13 +34,6 @@ class BrowserClient : public content::ContentBrowserClient { callback.Run(true); } - protected: - // Subclasses should override this to provide their own BrowserMainParts - // implementation. The lifetime of the returned instance is managed by the - // caller. - virtual BrowserMainParts* OverrideCreateBrowserMainParts( - const content::MainFunctionParams&); - // Subclasses that override this (e.g., to provide their own protocol // handlers) should call this implementation after doing their own work. content::BrowserMainParts* CreateBrowserMainParts( @@ -48,12 +42,21 @@ class BrowserClient : public content::ContentBrowserClient { content::PlatformNotificationService* GetPlatformNotificationService() override; void GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) override; + net::NetLog* GetNetLog() override; base::FilePath GetDefaultDownloadDirectory() override; content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override; - BrowserMainParts* browser_main_parts_; + protected: + // Subclasses should override this to provide their own BrowserMainParts + // implementation. The lifetime of the returned instance is managed by the + // caller. + virtual BrowserMainParts* OverrideCreateBrowserMainParts( + const content::MainFunctionParams&); private: + BrowserMainParts* browser_main_parts_; + NetLog net_log_; + std::unique_ptr notification_service_; std::unique_ptr notification_presenter_; diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 9992f06eb0f..236a8f5c1f2 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -5,6 +5,7 @@ #include "browser/browser_context.h" #include "browser/brightray_paths.h" +#include "browser/browser_client.h" #include "browser/inspectable_web_contents_impl.h" #include "browser/network_delegate.h" #include "browser/permission_manager.h" @@ -145,7 +146,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( url_request_getter_ = new URLRequestContextGetter( this, network_controller_handle(), - &net_log_, + static_cast(BrowserClient::Get()->GetNetLog()), GetPath(), in_memory_, BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 00cf4d51f4d..31db2ce23f4 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -7,7 +7,6 @@ #include -#include "browser/net_log.h" #include "browser/net/devtools_network_controller_handle.h" #include "browser/permission_manager.h" #include "browser/url_request_context_getter.h" @@ -25,7 +24,6 @@ class SpecialStoragePolicy; namespace brightray { -class NetLog; class PermissionManager; class BrowserContext : public base::RefCounted, @@ -122,7 +120,6 @@ class BrowserContext : public base::RefCounted, bool in_memory_; DevToolsNetworkControllerHandle network_controller_handle_; - NetLog net_log_; std::unique_ptr resource_context_; scoped_refptr url_request_getter_; From 17064b483eec46059c0fd7317aadad0f2974a4c0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 May 2016 19:44:09 +0900 Subject: [PATCH 0840/1195] Link with xscrnsaver --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 3978a5e368d..b14a7d0097c 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -1,7 +1,7 @@ { 'variables': { # The libraries brightray will be compiled to. - 'linux_system_libraries': 'gtk+-2.0 dbus-1 x11 xi xcursor xdamage xrandr xcomposite xext xfixes xrender xtst gconf-2.0 gmodule-2.0 nss' + 'linux_system_libraries': 'gtk+-2.0 dbus-1 x11 xi xcursor xdamage xrandr xcomposite xext xfixes xrender xtst xscrnsaver gconf-2.0 gmodule-2.0 nss' }, 'includes': [ 'filenames.gypi', From 8250a66968f5c587be94051bd4435159deed2da4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 May 2016 22:05:08 +0900 Subject: [PATCH 0841/1195] Link with AVFoundation and CoreMedia --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b14a7d0097c..610f67dd528 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -169,7 +169,9 @@ # media.gyp: '$(SDKROOT)/System/Library/Frameworks/AudioToolbox.framework', '$(SDKROOT)/System/Library/Frameworks/AudioUnit.framework', + '$(SDKROOT)/System/Library/Frameworks/AVFoundation.framework', '$(SDKROOT)/System/Library/Frameworks/CoreAudio.framework', + '$(SDKROOT)/System/Library/Frameworks/CoreMedia.framework', '$(SDKROOT)/System/Library/Frameworks/CoreMIDI.framework', '$(SDKROOT)/System/Library/Frameworks/CoreVideo.framework', # surface.gyp: From cbcd48257d59319f42533fb4763cc35d4435428e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 May 2016 22:53:19 +0900 Subject: [PATCH 0842/1195] Link with necessary DLLs of Chrome 51 --- brightray/brightray.gyp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 610f67dd528..40c76e14cd6 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -275,12 +275,27 @@ 'usp10.lib', 'version.lib', 'winspool.lib', + 'wtsapi32.lib', + # bluetooth.gyp: + 'Bthprops.lib', + 'BluetoothApis.lib', # base.gyp: + 'cfgmgr32.lib', 'powrprof.lib', + 'setupapi.lib', + # net_common.gypi: + 'crypt32.lib', + 'dhcpcsvc.lib', + 'rpcrt4.lib', + 'secur32.lib', + 'urlmon.lib', + 'winhttp.lib', ], 'DelayLoadDLLs': [ + 'wtsapi32.dll', # content_common.gypi: 'd3d9.dll', + 'd3d11.dll', 'dxva2.dll', # media.gyp: 'mf.dll', @@ -291,7 +306,16 @@ 'Bthprops.cpl', 'setupapi.dll', # base.gyp: + 'cfgmgr32.dll', 'powrprof.dll', + 'setupapi.dll', + # net_common.gypi: + 'crypt32.dll', + 'dhcpcsvc.dll', + 'rpcrt4.dll', + 'secur32.dll', + 'urlmon.dll', + 'winhttp.dll', # windows runtime 'API-MS-WIN-CORE-WINRT-L1-1-0.DLL', 'API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL', From f395b35b620747b71243f777399895e88e53b48c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 May 2016 23:24:16 +0900 Subject: [PATCH 0843/1195] Add a few more media related libs --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 40c76e14cd6..b5fcbbd05c0 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -259,7 +259,9 @@ '-lmfplat.lib', '-lmfuuid.lib', # media.gyp: + '-ldxguid.lib', '-lmfreadwrite.lib', + '-lmfuuid.lib', ], 'msvs_settings': { 'VCLinkerTool': { From 1cc0d0599e5200eabc4a5df8e454b7c46db03f34 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 May 2016 14:38:36 +0900 Subject: [PATCH 0844/1195] Update to Chrome 51.0.2704.63 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 31ff4384348..eda589282bd 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 31ff4384348b139d9e138d4df41b85a11d1a4dbb +Subproject commit eda589282bd7729f36960d2e669d4b81375b897c From a09e270efdca610340aa7a0116beae095b817ad9 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 31 May 2016 12:36:51 +0530 Subject: [PATCH 0845/1195] initialize bluetooth for linux --- brightray/browser/browser_main_parts.cc | 15 +++++++++++++++ brightray/browser/browser_main_parts.h | 1 + 2 files changed, 16 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 43c49de8d44..6cf1f4fd5a0 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -48,6 +48,11 @@ #include "ui/gfx/platform_font_win.h" #endif +#if defined(OS_LINUX) +#include "device/bluetooth/bluetooth_adapter_factory.h" +#include "device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h" +#endif + using content::BrowserThread; namespace brightray { @@ -219,6 +224,9 @@ void BrowserMainParts::PostMainMessageLoopStart() { // if X exits before us. ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler); #endif +#if defined(OS_LINUX) + bluez::DBusBluezManagerWrapperLinux::Initialize(); +#endif } void BrowserMainParts::PostMainMessageLoopRun() { @@ -244,4 +252,11 @@ int BrowserMainParts::PreCreateThreads() { return 0; } +void BrowserMainParts::PostDestroyThreads() { +#if defined(OS_LINUX) + device::BluetoothAdapterFactory::Shutdown(); + bluez::DBusBluezManagerWrapperLinux::Shutdown(); +#endif +} + } // namespace brightray diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 40adc027282..042f5d62c74 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -45,6 +45,7 @@ class BrowserMainParts : public content::BrowserMainParts { void PostMainMessageLoopStart() override; void PostMainMessageLoopRun() override; int PreCreateThreads() override; + void PostDestroyThreads() override; private: #if defined(OS_MACOSX) From 7eb78777d79ad790fa52651a9a65a7c647093dd8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Jun 2016 15:21:32 +0900 Subject: [PATCH 0846/1195] Update libchromiumcontent to 51.0.2704.79 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index eda589282bd..7c25d3c3c88 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit eda589282bd7729f36960d2e669d4b81375b897c +Subproject commit 7c25d3c3c8859429b2bb2230940d1ab22d761da5 From 98eeadeb84cdddc83407cc22f78c26904403ca4c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 8 Jun 2016 11:06:06 +0900 Subject: [PATCH 0847/1195] Update libchromiumcontent to 51.0.2704.84 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 7c25d3c3c88..1b22a46e7dd 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 7c25d3c3c8859429b2bb2230940d1ab22d761da5 +Subproject commit 1b22a46e7dd18f6fefaa3a03917a93eb9be134fb From 8ebc34aeee47485a9c44a259c234dab40429b0a6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 14 Jun 2016 13:38:28 +0900 Subject: [PATCH 0848/1195] Fix double free when closing window with devtools opened --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 99efcd3984c..70119c15582 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -226,6 +226,7 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( } InspectableWebContentsImpl::~InspectableWebContentsImpl() { + Observe(nullptr); } InspectableWebContentsView* InspectableWebContentsImpl::GetView() const { @@ -618,7 +619,6 @@ void InspectableWebContentsImpl::RenderFrameHostChanged( void InspectableWebContentsImpl::WebContentsDestroyed() { frontend_loaded_ = false; - Observe(nullptr); Detach(); for (const auto& pair : pending_requests_) From d37a120a6a9567846530b3d1b32e837427e15fb4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 15 Jun 2016 20:30:26 +0900 Subject: [PATCH 0849/1195] Provide access to JobFactory in URLRequestContextGetter --- brightray/browser/browser_context.h | 2 +- .../browser/url_request_context_getter.cc | 40 +++++++++++-------- .../browser/url_request_context_getter.h | 9 +++-- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 31db2ce23f4..421ef51f43c 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -65,7 +65,7 @@ class BrowserContext : public base::RefCounted, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptors) override; - net::URLRequestContextGetter* url_request_context_getter() const { + URLRequestContextGetter* url_request_context_getter() const { return url_request_getter_.get(); } diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index e9ba78ff080..12d13d71c43 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -107,13 +107,13 @@ std::string URLRequestContextGetter::Delegate::GetUserAgent() { std::unique_ptr URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector* protocol_interceptors) { + content::ProtocolHandlerMap* protocol_handlers) { std::unique_ptr job_factory(new net::URLRequestJobFactoryImpl); - for (auto it = protocol_handlers->begin(); it != protocol_handlers->end(); ++it) + for (auto& it : *protocol_handlers) { job_factory->SetProtocolHandler( - it->first, base::WrapUnique(it->second.release())); + it.first, base::WrapUnique(it.second.release())); + } protocol_handlers->clear(); job_factory->SetProtocolHandler( @@ -124,15 +124,7 @@ URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)))); - // Set up interceptors in the reverse order. - std::unique_ptr top_job_factory = std::move(job_factory); - content::URLRequestInterceptorScopedVector::reverse_iterator i; - for (i = protocol_interceptors->rbegin(); i != protocol_interceptors->rend(); ++i) - top_job_factory.reset(new net::URLRequestInterceptingJobFactory( - std::move(top_job_factory), base::WrapUnique(*i))); - protocol_interceptors->weak_clear(); - - return top_job_factory; + return std::move(job_factory); } net::HttpCache::BackendFactory* @@ -172,7 +164,8 @@ URLRequestContextGetter::URLRequestContextGetter( in_memory_(in_memory), io_loop_(io_loop), file_loop_(file_loop), - protocol_interceptors_(std::move(protocol_interceptors)) { + protocol_interceptors_(std::move(protocol_interceptors)), + job_factory_(nullptr) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -373,8 +366,23 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { false))); } - storage_->set_job_factory(delegate_->CreateURLRequestJobFactory( - &protocol_handlers_, &protocol_interceptors_)); + std::unique_ptr job_factory = + delegate_->CreateURLRequestJobFactory(&protocol_handlers_); + job_factory_ = job_factory.get(); + + // Set up interceptors in the reverse order. + std::unique_ptr top_job_factory = + std::move(job_factory); + content::URLRequestInterceptorScopedVector::reverse_iterator it; + for (it = protocol_interceptors_.rbegin(); + it != protocol_interceptors_.rend(); + ++it) { + top_job_factory.reset(new net::URLRequestInterceptingJobFactory( + std::move(top_job_factory), make_scoped_ptr(*it))); + } + protocol_interceptors_.weak_clear(); + + storage_->set_job_factory(std::move(top_job_factory)); } return url_request_context_.get(); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 30ec8a3f3e4..7dc5ccfff8b 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -40,9 +40,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; } virtual std::string GetUserAgent(); - virtual std::unique_ptr CreateURLRequestJobFactory( - content::ProtocolHandlerMap* protocol_handlers, - content::URLRequestInterceptorScopedVector* protocol_interceptors); + virtual std::unique_ptr + CreateURLRequestJobFactory( + content::ProtocolHandlerMap* protocol_handlers); virtual net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory( const base::FilePath& base_path); virtual std::unique_ptr CreateCertVerifier(); @@ -66,6 +66,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { scoped_refptr GetNetworkTaskRunner() const override; net::HostResolver* host_resolver(); + net::URLRequestJobFactory* job_factory() const { return job_factory_; } private: Delegate* delegate_; @@ -87,6 +88,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { content::ProtocolHandlerMap protocol_handlers_; content::URLRequestInterceptorScopedVector protocol_interceptors_; + net::URLRequestJobFactory* job_factory_; // weak ref + DISALLOW_COPY_AND_ASSIGN(URLRequestContextGetter); }; From df726d0f416a4bd8a4ec58e197c29150e9ab0892 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 17 Jun 2016 10:26:48 -0700 Subject: [PATCH 0850/1195] Redispatch key events to handle native shortcuts --- .../mac/bry_inspectable_web_contents_view.mm | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index a1b8dd3c054..e0b497f8403 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -10,6 +10,44 @@ using namespace brightray; +@interface EventDispatchingWindow : UnderlayOpenGLHostingWindow { + @private + BOOL redispatchingEvent_; +} + +- (void)redispatchKeyEvent:(NSEvent*)event; + +@end + +@implementation EventDispatchingWindow + +- (void)sendEvent:(NSEvent*)event { + if (!redispatchingEvent_) + [super sendEvent:event]; +} + +- (BOOL)performKeyEquivalent:(NSEvent*)event { + if (redispatchingEvent_) + return NO; + else + return [super performKeyEquivalent:event]; + } + +- (void)redispatchKeyEvent:(NSEvent*)event { + NSEventType eventType = [event type]; + if (eventType != NSKeyDown && eventType != NSKeyUp && + eventType != NSFlagsChanged) { + return; + } + + // Redispatch the event. + redispatchingEvent_ = YES; + [NSApp sendEvent:event]; + redispatchingEvent_ = NO; +} + +@end + @implementation BRYInspectableWebContentsView - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view { @@ -132,7 +170,7 @@ using namespace brightray; NSMiniaturizableWindowMask | NSResizableWindowMask | NSTexturedBackgroundWindowMask | NSUnifiedTitleAndToolbarWindowMask; - devtools_window_.reset([[UnderlayOpenGLHostingWindow alloc] + devtools_window_.reset([[EventDispatchingWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600) styleMask:styleMask backing:NSBackingStoreBuffered From 8bee2d7b7f7201f8484872f868b2663662d5a37c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 17 Jun 2016 10:57:28 -0700 Subject: [PATCH 0851/1195] Break out EventDispatchingWindow into separate class --- .../mac/bry_inspectable_web_contents_view.mm | 39 +------------------ .../browser/mac/event_dispatching_window.h | 19 +++++++++ .../browser/mac/event_dispatching_window.mm | 34 ++++++++++++++++ brightray/filenames.gypi | 2 + 4 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 brightray/browser/mac/event_dispatching_window.h create mode 100644 brightray/browser/mac/event_dispatching_window.mm diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index e0b497f8403..ade97d1c5fb 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -3,6 +3,7 @@ #include "browser/inspectable_web_contents_impl.h" #include "browser/inspectable_web_contents_view_delegate.h" #include "browser/inspectable_web_contents_view_mac.h" +#include "browser/mac/event_dispatching_window.h" #include "content/public/browser/render_widget_host_view.h" #import "ui/base/cocoa/underlay_opengl_hosting_window.h" @@ -10,44 +11,6 @@ using namespace brightray; -@interface EventDispatchingWindow : UnderlayOpenGLHostingWindow { - @private - BOOL redispatchingEvent_; -} - -- (void)redispatchKeyEvent:(NSEvent*)event; - -@end - -@implementation EventDispatchingWindow - -- (void)sendEvent:(NSEvent*)event { - if (!redispatchingEvent_) - [super sendEvent:event]; -} - -- (BOOL)performKeyEquivalent:(NSEvent*)event { - if (redispatchingEvent_) - return NO; - else - return [super performKeyEquivalent:event]; - } - -- (void)redispatchKeyEvent:(NSEvent*)event { - NSEventType eventType = [event type]; - if (eventType != NSKeyDown && eventType != NSKeyUp && - eventType != NSFlagsChanged) { - return; - } - - // Redispatch the event. - redispatchingEvent_ = YES; - [NSApp sendEvent:event]; - redispatchingEvent_ = NO; -} - -@end - @implementation BRYInspectableWebContentsView - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view { diff --git a/brightray/browser/mac/event_dispatching_window.h b/brightray/browser/mac/event_dispatching_window.h new file mode 100644 index 00000000000..27ed9e6bf2f --- /dev/null +++ b/brightray/browser/mac/event_dispatching_window.h @@ -0,0 +1,19 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef BROWSER_EVENT_DISPATCHING_WINDOW_H_ +#define BROWSER_EVENT_DISPATCHING_WINDOW_H_ + +#import "ui/base/cocoa/underlay_opengl_hosting_window.h" + +@interface EventDispatchingWindow : UnderlayOpenGLHostingWindow { + @private + BOOL redispatchingEvent_; +} + +- (void)redispatchKeyEvent:(NSEvent*)event; + +@end + +#endif // BROWSER_EVENT_DISPATCHING_WINDOW_H_ diff --git a/brightray/browser/mac/event_dispatching_window.mm b/brightray/browser/mac/event_dispatching_window.mm new file mode 100644 index 00000000000..08e8edebb0b --- /dev/null +++ b/brightray/browser/mac/event_dispatching_window.mm @@ -0,0 +1,34 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "browser/mac/event_dispatching_window.h" + +@implementation EventDispatchingWindow + +- (void)sendEvent:(NSEvent*)event { + if (!redispatchingEvent_) + [super sendEvent:event]; +} + +- (BOOL)performKeyEquivalent:(NSEvent*)event { + if (redispatchingEvent_) + return NO; + else + return [super performKeyEquivalent:event]; + } + +- (void)redispatchKeyEvent:(NSEvent*)event { + NSEventType eventType = [event type]; + if (eventType != NSKeyDown && eventType != NSKeyUp && + eventType != NSFlagsChanged) { + return; + } + + // Redispatch the event. + redispatchingEvent_ = YES; + [NSApp sendEvent:event]; + redispatchingEvent_ = NO; +} + +@end diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 98818759d26..944b8824da0 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -35,6 +35,8 @@ 'browser/mac/bry_inspectable_web_contents_view.mm', 'browser/mac/cocoa_notification.h', 'browser/mac/cocoa_notification.mm', + 'browser/mac/event_dispatching_window.h', + 'browser/mac/event_dispatching_window.mm', 'browser/mac/notification_center_delegate.h', 'browser/mac/notification_center_delegate.mm', 'browser/mac/notification_presenter_mac.h', From ebc7432893747b9281caef7830008927fe7ce778 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 17 Jun 2016 11:37:29 -0700 Subject: [PATCH 0852/1195] Remove unused import --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index ade97d1c5fb..16174ed3617 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -6,7 +6,6 @@ #include "browser/mac/event_dispatching_window.h" #include "content/public/browser/render_widget_host_view.h" -#import "ui/base/cocoa/underlay_opengl_hosting_window.h" #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" using namespace brightray; From 1d5e9fe7da2013f984b558970ac8670e9584b026 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 19 Jun 2016 21:06:46 +0900 Subject: [PATCH 0853/1195] Update to Chrome 51.0.2704.103 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 1b22a46e7dd..aab0223c9be 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 1b22a46e7dd18f6fefaa3a03917a93eb9be134fb +Subproject commit aab0223c9be3d3073f38ce0c69bc44319b2690c3 From ecf9052ace10f9ae6ea56ecdc0cb61fdaca8257c Mon Sep 17 00:00:00 2001 From: Nicola Squartini Date: Sun, 19 Jun 2016 21:27:28 +0900 Subject: [PATCH 0854/1195] Replace --whole-archive with --start-group --- brightray/brightray.gyp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b5fcbbd05c0..156f95de362 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -36,14 +36,13 @@ 'conditions': [ # Link with libraries of libchromiumcontent. ['OS=="linux" and libchromiumcontent_component==0', { - # On Linux we have to use "--whole-archive" to force executable - # to include all symbols, otherwise we will have plenty of + # On Linux we have to use "--start-group" or we will have plenty of # unresolved symbols errors. - 'direct_dependent_settings': { - 'ldflags': [ - '-Wl,--whole-archive', + 'link_settings': { + 'libraries': [ + '-Wl,--start-group', '<@(libchromiumcontent_libraries)', - '-Wl,--no-whole-archive', + '-Wl,--end-group' ], } }, { # (Release build on Linux) From babd741786e92481fb4acd723d56ff424576303b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 22 Jun 2016 15:40:52 +0900 Subject: [PATCH 0855/1195] Get rid of default BrowserContext --- brightray/browser/browser_client.cc | 4 ---- brightray/browser/browser_client.h | 1 - brightray/browser/browser_main_parts.cc | 4 ---- brightray/browser/browser_main_parts.h | 5 ----- 4 files changed, 14 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 4ba0caa67d9..c34b6613d38 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -38,10 +38,6 @@ BrowserClient::BrowserClient() BrowserClient::~BrowserClient() { } -BrowserContext* BrowserClient::browser_context() { - return browser_main_parts_->browser_context(); -} - NotificationPresenter* BrowserClient::GetNotificationPresenter() { #if defined(OS_WIN) // Bail out if on Windows 7 or even lower, no operating will follow diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index acb12b99708..46ce320bac7 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -23,7 +23,6 @@ class BrowserClient : public content::ContentBrowserClient { BrowserClient(); ~BrowserClient(); - BrowserContext* browser_context(); BrowserMainParts* browser_main_parts() { return browser_main_parts_; } NotificationPresenter* GetNotificationPresenter(); diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 6cf1f4fd5a0..8b1ade8e509 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -206,8 +206,6 @@ void BrowserMainParts::PreMainMessageLoopStart() { } void BrowserMainParts::PreMainMessageLoopRun() { - browser_context_ = BrowserContext::From("", false); - content::WebUIControllerFactory::RegisterFactory( WebUIControllerFactory::GetInstance()); @@ -230,8 +228,6 @@ void BrowserMainParts::PostMainMessageLoopStart() { } void BrowserMainParts::PostMainMessageLoopRun() { - browser_context_ = nullptr; - #if defined(USE_X11) // Unset the X11 error handlers. The X11 error handlers log the errors using a // |PostTask()| on the message-loop. But since the message-loop is in the diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index 042f5d62c74..a0d58e7609e 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -27,15 +27,11 @@ class WMState; namespace brightray { -class BrowserContext; - class BrowserMainParts : public content::BrowserMainParts { public: BrowserMainParts(); ~BrowserMainParts(); - BrowserContext* browser_context() { return browser_context_.get(); } - protected: // content::BrowserMainParts: void PreEarlyInitialization() override; @@ -52,7 +48,6 @@ class BrowserMainParts : public content::BrowserMainParts { void InitializeMainNib(); #endif - scoped_refptr browser_context_; std::unique_ptr devtools_http_handler_; #if defined(TOOLKIT_VIEWS) From 8eca432b6d2edf6853e8425cac24dafa7e852197 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 22 Jun 2016 15:52:04 +0900 Subject: [PATCH 0856/1195] Call on GetUserAgent on UI thread --- brightray/browser/url_request_context_getter.cc | 5 ++++- brightray/browser/url_request_context_getter.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 12d13d71c43..feec4ce6f84 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -172,6 +172,9 @@ URLRequestContextGetter::URLRequestContextGetter( if (protocol_handlers) std::swap(protocol_handlers_, *protocol_handlers); + if (delegate_) + user_agent_ = delegate_->GetUserAgent(); + // 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 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). @@ -230,7 +233,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_http_user_agent_settings(base::WrapUnique( new net::StaticHttpUserAgentSettings( net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang), - delegate_->GetUserAgent()))); + user_agent_))); std::unique_ptr host_resolver(net::HostResolver::CreateDefaultResolver(nullptr)); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 7dc5ccfff8b..aef0e96fe6f 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -78,6 +78,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { base::MessageLoop* io_loop_; base::MessageLoop* file_loop_; + std::string user_agent_; + std::unique_ptr proxy_config_service_; std::unique_ptr network_delegate_; std::unique_ptr storage_; From 7fd7699adad0c64070bce96d9e9741d9cd72b6d1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 23 Jun 2016 11:15:56 +0900 Subject: [PATCH 0857/1195] Revert "Replace --whole-archive with --start-group" --- brightray/brightray.gyp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 156f95de362..b5fcbbd05c0 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -36,13 +36,14 @@ 'conditions': [ # Link with libraries of libchromiumcontent. ['OS=="linux" and libchromiumcontent_component==0', { - # On Linux we have to use "--start-group" or we will have plenty of + # On Linux we have to use "--whole-archive" to force executable + # to include all symbols, otherwise we will have plenty of # unresolved symbols errors. - 'link_settings': { - 'libraries': [ - '-Wl,--start-group', + 'direct_dependent_settings': { + 'ldflags': [ + '-Wl,--whole-archive', '<@(libchromiumcontent_libraries)', - '-Wl,--end-group' + '-Wl,--no-whole-archive', ], } }, { # (Release build on Linux) From f7a8aa12ac228d6d14c997805083e1fda5e1b764 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Sat, 2 Jul 2016 13:26:58 +1200 Subject: [PATCH 0858/1195] Patch OnWebNotificationAllowed to mark notifications as silent in muted WebContents --- brightray/browser/browser_client.h | 4 ++++ brightray/browser/platform_notification_service.cc | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 46ce320bac7..21360ba04a8 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -33,6 +33,10 @@ class BrowserClient : public content::ContentBrowserClient { callback.Run(true); } + virtual bool WebContentsAudioMuted(int render_process_id) { + return false; + } + // Subclasses that override this (e.g., to provide their own protocol // handlers) should call this implementation after doing their own work. content::BrowserMainParts* CreateBrowserMainParts( diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 023f0a2a131..873e82df27f 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -22,6 +22,7 @@ void RemoveNotification(base::WeakPtr notification) { } void OnWebNotificationAllowed( + int render_process_id, brightray::BrowserClient* browser_client, const SkBitmap& icon, const content::PlatformNotificationData& data, @@ -37,8 +38,12 @@ void OnWebNotificationAllowed( new NotificationDelegateAdapter(std::move(delegate))); auto notification = presenter->CreateNotification(adapter.get()); if (notification) { + bool silent = data.silent; + if (!silent) { + silent = browser_client->WebContentsAudioMuted(render_process_id); + } ignore_result(adapter.release()); // it will release itself automatically. - notification->Show(data.title, data.body, data.tag, data.icon, icon, data.silent); + notification->Show(data.title, data.body, data.tag, data.icon, icon, silent); *cancel_callback = base::Bind(&RemoveNotification, notification); } } @@ -78,6 +83,7 @@ void PlatformNotificationService::DisplayNotification( browser_client_->WebNotificationAllowed( render_process_id_, base::Bind(&OnWebNotificationAllowed, + render_process_id_, browser_client_, notification_resources.notification_icon, notification_data, From b8ac95660fb865acc00247efe10225a790338c1d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 2 Jul 2016 13:53:28 +0900 Subject: [PATCH 0859/1195] Update to Chrome Update to Chrome 51.0.2704.106 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index aab0223c9be..31144d583c1 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit aab0223c9be3d3073f38ce0c69bc44319b2690c3 +Subproject commit 31144d583c19b70d8d9de7d4ef15f0f720779860 From bf9d2b7fa97f7f41894543b81ddde58997cbc23c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 2 Jul 2016 16:53:48 +0900 Subject: [PATCH 0860/1195] Avoid adding WebContentsAudioMuted method --- brightray/browser/browser_client.h | 11 ++++------- brightray/browser/platform_notification_service.cc | 10 +++------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index 21360ba04a8..e810a44fadc 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -28,13 +28,10 @@ class BrowserClient : public content::ContentBrowserClient { NotificationPresenter* GetNotificationPresenter(); // Subclasses should override this to enable or disable WebNotification. - virtual void WebNotificationAllowed(int render_process_id, - const base::Callback& callback) { - callback.Run(true); - } - - virtual bool WebContentsAudioMuted(int render_process_id) { - return false; + virtual void WebNotificationAllowed( + int render_process_id, + const base::Callback& callback) { + callback.Run(false, true); } // Subclasses that override this (e.g., to provide their own protocol diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 873e82df27f..7821de440a9 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -22,12 +22,12 @@ void RemoveNotification(base::WeakPtr notification) { } void OnWebNotificationAllowed( - int render_process_id, brightray::BrowserClient* browser_client, const SkBitmap& icon, const content::PlatformNotificationData& data, std::unique_ptr delegate, base::Closure* cancel_callback, + bool audio_muted, bool allowed) { if (!allowed) return; @@ -38,12 +38,9 @@ void OnWebNotificationAllowed( new NotificationDelegateAdapter(std::move(delegate))); auto notification = presenter->CreateNotification(adapter.get()); if (notification) { - bool silent = data.silent; - if (!silent) { - silent = browser_client->WebContentsAudioMuted(render_process_id); - } ignore_result(adapter.release()); // it will release itself automatically. - notification->Show(data.title, data.body, data.tag, data.icon, icon, silent); + notification->Show(data.title, data.body, data.tag, data.icon, icon, + audio_muted ? true : data.silent); *cancel_callback = base::Bind(&RemoveNotification, notification); } } @@ -83,7 +80,6 @@ void PlatformNotificationService::DisplayNotification( browser_client_->WebNotificationAllowed( render_process_id_, base::Bind(&OnWebNotificationAllowed, - render_process_id_, browser_client_, notification_resources.notification_icon, notification_data, From 8f7394a7b73739f166978a3c95f8de40d2f104e4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 4 Jul 2016 13:48:28 +0900 Subject: [PATCH 0861/1195] Upgrade to Chrome 52 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 31144d583c1..1dd3cbf7c4d 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 31144d583c19b70d8d9de7d4ef15f0f720779860 +Subproject commit 1dd3cbf7c4d3cc6511fa1a2a145b0e9cd86752b6 From 4e9782897c893aa2f36a29a6e5963491d18ef35a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 4 Jul 2016 15:06:05 +0900 Subject: [PATCH 0862/1195] Update to API changes of Chrome 52 --- brightray/browser/browser_context.cc | 33 +++++++------------ brightray/browser/browser_context.h | 10 +++--- brightray/browser/browser_main_parts.cc | 6 ++-- .../browser/inspectable_web_contents_impl.cc | 24 +++++++------- .../media/media_capture_devices_dispatcher.cc | 8 +++++ .../media/media_capture_devices_dispatcher.h | 5 +++ .../browser/platform_notification_service.cc | 8 ++--- .../browser/platform_notification_service.h | 4 +-- .../browser/url_request_context_getter.cc | 2 +- 9 files changed, 50 insertions(+), 50 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 236a8f5c1f2..4138b8e0f89 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -174,27 +174,6 @@ bool BrowserContext::IsOffTheRecord() const { return in_memory_; } -net::URLRequestContextGetter* BrowserContext::GetRequestContext() { - return GetDefaultStoragePartition(this)->GetURLRequestContext(); -} - -net::URLRequestContextGetter* BrowserContext::GetMediaRequestContext() { - return GetRequestContext(); -} - -net::URLRequestContextGetter* - BrowserContext::GetMediaRequestContextForRenderProcess( - int renderer_child_id) { - return GetRequestContext(); -} - -net::URLRequestContextGetter* - BrowserContext::GetMediaRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory) { - return GetRequestContext(); -} - content::ResourceContext* BrowserContext::GetResourceContext() { return resource_context_.get(); } @@ -238,4 +217,16 @@ BrowserContext::CreateRequestContextForStoragePartition( return nullptr; } +net::URLRequestContextGetter* +BrowserContext::CreateMediaRequestContext() { + return url_request_getter_.get(); +} + +net::URLRequestContextGetter* +BrowserContext::CreateMediaRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory) { + return nullptr; +} + } // namespace brightray diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 421ef51f43c..fb816b79b52 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -42,12 +42,6 @@ class BrowserContext : public base::RefCounted, std::unique_ptr CreateZoomLevelDelegate( const base::FilePath& partition_path) override; bool IsOffTheRecord() const override; - net::URLRequestContextGetter* GetRequestContext() override; - net::URLRequestContextGetter* GetMediaRequestContext() override; - net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( - int renderer_child_id) override; - net::URLRequestContextGetter* GetMediaRequestContextForStoragePartition( - const base::FilePath& partition_path, bool in_memory) override; content::ResourceContext* GetResourceContext() override; content::DownloadManagerDelegate* GetDownloadManagerDelegate() override; content::BrowserPluginGuestManager* GetGuestManager() override; @@ -64,6 +58,10 @@ class BrowserContext : public base::RefCounted, bool in_memory, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptors) override; + net::URLRequestContextGetter* CreateMediaRequestContext() override; + net::URLRequestContextGetter* CreateMediaRequestContextForStoragePartition( + const base::FilePath& partition_path, + bool in_memory) override; 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 8b1ade8e509..9f0ef0245db 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -21,7 +21,7 @@ #include "ui/base/l10n/l10n_util.h" #if defined(USE_AURA) -#include "ui/gfx/screen.h" +#include "ui/display/screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h" #endif @@ -238,8 +238,8 @@ void BrowserMainParts::PostMainMessageLoopRun() { int BrowserMainParts::PreCreateThreads() { #if defined(USE_AURA) - gfx::Screen* screen = views::CreateDesktopScreen(); - gfx::Screen::SetScreenInstance(screen); + display::Screen* screen = views::CreateDesktopScreen(); + display::Screen::SetScreenInstance(screen); #if defined(USE_X11) views::LinuxUI::instance()->UpdateDeviceScaleFactor( screen->GetPrimaryDisplay().device_scale_factor()); diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 70119c15582..ab610748f2e 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -5,25 +5,22 @@ #include "browser/inspectable_web_contents_impl.h" +#include "base/json/json_reader.h" +#include "base/json/json_writer.h" +#include "base/metrics/histogram.h" +#include "base/strings/pattern.h" +#include "base/strings/stringprintf.h" +#include "base/strings/utf_string_conversions.h" +#include "base/values.h" #include "browser/browser_client.h" #include "browser/browser_context.h" #include "browser/browser_main_parts.h" #include "browser/inspectable_web_contents_delegate.h" #include "browser/inspectable_web_contents_view.h" #include "browser/inspectable_web_contents_view_delegate.h" - -#include "base/json/json_reader.h" -#include "base/json/json_writer.h" -#include "base/metrics/histogram.h" - #include "components/prefs/pref_service.h" #include "components/prefs/scoped_user_pref_update.h" #include "components/prefs/pref_registry_simple.h" - -#include "base/strings/pattern.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/host_zoom_map.h" #include "content/public/browser/render_frame_host.h" @@ -33,7 +30,8 @@ #include "net/http/http_response_headers.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher_response_writer.h" -#include "ui/gfx/screen.h" +#include "ui/display/display.h" +#include "ui/display/screen.h" namespace brightray { @@ -214,7 +212,7 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( devtools_bounds_.set_height(600); devtools_bounds_.set_width(800); } - gfx::Rect display = gfx::Screen::GetScreen() + gfx::Rect display = display::Screen::GetScreen() ->GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); if (!IsPointInRect(devtools_bounds_.origin(), display)) { devtools_bounds_.set_x(display.x() + (display.width() - devtools_bounds_.width()) / 2); @@ -361,7 +359,7 @@ void InspectableWebContentsImpl::ActivateWindow() { } void InspectableWebContentsImpl::CloseWindow() { - GetDevToolsWebContents()->DispatchBeforeUnload(false); + GetDevToolsWebContents()->DispatchBeforeUnload(); } void InspectableWebContentsImpl::LoadCompleted() { diff --git a/brightray/browser/media/media_capture_devices_dispatcher.cc b/brightray/browser/media/media_capture_devices_dispatcher.cc index 09c71b82a49..9ebe5e1a315 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.cc +++ b/brightray/browser/media/media_capture_devices_dispatcher.cc @@ -147,4 +147,12 @@ void MediaCaptureDevicesDispatcher::OnCreatingAudioStream( int render_view_id) { } +void MediaCaptureDevicesDispatcher::OnSetCapturingLinkSecured( + int render_process_id, + int render_frame_id, + int page_request_id, + content::MediaStreamType stream_type, + bool is_secure) { +} + } // namespace brightray diff --git a/brightray/browser/media/media_capture_devices_dispatcher.h b/brightray/browser/media/media_capture_devices_dispatcher.h index 27fe6766469..dbbd66d2580 100644 --- a/brightray/browser/media/media_capture_devices_dispatcher.h +++ b/brightray/browser/media/media_capture_devices_dispatcher.h @@ -61,6 +61,11 @@ class MediaCaptureDevicesDispatcher : public content::MediaObserver { content::MediaRequestState state) override; void OnCreatingAudioStream(int render_process_id, int render_view_id) override; + void OnSetCapturingLinkSecured(int render_process_id, + int render_frame_id, + int page_request_id, + content::MediaStreamType stream_type, + bool is_secure) override; private: friend struct base::DefaultSingletonTraits; diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 7821de440a9..77ca31a5bb5 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -55,19 +55,19 @@ PlatformNotificationService::PlatformNotificationService( PlatformNotificationService::~PlatformNotificationService() {} -blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnUIThread( +blink::mojom::PermissionStatus PlatformNotificationService::CheckPermissionOnUIThread( content::BrowserContext* browser_context, const GURL& origin, int render_process_id) { render_process_id_ = render_process_id; - return blink::WebNotificationPermissionAllowed; + return blink::mojom::PermissionStatus::GRANTED; } -blink::WebNotificationPermission PlatformNotificationService::CheckPermissionOnIOThread( +blink::mojom::PermissionStatus PlatformNotificationService::CheckPermissionOnIOThread( content::ResourceContext* resource_context, const GURL& origin, int render_process_id) { - return blink::WebNotificationPermissionAllowed; + return blink::mojom::PermissionStatus::GRANTED; } void PlatformNotificationService::DisplayNotification( diff --git a/brightray/browser/platform_notification_service.h b/brightray/browser/platform_notification_service.h index 1c4b53da94a..9c478929378 100644 --- a/brightray/browser/platform_notification_service.h +++ b/brightray/browser/platform_notification_service.h @@ -20,11 +20,11 @@ class PlatformNotificationService protected: // content::PlatformNotificationService: - blink::WebNotificationPermission CheckPermissionOnUIThread( + blink::mojom::PermissionStatus CheckPermissionOnUIThread( content::BrowserContext* browser_context, const GURL& origin, int render_process_id) override; - blink::WebNotificationPermission CheckPermissionOnIOThread( + blink::mojom::PermissionStatus CheckPermissionOnIOThread( content::ResourceContext* resource_context, const GURL& origin, int render_process_id) override; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index feec4ce6f84..2bbb3f59484 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -381,7 +381,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { it != protocol_interceptors_.rend(); ++it) { top_job_factory.reset(new net::URLRequestInterceptingJobFactory( - std::move(top_job_factory), make_scoped_ptr(*it))); + std::move(top_job_factory), base::WrapUnique(*it))); } protocol_interceptors_.weak_clear(); From d166ba9ed2f7d1f66f94b787513505049b3edbc3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 4 Jul 2016 15:06:15 +0900 Subject: [PATCH 0863/1195] Disable compiler warning caused by blink --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index d22c458ce14..2800409124d 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -42,6 +42,7 @@ '-Wno-missing-field-initializers', '-Wno-deprecated-declarations', '-Wno-unneeded-internal-declaration', + '-Wno-inconsistent-missing-override', ], }, 'msvs_configuration_attributes': { From c1b07b3da98f26d154f0d0385dc8d3d51ee95064 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 4 Jul 2016 15:06:58 +0900 Subject: [PATCH 0864/1195] Make it possible to include SkUserConfig.h --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b5fcbbd05c0..4de2f5259a9 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -26,6 +26,7 @@ '<(libchromiumcontent_src_dir)', '<(libchromiumcontent_src_dir)/skia/config', '<(libchromiumcontent_src_dir)/third_party/skia/include/core', + '<(libchromiumcontent_src_dir)/third_party/skia/include/config', '<(libchromiumcontent_src_dir)/third_party/icu/source/common', '<(libchromiumcontent_src_dir)/third_party/mojo/src', '<(libchromiumcontent_src_dir)/third_party/WebKit', From 4afa3f7206e64f4d4984e9c30da35a20cb355393 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 4 Jul 2016 15:29:43 +0900 Subject: [PATCH 0865/1195] Add BrowserContext::GetRequestContext --- brightray/browser/browser_context.cc | 17 +++++++++++------ brightray/browser/browser_context.h | 3 +++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 4138b8e0f89..15b45ae2db0 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -115,6 +115,12 @@ BrowserContext::BrowserContext(const std::string& partition, bool in_memory) content::BrowserContext::Initialize(this, path_); } +BrowserContext::~BrowserContext() { + BrowserThread::DeleteSoon(BrowserThread::IO, + FROM_HERE, + resource_context_.release()); +} + void BrowserContext::InitPrefs() { auto prefs_path = GetPath().Append(FILE_PATH_LITERAL("Preferences")); PrefServiceFactory prefs_factory; @@ -129,16 +135,15 @@ void BrowserContext::InitPrefs() { prefs_ = prefs_factory.Create(registry.get()); } -BrowserContext::~BrowserContext() { - BrowserThread::DeleteSoon(BrowserThread::IO, - FROM_HERE, - resource_context_.release()); -} - void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { InspectableWebContentsImpl::RegisterPrefs(registry); } +URLRequestContextGetter* BrowserContext::GetRequestContext() { + return static_cast( + GetDefaultStoragePartition(this)->GetURLRequestContext()); +} + net::URLRequestContextGetter* BrowserContext::CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors) { diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index fb816b79b52..bda4f3a9e4e 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -38,6 +38,9 @@ class BrowserContext : public base::RefCounted, static scoped_refptr Create( const std::string& partition, bool in_memory); + // Get the request context, if there is no one, create it. + URLRequestContextGetter* GetRequestContext(); + // content::BrowserContext: std::unique_ptr CreateZoomLevelDelegate( const base::FilePath& partition_path) override; From 0ae344e5cd7e8d4fc66524ec6b0ca9199440d4ca Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 4 Jul 2016 16:40:46 +0900 Subject: [PATCH 0866/1195] Fix building on Linux --- brightray/brightray.gypi | 68 +++++++++++++++---------- brightray/browser/browser_main_parts.cc | 3 +- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 2800409124d..038348fe6c5 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -35,15 +35,6 @@ 'MACOSX_DEPLOYMENT_TARGET': '10.8', 'RUN_CLANG_STATIC_ANALYZER': 'YES', 'USE_HEADER_MAP': 'NO', - 'WARNING_CFLAGS': [ - '-Wall', - '-Wextra', - '-Wno-unused-parameter', - '-Wno-missing-field-initializers', - '-Wno-deprecated-declarations', - '-Wno-unneeded-internal-declaration', - '-Wno-inconsistent-missing-override', - ], }, 'msvs_configuration_attributes': { 'OutputDirectory': '<(DEPTH)\\build\\$(ConfigurationName)', @@ -92,24 +83,6 @@ ], }, }, - 'msvs_disabled_warnings': [ - 4100, # unreferenced formal parameter - 4121, # alignment of a member was sensitive to packing - 4127, # conditional expression is constant - 4189, # local variable is initialized but not referenced - 4244, # 'initializing' : conversion from 'double' to 'size_t', possible loss of data - 4245, # 'initializing' : conversion from 'int' to 'const net::QuicVersionTag', signed/unsigned mismatch - 4251, # class 'std::xx' needs to have dll-interface. - 4310, # cast truncates constant value - 4355, # 'this' : used in base member initializer list - 4480, # nonstandard extension used: specifying underlying type for enum - 4481, # nonstandard extension used: override specifier 'override' - 4510, # default constructor could not be generated - 4512, # assignment operator could not be generated - 4610, # user defined constructor required - 4702, # unreachable code - 4819, # The file contains a character that cannot be represented in the current code page - ], 'configurations': { # The "Debug" and "Release" configurations are not actually used. 'Debug': {}, @@ -342,5 +315,46 @@ ], }], ], # target_conditions + # Ignored compiler warnings of Chromium. + 'conditions': [ + ['OS=="mac"', { + 'xcode_settings': { + 'WARNING_CFLAGS': [ + '-Wall', + '-Wextra', + '-Wno-unused-parameter', + '-Wno-missing-field-initializers', + '-Wno-deprecated-declarations', + '-Wno-unneeded-internal-declaration', + '-Wno-inconsistent-missing-override', + ], + }, + }], + ['OS=="linux"', { + 'cflags': [ + '-Wno-inconsistent-missing-override', + ], + }], + ['OS=="win"', { + 'msvs_disabled_warnings': [ + 4100, # unreferenced formal parameter + 4121, # alignment of a member was sensitive to packing + 4127, # conditional expression is constant + 4189, # local variable is initialized but not referenced + 4244, # 'initializing' : conversion from 'double' to 'size_t', possible loss of data + 4245, # 'initializing' : conversion from 'int' to 'const net::QuicVersionTag', signed/unsigned mismatch + 4251, # class 'std::xx' needs to have dll-interface. + 4310, # cast truncates constant value + 4355, # 'this' : used in base member initializer list + 4480, # nonstandard extension used: specifying underlying type for enum + 4481, # nonstandard extension used: override specifier 'override' + 4510, # default constructor could not be generated + 4512, # assignment operator could not be generated + 4610, # user defined constructor required + 4702, # unreachable code + 4819, # The file contains a character that cannot be represented in the current code page + ], + }], + ], # conditions }, # target_defaults } diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 9f0ef0245db..c2127b3b5aa 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -21,6 +21,7 @@ #include "ui/base/l10n/l10n_util.h" #if defined(USE_AURA) +#include "ui/display/display.h" #include "ui/display/screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h" #endif @@ -33,7 +34,7 @@ #include "base/environment.h" #include "base/path_service.h" #include "base/nix/xdg_util.h" -#include "base/thread_task_runner_handle.h" +#include "base/threading/thread_task_runner_handle.h" #include "browser/brightray_paths.h" #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" #include "ui/base/x/x11_util.h" From fd1448dd8b84c9caa377055b8f88efa20aaa2f0b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 5 Jul 2016 09:41:05 +0900 Subject: [PATCH 0867/1195] Initialize MaterialDesignController --- brightray/browser/browser_main_parts.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index c2127b3b5aa..0aae4bcc5bc 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -19,6 +19,7 @@ #include "media/base/media_resources.h" #include "net/proxy/proxy_resolver_v8.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/base/material_design/material_design_controller.h" #if defined(USE_AURA) #include "ui/display/display.h" @@ -176,6 +177,8 @@ void BrowserMainParts::PreEarlyInitialization() { } void BrowserMainParts::ToolkitInitialized() { + ui::MaterialDesignController::Initialize(); + #if defined(USE_AURA) && defined(USE_X11) views::LinuxUI::instance()->Initialize(); wm_state_.reset(new wm::WMState); From b85c3b5e7fc8da5bc376f7f68220ef22bb5ffe54 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sat, 9 Jul 2016 22:24:40 +0200 Subject: [PATCH 0868/1195] 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 6f5bdc7bfa5..855474d93bb 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 60a3a15a0a3..584840533be 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 0869/1195] 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 09c71b82a49..535635159d3 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 103feea369d..b3548bbe409 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 feec4ce6f84..f24b9b2bde7 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 3313d3a6c63..c59e5bb0c66 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 0870/1195] 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 f45d90d753f..9df6a08b6de 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 788db1fa630..f9841441ad2 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 70119c15582..c6f6eb5b46a 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 535635159d3..44b781fafaf 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 cb2f92ba222..cfa4e234712 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 9876b49418b..f141c7ef2e4 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 0871/1195] 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 1464362f3ad..368ac3a6073 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 6f5bdc7bfa5..e3452fa8b79 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 0872/1195] 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 44b781fafaf..4a0a71c7c3f 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 0873/1195] 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 c6f6eb5b46a..dfb46ff0124 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 0874/1195] 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 236a8f5c1f2..91928d9e367 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 421ef51f43c..7ae9b269209 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 0875/1195] 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 09c9ab6f801..1a438f200e3 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; From b2546a2b34a7c99f0f43c76d1176bb1cab6eda9b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 21 Jul 2016 06:03:11 -0600 Subject: [PATCH 0876/1195] Fix compilation error after merge --- brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 17463b10edf..dc3110be4ec 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -90,7 +90,7 @@ bool IsPointInRect(const gfx::Point& point, const gfx::Rect& rect) { } bool IsPointInScreen(const gfx::Point& point) { - for (const auto& display : gfx::Screen::GetScreen()->GetAllDisplays()) { + for (const auto& display : display::Screen::GetScreen()->GetAllDisplays()) { if (IsPointInRect(point, display.bounds())) return true; } @@ -221,7 +221,7 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( devtools_bounds_.set_width(800); } if (!IsPointInScreen(devtools_bounds_.origin())) { - gfx::Rect display = gfx::Screen::GetScreen()-> + gfx::Rect display = display::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 caba44ab6c58c703cd716bcb85b40c898b7bf7fe Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Fri, 22 Jul 2016 19:19:42 +0530 Subject: [PATCH 0877/1195] allow delegate to handle file and color chooser --- .../browser/inspectable_web_contents_impl.cc | 27 +++++++++++++++++++ .../browser/inspectable_web_contents_impl.h | 9 +++++++ 2 files changed, 36 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index dc3110be4ec..210a69392e2 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -670,6 +670,33 @@ void InspectableWebContentsImpl::CloseContents(content::WebContents* source) { CloseDevTools(); } +content::ColorChooser* InspectableWebContentsImpl::OpenColorChooser( + content::WebContents* source, + SkColor color, + const std::vector& suggestions) { + auto delegate = web_contents_->GetDelegate(); + if (delegate) + return delegate->OpenColorChooser(source, color, suggestions); + return nullptr; +} + +void InspectableWebContentsImpl::RunFileChooser( + content::WebContents* source, + const content::FileChooserParams& params) { + auto delegate = web_contents_->GetDelegate(); + if (delegate) + delegate->RunFileChooser(source, params); +} + +void InspectableWebContentsImpl::EnumerateDirectory( + content::WebContents* source, + int request_id, + const base::FilePath& path) { + auto delegate = web_contents_->GetDelegate(); + if (delegate) + delegate->EnumerateDirectory(source, request_id, path); +} + void InspectableWebContentsImpl::OnWebContentsFocused() { #if defined(TOOLKIT_VIEWS) if (view_->GetDelegate()) diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index f9496a75398..249829aed83 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -153,6 +153,15 @@ class InspectableWebContentsImpl : void HandleKeyboardEvent( content::WebContents*, const content::NativeWebKeyboardEvent&) override; void CloseContents(content::WebContents* source) override; + content::ColorChooser* OpenColorChooser( + content::WebContents* source, + SkColor color, + const std::vector& suggestions) override; + void RunFileChooser(content::WebContents* source, + const content::FileChooserParams& params) override; + void EnumerateDirectory(content::WebContents* source, + int request_id, + const base::FilePath& path) override; // net::URLFetcherDelegate: void OnURLFetchComplete(const net::URLFetcher* source) override; From 2b87813ed332172a17367956b39a4ef81a37ee43 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 25 Jul 2016 11:10:20 +0900 Subject: [PATCH 0878/1195] Load a few more pak files --- brightray/common/main_delegate.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 7dd1d153f5d..2f3c198de2d 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -62,11 +62,17 @@ void InitializeResourceBundle(const std::string& locale) { bundle.AddDataPackFromPath(path, ui::GetSupportedScaleFactors()[0]); #if defined(OS_WIN) bundle.AddDataPackFromPath( - pak_dir.Append(FILE_PATH_LITERAL("ui_resources_200_percent.pak")), + pak_dir.Append(FILE_PATH_LITERAL("blink_image_resources_200_percent.pak")), ui::SCALE_FACTOR_200P); bundle.AddDataPackFromPath( pak_dir.Append(FILE_PATH_LITERAL("content_resources_200_percent.pak")), ui::SCALE_FACTOR_200P); + bundle.AddDataPackFromPath( + pak_dir.Append(FILE_PATH_LITERAL("ui_resources_200_percent.pak")), + ui::SCALE_FACTOR_200P); + bundle.AddDataPackFromPath( + pak_dir.Append(FILE_PATH_LITERAL("views_resources_200_percent.pak")), + ui::SCALE_FACTOR_200P); #endif } From de692c989660a2d20340a9bffee954ca62660df3 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 26 Jul 2016 16:32:14 +0530 Subject: [PATCH 0879/1195] bring back fix from #152 --- brightray/browser/browser_context.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 02869a78ab8..a1136577cd3 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -109,7 +109,6 @@ 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(); From ecef83f8f570fd051175358cd85d3d0ca5813adf Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Thu, 28 Jul 2016 02:07:37 +0200 Subject: [PATCH 0880/1195] added khronos and fix for offscreen --- brightray/brightray.gyp | 1 + brightray/browser/inspectable_web_contents_impl.cc | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 4de2f5259a9..4bbfbdf991c 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -29,6 +29,7 @@ '<(libchromiumcontent_src_dir)/third_party/skia/include/config', '<(libchromiumcontent_src_dir)/third_party/icu/source/common', '<(libchromiumcontent_src_dir)/third_party/mojo/src', + '<(libchromiumcontent_src_dir)/third_party/khronos', '<(libchromiumcontent_src_dir)/third_party/WebKit', '<(libchromiumcontent_dir)/gen', ], diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 210a69392e2..a83a9d8b2a8 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -221,8 +221,14 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( devtools_bounds_.set_width(800); } if (!IsPointInScreen(devtools_bounds_.origin())) { - gfx::Rect display = display::Screen::GetScreen()-> + gfx::Rect display; + if (web_contents->GetNativeView()) { + display = display::Screen::GetScreen()-> GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); + } else { + display = display::Screen::GetScreen()->GetPrimaryDisplay().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 97b153fce658023b1c71291539d847cf9b7dab1a Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Thu, 28 Jul 2016 02:11:57 +0200 Subject: [PATCH 0881/1195] fix for offscreen and added khronos --- brightray/brightray.gyp | 1 + brightray/browser/inspectable_web_contents_impl.cc | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 4de2f5259a9..4bbfbdf991c 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -29,6 +29,7 @@ '<(libchromiumcontent_src_dir)/third_party/skia/include/config', '<(libchromiumcontent_src_dir)/third_party/icu/source/common', '<(libchromiumcontent_src_dir)/third_party/mojo/src', + '<(libchromiumcontent_src_dir)/third_party/khronos', '<(libchromiumcontent_src_dir)/third_party/WebKit', '<(libchromiumcontent_dir)/gen', ], diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 210a69392e2..a83a9d8b2a8 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -221,8 +221,14 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( devtools_bounds_.set_width(800); } if (!IsPointInScreen(devtools_bounds_.origin())) { - gfx::Rect display = display::Screen::GetScreen()-> + gfx::Rect display; + if (web_contents->GetNativeView()) { + display = display::Screen::GetScreen()-> GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); + } else { + display = display::Screen::GetScreen()->GetPrimaryDisplay().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 f28fb3838c48f3b4232d2ecaa5b95c2d6971ff84 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Fri, 29 Jul 2016 01:17:59 +0200 Subject: [PATCH 0882/1195] add gl2chromium headers too direct dependent settings so we don't have to copy anymore : ) --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 4bbfbdf991c..d089dbaceb8 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -24,6 +24,7 @@ '.', '..', '<(libchromiumcontent_src_dir)', + '<(libchromiumcontent_src_dir)/gpu', '<(libchromiumcontent_src_dir)/skia/config', '<(libchromiumcontent_src_dir)/third_party/skia/include/core', '<(libchromiumcontent_src_dir)/third_party/skia/include/config', From 10ea1606df9b0a208e75ebc443fba1dc472727aa Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 29 Jul 2016 10:50:48 +0900 Subject: [PATCH 0883/1195] Load 200 DPI resources on Linux --- brightray/common/main_delegate.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 2f3c198de2d..69719ba3b9d 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -60,7 +60,7 @@ void InitializeResourceBundle(const std::string& locale) { ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); bundle.AddDataPackFromPath(path, ui::GetSupportedScaleFactors()[0]); -#if defined(OS_WIN) +#if !defined(OS_MACOSX) bundle.AddDataPackFromPath( pak_dir.Append(FILE_PATH_LITERAL("blink_image_resources_200_percent.pak")), ui::SCALE_FACTOR_200P); From 826fbf3e21f6e43918ad2690c1b87f38be4438c6 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 3 Aug 2016 15:52:09 +0530 Subject: [PATCH 0884/1195] allow additional schemes that should support cookies --- .../browser/url_request_context_getter.cc | 94 +++++++------------ brightray/common/switches.cc | 57 +++++++++++ brightray/common/switches.h | 26 +++++ brightray/filenames.gypi | 2 + 4 files changed, 117 insertions(+), 62 deletions(-) create mode 100644 brightray/common/switches.cc create mode 100644 brightray/common/switches.h diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 41b570cd7cf..b07fe88d663 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -10,9 +10,11 @@ #include "browser/net/devtools_network_transaction_factory.h" #include "browser/net_log.h" #include "browser/network_delegate.h" +#include "common/switches.h" #include "base/command_line.h" #include "base/memory/ptr_util.h" +#include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" @@ -56,51 +58,6 @@ using content::BrowserThread; namespace brightray { -namespace { - -// Comma-separated list of rules that control how hostnames are mapped. -// -// For example: -// "MAP * 127.0.0.1" --> Forces all hostnames to be mapped to 127.0.0.1 -// "MAP *.google.com proxy" --> Forces all google.com subdomains to be -// resolved to "proxy". -// "MAP test.com [::1]:77 --> Forces "test.com" to resolve to IPv6 loopback. -// Will also force the port of the resulting -// socket address to be 77. -// "MAP * baz, EXCLUDE www.google.com" --> Remaps everything to "baz", -// except for "www.google.com". -// -// These mappings apply to the endpoint host in a net::URLRequest (the TCP -// connect and host resolver in a direct connection, and the CONNECT in an http -// proxy connection, and the endpoint host in a SOCKS proxy connection). -const char kHostRules[] = "host-rules"; - -// Don't use a proxy server, always make direct connections. Overrides any -// other proxy server flags that are passed. -const char kNoProxyServer[] = "no-proxy-server"; - -// Uses a specified proxy server, overrides system settings. This switch only -// affects HTTP and HTTPS requests. -const char kProxyServer[] = "proxy-server"; - -// Bypass specified proxy for the given semi-colon-separated list of hosts. This -// flag has an effect only when --proxy-server is set. -const char kProxyBypassList[] = "proxy-bypass-list"; - -// Uses the pac script at the given URL. -const char kProxyPacUrl[] = "proxy-pac-url"; - -// Disable HTTP/2 and SPDY/3.1 protocols. -const char kDisableHttp2[] = "disable-http2"; - -// Whitelist containing servers for which Integrated Authentication is enabled. -const char kAuthServerWhitelist[] = "auth-server-whitelist"; - -// Whitelist containing servers for which Kerberos delegation is allowed. -const char kAuthNegotiateDelegateWhitelist[] = "auth-negotiate-delegate-whitelist"; - -} // namespace - std::string URLRequestContextGetter::Delegate::GetUserAgent() { return base::EmptyString(); } @@ -215,13 +172,26 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_.reset(new net::URLRequestContextStorage(url_request_context_.get())); std::unique_ptr cookie_store = nullptr; + std::vector default_cookieable_schemes = {"http", "https", "ws", "wss"}; + auto schemes_string = command_line.GetSwitchValueASCII(switches::kCookieableSchemes); + if (!schemes_string.empty()) { + auto additional_cookieable_schemes = base::SplitString(schemes_string, ",", + base::TRIM_WHITESPACE, + base::SPLIT_WANT_NONEMPTY); + default_cookieable_schemes.insert(default_cookieable_schemes.end(), + additional_cookieable_schemes.begin(), + additional_cookieable_schemes.end()); + } if (in_memory_) { - cookie_store = content::CreateCookieStore(content::CookieStoreConfig()); + auto cookie_config = content::CookieStoreConfig(); + cookie_config.cookieable_schemes = default_cookieable_schemes; + cookie_store = content::CreateCookieStore(cookie_config); } else { auto cookie_config = content::CookieStoreConfig( base_path_.Append(FILE_PATH_LITERAL("Cookies")), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, nullptr, nullptr); + cookie_config.cookieable_schemes = default_cookieable_schemes; cookie_store = content::CreateCookieStore(cookie_config); } storage_->set_cookie_store(std::move(cookie_store)); @@ -238,28 +208,28 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { std::unique_ptr host_resolver(net::HostResolver::CreateDefaultResolver(nullptr)); // --host-resolver-rules - if (command_line.HasSwitch(switches::kHostResolverRules)) { + if (command_line.HasSwitch(::switches::kHostResolverRules)) { std::unique_ptr remapped_resolver( new net::MappedHostResolver(std::move(host_resolver))); remapped_resolver->SetRulesFromString( - command_line.GetSwitchValueASCII(switches::kHostResolverRules)); + command_line.GetSwitchValueASCII(::switches::kHostResolverRules)); host_resolver = std::move(remapped_resolver); } // --proxy-server net::DhcpProxyScriptFetcherFactory dhcp_factory; - if (command_line.HasSwitch(kNoProxyServer)) { + if (command_line.HasSwitch(switches::kNoProxyServer)) { storage_->set_proxy_service(net::ProxyService::CreateDirect()); - } else if (command_line.HasSwitch(kProxyServer)) { + } else if (command_line.HasSwitch(switches::kProxyServer)) { net::ProxyConfig proxy_config; proxy_config.proxy_rules().ParseFromString( - command_line.GetSwitchValueASCII(kProxyServer)); + command_line.GetSwitchValueASCII(switches::kProxyServer)); proxy_config.proxy_rules().bypass_rules.ParseFromString( - command_line.GetSwitchValueASCII(kProxyBypassList)); + command_line.GetSwitchValueASCII(switches::kProxyBypassList)); storage_->set_proxy_service(net::ProxyService::CreateFixed(proxy_config)); - } else if (command_line.HasSwitch(kProxyPacUrl)) { + } else if (command_line.HasSwitch(switches::kProxyPacUrl)) { auto proxy_config = net::ProxyConfig::CreateFromCustomPacURL( - GURL(command_line.GetSwitchValueASCII(kProxyPacUrl))); + GURL(command_line.GetSwitchValueASCII(switches::kProxyPacUrl))); proxy_config.set_pac_mandatory(true); storage_->set_proxy_service(net::ProxyService::CreateFixed( proxy_config)); @@ -287,15 +257,15 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { #endif // --auth-server-whitelist - if (command_line.HasSwitch(kAuthServerWhitelist)) { + if (command_line.HasSwitch(switches::kAuthServerWhitelist)) { http_auth_preferences_->set_server_whitelist( - command_line.GetSwitchValueASCII(kAuthServerWhitelist)); + command_line.GetSwitchValueASCII(switches::kAuthServerWhitelist)); } // --auth-negotiate-delegate-whitelist - if (command_line.HasSwitch(kAuthNegotiateDelegateWhitelist)) { + if (command_line.HasSwitch(switches::kAuthNegotiateDelegateWhitelist)) { http_auth_preferences_->set_delegate_whitelist( - command_line.GetSwitchValueASCII(kAuthNegotiateDelegateWhitelist)); + command_line.GetSwitchValueASCII(switches::kAuthNegotiateDelegateWhitelist)); } auto auth_handler_factory = @@ -326,19 +296,19 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.net_log = url_request_context_->net_log(); // --disable-http2 - if (command_line.HasSwitch(kDisableHttp2)) { + if (command_line.HasSwitch(switches::kDisableHttp2)) { network_session_params.enable_spdy31 = false; network_session_params.enable_http2 = false; } // --ignore-certificate-errors - if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) + if (command_line.HasSwitch(::switches::kIgnoreCertificateErrors)) network_session_params.ignore_certificate_errors = true; // --host-rules - if (command_line.HasSwitch(kHostRules)) { + if (command_line.HasSwitch(switches::kHostRules)) { host_mapping_rules_.reset(new net::HostMappingRules); - host_mapping_rules_->SetRulesFromString(command_line.GetSwitchValueASCII(kHostRules)); + host_mapping_rules_->SetRulesFromString(command_line.GetSwitchValueASCII(switches::kHostRules)); network_session_params.host_mapping_rules = host_mapping_rules_.get(); } diff --git a/brightray/common/switches.cc b/brightray/common/switches.cc new file mode 100644 index 00000000000..3fc6d312591 --- /dev/null +++ b/brightray/common/switches.cc @@ -0,0 +1,57 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "common/switches.h" + +namespace brightray { + +namespace switches { + +// Comma-separated list of rules that control how hostnames are mapped. +// +// For example: +// "MAP * 127.0.0.1" --> Forces all hostnames to be mapped to 127.0.0.1 +// "MAP *.google.com proxy" --> Forces all google.com subdomains to be +// resolved to "proxy". +// "MAP test.com [::1]:77 --> Forces "test.com" to resolve to IPv6 loopback. +// Will also force the port of the resulting +// socket address to be 77. +// "MAP * baz, EXCLUDE www.google.com" --> Remaps everything to "baz", +// except for "www.google.com". +// +// These mappings apply to the endpoint host in a net::URLRequest (the TCP +// connect and host resolver in a direct connection, and the CONNECT in an http +// proxy connection, and the endpoint host in a SOCKS proxy connection). +const char kHostRules[] = "host-rules"; + +// Don't use a proxy server, always make direct connections. Overrides any +// other proxy server flags that are passed. +const char kNoProxyServer[] = "no-proxy-server"; + +// Uses a specified proxy server, overrides system settings. This switch only +// affects HTTP and HTTPS requests. +const char kProxyServer[] = "proxy-server"; + +// Bypass specified proxy for the given semi-colon-separated list of hosts. This +// flag has an effect only when --proxy-server is set. +const char kProxyBypassList[] = "proxy-bypass-list"; + +// Uses the pac script at the given URL. +const char kProxyPacUrl[] = "proxy-pac-url"; + +// Disable HTTP/2 and SPDY/3.1 protocols. +const char kDisableHttp2[] = "disable-http2"; + +// Whitelist containing servers for which Integrated Authentication is enabled. +const char kAuthServerWhitelist[] = "auth-server-whitelist"; + +// Whitelist containing servers for which Kerberos delegation is allowed. +const char kAuthNegotiateDelegateWhitelist[] = "auth-negotiate-delegate-whitelist"; + +// Comma separated list of schemes that should support cookies. +const char kCookieableSchemes[] = "cookieable-schemes"; + +} // namespace switches + +} // namespace brightray diff --git a/brightray/common/switches.h b/brightray/common/switches.h new file mode 100644 index 00000000000..962e4149e33 --- /dev/null +++ b/brightray/common/switches.h @@ -0,0 +1,26 @@ +// Copyright (c) 2016 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef BRIGHTRAY_COMMON_SWITCHES_H_ +#define BRIGHTRAY_COMMON_SWITCHES_H_ + +namespace brightray { + +namespace switches { + +extern const char kHostRules[]; +extern const char kNoProxyServer[]; +extern const char kProxyServer[]; +extern const char kProxyBypassList[]; +extern const char kProxyPacUrl[]; +extern const char kDisableHttp2[]; +extern const char kAuthServerWhitelist[]; +extern const char kAuthNegotiateDelegateWhitelist[]; +extern const char kCookieableSchemes[]; + +} // namespace switches + +} // namespace brightray + +#endif // BRIGHTRAY_COMMON_SWITCHES_H_ diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 944b8824da0..c36bddea5d8 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -109,6 +109,8 @@ 'common/main_delegate.cc', 'common/main_delegate.h', 'common/main_delegate_mac.mm', + 'common/switches.cc', + 'common/switches.h', ], }, } From e96b22430765d9fb7fef4d3e2bd8550d269a59cc Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 4 Aug 2016 12:20:19 +0530 Subject: [PATCH 0885/1195] allow delegate to provide cookieable schemes --- brightray/browser/url_request_context_getter.cc | 15 ++------------- brightray/browser/url_request_context_getter.h | 3 +++ brightray/common/switches.cc | 3 --- brightray/common/switches.h | 1 - 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index b07fe88d663..46860d79198 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -14,7 +14,6 @@ #include "base/command_line.h" #include "base/memory/ptr_util.h" -#include "base/strings/string_split.h" #include "base/strings/string_util.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" @@ -172,26 +171,16 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_.reset(new net::URLRequestContextStorage(url_request_context_.get())); std::unique_ptr cookie_store = nullptr; - std::vector default_cookieable_schemes = {"http", "https", "ws", "wss"}; - auto schemes_string = command_line.GetSwitchValueASCII(switches::kCookieableSchemes); - if (!schemes_string.empty()) { - auto additional_cookieable_schemes = base::SplitString(schemes_string, ",", - base::TRIM_WHITESPACE, - base::SPLIT_WANT_NONEMPTY); - default_cookieable_schemes.insert(default_cookieable_schemes.end(), - additional_cookieable_schemes.begin(), - additional_cookieable_schemes.end()); - } if (in_memory_) { auto cookie_config = content::CookieStoreConfig(); - cookie_config.cookieable_schemes = default_cookieable_schemes; + cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes(); cookie_store = content::CreateCookieStore(cookie_config); } else { auto cookie_config = content::CookieStoreConfig( base_path_.Append(FILE_PATH_LITERAL("Cookies")), content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, nullptr, nullptr); - cookie_config.cookieable_schemes = default_cookieable_schemes; + cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes(); cookie_store = content::CreateCookieStore(cookie_config); } storage_->set_cookie_store(std::move(cookie_store)); diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index aef0e96fe6f..dfe233f2831 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -47,6 +47,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { const base::FilePath& base_path); virtual std::unique_ptr CreateCertVerifier(); virtual net::SSLConfigService* CreateSSLConfigService(); + virtual std::vector GetCookieableSchemes() { + return std::vector(); + } }; URLRequestContextGetter( diff --git a/brightray/common/switches.cc b/brightray/common/switches.cc index 3fc6d312591..7ca869ae98f 100644 --- a/brightray/common/switches.cc +++ b/brightray/common/switches.cc @@ -49,9 +49,6 @@ const char kAuthServerWhitelist[] = "auth-server-whitelist"; // Whitelist containing servers for which Kerberos delegation is allowed. const char kAuthNegotiateDelegateWhitelist[] = "auth-negotiate-delegate-whitelist"; -// Comma separated list of schemes that should support cookies. -const char kCookieableSchemes[] = "cookieable-schemes"; - } // namespace switches } // namespace brightray diff --git a/brightray/common/switches.h b/brightray/common/switches.h index 962e4149e33..3af00813830 100644 --- a/brightray/common/switches.h +++ b/brightray/common/switches.h @@ -17,7 +17,6 @@ extern const char kProxyPacUrl[]; extern const char kDisableHttp2[]; extern const char kAuthServerWhitelist[]; extern const char kAuthNegotiateDelegateWhitelist[]; -extern const char kCookieableSchemes[]; } // namespace switches From 1a80cb22b72e153514511d6ed9547d79f62de8b4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 4 Aug 2016 16:35:09 +0900 Subject: [PATCH 0886/1195] Show label for offscreen webview --- brightray/browser/inspectable_web_contents_impl.cc | 4 ++-- .../views/inspectable_web_contents_view_views.cc | 12 ++++++++++-- .../views/inspectable_web_contents_view_views.h | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index a83a9d8b2a8..6ace243cac3 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -224,11 +224,11 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( gfx::Rect display; if (web_contents->GetNativeView()) { display = display::Screen::GetScreen()-> - GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); + GetDisplayNearestWindow(web_contents->GetNativeView()).bounds(); } else { display = display::Screen::GetScreen()->GetPrimaryDisplay().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); } diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 1a438f200e3..ccb76126d54 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -5,6 +5,7 @@ #include "browser/inspectable_web_contents_view_delegate.h" #include "base/strings/utf_string_conversions.h" +#include "ui/views/controls/label.h" #include "ui/views/controls/webview/webview.h" #include "ui/views/widget/widget.h" #include "ui/views/widget/widget_delegate.h" @@ -76,14 +77,21 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews( InspectableWebContentsImpl* inspectable_web_contents) : inspectable_web_contents_(inspectable_web_contents), devtools_window_web_view_(nullptr), - contents_web_view_(new views::WebView(nullptr)), + contents_web_view_(nullptr), devtools_web_view_(new views::WebView(nullptr)), devtools_visible_(false), devtools_window_delegate_(nullptr) { set_owned_by_client(); + if (inspectable_web_contents_->GetWebContents()->GetNativeView()) { + views::WebView* contents_web_view = new views::WebView(nullptr); + contents_web_view->SetWebContents(inspectable_web_contents_->GetWebContents()); + contents_web_view_ = contents_web_view; + } else { + contents_web_view_ = new views::Label(L"No content under offscreen mode"); + } + devtools_web_view_->SetVisible(false); - contents_web_view_->SetWebContents(inspectable_web_contents_->GetWebContents()); AddChildView(devtools_web_view_); AddChildView(contents_web_view_); } diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index e73ea187ff7..8205cc5f06e 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -56,7 +56,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, std::unique_ptr devtools_window_; views::WebView* devtools_window_web_view_; - views::WebView* contents_web_view_; + views::View* contents_web_view_; views::WebView* devtools_web_view_; DevToolsContentsResizingStrategy strategy_; From 03e225063862778e873de8d6d446ad9ddc459ef5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 4 Aug 2016 16:39:52 +0900 Subject: [PATCH 0887/1195] Fix building under linux --- brightray/browser/views/inspectable_web_contents_view_views.cc | 2 +- 1 file changed, 1 insertion(+), 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 ccb76126d54..fb1f8493cd9 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -88,7 +88,7 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews( contents_web_view->SetWebContents(inspectable_web_contents_->GetWebContents()); contents_web_view_ = contents_web_view; } else { - contents_web_view_ = new views::Label(L"No content under offscreen mode"); + contents_web_view_ = new views::Label(base::ASCIIToUTF16("No content under offscreen mode")); } devtools_web_view_->SetVisible(false); From 900225bb03b6a43c309d8baf736470af1f18ec96 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Aug 2016 16:23:31 +0900 Subject: [PATCH 0888/1195] Put definetion of GetCookieableSchemes in .cc to match other methods --- brightray/browser/url_request_context_getter.cc | 4 ++++ brightray/browser/url_request_context_getter.h | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 46860d79198..ce12bacbc98 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -103,6 +103,10 @@ net::SSLConfigService* URLRequestContextGetter::Delegate::CreateSSLConfigService return new net::SSLConfigServiceDefaults; } +std::vector URLRequestContextGetter::Delegate::GetCookieableSchemes() { + return { "http", "https", "ws", "wss" }; +} + URLRequestContextGetter::URLRequestContextGetter( Delegate* delegate, DevToolsNetworkControllerHandle* handle, diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index dfe233f2831..ed2814c738b 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -47,9 +47,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { const base::FilePath& base_path); virtual std::unique_ptr CreateCertVerifier(); virtual net::SSLConfigService* CreateSSLConfigService(); - virtual std::vector GetCookieableSchemes() { - return std::vector(); - } + virtual std::vector GetCookieableSchemes(); }; URLRequestContextGetter( From 0060cd5b1beade1acbd78747b5b0aaf55ef6deb0 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 8 Aug 2016 20:17:22 +0900 Subject: [PATCH 0889/1195] Update libchromiumcontent to latest --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 0b5aa7b6ca4..086d162df09 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 0b5aa7b6ca450681c58087e14f72238aab5ab823 +Subproject commit 086d162df0962c12d2db5a9fbe488aa52ad9a327 From c3049688b88337cb349b4394e913bb5e9e88f9c7 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 11 Aug 2016 20:57:17 +0200 Subject: [PATCH 0890/1195] Disable -Wundefined-var-template. --- brightray/brightray.gypi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 038348fe6c5..634aec03812 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -325,6 +325,7 @@ '-Wno-unused-parameter', '-Wno-missing-field-initializers', '-Wno-deprecated-declarations', + '-Wno-undefined-var-template', # https://crbug.com/604888 '-Wno-unneeded-internal-declaration', '-Wno-inconsistent-missing-override', ], @@ -333,6 +334,7 @@ ['OS=="linux"', { 'cflags': [ '-Wno-inconsistent-missing-override', + '-Wno-undefined-var-template', # https://crbug.com/604888 ], }], ['OS=="win"', { From db6f2462c02d08ccdf33333e281fef31103e0086 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 1 Sep 2016 19:12:33 +0900 Subject: [PATCH 0891/1195] Update libchromiumcontent --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 086d162df09..c5cf295ef93 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 086d162df0962c12d2db5a9fbe488aa52ad9a327 +Subproject commit c5cf295ef93d4ee88bff0c4b06b28ff0969a890e From a56c6b1b79e6cc3c69b020bf159b12152f961d04 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sat, 3 Sep 2016 11:05:38 +0530 Subject: [PATCH 0892/1195] initialize crypto delegate in CookieStoreConfig --- brightray/brightray.gyp | 6 ++++++ brightray/browser/url_request_context_getter.cc | 2 ++ 2 files changed, 8 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index d089dbaceb8..049cd011b11 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -99,6 +99,8 @@ '<(libchromiumcontent_dir)/libyuv.a', '<(libchromiumcontent_dir)/libcdm_renderer.a', '<(libchromiumcontent_dir)/libsecurity_state.a', + '<(libchromiumcontent_dir)/libcookie_config.a', + '<(libchromiumcontent_dir)/libos_crypt.a', ], }, }, { @@ -154,6 +156,8 @@ '<(libchromiumcontent_dir)/libyuv.a', '<(libchromiumcontent_dir)/libcdm_renderer.a', '<(libchromiumcontent_dir)/libsecurity_state.a', + '<(libchromiumcontent_dir)/libcookie_config.a', + '<(libchromiumcontent_dir)/libos_crypt.a', ], }, }, { @@ -218,6 +222,8 @@ '<(libchromiumcontent_dir)/libyuv.lib', '<(libchromiumcontent_dir)/cdm_renderer.lib', '<(libchromiumcontent_dir)/security_state.lib', + '<(libchromiumcontent_dir)/cookie_config.lib', + '<(libchromiumcontent_dir)/os_crypt.lib', # Friends of pdf.lib: '<(libchromiumcontent_dir)/pdf.lib', '<(libchromiumcontent_dir)/ppapi_cpp_objects.lib', diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index ce12bacbc98..c790a1d5f69 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -17,6 +17,7 @@ #include "base/strings/string_util.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" +#include "components/cookie_config/cookie_store_util.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/cookie_store_factory.h" #include "content/public/common/content_switches.h" @@ -185,6 +186,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, nullptr, nullptr); cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes(); + cookie_config.crypto_delegate = cookie_config::GetCookieCryptoDelegate(); cookie_store = content::CreateCookieStore(cookie_config); } storage_->set_cookie_store(std::move(cookie_store)); From bff2d41e738319e97a0c985f4b56a7e5ffd36c31 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 5 Sep 2016 15:55:35 +0900 Subject: [PATCH 0893/1195] Update libchromiumcontent to Chrome 53 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index c5cf295ef93..60ec84b4b3e 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit c5cf295ef93d4ee88bff0c4b06b28ff0969a890e +Subproject commit 60ec84b4b3ee4862aa8c93c0e0e04871ee3ac177 From ab14221a85dae5192368defde7a18ab9e1ec6114 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 6 Sep 2016 17:22:52 +0900 Subject: [PATCH 0894/1195] Fix API changes of Chrome 53 --- brightray/browser/browser_context.cc | 22 ------------------- .../devtools_embedder_message_dispatcher.cc | 19 ++++++++-------- .../browser/inspectable_web_contents_impl.cc | 8 +++---- .../browser/inspectable_web_contents_impl.h | 2 +- .../net/devtools_network_transaction.cc | 6 ++--- .../net/devtools_network_transaction.h | 4 ++-- brightray/browser/network_delegate.cc | 16 ++++++++------ brightray/browser/network_delegate.h | 17 +++++++------- .../browser/url_request_context_getter.cc | 2 +- brightray/common/content_client.cc | 4 ++-- brightray/common/content_client.h | 3 +-- brightray/common/switches.cc | 3 +++ brightray/common/switches.h | 1 + 13 files changed, 46 insertions(+), 61 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index a1136577cd3..7694d6143a4 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -25,15 +25,6 @@ #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" #include "net/base/escape.h" -#include "net/ssl/client_cert_store.h" - -#if defined(USE_NSS_CERTS) -#include "net/ssl/client_cert_store_nss.h" -#elif defined(OS_WIN) -#include "net/ssl/client_cert_store_win.h" -#elif defined(OS_MACOSX) -#include "net/ssl/client_cert_store_mac.h" -#endif using content::BrowserThread; @@ -65,19 +56,6 @@ class BrowserContext::ResourceContext : public content::ResourceContext { return getter_->GetURLRequestContext(); } - std::unique_ptr CreateClientCertStore() override { - #if defined(USE_NSS_CERTS) - return std::unique_ptr(new net::ClientCertStoreNSS( - net::ClientCertStoreNSS::PasswordDelegateFactory())); - #elif defined(OS_WIN) - return std::unique_ptr(new net::ClientCertStoreWin()); - #elif defined(OS_MACOSX) - return std::unique_ptr(new net::ClientCertStoreMac()); - #elif defined(USE_OPENSSL) - return std::unique_ptr(); - #endif - } - URLRequestContextGetter* getter_; }; diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index 9df6a08b6de..ffba3268aec 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -13,21 +13,21 @@ namespace { using DispatchCallback = DevToolsEmbedderMessageDispatcher::DispatchCallback; -bool GetValue(const base::Value* value, std::string* result) { - return value->GetAsString(result); +bool GetValue(const base::Value& value, std::string* result) { + return value.GetAsString(result); } -bool GetValue(const base::Value* value, int* result) { - return value->GetAsInteger(result); +bool GetValue(const base::Value& value, int* result) { + return value.GetAsInteger(result); } -bool GetValue(const base::Value* value, bool* result) { - return value->GetAsBoolean(result); +bool GetValue(const base::Value& value, bool* result) { + return value.GetAsBoolean(result); } -bool GetValue(const base::Value* value, gfx::Rect* rect) { +bool GetValue(const base::Value& value, gfx::Rect* rect) { const base::DictionaryValue* dict; - if (!value->GetAsDictionary(&dict)) + if (!value.GetAsDictionary(&dict)) return false; int x = 0; int y = 0; @@ -69,7 +69,8 @@ template struct ParamTuple { bool Parse(const base::ListValue& list, const base::ListValue::const_iterator& it) { - return it != list.end() && GetValue(*it, &head) && tail.Parse(list, it + 1); + return it != list.end() && GetValue(**it, &head) && + tail.Parse(list, it + 1); } template diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 6ace243cac3..4295074888b 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -317,7 +317,7 @@ void InspectableWebContentsImpl::AttachTo(const scoped_refptrDetachClient(); + agent_host_->DetachClient(this); agent_host_ = nullptr; } @@ -530,7 +530,7 @@ void InspectableWebContentsImpl::DispatchProtocolMessageFromDevToolsFrontend( } if (agent_host_.get()) - agent_host_->DispatchProtocolMessage(message); + agent_host_->DispatchProtocolMessage(this, message); } void InspectableWebContentsImpl::RecordActionUMA(const std::string& name, int action) { @@ -687,11 +687,11 @@ content::ColorChooser* InspectableWebContentsImpl::OpenColorChooser( } void InspectableWebContentsImpl::RunFileChooser( - content::WebContents* source, + content::RenderFrameHost* render_frame_host, const content::FileChooserParams& params) { auto delegate = web_contents_->GetDelegate(); if (delegate) - delegate->RunFileChooser(source, params); + delegate->RunFileChooser(render_frame_host, params); } void InspectableWebContentsImpl::EnumerateDirectory( diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 249829aed83..d25f1be5f99 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -157,7 +157,7 @@ class InspectableWebContentsImpl : content::WebContents* source, SkColor color, const std::vector& suggestions) override; - void RunFileChooser(content::WebContents* source, + void RunFileChooser(content::RenderFrameHost* render_frame_host, const content::FileChooserParams& params) override; void EnumerateDirectory(content::WebContents* source, int request_id, diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc index e4c057b289d..0a62346392a 100644 --- a/brightray/browser/net/devtools_network_transaction.cc +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -284,9 +284,9 @@ void DevToolsNetworkTransaction::SetBeforeNetworkStartCallback( transaction_->SetBeforeNetworkStartCallback(callback); } -void DevToolsNetworkTransaction::SetBeforeProxyHeadersSentCallback( - const BeforeProxyHeadersSentCallback& callback) { - transaction_->SetBeforeProxyHeadersSentCallback(callback); +void DevToolsNetworkTransaction::SetBeforeHeadersSentCallback( + const BeforeHeadersSentCallback& callback) { + transaction_->SetBeforeHeadersSentCallback(callback); } int DevToolsNetworkTransaction::ResumeNetworkStart() { diff --git a/brightray/browser/net/devtools_network_transaction.h b/brightray/browser/net/devtools_network_transaction.h index 3de3a158767..3648ca71c74 100644 --- a/brightray/browser/net/devtools_network_transaction.h +++ b/brightray/browser/net/devtools_network_transaction.h @@ -62,8 +62,8 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { net::WebSocketHandshakeStreamBase::CreateHelper* create_helper) override; void SetBeforeNetworkStartCallback( const BeforeNetworkStartCallback& callback) override; - void SetBeforeProxyHeadersSentCallback( - const BeforeProxyHeadersSentCallback& callback) override; + void SetBeforeHeadersSentCallback( + const BeforeHeadersSentCallback& callback) override; int ResumeNetworkStart() override; void GetConnectionAttempts(net::ConnectionAttempts* out) const override; diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index 5e63a0c57c0..e0ef20bb57b 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -50,23 +50,25 @@ int NetworkDelegate::OnBeforeURLRequest( return net::OK; } -int NetworkDelegate::OnBeforeSendHeaders( +int NetworkDelegate::OnBeforeStartTransaction( net::URLRequest* request, const net::CompletionCallback& callback, net::HttpRequestHeaders* headers) { return net::OK; } -void NetworkDelegate::OnBeforeSendProxyHeaders(net::URLRequest* request, - const net::ProxyInfo& proxy_info, - net::HttpRequestHeaders* headers) { -} - -void NetworkDelegate::OnSendHeaders( +void NetworkDelegate::OnStartTransaction( net::URLRequest* request, const net::HttpRequestHeaders& headers) { } +void NetworkDelegate::OnBeforeSendHeaders( + net::URLRequest* request, + const net::ProxyInfo& proxy_info, + const net::ProxyRetryInfoMap& proxy_retry_info, + net::HttpRequestHeaders* headers) { +} + int NetworkDelegate::OnHeadersReceived( net::URLRequest* request, const net::CompletionCallback& callback, diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index bc2601886ac..752434222ac 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -22,14 +22,15 @@ class NetworkDelegate : public net::NetworkDelegate { int OnBeforeURLRequest(net::URLRequest* request, const net::CompletionCallback& callback, GURL* new_url) override; - int OnBeforeSendHeaders(net::URLRequest* request, - const net::CompletionCallback& callback, - net::HttpRequestHeaders* headers) override; - void OnBeforeSendProxyHeaders(net::URLRequest* request, - const net::ProxyInfo& proxy_info, - net::HttpRequestHeaders* headers) override; - void OnSendHeaders(net::URLRequest* request, - const net::HttpRequestHeaders& headers) override; + int OnBeforeStartTransaction(net::URLRequest* request, + const net::CompletionCallback& callback, + net::HttpRequestHeaders* headers) override; + void OnBeforeSendHeaders(net::URLRequest* request, + const net::ProxyInfo& proxy_info, + const net::ProxyRetryInfoMap& proxy_retry_info, + net::HttpRequestHeaders* headers) override; + void OnStartTransaction(net::URLRequest* request, + const net::HttpRequestHeaders& headers) override; int OnHeadersReceived( net::URLRequest* request, const net::CompletionCallback& callback, diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index ce12bacbc98..6caf52065c7 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -295,7 +295,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } // --ignore-certificate-errors - if (command_line.HasSwitch(::switches::kIgnoreCertificateErrors)) + if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) network_session_params.ignore_certificate_errors = true; // --host-rules diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc index b13fc73ef90..ebe066be613 100644 --- a/brightray/common/content_client.cc +++ b/brightray/common/content_client.cc @@ -54,8 +54,8 @@ gfx::Image& ContentClient::GetNativeImageNamed(int resource_id) const { resource_id); } -base::RefCountedStaticMemory* ContentClient::GetDataResourceBytes( - int resource_id) const { +base::RefCountedMemory* ContentClient::GetDataResourceBytes( + int resource_id) const { return ResourceBundle::GetSharedInstance().LoadDataResourceBytes(resource_id); } diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h index d54cf5df730..4d1d6238c95 100644 --- a/brightray/common/content_client.h +++ b/brightray/common/content_client.h @@ -24,8 +24,7 @@ class ContentClient : public content::ContentClient { base::StringPiece GetDataResource(int resource_id, ui::ScaleFactor) const override; gfx::Image& GetNativeImageNamed(int resource_id) const override; - base::RefCountedStaticMemory* GetDataResourceBytes( - int resource_id) const override; + base::RefCountedMemory* GetDataResourceBytes(int resource_id) const override; DISALLOW_COPY_AND_ASSIGN(ContentClient); }; diff --git a/brightray/common/switches.cc b/brightray/common/switches.cc index 7ca869ae98f..c46fe3bda97 100644 --- a/brightray/common/switches.cc +++ b/brightray/common/switches.cc @@ -49,6 +49,9 @@ const char kAuthServerWhitelist[] = "auth-server-whitelist"; // Whitelist containing servers for which Kerberos delegation is allowed. const char kAuthNegotiateDelegateWhitelist[] = "auth-negotiate-delegate-whitelist"; +// Ignores certificate-related errors. +const char kIgnoreCertificateErrors[] = "ignore-certificate-errors"; + } // namespace switches } // namespace brightray diff --git a/brightray/common/switches.h b/brightray/common/switches.h index 3af00813830..3aad50656b7 100644 --- a/brightray/common/switches.h +++ b/brightray/common/switches.h @@ -17,6 +17,7 @@ extern const char kProxyPacUrl[]; extern const char kDisableHttp2[]; extern const char kAuthServerWhitelist[]; extern const char kAuthNegotiateDelegateWhitelist[]; +extern const char kIgnoreCertificateErrors[]; } // namespace switches From 2bb774996b7c3530953d494f322eba5547f9a5b2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 6 Sep 2016 19:54:49 +0900 Subject: [PATCH 0895/1195] Link with d3d11.lib --- brightray/brightray.gyp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index d089dbaceb8..764d8d5dba7 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -199,10 +199,11 @@ ['OS=="win"', { 'conditions': [ ['libchromiumcontent_component', { - # sandbox, base_static, devtools_discovery, devtools_http_handler, - # http_server are always linked statically. 'link_settings': { 'libraries': [ + # Needed by desktop_capture.lib: + '-ld3d11.lib', + # Following libs are always linked statically. '<(libchromiumcontent_dir)/base_static.lib', '<(libchromiumcontent_dir)/sandbox.lib', '<(libchromiumcontent_dir)/sandbox_helper_win.lib', From 676a389ecdae5c004a5da8b142ae05194da25cf9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 7 Sep 2016 17:54:21 +0900 Subject: [PATCH 0896/1195] Add new network parameters needed by chrome53 --- brightray/browser/url_request_context_getter.cc | 8 ++++++++ brightray/browser/url_request_context_getter.h | 2 ++ brightray/vendor/libchromiumcontent | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 6caf52065c7..601006e5c4e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -22,6 +22,8 @@ #include "content/public/common/content_switches.h" #include "net/base/host_mapping_rules.h" #include "net/cert/cert_verifier.h" +#include "net/cert/ct_policy_enforcer.h" +#include "net/cert/multi_log_ct_verifier.h" #include "net/cookies/cookie_monster.h" #include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_filter.h" @@ -274,6 +276,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { new net::HttpServerPropertiesImpl); storage_->set_http_server_properties(std::move(server_properties)); + cert_transparency_verifier_.reset(new net::MultiLogCTVerifier()); + ct_policy_enforcer_.reset(new net::CTPolicyEnforcer()); + net::HttpNetworkSession::Params network_session_params; network_session_params.cert_verifier = url_request_context_->cert_verifier(); network_session_params.proxy_service = url_request_context_->proxy_service(); @@ -287,6 +292,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.http_auth_handler_factory = url_request_context_->http_auth_handler_factory(); network_session_params.net_log = url_request_context_->net_log(); + network_session_params.cert_transparency_verifier = + cert_transparency_verifier_.get(); + network_session_params.ct_policy_enforcer = ct_policy_enforcer_.get(); // --disable-http2 if (command_line.HasSwitch(switches::kDisableHttp2)) { diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index ed2814c738b..31427d0ccdb 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -88,6 +88,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { std::unique_ptr host_mapping_rules_; std::unique_ptr http_auth_preferences_; std::unique_ptr http_network_session_; + std::unique_ptr cert_transparency_verifier_; + std::unique_ptr ct_policy_enforcer_; content::ProtocolHandlerMap protocol_handlers_; content::URLRequestInterceptorScopedVector protocol_interceptors_; diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 60ec84b4b3e..346dfe40a96 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 60ec84b4b3ee4862aa8c93c0e0e04871ee3ac177 +Subproject commit 346dfe40a9658cc40924d29a1deb1d9669509076 From 4203b2a4ce8af95a710ec49a50b191c55ffc87f6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 8 Sep 2016 15:24:27 +0900 Subject: [PATCH 0897/1195] Target OS X 10.9 We do not support 10.8. --- brightray/brightray.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 634aec03812..a434145d611 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -32,7 +32,7 @@ 'GCC_ENABLE_CPP_RTTI': 'NO', 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES', 'CLANG_CXX_LANGUAGE_STANDARD': 'c++11', - 'MACOSX_DEPLOYMENT_TARGET': '10.8', + 'MACOSX_DEPLOYMENT_TARGET': '10.9', 'RUN_CLANG_STATIC_ANALYZER': 'YES', 'USE_HEADER_MAP': 'NO', }, From 296e06be1cfdda13d460623c92dbed48b68f6f7e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 15 Sep 2016 14:27:07 +0900 Subject: [PATCH 0898/1195] Update to Chrome 53.0.2785.113 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 346dfe40a96..63b939087a4 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 346dfe40a9658cc40924d29a1deb1d9669509076 +Subproject commit 63b939087a4a8170a82c8caf0f6e9cfcf234472b From d435df77f888be12f48a7a5973aec3cf652c80c8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 19 Sep 2016 16:30:16 +0900 Subject: [PATCH 0899/1195] Revert "initialize crypto delegate in CookieStoreConfig" This reverts commit ad1d1dce72c6fcb6c15a18dac04ff382d9bf4db0. --- brightray/brightray.gyp | 6 ------ brightray/browser/url_request_context_getter.cc | 2 -- 2 files changed, 8 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 6931abd449b..764d8d5dba7 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -99,8 +99,6 @@ '<(libchromiumcontent_dir)/libyuv.a', '<(libchromiumcontent_dir)/libcdm_renderer.a', '<(libchromiumcontent_dir)/libsecurity_state.a', - '<(libchromiumcontent_dir)/libcookie_config.a', - '<(libchromiumcontent_dir)/libos_crypt.a', ], }, }, { @@ -156,8 +154,6 @@ '<(libchromiumcontent_dir)/libyuv.a', '<(libchromiumcontent_dir)/libcdm_renderer.a', '<(libchromiumcontent_dir)/libsecurity_state.a', - '<(libchromiumcontent_dir)/libcookie_config.a', - '<(libchromiumcontent_dir)/libos_crypt.a', ], }, }, { @@ -223,8 +219,6 @@ '<(libchromiumcontent_dir)/libyuv.lib', '<(libchromiumcontent_dir)/cdm_renderer.lib', '<(libchromiumcontent_dir)/security_state.lib', - '<(libchromiumcontent_dir)/cookie_config.lib', - '<(libchromiumcontent_dir)/os_crypt.lib', # Friends of pdf.lib: '<(libchromiumcontent_dir)/pdf.lib', '<(libchromiumcontent_dir)/ppapi_cpp_objects.lib', diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index f857759b9d4..601006e5c4e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -17,7 +17,6 @@ #include "base/strings/string_util.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" -#include "components/cookie_config/cookie_store_util.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/cookie_store_factory.h" #include "content/public/common/content_switches.h" @@ -188,7 +187,6 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, nullptr, nullptr); cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes(); - cookie_config.crypto_delegate = cookie_config::GetCookieCryptoDelegate(); cookie_store = content::CreateCookieStore(cookie_config); } storage_->set_cookie_store(std::move(cookie_store)); From 39a69467ed92d5c0ab5bb06714306e2c53988d09 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 21 Sep 2016 09:48:17 -0700 Subject: [PATCH 0900/1195] Add verifiers for known logs --- brightray/browser/url_request_context_getter.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 601006e5c4e..cbb9b1a10e7 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -22,6 +22,8 @@ #include "content/public/common/content_switches.h" #include "net/base/host_mapping_rules.h" #include "net/cert/cert_verifier.h" +#include "net/cert/ct_known_logs.h" +#include "net/cert/ct_log_verifier.h" #include "net/cert/ct_policy_enforcer.h" #include "net/cert/multi_log_ct_verifier.h" #include "net/cookies/cookie_monster.h" @@ -276,7 +278,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { new net::HttpServerPropertiesImpl); storage_->set_http_server_properties(std::move(server_properties)); - cert_transparency_verifier_.reset(new net::MultiLogCTVerifier()); + auto multi_log_ct_verifier = new net::MultiLogCTVerifier(); + multi_log_ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); + cert_transparency_verifier_.reset(multi_log_ct_verifier); ct_policy_enforcer_.reset(new net::CTPolicyEnforcer()); net::HttpNetworkSession::Params network_session_params; From bffd87c118c97447d066c2d469bce6de14bf5e00 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 21 Sep 2016 10:16:05 -0700 Subject: [PATCH 0901/1195] Call AddLogs through unique pointer --- brightray/browser/url_request_context_getter.cc | 7 +++---- brightray/browser/url_request_context_getter.h | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index cbb9b1a10e7..45daf0e4aeb 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -25,7 +25,6 @@ #include "net/cert/ct_known_logs.h" #include "net/cert/ct_log_verifier.h" #include "net/cert/ct_policy_enforcer.h" -#include "net/cert/multi_log_ct_verifier.h" #include "net/cookies/cookie_monster.h" #include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_filter.h" @@ -278,9 +277,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { new net::HttpServerPropertiesImpl); storage_->set_http_server_properties(std::move(server_properties)); - auto multi_log_ct_verifier = new net::MultiLogCTVerifier(); - multi_log_ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); - cert_transparency_verifier_.reset(multi_log_ct_verifier); + cert_transparency_verifier_.reset(new net::MultiLogCTVerifier()); + cert_transparency_verifier_->AddLogs( + net::ct::CreateLogVerifiersForKnownLogs()); ct_policy_enforcer_.reset(new net::CTPolicyEnforcer()); net::HttpNetworkSession::Params network_session_params; diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 31427d0ccdb..37c9abb0674 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -8,6 +8,7 @@ #include "base/files/file_path.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" +#include "net/cert/multi_log_ct_verifier.h" #include "net/http/http_cache.h" #include "net/http/url_security_manager.h" #include "net/url_request/url_request_context_getter.h" @@ -88,7 +89,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { std::unique_ptr host_mapping_rules_; std::unique_ptr http_auth_preferences_; std::unique_ptr http_network_session_; - std::unique_ptr cert_transparency_verifier_; + std::unique_ptr cert_transparency_verifier_; std::unique_ptr ct_policy_enforcer_; content::ProtocolHandlerMap protocol_handlers_; content::URLRequestInterceptorScopedVector protocol_interceptors_; From 14c4b1eabb38aed481711d2b399f8f77675a9011 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 28 Sep 2016 11:14:18 -0700 Subject: [PATCH 0902/1195] Set certificate transparency objects on URLRequestContextStorage --- brightray/browser/url_request_context_getter.cc | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 45daf0e4aeb..9349271b8aa 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -277,10 +277,11 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { new net::HttpServerPropertiesImpl); storage_->set_http_server_properties(std::move(server_properties)); - cert_transparency_verifier_.reset(new net::MultiLogCTVerifier()); - cert_transparency_verifier_->AddLogs( - net::ct::CreateLogVerifiersForKnownLogs()); - ct_policy_enforcer_.reset(new net::CTPolicyEnforcer()); + std::unique_ptr ct_verifier = + base::MakeUnique(); + ct_verifier->AddLogs(net::ct::CreateLogVerifiersForKnownLogs()); + storage_->set_cert_transparency_verifier(std::move(ct_verifier)); + storage_->set_ct_policy_enforcer(base::MakeUnique()); net::HttpNetworkSession::Params network_session_params; network_session_params.cert_verifier = url_request_context_->cert_verifier(); @@ -296,8 +297,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { url_request_context_->http_auth_handler_factory(); network_session_params.net_log = url_request_context_->net_log(); network_session_params.cert_transparency_verifier = - cert_transparency_verifier_.get(); - network_session_params.ct_policy_enforcer = ct_policy_enforcer_.get(); + url_request_context_->cert_transparency_verifier(); + network_session_params.ct_policy_enforcer = + url_request_context_->ct_policy_enforcer(); // --disable-http2 if (command_line.HasSwitch(switches::kDisableHttp2)) { From 096d3e61fafe16aa5e84afadc4846ec6f12e750d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 28 Sep 2016 11:17:42 -0700 Subject: [PATCH 0903/1195] Remove unused instance variables --- brightray/browser/url_request_context_getter.cc | 1 + brightray/browser/url_request_context_getter.h | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 9349271b8aa..e375061a83c 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -25,6 +25,7 @@ #include "net/cert/ct_known_logs.h" #include "net/cert/ct_log_verifier.h" #include "net/cert/ct_policy_enforcer.h" +#include "net/cert/multi_log_ct_verifier.h" #include "net/cookies/cookie_monster.h" #include "net/dns/mapped_host_resolver.h" #include "net/http/http_auth_filter.h" diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 37c9abb0674..ed2814c738b 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -8,7 +8,6 @@ #include "base/files/file_path.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" -#include "net/cert/multi_log_ct_verifier.h" #include "net/http/http_cache.h" #include "net/http/url_security_manager.h" #include "net/url_request/url_request_context_getter.h" @@ -89,8 +88,6 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { std::unique_ptr host_mapping_rules_; std::unique_ptr http_auth_preferences_; std::unique_ptr http_network_session_; - std::unique_ptr cert_transparency_verifier_; - std::unique_ptr ct_policy_enforcer_; content::ProtocolHandlerMap protocol_handlers_; content::URLRequestInterceptorScopedVector protocol_interceptors_; From c46200761f6bbee9418b19d5139e62c792fac552 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 28 Sep 2016 16:00:23 -0700 Subject: [PATCH 0904/1195] Use net::URLRequestContextBuilder::SetHttpNetworkSessionComponents helper --- .../browser/url_request_context_getter.cc | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index e375061a83c..a5110a8f713 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -46,6 +46,7 @@ #include "net/url_request/file_protocol_handler.h" #include "net/url_request/static_http_user_agent_settings.h" #include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_context_builder.h" #include "net/url_request/url_request_context_storage.h" #include "net/url_request/url_request_intercepting_job_factory.h" #include "net/url_request/url_request_job_factory_impl.h" @@ -285,22 +286,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_ct_policy_enforcer(base::MakeUnique()); net::HttpNetworkSession::Params network_session_params; - network_session_params.cert_verifier = url_request_context_->cert_verifier(); - network_session_params.proxy_service = url_request_context_->proxy_service(); - network_session_params.ssl_config_service = url_request_context_->ssl_config_service(); - network_session_params.http_server_properties = url_request_context_->http_server_properties(); + net::URLRequestContextBuilder::SetHttpNetworkSessionComponents( + url_request_context_.get(), &network_session_params); network_session_params.ignore_certificate_errors = false; - network_session_params.transport_security_state = - url_request_context_->transport_security_state(); - network_session_params.channel_id_service = - url_request_context_->channel_id_service(); - network_session_params.http_auth_handler_factory = - url_request_context_->http_auth_handler_factory(); - network_session_params.net_log = url_request_context_->net_log(); - network_session_params.cert_transparency_verifier = - url_request_context_->cert_transparency_verifier(); - network_session_params.ct_policy_enforcer = - url_request_context_->ct_policy_enforcer(); // --disable-http2 if (command_line.HasSwitch(switches::kDisableHttp2)) { From cbe92b5fb526689ac57c729ba9d4956531c09de4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 21 Sep 2016 09:09:43 -0700 Subject: [PATCH 0905/1195] Support configuring a cookie delegate --- .../browser/url_request_context_getter.cc | 21 ++++++++----------- .../browser/url_request_context_getter.h | 6 +++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index a5110a8f713..535beb590a0 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -180,18 +180,15 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_.reset(new net::URLRequestContextStorage(url_request_context_.get())); std::unique_ptr cookie_store = nullptr; - if (in_memory_) { - auto cookie_config = content::CookieStoreConfig(); - cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes(); - cookie_store = content::CreateCookieStore(cookie_config); - } else { - auto cookie_config = content::CookieStoreConfig( - base_path_.Append(FILE_PATH_LITERAL("Cookies")), - content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, - nullptr, nullptr); - cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes(); - cookie_store = content::CreateCookieStore(cookie_config); - } + auto cookie_path = in_memory_ ? + base::FilePath() : base_path_.Append(FILE_PATH_LITERAL("Cookies")); + auto cookie_config = content::CookieStoreConfig( + cookie_path, + content::CookieStoreConfig::EPHEMERAL_SESSION_COOKIES, + nullptr, + delegate_->CreateCookieDelegate()); + cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes(); + 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(nullptr), diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index ed2814c738b..1b10c2d75a1 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -8,6 +8,7 @@ #include "base/files/file_path.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/content_browser_client.h" +#include "net/cookies/cookie_monster.h" #include "net/http/http_cache.h" #include "net/http/url_security_manager.h" #include "net/url_request/url_request_context_getter.h" @@ -38,7 +39,10 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { Delegate() {} virtual ~Delegate() {} - virtual net::NetworkDelegate* CreateNetworkDelegate() { return NULL; } + virtual net::NetworkDelegate* CreateNetworkDelegate() { return nullptr; } + virtual net::CookieMonsterDelegate* CreateCookieDelegate() { + return nullptr; + } virtual std::string GetUserAgent(); virtual std::unique_ptr CreateURLRequestJobFactory( From 67eff02a6543652e07b8ebfea5b7f92d0be540eb Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 28 Sep 2016 16:49:26 -0700 Subject: [PATCH 0906/1195] :art: --- brightray/browser/url_request_context_getter.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 535beb590a0..57ca1f1b405 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -179,7 +179,6 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_.reset(new net::URLRequestContextStorage(url_request_context_.get())); - std::unique_ptr cookie_store = nullptr; auto cookie_path = in_memory_ ? base::FilePath() : base_path_.Append(FILE_PATH_LITERAL("Cookies")); auto cookie_config = content::CookieStoreConfig( @@ -188,7 +187,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { nullptr, delegate_->CreateCookieDelegate()); cookie_config.cookieable_schemes = delegate_->GetCookieableSchemes(); - cookie_store = content::CreateCookieStore(cookie_config); + std::unique_ptr 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(nullptr), From 4172bbd683a04575c607a90eebca8163e85bdd02 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 3 Oct 2016 15:46:09 -0700 Subject: [PATCH 0907/1195] Link to electron instead of brightray_example --- brightray/README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/brightray/README.md b/brightray/README.md index eba0f515c9a..655fca98fe6 100644 --- a/brightray/README.md +++ b/brightray/README.md @@ -6,8 +6,8 @@ use in applications. ## Using it in your app -See [brightray_example](https://github.com/electron/brightray_example) for a -sample application written using Brightray. +See [electron](https://github.com/electron/electron) for example of an +application written using Brightray. ## Development @@ -33,9 +33,7 @@ You must previously have built and uploaded libchromiumcontent using its $ script/build Building Brightray on its own isn’t all that interesting, since it’s just a -static library. Building it into an application (like -[brightray_example](https://github.com/electron/brightray_example)) is the only -way to test it. +static library. Building it into an application is the only way to test it. ## License From cc8b07985d2fe4296fffe280b89ee2f67fe650d0 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Wed, 5 Oct 2016 18:32:24 +0200 Subject: [PATCH 0908/1195] Add /LARGEADDRESSAWARE to linker options (Windows) --- brightray/brightray.gypi | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index a434145d611..064ae1a2df0 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -64,6 +64,7 @@ 'GenerateDebugInformation': 'true', 'MapFileName': '$(OutDir)\\$(TargetName).map', 'ImportLibrary': '$(OutDir)\\lib\\$(TargetName).lib', + 'LargeAddressAware': '2', 'AdditionalOptions': [ # ATL 8.0 included in WDK 7.1 makes the linker to generate # following From 968bc5c9a2286f455fda349b522079389e298278 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 6 Oct 2016 17:29:32 +0530 Subject: [PATCH 0909/1195] set dock state using devtools dockController --- .../browser/inspectable_web_contents_impl.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 4295074888b..6506e4490db 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -124,15 +124,11 @@ GURL GetRemoteBaseURL() { content::GetWebKitRevision().c_str())); } -GURL GetDevToolsURL( - bool can_dock, - const std::string& dock_state) { +GURL GetDevToolsURL(bool can_dock) { auto url_string = base::StringPrintf(kChromeUIDevToolsURL, GetRemoteBaseURL().spec().c_str(), can_dock ? "true" : ""); - if (!dock_state.empty()) - url_string += "&settings={\"currentDockState\":\"\\\"" + dock_state + "\\\"\"}&"; return GURL(url_string); } @@ -287,7 +283,7 @@ void InspectableWebContentsImpl::ShowDevTools() { agent_host_->AttachClient(this); devtools_web_contents_->GetController().LoadURL( - GetDevToolsURL(can_dock_, dock_state_), + GetDevToolsURL(can_dock_), content::Referrer(), ui::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); @@ -381,8 +377,13 @@ void InspectableWebContentsImpl::LoadCompleted() { view_->ShowDevTools(); // If the devtools can dock, "SetIsDocked" will be called by devtools itself. - if (!can_dock_) + if (!can_dock_) { SetIsDocked(DispatchCallback(), false); + } else { + base::string16 javascript = base::UTF8ToUTF16( + "WebInspector.dockController.setDockSide(\"" + dock_state_ + "\");"); + devtools_web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); + } if (view_->GetDelegate()) view_->GetDelegate()->DevToolsOpened(); From f652760c7a1d4053bb81fd29f40975dacd5b192b Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 11 Oct 2016 13:47:06 +0530 Subject: [PATCH 0910/1195] use dock state from peferences when not set by embedder --- brightray/browser/inspectable_web_contents_impl.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 6506e4490db..4affb2f786d 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -380,6 +380,13 @@ void InspectableWebContentsImpl::LoadCompleted() { if (!can_dock_) { SetIsDocked(DispatchCallback(), false); } else { + if (dock_state_.empty()) { + const base::DictionaryValue* prefs = pref_service_->GetDictionary( + kDevToolsPreferences); + std::string current_dock_state; + prefs->GetString("currentDockState", ¤t_dock_state); + base::RemoveChars(current_dock_state, "\"", &dock_state_); + } base::string16 javascript = base::UTF8ToUTF16( "WebInspector.dockController.setDockSide(\"" + dock_state_ + "\");"); devtools_web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); From aa7255bad5e77c21faa33e06f6013080e5ef82a3 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 17 Oct 2016 16:06:37 +0530 Subject: [PATCH 0911/1195] allow embedder to provide RequireCTDelegate --- brightray/browser/url_request_context_getter.cc | 7 +++++-- brightray/browser/url_request_context_getter.h | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 57ca1f1b405..ad2838a8efe 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -267,9 +267,12 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { net::HttpAuthHandlerRegistryFactory::Create( http_auth_preferences_.get(), host_resolver.get()); + std::unique_ptr transport_security_state = + base::WrapUnique(new net::TransportSecurityState); + transport_security_state->SetRequireCTDelegate( + delegate_->GetRequireCTDelegate()); + storage_->set_transport_security_state(std::move(transport_security_state)); storage_->set_cert_verifier(delegate_->CreateCertVerifier()); - storage_->set_transport_security_state( - base::WrapUnique(new net::TransportSecurityState)); storage_->set_ssl_config_service(delegate_->CreateSSLConfigService()); storage_->set_http_auth_handler_factory(std::move(auth_handler_factory)); std::unique_ptr server_properties( diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 1b10c2d75a1..88fdc392b90 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -10,6 +10,7 @@ #include "content/public/browser/content_browser_client.h" #include "net/cookies/cookie_monster.h" #include "net/http/http_cache.h" +#include "net/http/transport_security_state.h" #include "net/http/url_security_manager.h" #include "net/url_request/url_request_context_getter.h" @@ -52,6 +53,10 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { virtual std::unique_ptr CreateCertVerifier(); virtual net::SSLConfigService* CreateSSLConfigService(); virtual std::vector GetCookieableSchemes(); + virtual net::TransportSecurityState::RequireCTDelegate* + GetRequireCTDelegate() { + return nullptr; + } }; URLRequestContextGetter( From ee4442f964a78e2425bb1b680c9bed0b7bd0f4ee Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 25 Oct 2016 19:02:06 +0530 Subject: [PATCH 0912/1195] set notification close callback before requesting user permission --- .../browser/linux/libnotify_notification.cc | 6 ++- brightray/browser/mac/cocoa_notification.mm | 5 +- brightray/browser/notification.h | 6 +-- .../browser/platform_notification_service.cc | 51 +++++++++---------- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index a3f273c1c02..6946abbc93f 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -82,8 +82,10 @@ LibnotifyNotification::LibnotifyNotification(NotificationDelegate* delegate, } LibnotifyNotification::~LibnotifyNotification() { - g_signal_handlers_disconnect_by_data(notification_, this); - g_object_unref(notification_); + if (notification_) { + g_signal_handlers_disconnect_by_data(notification_, this); + g_object_unref(notification_); + } } void LibnotifyNotification::Show(const base::string16& title, diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index e7ed61dbf36..fe21000e376 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -24,8 +24,9 @@ CocoaNotification::CocoaNotification(NotificationDelegate* delegate, } CocoaNotification::~CocoaNotification() { - [NSUserNotificationCenter.defaultUserNotificationCenter - removeDeliveredNotification:notification_]; + if (notification_) + [NSUserNotificationCenter.defaultUserNotificationCenter + removeDeliveredNotification:notification_]; } void CocoaNotification::Show(const base::string16& title, diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index afacd50c193..87096bbe263 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -34,6 +34,9 @@ class Notification { void NotificationDismissed(); void NotificationFailed(); + // delete this. + void Destroy(); + base::WeakPtr GetWeakPtr() { return weak_factory_.GetWeakPtr(); } @@ -46,9 +49,6 @@ class Notification { NotificationPresenter* presenter); virtual ~Notification(); - // delete this. - void Destroy(); - private: friend class NotificationPresenter; diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 77ca31a5bb5..5fabac82c34 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -21,28 +21,17 @@ void RemoveNotification(base::WeakPtr notification) { notification->Dismiss(); } -void OnWebNotificationAllowed( - brightray::BrowserClient* browser_client, - const SkBitmap& icon, - const content::PlatformNotificationData& data, - std::unique_ptr delegate, - base::Closure* cancel_callback, - bool audio_muted, - bool allowed) { - if (!allowed) +void OnWebNotificationAllowed(base::WeakPtr notification, + const SkBitmap& icon, + const content::PlatformNotificationData& data, + bool audio_muted, + bool allowed) { + if (!allowed) { + notification->Destroy(); return; - auto presenter = browser_client->GetNotificationPresenter(); - if (!presenter) - return; - std::unique_ptr adapter( - new NotificationDelegateAdapter(std::move(delegate))); - auto notification = presenter->CreateNotification(adapter.get()); - if (notification) { - ignore_result(adapter.release()); // it will release itself automatically. - notification->Show(data.title, data.body, data.tag, data.icon, icon, - audio_muted ? true : data.silent); - *cancel_callback = base::Bind(&RemoveNotification, notification); } + notification->Show(data.title, data.body, data.tag, data.icon, icon, + audio_muted ? true : data.silent); } } // namespace @@ -77,14 +66,20 @@ void PlatformNotificationService::DisplayNotification( const content::NotificationResources& notification_resources, std::unique_ptr delegate, base::Closure* cancel_callback) { - browser_client_->WebNotificationAllowed( - render_process_id_, - base::Bind(&OnWebNotificationAllowed, - browser_client_, - notification_resources.notification_icon, - notification_data, - base::Passed(&delegate), - cancel_callback)); + auto presenter = browser_client_->GetNotificationPresenter(); + if (!presenter) + return; + std::unique_ptr adapter( + new NotificationDelegateAdapter(std::move(delegate))); + auto notification = presenter->CreateNotification(adapter.get()); + if (notification) { + ignore_result(adapter.release()); // it will release itself automatically. + *cancel_callback = base::Bind(&RemoveNotification, notification); + browser_client_->WebNotificationAllowed( + render_process_id_, base::Bind(&OnWebNotificationAllowed, notification, + notification_resources.notification_icon, + notification_data)); + } } void PlatformNotificationService::DisplayPersistentNotification( From 0a5f7171d4bd6aae36d6690b1046a4f16bf5f254 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 28 Oct 2016 10:54:55 -0700 Subject: [PATCH 0913/1195] Add more guards around null notification --- brightray/browser/mac/cocoa_notification.mm | 5 +++-- brightray/browser/platform_notification_service.cc | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index fe21000e376..4e9ee3238b8 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -57,8 +57,9 @@ void CocoaNotification::Show(const base::string16& title, } void CocoaNotification::Dismiss() { - [NSUserNotificationCenter.defaultUserNotificationCenter - removeDeliveredNotification:notification_]; + if (notification_) + [NSUserNotificationCenter.defaultUserNotificationCenter + removeDeliveredNotification:notification_]; NotificationDismissed(); } diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 5fabac82c34..c9f2e5a1f91 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -26,12 +26,13 @@ void OnWebNotificationAllowed(base::WeakPtr notification, const content::PlatformNotificationData& data, bool audio_muted, bool allowed) { - if (!allowed) { - notification->Destroy(); + if (!notification) return; - } - notification->Show(data.title, data.body, data.tag, data.icon, icon, - audio_muted ? true : data.silent); + if (allowed) + notification->Show(data.title, data.body, data.tag, data.icon, icon, + audio_muted ? true : data.silent); + else + notification->Destroy(); } } // namespace From 7cb8c1fdb969226f410b54ccc9e1194289f36116 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 28 Oct 2016 11:24:47 -0700 Subject: [PATCH 0914/1195] Add dismiss notification guard on Linux --- brightray/browser/linux/libnotify_notification.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index 6946abbc93f..0fd71faaf18 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -146,6 +146,11 @@ void LibnotifyNotification::Show(const base::string16& title, } void LibnotifyNotification::Dismiss() { + if (!notification_) { + Destroy(); + return; + } + GError* error = nullptr; libnotify_loader_.notify_notification_close(notification_, &error); if (error) { From 66b5f0c80c8b1089d507d77a4138d8ee2f296836 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Nov 2016 14:33:54 -0800 Subject: [PATCH 0915/1195] Upgrade to Chrome 53.0.2785.143 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 63b939087a4..76bb29da18c 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 63b939087a4a8170a82c8caf0f6e9cfcf234472b +Subproject commit 76bb29da18cbeec0051e0690bc1b95e78034a422 From cef773a439be9c6083d33ada8baf26734db7dd83 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 28 Nov 2016 15:23:03 -0800 Subject: [PATCH 0916/1195] Always link dom_keycode_converter This is needed for electron/electron#7586. --- brightray/brightray.gyp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 764d8d5dba7..c5b02fca9df 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -92,6 +92,7 @@ '<(libchromiumcontent_dir)/libhttp_server.a', '<(libchromiumcontent_dir)/libdesktop_capture.a', '<(libchromiumcontent_dir)/libdesktop_capture_differ_sse2.a', + '<(libchromiumcontent_dir)/libdom_keycode_converter.a', '<(libchromiumcontent_dir)/libsystem_wrappers.a', '<(libchromiumcontent_dir)/librtc_base.a', '<(libchromiumcontent_dir)/librtc_base_approved.a', @@ -147,6 +148,7 @@ '<(libchromiumcontent_dir)/libhttp_server.a', '<(libchromiumcontent_dir)/libdesktop_capture.a', '<(libchromiumcontent_dir)/libdesktop_capture_differ_sse2.a', + '<(libchromiumcontent_dir)/libdom_keycode_converter.a', '<(libchromiumcontent_dir)/librtc_base.a', '<(libchromiumcontent_dir)/librtc_base_approved.a', '<(libchromiumcontent_dir)/libsystem_wrappers.a', @@ -212,6 +214,7 @@ '<(libchromiumcontent_dir)/http_server.lib', '<(libchromiumcontent_dir)/desktop_capture.lib', '<(libchromiumcontent_dir)/desktop_capture_differ_sse2.lib', + '<(libchromiumcontent_dir)/dom_keycode_converter.lib', '<(libchromiumcontent_dir)/rtc_base.lib', '<(libchromiumcontent_dir)/rtc_base_approved.lib', '<(libchromiumcontent_dir)/system_wrappers.lib', From dbf4e52e05e2b93b17b8126a263e7ef6ec787919 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sat, 3 Dec 2016 16:42:48 +0530 Subject: [PATCH 0917/1195] persist media device id salt across sessions --- brightray/browser/browser_context.cc | 17 ++++++ brightray/browser/browser_context.h | 3 ++ .../browser/media/media_device_id_salt.cc | 53 +++++++++++++++++++ .../browser/media/media_device_id_salt.h | 40 ++++++++++++++ .../browser/url_request_context_getter.h | 5 ++ brightray/filenames.gypi | 2 + 6 files changed, 120 insertions(+) create mode 100644 brightray/browser/media/media_device_id_salt.cc create mode 100644 brightray/browser/media/media_device_id_salt.h diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 7694d6143a4..bbb2a4e7f9b 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -4,6 +4,7 @@ #include "browser/browser_context.h" +#include "browser/media/media_device_id_salt.h" #include "browser/brightray_paths.h" #include "browser/browser_client.h" #include "browser/inspectable_web_contents_impl.h" @@ -56,6 +57,13 @@ class BrowserContext::ResourceContext : public content::ResourceContext { return getter_->GetURLRequestContext(); } + std::string GetMediaDeviceIDSalt() override { + auto media_device_id_salt_ = getter_->GetMediaDeviceIDSalt(); + if (media_device_id_salt_) + return media_device_id_salt_->GetSalt(); + return content::ResourceContext::GetMediaDeviceIDSalt(); + } + URLRequestContextGetter* getter_; }; @@ -114,6 +122,7 @@ void BrowserContext::InitPrefs() { void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { InspectableWebContentsImpl::RegisterPrefs(registry); + MediaDeviceIDSalt::RegisterPrefs(registry); } URLRequestContextGetter* BrowserContext::GetRequestContext() { @@ -143,6 +152,14 @@ net::NetworkDelegate* BrowserContext::CreateNetworkDelegate() { return new NetworkDelegate; } +MediaDeviceIDSalt* BrowserContext::GetMediaDeviceIDSalt() { + if (IsOffTheRecord()) + return nullptr; + if (!media_device_id_salt_.get()) + media_device_id_salt_.reset(new MediaDeviceIDSalt(prefs_.get())); + return media_device_id_salt_.get(); +} + base::FilePath BrowserContext::GetPath() const { return path_; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 868c253aaed..498fe9940ad 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -24,6 +24,7 @@ class SpecialStoragePolicy; namespace brightray { +class MediaDeviceIDSalt; class PermissionManager; class BrowserContext : public base::RefCounted, @@ -87,6 +88,7 @@ class BrowserContext : public base::RefCounted, // URLRequestContextGetter::Delegate: net::NetworkDelegate* CreateNetworkDelegate() override; + MediaDeviceIDSalt* GetMediaDeviceIDSalt() override; base::FilePath GetPath() const override; @@ -128,6 +130,7 @@ class BrowserContext : public base::RefCounted, scoped_refptr storage_policy_; std::unique_ptr prefs_; std::unique_ptr permission_manager_; + std::unique_ptr media_device_id_salt_; base::WeakPtrFactory weak_factory_; diff --git a/brightray/browser/media/media_device_id_salt.cc b/brightray/browser/media/media_device_id_salt.cc new file mode 100644 index 00000000000..612449b25de --- /dev/null +++ b/brightray/browser/media/media_device_id_salt.cc @@ -0,0 +1,53 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +#include "browser/media/media_device_id_salt.h" + +#include "components/prefs/pref_registry_simple.h" +#include "components/prefs/pref_service.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/browser/resource_context.h" + +using content::BrowserThread; + +namespace brightray { + +namespace { + +const char kMediaDeviceIdSalt[] = "brightray.media.device_id_salt"; + +} // namespace + +MediaDeviceIDSalt::MediaDeviceIDSalt(PrefService* pref_service) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + + media_device_id_salt_.Init(kMediaDeviceIdSalt, pref_service); + if (media_device_id_salt_.GetValue().empty()) { + media_device_id_salt_.SetValue( + content::ResourceContext::CreateRandomMediaDeviceIDSalt()); + } +} + +MediaDeviceIDSalt::~MediaDeviceIDSalt() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + media_device_id_salt_.Destroy(); +} + +std::string MediaDeviceIDSalt::GetSalt() { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + return media_device_id_salt_.GetValue(); +} + +// static +void MediaDeviceIDSalt::RegisterPrefs(PrefRegistrySimple* registry) { + registry->RegisterStringPref(kMediaDeviceIdSalt, std::string()); +} + +// static +void MediaDeviceIDSalt::Reset(PrefService* pref_service) { + pref_service->SetString( + kMediaDeviceIdSalt, + content::ResourceContext::CreateRandomMediaDeviceIDSalt()); +} + +} // namespace brightray diff --git a/brightray/browser/media/media_device_id_salt.h b/brightray/browser/media/media_device_id_salt.h new file mode 100644 index 00000000000..7941af8a563 --- /dev/null +++ b/brightray/browser/media/media_device_id_salt.h @@ -0,0 +1,40 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BRIGHTRAY_BROWSER_MEDIA_MEDIA_DEVICE_ID_SALT_H_ +#define BRIGHTRAY_BROWSER_MEDIA_MEDIA_DEVICE_ID_SALT_H_ + +#include + +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "components/prefs/pref_member.h" + +class PrefRegistrySimple; +class PrefService; + +namespace brightray { + +// MediaDeviceIDSalt is responsible for creating and retrieving a salt string +// that is used for creating MediaSource IDs that can be cached by a web +// service. If the cache is cleared, the MediaSourceIds are invalidated. +class MediaDeviceIDSalt { + public: + explicit MediaDeviceIDSalt(PrefService* pref_service); + ~MediaDeviceIDSalt(); + + std::string GetSalt(); + + static void RegisterPrefs(PrefRegistrySimple* pref_registry); + static void Reset(PrefService* pref_service); + + private: + StringPrefMember media_device_id_salt_; + + DISALLOW_COPY_AND_ASSIGN(MediaDeviceIDSalt); +}; + +} // namespace brightray + +#endif // BRIGHTRAY_BROWSER_MEDIA_MEDIA_DEVICE_ID_SALT_H_ diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index 88fdc392b90..c4ff58e2426 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -31,6 +31,7 @@ class URLRequestJobFactory; namespace brightray { class DevToolsNetworkControllerHandle; +class MediaDeviceIDSalt; class NetLog; class URLRequestContextGetter : public net::URLRequestContextGetter { @@ -57,6 +58,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { GetRequireCTDelegate() { return nullptr; } + virtual MediaDeviceIDSalt* GetMediaDeviceIDSalt() { return nullptr; } }; URLRequestContextGetter( @@ -77,6 +79,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { net::HostResolver* host_resolver(); net::URLRequestJobFactory* job_factory() const { return job_factory_; } + MediaDeviceIDSalt* GetMediaDeviceIDSalt() const { + return delegate_->GetMediaDeviceIDSalt(); + } private: Delegate* delegate_; diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index c36bddea5d8..7b2db49869d 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -43,6 +43,8 @@ 'browser/mac/notification_presenter_mac.mm', 'browser/media/media_capture_devices_dispatcher.cc', 'browser/media/media_capture_devices_dispatcher.h', + 'browser/media/media_device_id_salt.cc', + 'browser/media/media_device_id_salt.h', 'browser/media/media_stream_devices_controller.cc', 'browser/media/media_stream_devices_controller.h', 'browser/net/devtools_network_conditions.cc', From 237cb7d0a37772d63c53c1bfda03f62e7cace16f Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Fri, 6 Jan 2017 23:28:49 +0530 Subject: [PATCH 0918/1195] interceptor should handle default values of download and upload throughput --- .../browser/net/devtools_network_interceptor.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/brightray/browser/net/devtools_network_interceptor.cc b/brightray/browser/net/devtools_network_interceptor.cc index fa866b4aa12..f0e3e0e488d 100644 --- a/brightray/browser/net/devtools_network_interceptor.cc +++ b/brightray/browser/net/devtools_network_interceptor.cc @@ -195,15 +195,20 @@ base::TimeTicks DevToolsNetworkInterceptor::CalculateDesiredTime( void DevToolsNetworkInterceptor::ArmTimer(base::TimeTicks now) { size_t suspend_count = suspended_.size(); - if (!download_.size() && !upload_.size() && !suspend_count) + if (!download_.size() && !upload_.size() && !suspend_count) { + timer_.Stop(); return; + } base::TimeTicks desired_time = CalculateDesiredTime( download_, download_last_tick_, download_tick_length_); + if (desired_time == offset_) { + FinishRecords(&download_, false); + } base::TimeTicks upload_time = CalculateDesiredTime( upload_, upload_last_tick_, upload_tick_length_); - if (upload_time < desired_time) + if (upload_time != offset_ && upload_time < desired_time) desired_time = upload_time; int64_t min_baseline = std::numeric_limits::max(); @@ -218,9 +223,9 @@ void DevToolsNetworkInterceptor::ArmTimer(base::TimeTicks now) { desired_time = activation_time; } - timer_.Start(FROM_HERE, desired_time - now, - base::Bind(&DevToolsNetworkInterceptor::OnTimer, - base::Unretained(this))); + timer_.Start( + FROM_HERE, (desired_time - now).magnitude(), + base::Bind(&DevToolsNetworkInterceptor::OnTimer, base::Unretained(this))); } int DevToolsNetworkInterceptor::StartThrottle( From cddce77ea4e3bb8d98646eff4fff589d285f080d Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 10 Jan 2017 16:43:16 +0530 Subject: [PATCH 0919/1195] force attach devtools client when requested by inspectable webcontents --- brightray/browser/inspectable_web_contents.h | 2 +- brightray/browser/inspectable_web_contents_impl.cc | 10 ++++++---- brightray/browser/inspectable_web_contents_impl.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 01e9c6d2741..86324115acd 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -38,7 +38,7 @@ class InspectableWebContents { virtual void ShowDevTools() = 0; virtual void CloseDevTools() = 0; virtual bool IsDevToolsViewShowing() = 0; - virtual void AttachTo(const scoped_refptr&) = 0; + virtual void AttachTo(scoped_refptr) = 0; virtual void Detach() = 0; virtual void CallClientFunction(const std::string& function_name, const base::Value* arg1 = nullptr, diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 4affb2f786d..3ad08952987 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -279,8 +279,8 @@ void InspectableWebContentsImpl::ShowDevTools() { Observe(devtools_web_contents_.get()); devtools_web_contents_->SetDelegate(this); - agent_host_ = content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()); - agent_host_->AttachClient(this); + AttachTo(std::move( + content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()))); devtools_web_contents_->GetController().LoadURL( GetDevToolsURL(can_dock_), @@ -304,11 +304,13 @@ bool InspectableWebContentsImpl::IsDevToolsViewShowing() { return devtools_web_contents_ && view_->IsDevToolsViewShowing(); } -void InspectableWebContentsImpl::AttachTo(const scoped_refptr& host) { +void InspectableWebContentsImpl::AttachTo( + scoped_refptr host) { if (agent_host_.get()) Detach(); agent_host_ = host; - agent_host_->AttachClient(this); + // Terminate existing debugging connections and start debugging. + agent_host_->ForceAttachClient(this); } void InspectableWebContentsImpl::Detach() { diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index d25f1be5f99..818481efbf6 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -54,7 +54,7 @@ class InspectableWebContentsImpl : void ShowDevTools() override; void CloseDevTools() override; bool IsDevToolsViewShowing() override; - void AttachTo(const scoped_refptr&) override; + void AttachTo(scoped_refptr) override; void Detach() override; void CallClientFunction(const std::string& function_name, const base::Value* arg1, From 99786c743710ccf40943565e89388d09ed00ba80 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Jan 2017 10:11:03 -0800 Subject: [PATCH 0920/1195] Build through Electron in cibuild and add Travis config --- brightray/.travis.yml | 18 ++++++++++++++ brightray/script/cibuild | 54 +++++++++++++++------------------------- 2 files changed, 38 insertions(+), 34 deletions(-) create mode 100644 brightray/.travis.yml diff --git a/brightray/.travis.yml b/brightray/.travis.yml new file mode 100644 index 00000000000..06118787cb7 --- /dev/null +++ b/brightray/.travis.yml @@ -0,0 +1,18 @@ +notifications: + email: false + +language: node_js +node_js: + - "6" +os: + - linux + - osx +env: + - TARGET_ARCH=x64 +osx_image: xcode7.3 + +script: './script/cibuild' + +branches: + only: + - master diff --git a/brightray/script/cibuild b/brightray/script/cibuild index bfe1ec92b80..b16f69b1c54 100755 --- a/brightray/script/cibuild +++ b/brightray/script/cibuild @@ -1,41 +1,27 @@ -#!/usr/bin/env python +#!/usr/bin/env bash -import os -import subprocess -import sys +set -ex +# Make cloned repository complete +git fetch --unshallow origin HEAD -SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) -# We're in JENKINS_ROOT/workspace/brightray. Walk up to JENKINS_ROOT. -JENKINS_ROOT = os.path.dirname(os.path.dirname(SOURCE_ROOT)) -S3_CREDENTIALS_FILE = os.path.join(JENKINS_ROOT, 'config', 's3credentials') +# Clone Electron +git clone https://github.com/electron/electron --depth 1 --recursive +# Checkout current brightray commit into Electron +cd electron/vendor/brightray +git fetch ../../.. +git reset --hard FETCH_HEAD -def main(): - if not os.path.isfile(S3_CREDENTIALS_FILE): - return 'Error: Can\'t find {0}'.format(S3_CREDENTIALS_FILE) - copy_to_environment(S3_CREDENTIALS_FILE) +# Commit change +cd ../.. +git add vendor/brightray +git config --local user.email "test@github.com" +git config --local user.name "Test" +git commit --message 'Upgrading brightray' - url = 'https://{0}.s3.amazonaws.com/libchromiumcontent'.format(os.environ['JANKY_ARTIFACTS_S3_BUCKET']) - return (run_script('bootstrap', url) or - run_script('build') or - run_script('cpplint')) +# Bootstrap Electron +npm run bootstrap -- --dev - -def copy_to_environment(credentials_file): - with open(credentials_file, 'r') as f: - for line in f: - key, value = line.strip().split('=') - value = value.strip("'") - os.environ[key] = value - - -def run_script(script, *args): - script = os.path.join('script', script) - sys.stderr.write('+ {0}\n'.format(script)) - sys.stderr.flush() - return subprocess.call([sys.executable, script] + list(args)) - - -if __name__ == '__main__': - sys.exit(main()) +# Build Electron with brightray commit +npm run build From 6087a1223f11509ad199b3c2d8df0cb3e708cdb2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 12 Jan 2017 11:25:50 -0800 Subject: [PATCH 0921/1195] Add initial AppVeyor config --- brightray/appveyor.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 brightray/appveyor.yml diff --git a/brightray/appveyor.yml b/brightray/appveyor.yml new file mode 100644 index 00000000000..46a91007e6e --- /dev/null +++ b/brightray/appveyor.yml @@ -0,0 +1,24 @@ +version: "{build}" + +clone_depth: 10 + +os: Visual Studio 2015 + +init: + - git config --global core.autocrlf input + +platform: + - x64 + +install: + - cmd: SET PATH=C:\Program Files (x86)\MSBuild\14.0\bin\;%PATH% + - cmd: SET PATH=C:\python27;%PATH% + - cmd: bash script/cibuild + +branches: + only: + - master + +# disable build and test phases +build: off +test: off From e5ec6adf7d4e534b2958999aeeb90af66b3ae2f7 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 11 Jan 2017 20:06:25 -0800 Subject: [PATCH 0922/1195] Update std:move call to fix macOS compiler error --- brightray/browser/inspectable_web_contents_impl.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 3ad08952987..ea099c58c03 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -279,8 +279,7 @@ void InspectableWebContentsImpl::ShowDevTools() { Observe(devtools_web_contents_.get()); devtools_web_contents_->SetDelegate(this); - AttachTo(std::move( - content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get()))); + AttachTo(content::DevToolsAgentHost::GetOrCreateFor(web_contents_.get())); devtools_web_contents_->GetController().LoadURL( GetDevToolsURL(can_dock_), @@ -308,7 +307,7 @@ void InspectableWebContentsImpl::AttachTo( scoped_refptr host) { if (agent_host_.get()) Detach(); - agent_host_ = host; + agent_host_ = std::move(host); // Terminate existing debugging connections and start debugging. agent_host_->ForceAttachClient(this); } From eaea039155f85794ced8de5a3bb07dfdbbea2893 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Mon, 9 Jan 2017 13:26:59 +0100 Subject: [PATCH 0923/1195] Adjust linked static libraries after migrating libchromiumcontent to GN --- brightray/brightray.gyp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index c5b02fca9df..87e400140ea 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -91,14 +91,13 @@ '<(libchromiumcontent_dir)/libdevtools_http_handler.a', '<(libchromiumcontent_dir)/libhttp_server.a', '<(libchromiumcontent_dir)/libdesktop_capture.a', - '<(libchromiumcontent_dir)/libdesktop_capture_differ_sse2.a', '<(libchromiumcontent_dir)/libdom_keycode_converter.a', '<(libchromiumcontent_dir)/libsystem_wrappers.a', '<(libchromiumcontent_dir)/librtc_base.a', '<(libchromiumcontent_dir)/librtc_base_approved.a', '<(libchromiumcontent_dir)/libwebrtc_common.a', '<(libchromiumcontent_dir)/libyuv.a', - '<(libchromiumcontent_dir)/libcdm_renderer.a', + '<(libchromiumcontent_dir)/librenderer.a', '<(libchromiumcontent_dir)/libsecurity_state.a', ], }, @@ -147,14 +146,13 @@ '<(libchromiumcontent_dir)/libdevtools_http_handler.a', '<(libchromiumcontent_dir)/libhttp_server.a', '<(libchromiumcontent_dir)/libdesktop_capture.a', - '<(libchromiumcontent_dir)/libdesktop_capture_differ_sse2.a', '<(libchromiumcontent_dir)/libdom_keycode_converter.a', '<(libchromiumcontent_dir)/librtc_base.a', '<(libchromiumcontent_dir)/librtc_base_approved.a', '<(libchromiumcontent_dir)/libsystem_wrappers.a', '<(libchromiumcontent_dir)/libwebrtc_common.a', '<(libchromiumcontent_dir)/libyuv.a', - '<(libchromiumcontent_dir)/libcdm_renderer.a', + '<(libchromiumcontent_dir)/librenderer.a', '<(libchromiumcontent_dir)/libsecurity_state.a', ], }, @@ -213,14 +211,13 @@ '<(libchromiumcontent_dir)/devtools_http_handler.lib', '<(libchromiumcontent_dir)/http_server.lib', '<(libchromiumcontent_dir)/desktop_capture.lib', - '<(libchromiumcontent_dir)/desktop_capture_differ_sse2.lib', '<(libchromiumcontent_dir)/dom_keycode_converter.lib', '<(libchromiumcontent_dir)/rtc_base.lib', '<(libchromiumcontent_dir)/rtc_base_approved.lib', '<(libchromiumcontent_dir)/system_wrappers.lib', '<(libchromiumcontent_dir)/webrtc_common.lib', '<(libchromiumcontent_dir)/libyuv.lib', - '<(libchromiumcontent_dir)/cdm_renderer.lib', + '<(libchromiumcontent_dir)/renderer.lib', '<(libchromiumcontent_dir)/security_state.lib', # Friends of pdf.lib: '<(libchromiumcontent_dir)/pdf.lib', @@ -240,7 +237,6 @@ '<(libchromiumcontent_dir)/fxge.lib', '<(libchromiumcontent_dir)/javascript.lib', '<(libchromiumcontent_dir)/pdfwindow.lib', - '<(libchromiumcontent_dir)/bigint.lib', '<(libchromiumcontent_dir)/fx_agg.lib', '<(libchromiumcontent_dir)/fx_freetype.lib', '<(libchromiumcontent_dir)/fx_lcms2.lib', From 85db1bb47d144d01c06acbb3226af50cce7dc3c2 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Fri, 13 Jan 2017 09:52:45 +0100 Subject: [PATCH 0924/1195] Adjustments after upgrading to Chromium 54 --- brightray/brightray.gyp | 7 +++++++ brightray/browser/devtools_file_system_indexer.cc | 4 ++-- brightray/browser/devtools_manager_delegate.cc | 2 +- brightray/browser/inspectable_web_contents.h | 1 + brightray/browser/inspectable_web_contents_impl.cc | 5 +++++ brightray/browser/inspectable_web_contents_impl.h | 1 + .../browser/net/devtools_network_upload_data_stream.cc | 4 ++-- .../browser/net/devtools_network_upload_data_stream.h | 2 +- brightray/browser/permission_manager.cc | 2 ++ brightray/browser/permission_manager.h | 2 ++ brightray/browser/platform_notification_service.cc | 1 + brightray/browser/platform_notification_service.h | 1 + brightray/browser/url_request_context_getter.cc | 8 +++----- 13 files changed, 29 insertions(+), 11 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 87e400140ea..593aeadf643 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -185,6 +185,8 @@ '$(SDKROOT)/System/Library/Frameworks/ApplicationServices.framework', '$(SDKROOT)/System/Library/Frameworks/Carbon.framework', '$(SDKROOT)/System/Library/Frameworks/CoreFoundation.framework', + # device/gamepad/BUILD.gn: + '$(SDKROOT)/System/Library/Frameworks/GameController.framework', # content_browser.gypi: '-lbsm', # content_common.gypi: @@ -203,6 +205,7 @@ 'libraries': [ # Needed by desktop_capture.lib: '-ld3d11.lib', + '-ldxgi.lib', # Following libs are always linked statically. '<(libchromiumcontent_dir)/base_static.lib', '<(libchromiumcontent_dir)/sandbox.lib', @@ -235,6 +238,7 @@ '<(libchromiumcontent_dir)/fxcrt.lib', '<(libchromiumcontent_dir)/fxedit.lib', '<(libchromiumcontent_dir)/fxge.lib', + '<(libchromiumcontent_dir)/fxjs.lib', '<(libchromiumcontent_dir)/javascript.lib', '<(libchromiumcontent_dir)/pdfwindow.lib', '<(libchromiumcontent_dir)/fx_agg.lib', @@ -256,6 +260,7 @@ # content_common.gypi: '-ld3d9.lib', '-ld3d11.lib', + '-ldxgi.lib', '-ldxva2.lib', '-lstrmiids.lib', '-lmf.lib', @@ -295,6 +300,8 @@ 'secur32.lib', 'urlmon.lib', 'winhttp.lib', + # ui/gfx/BUILD.gn: + 'dwrite.lib', ], 'DelayLoadDLLs': [ 'wtsapi32.dll', diff --git a/brightray/browser/devtools_file_system_indexer.cc b/brightray/browser/devtools_file_system_indexer.cc index f9841441ad2..1700ff0eb99 100644 --- a/brightray/browser/devtools_file_system_indexer.cc +++ b/brightray/browser/devtools_file_system_indexer.cc @@ -267,8 +267,8 @@ DevToolsFileSystemIndexer::FileSystemIndexingJob::FileSystemIndexingJob( total_work_callback_(total_work_callback), worked_callback_(worked_callback), done_callback_(done_callback), - current_file_(BrowserThread::GetMessageLoopProxyForThread( - BrowserThread::FILE).get()), + current_file_( + BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()), files_indexed_(0), stopped_(false) { current_trigrams_set_.resize(kTrigramCount); diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index 368ac3a6073..eedc5616788 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -18,7 +18,6 @@ #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/grit/shell_resources.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/favicon_status.h" @@ -26,6 +25,7 @@ #include "content/public/common/content_switches.h" #include "content/public/common/url_constants.h" #include "content/public/common/user_agent.h" +#include "content/shell/grit/shell_resources.h" #include "net/base/net_errors.h" #include "net/socket/tcp_server_socket.h" #include "net/socket/stream_socket.h" diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index 86324115acd..a862344e2fb 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -44,6 +44,7 @@ class InspectableWebContents { const base::Value* arg1 = nullptr, const base::Value* arg2 = nullptr, const base::Value* arg3 = nullptr) = 0; + virtual void InspectElement(int x, int y) = 0; }; } // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index ea099c58c03..1ab496c6ecc 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -249,6 +249,11 @@ content::WebContents* InspectableWebContentsImpl::GetDevToolsWebContents() const return devtools_web_contents_.get(); } +void InspectableWebContentsImpl::InspectElement(int x, int y) { + if (agent_host_.get()) + agent_host_->InspectElement(this, x, y); +} + void InspectableWebContentsImpl::SetDelegate(InspectableWebContentsDelegate* delegate) { delegate_ = delegate; } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 818481efbf6..cab3e2132e3 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -60,6 +60,7 @@ class InspectableWebContentsImpl : const base::Value* arg1, const base::Value* arg2, const base::Value* arg3) override; + void InspectElement(int x, int y) override; // Return the last position and size of devtools window. gfx::Rect GetDevToolsBounds() const; diff --git a/brightray/browser/net/devtools_network_upload_data_stream.cc b/brightray/browser/net/devtools_network_upload_data_stream.cc index 31bd8f38199..975afa4d3c9 100644 --- a/brightray/browser/net/devtools_network_upload_data_stream.cc +++ b/brightray/browser/net/devtools_network_upload_data_stream.cc @@ -35,11 +35,11 @@ bool DevToolsNetworkUploadDataStream::IsInMemory() const { return false; } -int DevToolsNetworkUploadDataStream::InitInternal() { +int DevToolsNetworkUploadDataStream::InitInternal(const net::BoundNetLog& net_log) { throttled_byte_count_ = 0; int result = upload_data_stream_->Init( base::Bind(&DevToolsNetworkUploadDataStream::StreamInitCallback, - base::Unretained(this))); + base::Unretained(this)), net_log); if (result == net::OK && !is_chunked()) SetSize(upload_data_stream_->size()); return result; diff --git a/brightray/browser/net/devtools_network_upload_data_stream.h b/brightray/browser/net/devtools_network_upload_data_stream.h index e297836f8c5..8db7dd80c87 100644 --- a/brightray/browser/net/devtools_network_upload_data_stream.h +++ b/brightray/browser/net/devtools_network_upload_data_stream.h @@ -27,7 +27,7 @@ class DevToolsNetworkUploadDataStream : public net::UploadDataStream { private: // net::UploadDataStream implementation. bool IsInMemory() const override; - int InitInternal() override; + int InitInternal(const net::BoundNetLog& net_log) override; int ReadInternal(net::IOBuffer* buf, int buf_len) override; void ResetInternal() override; diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc index 5431035561a..f2b0d97d9ba 100644 --- a/brightray/browser/permission_manager.cc +++ b/brightray/browser/permission_manager.cc @@ -22,6 +22,7 @@ int PermissionManager::RequestPermission( content::PermissionType permission, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, + bool user_gesture, const base::Callback& callback) { if (permission == content::PermissionType::MIDI_SYSEX) { content::ChildProcessSecurityPolicy::GetInstance()-> @@ -35,6 +36,7 @@ int PermissionManager::RequestPermissions( const std::vector& permissions, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, + bool user_gesture, const base::Callback&)>& callback) { std::vector permissionStatuses; diff --git a/brightray/browser/permission_manager.h b/brightray/browser/permission_manager.h index 3f6001c18bf..67168ed2b31 100644 --- a/brightray/browser/permission_manager.h +++ b/brightray/browser/permission_manager.h @@ -21,11 +21,13 @@ class PermissionManager : public content::PermissionManager { content::PermissionType permission, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, + bool user_gesture, const base::Callback& callback) override; int RequestPermissions( const std::vector& permissions, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, + bool user_gesture, const base::Callback&)>& callback) override; void CancelPermissionRequest(int request_id) override; diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index c9f2e5a1f91..378cd1143f3 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -86,6 +86,7 @@ void PlatformNotificationService::DisplayNotification( void PlatformNotificationService::DisplayPersistentNotification( content::BrowserContext* browser_context, int64_t persistent_notification_id, + const GURL& service_worker_origin, const GURL& origin, const content::PlatformNotificationData& notification_data, const content::NotificationResources& notification_resources) { diff --git a/brightray/browser/platform_notification_service.h b/brightray/browser/platform_notification_service.h index 9c478929378..1e17a6fbae4 100644 --- a/brightray/browser/platform_notification_service.h +++ b/brightray/browser/platform_notification_service.h @@ -37,6 +37,7 @@ class PlatformNotificationService void DisplayPersistentNotification( content::BrowserContext* browser_context, int64_t persistent_notification_id, + const GURL& service_worker_origin, const GURL& origin, const content::PlatformNotificationData& notification_data, const content::NotificationResources& notification_resources) override; diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index ad2838a8efe..9fc8a721d77 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -96,7 +96,7 @@ URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(const base::Fil net::CACHE_BACKEND_DEFAULT, cache_path, 0, - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); + BrowserThread::GetTaskRunnerForThread(BrowserThread::CACHE)); } std::unique_ptr @@ -291,10 +291,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params.ignore_certificate_errors = false; // --disable-http2 - if (command_line.HasSwitch(switches::kDisableHttp2)) { - network_session_params.enable_spdy31 = false; + if (command_line.HasSwitch(switches::kDisableHttp2)) network_session_params.enable_http2 = false; - } // --ignore-certificate-errors if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) @@ -357,7 +355,7 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { } scoped_refptr URLRequestContextGetter::GetNetworkTaskRunner() const { - return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); + return BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); } } // namespace brightray From 72cd10a873db2eea400791d96f5eec924bac054a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 17 Jan 2017 17:20:27 +0900 Subject: [PATCH 0925/1195] Update libchromiumcontent to latest --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 76bb29da18c..9f8351f0849 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 76bb29da18cbeec0051e0690bc1b95e78034a422 +Subproject commit 9f8351f084989f9e4a08d8f804286c844ddd14e7 From e3cfb8ae5f1bb2d70feb920861cfd101fdc4d18b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 17 Jan 2017 14:09:22 -0800 Subject: [PATCH 0926/1195] Upgrade libcc to latest --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 9f8351f0849..25ec31e58d2 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 9f8351f084989f9e4a08d8f804286c844ddd14e7 +Subproject commit 25ec31e58d23002a02dc85dd4b8200b72d50a6c7 From f560fd56aaa87ba4e69673c37c2393c88b1e869f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 14:34:57 +0900 Subject: [PATCH 0927/1195] Update libchromiumcontent to Chrome 56 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 25ec31e58d2..63227c0c929 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 25ec31e58d23002a02dc85dd4b8200b72d50a6c7 +Subproject commit 63227c0c9299e01809bcc705bd7346aecf8b6855 From eb89edbf5b35524e5858e4840119fba99be31f19 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 14:48:23 +0900 Subject: [PATCH 0928/1195] devtools_discovery and devtools_http_handler are gone --- .../browser/devtools_manager_delegate.cc | 27 +++++++------------ brightray/browser/devtools_manager_delegate.h | 20 ++++++-------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index eedc5616788..a93d13d46da 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -15,11 +15,9 @@ #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.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_frontend_host.h" +#include "content/public/browser/devtools_socket_factory.h" #include "content/public/browser/favicon_status.h" #include "content/public/browser/navigation_entry.h" #include "content/public/common/content_switches.h" @@ -36,15 +34,14 @@ namespace brightray { namespace { -class TCPServerSocketFactory - : public devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory { +class TCPServerSocketFactory : public content::DevToolsSocketFactory { public: TCPServerSocketFactory(const std::string& address, int port) : address_(address), port_(port) { } private: - // content::DevToolsHttpHandler::ServerSocketFactory. + // content::ServerSocketFactory. std::unique_ptr CreateForHttpServer() override { std::unique_ptr socket( new net::TCPServerSocket(nullptr, net::NetLog::Source())); @@ -147,27 +144,23 @@ DevToolsManagerDelegate::CreateHttpHandler() { DevToolsManagerDelegate::DevToolsManagerDelegate() : handler_(new DevToolsNetworkProtocolHandler) { - // 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() { } -void DevToolsManagerDelegate::DevToolsAgentStateChanged( - content::DevToolsAgentHost* agent_host, - bool attached) { - handler_->DevToolsAgentStateChanged(agent_host, attached); +void DevToolsManagerDelegate::Inspect(content::DevToolsAgentHost* agent_host) { } base::DictionaryValue* DevToolsManagerDelegate::HandleCommand( - content::DevToolsAgentHost* agent_host, + DevToolsAgentHost* agent_host, base::DictionaryValue* command) { return handler_->HandleCommand(agent_host, command); } +scoped_refptr +DevToolsManagerDelegate::::CreateNewTarget(const GURL& url) { + return nullptr; +} + } // namespace brightray diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h index 23d28c74dbb..f808cdfd7be 100644 --- a/brightray/browser/devtools_manager_delegate.h +++ b/brightray/browser/devtools_manager_delegate.h @@ -7,31 +7,27 @@ #include "base/macros.h" #include "base/compiler_specific.h" -#include "components/devtools_http_handler/devtools_http_handler_delegate.h" +#include "content/browser/devtools/devtools_http_handler.h" #include "content/public/browser/devtools_manager_delegate.h" -namespace devtools_http_handler { -class DevToolsHttpHandler; -} - namespace brightray { class DevToolsNetworkProtocolHandler; class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { public: - static devtools_http_handler::DevToolsHttpHandler* CreateHttpHandler(); + static content::DevToolsHttpHandler* CreateHttpHandler(); DevToolsManagerDelegate(); virtual ~DevToolsManagerDelegate(); // DevToolsManagerDelegate implementation. - void Inspect(content::BrowserContext* browser_context, - content::DevToolsAgentHost* agent_host) override {} - void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host, - bool attached) override; - base::DictionaryValue* HandleCommand(content::DevToolsAgentHost* agent_host, - base::DictionaryValue* command) override; + void Inspect(content::DevToolsAgentHost* agent_host) override; + base::DictionaryValue* HandleCommand( + content::DevToolsAgentHost* agent_host, + base::DictionaryValue* command) override; + scoped_refptr CreateNewTarget( + const GURL& url) override; private: std::unique_ptr handler_; From 804d56e1392dcb9cbd2d2351e50833f6098b6ab4 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 14:55:06 +0900 Subject: [PATCH 0929/1195] Signature of StartDataRequest has changed --- brightray/browser/devtools_ui.cc | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/brightray/browser/devtools_ui.cc b/brightray/browser/devtools_ui.cc index 24d7d4737ca..9764886d571 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" - namespace brightray { namespace { @@ -62,19 +61,21 @@ class BundledDataSource : public content::URLDataSource { return kChromeUIDevToolsHost; } - void StartDataRequest(const std::string& path, - int render_process_id, - int render_frame_id, - const GotDataCallback& callback) override { + void StartDataRequest( + const std::string& path, + const content::ResourceRequestInfo::WebContentsGetter& wc_getter, + const GotDataCallback& callback) override { // Serve request from local bundle. std::string bundled_path_prefix(kChromeUIDevToolsBundledPath); bundled_path_prefix += "/"; if (base::StartsWith(path, bundled_path_prefix, base::CompareCase::INSENSITIVE_ASCII)) { StartBundledDataRequest(path.substr(bundled_path_prefix.length()), - render_process_id, render_frame_id, callback); + callback); return; } + + // We do not handle remote and custom requests. callback.Run(nullptr); } @@ -94,11 +95,8 @@ class BundledDataSource : public content::URLDataSource { return true; } - void StartBundledDataRequest( - const std::string& path, - int render_process_id, - int render_frame_id, - const content::URLDataSource::GotDataCallback& callback) { + void StartBundledDataRequest(const std::string& path, + const GotDataCallback& callback) { std::string filename = PathWithoutParams(path); base::StringPiece resource = content::DevToolsFrontendHost::GetFrontendResource(filename); From e7ee9f1be98701db43419bf5ccd62c8bcddd0e05 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 15:07:18 +0900 Subject: [PATCH 0930/1195] DevToolsDelegate is no longer needed --- brightray/browser/browser_main_parts.cc | 3 +- brightray/browser/browser_main_parts.h | 6 -- .../browser/devtools_manager_delegate.cc | 79 ++++++------------- brightray/browser/devtools_manager_delegate.h | 4 +- 4 files changed, 26 insertions(+), 66 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 0aae4bcc5bc..52f40a53501 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -13,7 +13,6 @@ #include "base/feature_list.h" #include "base/strings/string_number_conversions.h" #include "base/strings/utf_string_conversions.h" -#include "components/devtools_http_handler/devtools_http_handler.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" #include "media/base/media_resources.h" @@ -216,7 +215,7 @@ void BrowserMainParts::PreMainMessageLoopRun() { // --remote-debugging-port auto command_line = base::CommandLine::ForCurrentProcess(); if (command_line->HasSwitch(switches::kRemoteDebuggingPort)) - devtools_http_handler_.reset(DevToolsManagerDelegate::CreateHttpHandler()); + DevToolsManagerDelegate::StartHttpHandler(); } void BrowserMainParts::PostMainMessageLoopStart() { diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index a0d58e7609e..209e95d87b4 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -9,10 +9,6 @@ #include "base/memory/ref_counted.h" #include "content/public/browser/browser_main_parts.h" -namespace devtools_http_handler { -class DevToolsHttpHandler; -} - #if defined(TOOLKIT_VIEWS) namespace brightray { class ViewsDelegate; @@ -48,8 +44,6 @@ class BrowserMainParts : public content::BrowserMainParts { void InitializeMainNib(); #endif - std::unique_ptr devtools_http_handler_; - #if defined(TOOLKIT_VIEWS) std::unique_ptr views_delegate_; #endif diff --git a/brightray/browser/devtools_manager_delegate.cc b/brightray/browser/devtools_manager_delegate.cc index a93d13d46da..7d4ae4d7d45 100644 --- a/brightray/browser/devtools_manager_delegate.cc +++ b/brightray/browser/devtools_manager_delegate.cc @@ -44,12 +44,16 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory { // content::ServerSocketFactory. std::unique_ptr CreateForHttpServer() override { std::unique_ptr socket( - new net::TCPServerSocket(nullptr, net::NetLog::Source())); + new net::TCPServerSocket(nullptr, net::NetLogSource())); if (socket->ListenWithAddressAndPort(address_, port_, 10) != net::OK) return std::unique_ptr(); return socket; } + std::unique_ptr CreateForTethering( + std::string* name) override { + return std::unique_ptr(); + } std::string address_; uint16_t port_; @@ -57,7 +61,7 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory { DISALLOW_COPY_AND_ASSIGN(TCPServerSocketFactory); }; -std::unique_ptr +std::unique_ptr CreateSocketFactory() { auto& command_line = *base::CommandLine::ForCurrentProcess(); // See if the user specified a port on the command line (useful for @@ -74,55 +78,8 @@ CreateSocketFactory() { DLOG(WARNING) << "Invalid http debugger port number " << temp_port; } } - return std::unique_ptr< - devtools_http_handler::DevToolsHttpHandler::ServerSocketFactory>( - new TCPServerSocketFactory("127.0.0.1", port)); -} - - -// DevToolsDelegate -------------------------------------------------------- - -class DevToolsDelegate : - public devtools_http_handler::DevToolsHttpHandlerDelegate { - public: - DevToolsDelegate(); - ~DevToolsDelegate() override; - - // devtools_http_handler::DevToolsHttpHandlerDelegate. - std::string GetDiscoveryPageHTML() override; - std::string GetFrontendResource(const std::string& path) override; - std::string GetPageThumbnailData(const GURL& url) override; - content::DevToolsExternalAgentProxyDelegate* HandleWebSocketConnection( - const std::string& path) override; - - private: - DISALLOW_COPY_AND_ASSIGN(DevToolsDelegate); -}; - -DevToolsDelegate::DevToolsDelegate() { -} - -DevToolsDelegate::~DevToolsDelegate() { -} - -std::string DevToolsDelegate::GetDiscoveryPageHTML() { - return ResourceBundle::GetSharedInstance().GetRawDataResource( - IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); -} - - -std::string DevToolsDelegate::GetFrontendResource( - const std::string& path) { - return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); -} - -std::string DevToolsDelegate::GetPageThumbnailData(const GURL& url) { - return std::string(); -} - -content::DevToolsExternalAgentProxyDelegate* -DevToolsDelegate::HandleWebSocketConnection(const std::string& path) { - return nullptr; + return std::unique_ptr( + new TCPServerSocketFactory("127.0.0.1", port)); } } // namespace @@ -130,12 +87,10 @@ DevToolsDelegate::HandleWebSocketConnection(const std::string& path) { // DevToolsManagerDelegate --------------------------------------------------- // static -devtools_http_handler::DevToolsHttpHandler* -DevToolsManagerDelegate::CreateHttpHandler() { - return new devtools_http_handler::DevToolsHttpHandler( +void DevToolsManagerDelegate::StartHttpHandler() { + content::DevToolsAgentHost::StartRemoteDebuggingServer( CreateSocketFactory(), std::string(), - new DevToolsDelegate, base::FilePath(), base::FilePath(), std::string(), @@ -153,14 +108,24 @@ void DevToolsManagerDelegate::Inspect(content::DevToolsAgentHost* agent_host) { } base::DictionaryValue* DevToolsManagerDelegate::HandleCommand( - DevToolsAgentHost* agent_host, + content::DevToolsAgentHost* agent_host, base::DictionaryValue* command) { return handler_->HandleCommand(agent_host, command); } scoped_refptr -DevToolsManagerDelegate::::CreateNewTarget(const GURL& url) { +DevToolsManagerDelegate::CreateNewTarget(const GURL& url) { return nullptr; } +std::string DevToolsManagerDelegate::GetDiscoveryPageHTML() { + return ResourceBundle::GetSharedInstance().GetRawDataResource( + IDR_CONTENT_SHELL_DEVTOOLS_DISCOVERY_PAGE).as_string(); +} + +std::string DevToolsManagerDelegate::GetFrontendResource( + const std::string& path) { + return content::DevToolsFrontendHost::GetFrontendResource(path).as_string(); +} + } // namespace brightray diff --git a/brightray/browser/devtools_manager_delegate.h b/brightray/browser/devtools_manager_delegate.h index f808cdfd7be..2e2e09f43f5 100644 --- a/brightray/browser/devtools_manager_delegate.h +++ b/brightray/browser/devtools_manager_delegate.h @@ -16,7 +16,7 @@ class DevToolsNetworkProtocolHandler; class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { public: - static content::DevToolsHttpHandler* CreateHttpHandler(); + static void StartHttpHandler(); DevToolsManagerDelegate(); virtual ~DevToolsManagerDelegate(); @@ -28,6 +28,8 @@ class DevToolsManagerDelegate : public content::DevToolsManagerDelegate { base::DictionaryValue* command) override; scoped_refptr CreateNewTarget( const GURL& url) override; + std::string GetDiscoveryPageHTML() override; + std::string GetFrontendResource(const std::string& path) override; private: std::unique_ptr handler_; From 0236f8750730cdb0ce9c3ab29079af9c903bd1e3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 15:10:34 +0900 Subject: [PATCH 0931/1195] Update DevToolsNetworkTransaction --- .../browser/net/devtools_network_transaction.cc | 13 +++++-------- .../browser/net/devtools_network_transaction.h | 3 +-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc index 0a62346392a..dc9fdebd355 100644 --- a/brightray/browser/net/devtools_network_transaction.cc +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -106,7 +106,7 @@ bool DevToolsNetworkTransaction::CheckFailed() { int DevToolsNetworkTransaction::Start( const net::HttpRequestInfo* request, const net::CompletionCallback& callback, - const net::BoundNetLog& net_log) { + const net::BoundNe& net_log) { DCHECK(request); request_ = request; @@ -129,7 +129,8 @@ int DevToolsNetworkTransaction::Start( request_ = custom_request_.get(); } - DevToolsNetworkInterceptor* interceptor = controller_->GetInterceptor(client_id); + DevToolsNetworkInterceptor* interceptor = + controller_->GetInterceptor(client_id); if (interceptor) { interceptor_ = interceptor->GetWeakPtr(); if (custom_upload_data_stream_) @@ -140,9 +141,9 @@ int DevToolsNetworkTransaction::Start( return net::ERR_INTERNET_DISCONNECTED; if (!interceptor_) - return transaction_->Start(request_, callback, net_log); + return network_transaction_->Start(request_, callback, net_log); - int result = transaction_->Start(request_, + int result = network_transaction_->Start(request_, base::Bind(&DevToolsNetworkTransaction::IOCallback, base::Unretained(this), callback, true), net_log); @@ -246,10 +247,6 @@ net::LoadState DevToolsNetworkTransaction::GetLoadState() const { return transaction_->GetLoadState(); } -net::UploadProgress DevToolsNetworkTransaction::GetUploadProgress() const { - return transaction_->GetUploadProgress(); -} - void DevToolsNetworkTransaction::SetQuicServerInfo( net::QuicServerInfo* info) { transaction_->SetQuicServerInfo(info); diff --git a/brightray/browser/net/devtools_network_transaction.h b/brightray/browser/net/devtools_network_transaction.h index 3648ca71c74..7f01d73cad1 100644 --- a/brightray/browser/net/devtools_network_transaction.h +++ b/brightray/browser/net/devtools_network_transaction.h @@ -32,7 +32,7 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { // HttpTransaction methods: int Start(const net::HttpRequestInfo* request, const net::CompletionCallback& callback, - const net::BoundNetLog& net_log) override; + const net::NetLogWithSource& net_log) override; int RestartIgnoringLastError( const net::CompletionCallback& callback) override; int RestartWithCertificate(net::X509Certificate* client_cert, @@ -52,7 +52,6 @@ class DevToolsNetworkTransaction : public net::HttpTransaction { void DoneReading() override; const net::HttpResponseInfo* GetResponseInfo() const override; net::LoadState GetLoadState() const override; - net::UploadProgress GetUploadProgress() const override; void SetQuicServerInfo(net::QuicServerInfo* quic_server_info) override; bool GetLoadTimingInfo(net::LoadTimingInfo* load_timing_info) const override; bool GetRemoteEndpoint(net::IPEndPoint* endpoint) const override; From 43813ff6804126cfa69b2df04b578581a87c5074 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 15:13:28 +0900 Subject: [PATCH 0932/1195] Add a new include dir from boringssl --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 593aeadf643..e1057770678 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -14,6 +14,7 @@ '.', '<(libchromiumcontent_src_dir)', '<(libchromiumcontent_src_dir)/skia/config', + '<(libchromiumcontent_src_dir)/third_party/boringssl/src/include', '<(libchromiumcontent_src_dir)/third_party/skia/include/core', '<(libchromiumcontent_src_dir)/third_party/mojo/src', '<(libchromiumcontent_src_dir)/third_party/WebKit', From 70ffec11343e418aa571a29cc43fc2201afd1b7c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 15:14:38 +0900 Subject: [PATCH 0933/1195] There is no content::MEDIA_ENUMERATE_DEVICES anymore --- brightray/browser/media/media_stream_devices_controller.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index b3548bbe409..a744a08ae4d 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -137,10 +137,6 @@ void MediaStreamDevicesController::Accept() { webcam_requested_, &devices); break; - case content::MEDIA_ENUMERATE_DEVICES: - // Do nothing. - NOTREACHED(); - break; } } From db7959619eadcc574d23fd7cf8b5c063480129dc Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 15:18:52 +0900 Subject: [PATCH 0934/1195] Update DevToolsNetworkUploadDataStream --- brightray/browser/net/devtools_network_transaction.cc | 11 +++++------ .../net/devtools_network_upload_data_stream.cc | 6 ++++-- .../browser/net/devtools_network_upload_data_stream.h | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/brightray/browser/net/devtools_network_transaction.cc b/brightray/browser/net/devtools_network_transaction.cc index dc9fdebd355..ced70acc5e4 100644 --- a/brightray/browser/net/devtools_network_transaction.cc +++ b/brightray/browser/net/devtools_network_transaction.cc @@ -103,10 +103,9 @@ bool DevToolsNetworkTransaction::CheckFailed() { return false; } -int DevToolsNetworkTransaction::Start( - const net::HttpRequestInfo* request, - const net::CompletionCallback& callback, - const net::BoundNe& net_log) { +int DevToolsNetworkTransaction::Start(const net::HttpRequestInfo* request, + const net::CompletionCallback& callback, + const net::NetLogWithSource& net_log) { DCHECK(request); request_ = request; @@ -141,9 +140,9 @@ int DevToolsNetworkTransaction::Start( return net::ERR_INTERNET_DISCONNECTED; if (!interceptor_) - return network_transaction_->Start(request_, callback, net_log); + return transaction_->Start(request_, callback, net_log); - int result = network_transaction_->Start(request_, + int result = transaction_->Start(request_, base::Bind(&DevToolsNetworkTransaction::IOCallback, base::Unretained(this), callback, true), net_log); diff --git a/brightray/browser/net/devtools_network_upload_data_stream.cc b/brightray/browser/net/devtools_network_upload_data_stream.cc index 975afa4d3c9..c6369dcb458 100644 --- a/brightray/browser/net/devtools_network_upload_data_stream.cc +++ b/brightray/browser/net/devtools_network_upload_data_stream.cc @@ -35,11 +35,13 @@ bool DevToolsNetworkUploadDataStream::IsInMemory() const { return false; } -int DevToolsNetworkUploadDataStream::InitInternal(const net::BoundNetLog& net_log) { +int DevToolsNetworkUploadDataStream::InitInternal( + const net::NetLogWithSource& net_log) { throttled_byte_count_ = 0; int result = upload_data_stream_->Init( base::Bind(&DevToolsNetworkUploadDataStream::StreamInitCallback, - base::Unretained(this)), net_log); + base::Unretained(this)), + net_log); if (result == net::OK && !is_chunked()) SetSize(upload_data_stream_->size()); return result; diff --git a/brightray/browser/net/devtools_network_upload_data_stream.h b/brightray/browser/net/devtools_network_upload_data_stream.h index 8db7dd80c87..c3753e8286f 100644 --- a/brightray/browser/net/devtools_network_upload_data_stream.h +++ b/brightray/browser/net/devtools_network_upload_data_stream.h @@ -27,7 +27,7 @@ class DevToolsNetworkUploadDataStream : public net::UploadDataStream { private: // net::UploadDataStream implementation. bool IsInMemory() const override; - int InitInternal(const net::BoundNetLog& net_log) override; + int InitInternal(const net::NetLogWithSource& net_log) override; int ReadInternal(net::IOBuffer* buf, int buf_len) override; void ResetInternal() override; From 622fd8d1d7e7a6ae13e546e77450bc0e2328ce39 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 15:27:57 +0900 Subject: [PATCH 0935/1195] Update InspectableWebContentsImpl --- brightray/browser/inspectable_web_contents_impl.cc | 9 +++++---- brightray/browser/inspectable_web_contents_impl.h | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 1ab496c6ecc..7f18ce65d86 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -144,7 +144,7 @@ class ResponseWriter : public net::URLFetcherResponseWriter { int Write(net::IOBuffer* buffer, int num_bytes, const net::CompletionCallback& callback) override; - int Finish(const net::CompletionCallback& callback) override; + int Finish(int net_error, const net::CompletionCallback& callback) override; private: base::WeakPtr bindings_; @@ -181,7 +181,8 @@ int ResponseWriter::Write(net::IOBuffer* buffer, return num_bytes; } -int ResponseWriter::Finish(const net::CompletionCallback& callback) { +int ResponseWriter::Finish(int net_error, + const net::CompletionCallback& callback) { return net::OK; } @@ -654,7 +655,7 @@ void InspectableWebContentsImpl::WebContentsDestroyed() { view_->GetDelegate()->DevToolsClosed(); } -bool InspectableWebContentsImpl::AddMessageToConsole( +bool InspectableWebContentsImpl::DidAddMessageToConsole( content::WebContents* source, int32_t level, const base::string16& message, @@ -726,7 +727,7 @@ void InspectableWebContentsImpl::OnWebContentsFocused() { void InspectableWebContentsImpl::DidStartNavigationToPendingEntry( const GURL& url, - content::NavigationController::ReloadType reload_type) { + content::ReloadType reload_type) { frontend_host_.reset( content::DevToolsFrontendHost::Create( web_contents()->GetMainFrame(), diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index cab3e2132e3..9b565f0f2dd 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -133,14 +133,14 @@ class InspectableWebContentsImpl : void OnWebContentsFocused() override; void DidStartNavigationToPendingEntry( const GURL& url, - content::NavigationController::ReloadType reload_type) override; + content::ReloadType reload_type) override; // content::WebContentsDelegate: - bool AddMessageToConsole(content::WebContents* source, - int32_t level, - const base::string16& message, - int32_t line_no, - const base::string16& source_id) override; + bool DidAddMessageToConsole(content::WebContents* source, + int32_t level, + const base::string16& message, + int32_t line_no, + const base::string16& source_id) override; bool ShouldCreateWebContents( content::WebContents* web_contents, int32_t route_id, From ac4ef926e1afbdb3c01c406058b22542df842783 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 15:42:37 +0900 Subject: [PATCH 0936/1195] URLRequestContenxtGetter now accepts task runner --- brightray/browser/browser_context.cc | 4 ++-- brightray/browser/url_request_context_getter.cc | 10 +++++----- brightray/browser/url_request_context_getter.h | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index bbb2a4e7f9b..a28fec5d832 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -140,8 +140,8 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( static_cast(BrowserClient::Get()->GetNetLog()), GetPath(), in_memory_, - BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), - BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), + BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), + BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), protocol_handlers, std::move(protocol_interceptors)); resource_context_->set_url_request_context_getter(url_request_getter_.get()); diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 9fc8a721d77..e3e7dca5435 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -118,8 +118,8 @@ URLRequestContextGetter::URLRequestContextGetter( NetLog* net_log, const base::FilePath& base_path, bool in_memory, - base::MessageLoop* io_loop, - base::MessageLoop* file_loop, + scoped_refptr io_task_runner, + scoped_refptr file_task_runner, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors) : delegate_(delegate), @@ -127,8 +127,8 @@ URLRequestContextGetter::URLRequestContextGetter( net_log_(net_log), base_path_(base_path), in_memory_(in_memory), - io_loop_(io_loop), - file_loop_(file_loop), + io_task_runner_(io_task_runner), + file_task_runner_(file_task_runner), protocol_interceptors_(std::move(protocol_interceptors)), job_factory_(nullptr) { // Must first be created on the UI thread. @@ -144,7 +144,7 @@ URLRequestContextGetter::URLRequestContextGetter( // must synchronously run on the glib message loop. This will be passed to // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). proxy_config_service_ = net::ProxyService::CreateSystemProxyConfigService( - io_loop_->task_runner(), file_loop_->task_runner()); + io_task_runner_, file_task_runner_); } URLRequestContextGetter::~URLRequestContextGetter() { diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index c4ff58e2426..e08189d862d 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -67,8 +67,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { NetLog* net_log, const base::FilePath& base_path, bool in_memory, - base::MessageLoop* io_loop, - base::MessageLoop* file_loop, + scoped_refptr io_task_runner, + scoped_refptr file_task_runner, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector protocol_interceptors); virtual ~URLRequestContextGetter(); @@ -90,8 +90,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { NetLog* net_log_; base::FilePath base_path_; bool in_memory_; - base::MessageLoop* io_loop_; - base::MessageLoop* file_loop_; + scoped_refptr io_task_runner_; + scoped_refptr file_task_runner_; std::string user_agent_; From bf4c413947288278514ee337071862b48d388a89 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 23 Jan 2017 17:48:16 +0900 Subject: [PATCH 0937/1195] Update PlatformNotificationService --- brightray/browser/platform_notification_service.cc | 7 ++++--- brightray/browser/platform_notification_service.h | 13 +++++++------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 378cd1143f3..3fa04e0814c 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -62,6 +62,7 @@ blink::mojom::PermissionStatus PlatformNotificationService::CheckPermissionOnIOT void PlatformNotificationService::DisplayNotification( content::BrowserContext* browser_context, + const std::string& notification_id, const GURL& origin, const content::PlatformNotificationData& notification_data, const content::NotificationResources& notification_resources, @@ -85,8 +86,8 @@ void PlatformNotificationService::DisplayNotification( void PlatformNotificationService::DisplayPersistentNotification( content::BrowserContext* browser_context, - int64_t persistent_notification_id, - const GURL& service_worker_origin, + const std::string& notification_id, + const GURL& service_worker_scope, const GURL& origin, const content::PlatformNotificationData& notification_data, const content::NotificationResources& notification_resources) { @@ -94,7 +95,7 @@ void PlatformNotificationService::DisplayPersistentNotification( void PlatformNotificationService::ClosePersistentNotification( content::BrowserContext* browser_context, - int64_t persistent_notification_id) { + const std::string& notification_id) { } bool PlatformNotificationService::GetDisplayedPersistentNotifications( diff --git a/brightray/browser/platform_notification_service.h b/brightray/browser/platform_notification_service.h index 1e17a6fbae4..b2b6471d0fd 100644 --- a/brightray/browser/platform_notification_service.h +++ b/brightray/browser/platform_notification_service.h @@ -28,7 +28,9 @@ class PlatformNotificationService content::ResourceContext* resource_context, const GURL& origin, int render_process_id) override; - void DisplayNotification(content::BrowserContext* browser_context, + void DisplayNotification( + content::BrowserContext* browser_context, + const std::string& notification_id, const GURL& origin, const content::PlatformNotificationData& notification_data, const content::NotificationResources& notification_resources, @@ -36,14 +38,13 @@ class PlatformNotificationService base::Closure* cancel_callback) override; void DisplayPersistentNotification( content::BrowserContext* browser_context, - int64_t persistent_notification_id, - const GURL& service_worker_origin, + const std::string& notification_id, + const GURL& service_worker_scope, const GURL& origin, const content::PlatformNotificationData& notification_data, const content::NotificationResources& notification_resources) override; - void ClosePersistentNotification( - content::BrowserContext* browser_context, - int64_t persistent_notification_id) override; + void ClosePersistentNotification(content::BrowserContext* browser_context, + const std::string& notification_id) override; bool GetDisplayedPersistentNotifications( content::BrowserContext* browser_context, std::set* displayed_notifications) override; From de7da8e4bee80c58fa7ce1540977ec0747bc3d1b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 24 Jan 2017 17:32:46 +0900 Subject: [PATCH 0938/1195] Export boringssl's include dir to dependents --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index e1057770678..25358d2162e 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -27,6 +27,7 @@ '<(libchromiumcontent_src_dir)', '<(libchromiumcontent_src_dir)/gpu', '<(libchromiumcontent_src_dir)/skia/config', + '<(libchromiumcontent_src_dir)/third_party/boringssl/src/include', '<(libchromiumcontent_src_dir)/third_party/skia/include/core', '<(libchromiumcontent_src_dir)/third_party/skia/include/config', '<(libchromiumcontent_src_dir)/third_party/icu/source/common', From 7cdcce157adc6ecc2d6ad7c2eae25b74e6696ab8 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 24 Jan 2017 17:38:24 +0900 Subject: [PATCH 0939/1195] devtools_discovery and devtools_http_handler are part of content module now --- brightray/brightray.gyp | 6 ------ brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 25358d2162e..30568b3a40c 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -89,8 +89,6 @@ 'libraries': [ # 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', '<(libchromiumcontent_dir)/libdesktop_capture.a', '<(libchromiumcontent_dir)/libdom_keycode_converter.a', @@ -144,8 +142,6 @@ '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', '<(libchromiumcontent_dir)/libdesktop_capture.a', '<(libchromiumcontent_dir)/libdom_keycode_converter.a', @@ -212,8 +208,6 @@ '<(libchromiumcontent_dir)/base_static.lib', '<(libchromiumcontent_dir)/sandbox.lib', '<(libchromiumcontent_dir)/sandbox_helper_win.lib', - '<(libchromiumcontent_dir)/devtools_discovery.lib', - '<(libchromiumcontent_dir)/devtools_http_handler.lib', '<(libchromiumcontent_dir)/http_server.lib', '<(libchromiumcontent_dir)/desktop_capture.lib', '<(libchromiumcontent_dir)/dom_keycode_converter.lib', diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 63227c0c929..446afde7ffb 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 63227c0c9299e01809bcc705bd7346aecf8b6855 +Subproject commit 446afde7ffbd4dd2f73d4d7ae9811f093b1c017c From ce71d16fdda92b4bd74d51976a74d106b4bf1270 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 24 Jan 2017 21:12:26 +0900 Subject: [PATCH 0940/1195] Link with CoreWLAN.framework --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 30568b3a40c..b010d53ea29 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -191,6 +191,8 @@ '-lsandbox', # bluetooth.gyp: '$(SDKROOT)/System/Library/Frameworks/IOBluetooth.framework', + # components/wifi/BUILD.gn: + '$(SDKROOT)/System/Library/Frameworks/CoreWLAN.framework', ], }, }], From 94fdcb4f489c9b938679d79bf96cc39f0c984957 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 25 Jan 2017 08:43:27 +0900 Subject: [PATCH 0941/1195] WebInspector has been split up --- brightray/browser/inspectable_web_contents_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 7f18ce65d86..4f4100eb678 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -395,7 +395,7 @@ void InspectableWebContentsImpl::LoadCompleted() { base::RemoveChars(current_dock_state, "\"", &dock_state_); } base::string16 javascript = base::UTF8ToUTF16( - "WebInspector.dockController.setDockSide(\"" + dock_state_ + "\");"); + "Components.dockController.setDockSide(\"" + dock_state_ + "\");"); devtools_web_contents_->GetMainFrame()->ExecuteJavaScript(javascript); } From a749a3dd2af69f9598dc6ca679f3a04cb683477d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Jan 2017 16:09:45 +0900 Subject: [PATCH 0942/1195] Fix Debug building on Windows --- brightray/browser/views/views_delegate.cc | 4 ---- brightray/browser/views/views_delegate.h | 1 - brightray/browser/win/notification_presenter_win.cc | 2 +- brightray/vendor/libchromiumcontent | 2 +- 4 files changed, 2 insertions(+), 7 deletions(-) diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc index a18d52a6ae2..8dcbe38ae20 100644 --- a/brightray/browser/views/views_delegate.cc +++ b/brightray/browser/views/views_delegate.cc @@ -100,10 +100,6 @@ void ViewsDelegate::OnBeforeWidgetInit( } -base::TimeDelta ViewsDelegate::GetDefaultTextfieldObscuredRevealDuration() { - return base::TimeDelta(); -} - bool ViewsDelegate::WindowManagerProvidesTitleBar(bool maximized) { #if defined(OS_LINUX) // On Ubuntu Unity, the system always provides a title bar for maximized diff --git a/brightray/browser/views/views_delegate.h b/brightray/browser/views/views_delegate.h index 157660aa5d0..d63eeb533d6 100644 --- a/brightray/browser/views/views_delegate.h +++ b/brightray/browser/views/views_delegate.h @@ -51,7 +51,6 @@ class ViewsDelegate : public views::ViewsDelegate { void OnBeforeWidgetInit( views::Widget::InitParams* params, views::internal::NativeWidgetDelegate* delegate) override; - base::TimeDelta GetDefaultTextfieldObscuredRevealDuration() override; bool WindowManagerProvidesTitleBar(bool maximized) override; private: diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 107b62ea76b..018fa3212a4 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -56,7 +56,7 @@ bool NotificationPresenterWin::Init() { base::string16 NotificationPresenterWin::SaveIconToFilesystem( const SkBitmap& icon, const GURL& origin) { std::string filename = base::MD5String(origin.spec()) + ".png"; - base::FilePath path = temp_dir_.path().Append(base::UTF8ToUTF16(filename)); + base::FilePath path = temp_dir_.GetPath().Append(base::UTF8ToUTF16(filename)); if (base::PathExists(path)) return path.value(); if (SaveIconToPath(icon, path)) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 446afde7ffb..b71afafe599 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 446afde7ffbd4dd2f73d4d7ae9811f093b1c017c +Subproject commit b71afafe59998daf0cb275b50140378b8c88b101 From abececd78bc5d4aa4138b27154e9a12ee444234e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Jan 2017 19:54:24 +0900 Subject: [PATCH 0943/1195] libgtk2ui => libgtkui --- brightray/brightray.gyp | 4 ++-- brightray/browser/browser_main_parts.cc | 5 ++--- brightray/browser/linux/libnotify_notification.cc | 4 ++-- brightray/vendor/libchromiumcontent | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b010d53ea29..500662762ac 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -69,7 +69,7 @@ }, 'cflags': [ 'UpdateDeviceScaleFactor( - screen->GetPrimaryDisplay().device_scale_factor()); + views::LinuxUI::instance()->UpdateDeviceScaleFactor(); #endif #endif return 0; diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index 0fd71faaf18..ab296e21831 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -8,7 +8,7 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "browser/notification_delegate.h" -#include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" +#include "chrome/browser/ui/libgtkui/skia_utils_gtk.h" #include "common/application_info.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -111,7 +111,7 @@ void LibnotifyNotification::Show(const base::string16& title, } if (!icon.drawsNothing()) { - GdkPixbuf* pixbuf = libgtk2ui::GdkPixbufFromSkBitmap(icon); + GdkPixbuf* pixbuf = libgtkui::GdkPixbufFromSkBitmap(icon); libnotify_loader_.notify_notification_set_image_from_pixbuf( notification_, pixbuf); libnotify_loader_.notify_notification_set_timeout( diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index b71afafe599..0360b49dc59 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit b71afafe59998daf0cb275b50140378b8c88b101 +Subproject commit 0360b49dc59dcaad80bc056c9c9678273d4200e6 From 766d3c47bb7e74626e0c780e54e1ce05357201fe Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 27 Jan 2017 17:09:22 +0900 Subject: [PATCH 0944/1195] Link with ncrypt.lib on Windows --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 500662762ac..b627b66fb04 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -294,6 +294,7 @@ # net_common.gypi: 'crypt32.lib', 'dhcpcsvc.lib', + 'ncrypt.lib', 'rpcrt4.lib', 'secur32.lib', 'urlmon.lib', From 8488425e067c7223e3dae43071744119f97f4af7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 27 Jan 2017 17:11:33 +0900 Subject: [PATCH 0945/1195] Link with fontsub.lib --- brightray/brightray.gyp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index b627b66fb04..5d6459a6b98 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -301,6 +301,8 @@ 'winhttp.lib', # ui/gfx/BUILD.gn: 'dwrite.lib', + # skia/BUILD.gn: + 'fontsub.lib', ], 'DelayLoadDLLs': [ 'wtsapi32.dll', From 4afc765e280385711444c7c92f703f7ed04a8696 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 30 Jan 2017 15:28:24 +0900 Subject: [PATCH 0946/1195] Link with xcb on Linux --- brightray/brightray.gyp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 5d6459a6b98..2724510108f 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -1,7 +1,7 @@ { 'variables': { # The libraries brightray will be compiled to. - 'linux_system_libraries': 'gtk+-2.0 dbus-1 x11 xi xcursor xdamage xrandr xcomposite xext xfixes xrender xtst xscrnsaver gconf-2.0 gmodule-2.0 nss' + 'linux_system_libraries': 'gtk+-2.0 dbus-1 x11 x11-xcb xcb xi xcursor xdamage xrandr xcomposite xext xfixes xrender xtst xscrnsaver gconf-2.0 gmodule-2.0 nss' }, 'includes': [ 'filenames.gypi', From 6e2f9935feb86352bbcceedc8d9832041af6274c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 6 Feb 2017 10:11:37 +0900 Subject: [PATCH 0947/1195] Update to Chrome 56.0.2924.87 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 0360b49dc59..e0da1e9caa7 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 0360b49dc59dcaad80bc056c9c9678273d4200e6 +Subproject commit e0da1e9caa7c8f3da3519963a9ea32abba43c7c8 From 3487c90667885eddd30d2e2de0a400c7f17a1ba2 Mon Sep 17 00:00:00 2001 From: Catalin Ionut Fratila Date: Tue, 7 Feb 2017 11:21:58 +0100 Subject: [PATCH 0948/1195] Bootstrap: change working directory when doing submodule updates. --- brightray/script/bootstrap | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap index e241606c2de..29786398d72 100755 --- a/brightray/script/bootstrap +++ b/brightray/script/bootstrap @@ -58,9 +58,10 @@ def parse_args(): def update_submodules(): - return (subprocess.call(['git', 'submodule', 'sync', '--quiet']) or + return (subprocess.call(['git', 'submodule', 'sync', '--quiet'], + cwd=SOURCE_ROOT) or subprocess.call(['git', 'submodule', 'update', '--init', - '--recursive'])) + '--recursive'], cwd=SOURCE_ROOT)) def setup_libchromiumcontent(is_dev, commit, target_arch, url, From 0b76a9c073c3ec6aaf2b4fb9114cff7e0250762e Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 30 Jan 2017 17:25:46 +0530 Subject: [PATCH 0949/1195] Persist zoom levels per partition --- brightray/browser/browser_context.cc | 5 + brightray/browser/zoom_level_delegate.cc | 176 +++++++++++++++++++++++ brightray/browser/zoom_level_delegate.h | 61 ++++++++ brightray/filenames.gypi | 2 + 4 files changed, 244 insertions(+) create mode 100644 brightray/browser/zoom_level_delegate.cc create mode 100644 brightray/browser/zoom_level_delegate.h diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index a28fec5d832..e482b156f35 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -11,6 +11,7 @@ #include "browser/network_delegate.h" #include "browser/permission_manager.h" #include "browser/special_storage_policy.h" +#include "browser/zoom_level_delegate.h" #include "common/application_info.h" #include "base/files/file_path.h" @@ -123,6 +124,7 @@ void BrowserContext::InitPrefs() { void BrowserContext::RegisterInternalPrefs(PrefRegistrySimple* registry) { InspectableWebContentsImpl::RegisterPrefs(registry); MediaDeviceIDSalt::RegisterPrefs(registry); + ZoomLevelDelegate::RegisterPrefs(registry); } URLRequestContextGetter* BrowserContext::GetRequestContext() { @@ -166,6 +168,9 @@ base::FilePath BrowserContext::GetPath() const { std::unique_ptr BrowserContext::CreateZoomLevelDelegate( const base::FilePath& partition_path) { + if (!IsOffTheRecord()) { + return base::MakeUnique(prefs(), partition_path); + } return std::unique_ptr(); } diff --git a/brightray/browser/zoom_level_delegate.cc b/brightray/browser/zoom_level_delegate.cc new file mode 100644 index 00000000000..7148b18e18a --- /dev/null +++ b/brightray/browser/zoom_level_delegate.cc @@ -0,0 +1,176 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "browser/zoom_level_delegate.h" + +#include + +#include "base/bind.h" +#include "base/strings/string_number_conversions.h" +#include "base/values.h" +#include "components/prefs/json_pref_store.h" +#include "components/prefs/pref_filter.h" +#include "components/prefs/pref_registry_simple.h" +#include "components/prefs/pref_service_factory.h" +#include "components/prefs/scoped_user_pref_update.h" +#include "content/public/browser/browser_thread.h" +#include "content/public/common/page_zoom.h" + +namespace std { + +template <> +struct hash { + size_t operator()(const base::FilePath& f) const { + return hash()(f.value()); + } +}; + +} // namespace std + +namespace brightray { + +namespace { + +// Double that indicates the default zoom level. +const char kPartitionDefaultZoomLevel[] = "partition.default_zoom_level"; + +// Dictionary that maps hostnames to zoom levels. Hosts not in this pref will +// be displayed at the default zoom level. +const char kPartitionPerHostZoomLevels[] = "partition.per_host_zoom_levels"; + +std::string GetHash(const base::FilePath& partition_path) { + size_t int_key = std::hash()(partition_path); + return base::SizeTToString(int_key); +} + +} // namespace + +// static +void ZoomLevelDelegate::RegisterPrefs(PrefRegistrySimple* registry) { + registry->RegisterDictionaryPref(kPartitionDefaultZoomLevel); + registry->RegisterDictionaryPref(kPartitionPerHostZoomLevels); +} + +ZoomLevelDelegate::ZoomLevelDelegate(PrefService* pref_service, + const base::FilePath& partition_path) + : pref_service_(pref_service), host_zoom_map_(nullptr) { + DCHECK(pref_service_); + partition_key_ = GetHash(partition_path); +} + +ZoomLevelDelegate::~ZoomLevelDelegate() {} + +void ZoomLevelDelegate::SetDefaultZoomLevelPref(double level) { + if (content::ZoomValuesEqual(level, host_zoom_map_->GetDefaultZoomLevel())) + return; + + DictionaryPrefUpdate update(pref_service_, kPartitionDefaultZoomLevel); + update->SetDouble(partition_key_, level); + host_zoom_map_->SetDefaultZoomLevel(level); +} + +double ZoomLevelDelegate::GetDefaultZoomLevelPref() const { + double default_zoom_level = 0.0; + + const base::DictionaryValue* default_zoom_level_dictionary = + pref_service_->GetDictionary(kPartitionDefaultZoomLevel); + // If no default has been previously set, the default returned is the + // value used to initialize default_zoom_level in this function. + default_zoom_level_dictionary->GetDouble(partition_key_, &default_zoom_level); + return default_zoom_level; +} + +void ZoomLevelDelegate::OnZoomLevelChanged( + const content::HostZoomMap::ZoomLevelChange& change) { + if (change.mode != content::HostZoomMap::ZOOM_CHANGED_FOR_HOST) + return; + + double level = change.zoom_level; + DictionaryPrefUpdate update(pref_service_, kPartitionPerHostZoomLevels); + base::DictionaryValue* host_zoom_dictionaries = update.Get(); + DCHECK(host_zoom_dictionaries); + + bool modification_is_removal = + content::ZoomValuesEqual(level, host_zoom_map_->GetDefaultZoomLevel()); + + base::DictionaryValue* host_zoom_dictionary = nullptr; + if (!host_zoom_dictionaries->GetDictionary(partition_key_, + &host_zoom_dictionary)) { + host_zoom_dictionary = new base::DictionaryValue(); + host_zoom_dictionaries->Set(partition_key_, host_zoom_dictionary); + } + + if (modification_is_removal) + host_zoom_dictionary->RemoveWithoutPathExpansion(change.host, nullptr); + else + host_zoom_dictionary->SetDoubleWithoutPathExpansion(change.host, level); +} + +void ZoomLevelDelegate::ExtractPerHostZoomLevels( + const base::DictionaryValue* host_zoom_dictionary) { + std::vector keys_to_remove; + std::unique_ptr host_zoom_dictionary_copy = + host_zoom_dictionary->DeepCopyWithoutEmptyChildren(); + for (base::DictionaryValue::Iterator i(*host_zoom_dictionary_copy); + !i.IsAtEnd(); i.Advance()) { + const std::string& host(i.key()); + double zoom_level = 0; + + bool has_valid_zoom_level = i.value().GetAsDouble(&zoom_level); + + // Filter out A) the empty host, B) zoom levels equal to the default; and + // remember them, so that we can later erase them from Prefs. + // Values of type B could further have been stored before the default zoom + // level was set to its current value. In either case, SetZoomLevelForHost + // will ignore type B values, thus, to have consistency with HostZoomMap's + // internal state, these values must also be removed from Prefs. + if (host.empty() || !has_valid_zoom_level || + content::ZoomValuesEqual(zoom_level, + host_zoom_map_->GetDefaultZoomLevel())) { + keys_to_remove.push_back(host); + continue; + } + + host_zoom_map_->SetZoomLevelForHost(host, zoom_level); + } + + // Sanitize prefs to remove entries that match the default zoom level and/or + // have an empty host. + { + DictionaryPrefUpdate update(pref_service_, kPartitionPerHostZoomLevels); + base::DictionaryValue* host_zoom_dictionaries = update.Get(); + base::DictionaryValue* sanitized_host_zoom_dictionary = nullptr; + host_zoom_dictionaries->GetDictionary(partition_key_, + &sanitized_host_zoom_dictionary); + for (const std::string& s : keys_to_remove) + sanitized_host_zoom_dictionary->RemoveWithoutPathExpansion(s, nullptr); + } +} + +void ZoomLevelDelegate::InitHostZoomMap(content::HostZoomMap* host_zoom_map) { + // This init function must be called only once. + DCHECK(!host_zoom_map_); + DCHECK(host_zoom_map); + host_zoom_map_ = host_zoom_map; + + // Initialize the default zoom level. + host_zoom_map_->SetDefaultZoomLevel(GetDefaultZoomLevelPref()); + + // Initialize the HostZoomMap with per-host zoom levels from the persisted + // zoom-level preference values. + const base::DictionaryValue* host_zoom_dictionaries = + pref_service_->GetDictionary(kPartitionPerHostZoomLevels); + const base::DictionaryValue* host_zoom_dictionary = nullptr; + if (host_zoom_dictionaries->GetDictionary(partition_key_, + &host_zoom_dictionary)) { + // Since we're calling this before setting up zoom_subscription_ below we + // don't need to worry that host_zoom_dictionary is indirectly affected + // by calls to HostZoomMap::SetZoomLevelForHost(). + ExtractPerHostZoomLevels(host_zoom_dictionary); + } + zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind( + &ZoomLevelDelegate::OnZoomLevelChanged, base::Unretained(this))); +} + +} // namespace brightray diff --git a/brightray/browser/zoom_level_delegate.h b/brightray/browser/zoom_level_delegate.h new file mode 100644 index 00000000000..aed065d7ec6 --- /dev/null +++ b/brightray/browser/zoom_level_delegate.h @@ -0,0 +1,61 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef BRIGHTRAY_BROWSER_ZOOM_LEVEL_DELEGATE_H_ +#define BRIGHTRAY_BROWSER_ZOOM_LEVEL_DELEGATE_H_ + +#include "base/files/file_path.h" +#include "base/macros.h" +#include "components/prefs/pref_service.h" +#include "content/public/browser/host_zoom_map.h" +#include "content/public/browser/zoom_level_delegate.h" + +namespace base { +class DictionaryValue; +} + +class PrefRegistrySimple; + +namespace brightray { + +// A class to manage per-partition default and per-host zoom levels. +// It implements an interface between the content/ zoom +// levels in HostZoomMap and preference system. All changes +// to the per-partition default zoom levels flow through this +// class. Any changes to per-host levels are updated when HostZoomMap calls +// OnZoomLevelChanged. +class ZoomLevelDelegate : public content::ZoomLevelDelegate { + public: + static void RegisterPrefs(PrefRegistrySimple* pref_registry); + + ZoomLevelDelegate(PrefService* pref_service, + const base::FilePath& partition_path); + ~ZoomLevelDelegate() override; + + void SetDefaultZoomLevelPref(double level); + double GetDefaultZoomLevelPref() const; + + // content::ZoomLevelDelegate: + void InitHostZoomMap(content::HostZoomMap* host_zoom_map) override; + + private: + void ExtractPerHostZoomLevels( + const base::DictionaryValue* host_zoom_dictionary); + + // This is a callback function that receives notifications from HostZoomMap + // when per-host zoom levels change. It is used to update the per-host + // zoom levels (if any) managed by this class (for its associated partition). + void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& change); + + PrefService* pref_service_; + content::HostZoomMap* host_zoom_map_; + std::unique_ptr zoom_subscription_; + std::string partition_key_; + + DISALLOW_COPY_AND_ASSIGN(ZoomLevelDelegate); +}; + +} // namespace brightray + +#endif // BRIGHTRAY_BROWSER_ZOOM_LEVEL_DELEGATE_H_ diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index 7b2db49869d..a0858ea926c 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -100,6 +100,8 @@ 'browser/views/views_delegate.h', 'browser/web_ui_controller_factory.cc', 'browser/web_ui_controller_factory.h', + 'browser/zoom_level_delegate.cc', + 'browser/zoom_level_delegate.h', 'common/application_info.h', 'common/application_info_mac.mm', 'common/application_info_win.cc', From 4ed9f6398974bf2714084b9be65f81776c333906 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 10 Feb 2017 09:27:50 -0800 Subject: [PATCH 0950/1195] Cleanly shutdown browser context --- brightray/browser/browser_context.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index e482b156f35..2a17e327453 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -102,6 +102,8 @@ BrowserContext::BrowserContext(const std::string& partition, bool in_memory) } BrowserContext::~BrowserContext() { + NotifyWillBeDestroyed(this); + ShutdownStoragePartitions(); BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, resource_context_.release()); From 2b4948d6aa1b186974d5345e53179bd0c752a09b Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 17 Jan 2017 20:25:28 +0530 Subject: [PATCH 0951/1195] load pdf resource pak file --- brightray/common/main_delegate.cc | 13 ++++++------- brightray/common/main_delegate.h | 2 +- brightray/common/main_delegate_mac.mm | 13 +++++++++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 69719ba3b9d..f14415e681d 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -49,18 +49,17 @@ void InitializeResourceBundle(const std::string& locale) { locale, nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); // Load other resource files. - base::FilePath path; #if defined(OS_MACOSX) - path = GetResourcesPakFilePath(); + LoadCommonResources(); #else - base::FilePath pak_dir; + base::FilePath path, pak_dir; + ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); PathService::Get(base::DIR_MODULE, &pak_dir); path = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); -#endif - - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); bundle.AddDataPackFromPath(path, ui::GetSupportedScaleFactors()[0]); -#if !defined(OS_MACOSX) + bundle.AddDataPackFromPath( + pak_dir.Append(FILE_PATH_LITERAL("pdf_viewer_resources.pak")), + ui::GetSupportedScaleFactors()[0]); bundle.AddDataPackFromPath( pak_dir.Append(FILE_PATH_LITERAL("blink_image_resources_200_percent.pak")), ui::SCALE_FACTOR_200P); diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h index 058e553903c..2f63a2fb1b1 100644 --- a/brightray/common/main_delegate.h +++ b/brightray/common/main_delegate.h @@ -24,7 +24,7 @@ class BrowserClient; class ContentClient; void InitializeResourceBundle(const std::string& locale); -base::FilePath GetResourcesPakFilePath(); +void LoadCommonResources(); class MainDelegate : public content::ContentMainDelegate { public: diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index 464cf68b50f..191b39ff6a1 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -16,6 +16,7 @@ #include "base/strings/sys_string_conversions.h" #include "content/public/common/content_paths.h" #include "content/public/common/content_switches.h" +#include "ui/base/resource/resource_bundle.h" namespace brightray { @@ -27,11 +28,19 @@ base::FilePath GetFrameworksPath() { } -base::FilePath GetResourcesPakFilePath() { - auto path = [base::mac::FrameworkBundle() pathForResource:@"content_shell" ofType:@"pak"]; +base::FilePath GetResourcesPakFilePath(NSString* name) { + auto path = [base::mac::FrameworkBundle() pathForResource:name ofType:@"pak"]; return base::mac::NSStringToFilePath(path); } +void LoadCommonResources() { + ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); + bundle.AddDataPackFromPath(GetResourcesPakFilePath(@"content_shell"), + ui::GetSupportedScaleFactors()[0]); + bundle.AddDataPackFromPath(GetResourcesPakFilePath(@"pdf_viewer_resources"), + ui::GetSupportedScaleFactors()[0]); +} + void MainDelegate::OverrideFrameworkBundlePath() { base::FilePath helper_path = GetFrameworksPath().Append(GetApplicationName() + " Framework.framework"); From 5e842b1112442827f4525c34b33e240911e9dc2a Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 18 Jan 2017 13:02:16 +0530 Subject: [PATCH 0952/1195] link necessary pdf libraries --- brightray/brightray.gyp | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 2724510108f..bf011d8c951 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -99,6 +99,28 @@ '<(libchromiumcontent_dir)/libyuv.a', '<(libchromiumcontent_dir)/librenderer.a', '<(libchromiumcontent_dir)/libsecurity_state.a', + # Friends of libpdf.a: + '<(libchromiumcontent_dir)/libpdf.a', + '<(libchromiumcontent_dir)/libppapi_cpp_objects.a', + '<(libchromiumcontent_dir)/libppapi_internal_module.a', + '<(libchromiumcontent_dir)/liblibjpeg.a', + '<(libchromiumcontent_dir)/libpdfium.a', + '<(libchromiumcontent_dir)/libfdrm.a', + '<(libchromiumcontent_dir)/libformfiller.a', + '<(libchromiumcontent_dir)/libfpdfapi.a', + '<(libchromiumcontent_dir)/libfpdfdoc.a', + '<(libchromiumcontent_dir)/libfpdftext.a', + '<(libchromiumcontent_dir)/libfxcodec.a', + '<(libchromiumcontent_dir)/libfxcrt.a', + '<(libchromiumcontent_dir)/libfxedit.a', + '<(libchromiumcontent_dir)/libfxge.a', + '<(libchromiumcontent_dir)/libfxjs.a', + '<(libchromiumcontent_dir)/libjavascript.a', + '<(libchromiumcontent_dir)/libpdfwindow.a', + '<(libchromiumcontent_dir)/libfx_agg.a', + '<(libchromiumcontent_dir)/libfx_lcms2.a', + '<(libchromiumcontent_dir)/libfx_libopenjpeg.a', + '<(libchromiumcontent_dir)/libfx_zlib.a', ], }, }, { @@ -152,6 +174,28 @@ '<(libchromiumcontent_dir)/libyuv.a', '<(libchromiumcontent_dir)/librenderer.a', '<(libchromiumcontent_dir)/libsecurity_state.a', + # Friends of libpdf.a: + '<(libchromiumcontent_dir)/libpdf.a', + '<(libchromiumcontent_dir)/libppapi_cpp_objects.a', + '<(libchromiumcontent_dir)/libppapi_internal_module.a', + '<(libchromiumcontent_dir)/liblibjpeg.a', + '<(libchromiumcontent_dir)/libpdfium.a', + '<(libchromiumcontent_dir)/libfdrm.a', + '<(libchromiumcontent_dir)/libformfiller.a', + '<(libchromiumcontent_dir)/libfpdfapi.a', + '<(libchromiumcontent_dir)/libfpdfdoc.a', + '<(libchromiumcontent_dir)/libfpdftext.a', + '<(libchromiumcontent_dir)/libfxcodec.a', + '<(libchromiumcontent_dir)/libfxcrt.a', + '<(libchromiumcontent_dir)/libfxedit.a', + '<(libchromiumcontent_dir)/libfxge.a', + '<(libchromiumcontent_dir)/libfxjs.a', + '<(libchromiumcontent_dir)/libjavascript.a', + '<(libchromiumcontent_dir)/libpdfwindow.a', + '<(libchromiumcontent_dir)/libfx_agg.a', + '<(libchromiumcontent_dir)/libfx_lcms2.a', + '<(libchromiumcontent_dir)/libfx_libopenjpeg.a', + '<(libchromiumcontent_dir)/libfx_zlib.a', ], }, }, { From 7700884ebc0d3a468bdb7a3e4db4e775fd70ff40 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 18 Jan 2017 13:13:20 +0530 Subject: [PATCH 0953/1195] link pdf libraries on linux with whole-archive option --- brightray/brightray.gyp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index bf011d8c951..66eea978927 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -100,10 +100,11 @@ '<(libchromiumcontent_dir)/librenderer.a', '<(libchromiumcontent_dir)/libsecurity_state.a', # Friends of libpdf.a: + '-Wl,--whole-archive', '<(libchromiumcontent_dir)/libpdf.a', '<(libchromiumcontent_dir)/libppapi_cpp_objects.a', '<(libchromiumcontent_dir)/libppapi_internal_module.a', - '<(libchromiumcontent_dir)/liblibjpeg.a', + '<(libchromiumcontent_dir)/libjpeg.a', '<(libchromiumcontent_dir)/libpdfium.a', '<(libchromiumcontent_dir)/libfdrm.a', '<(libchromiumcontent_dir)/libformfiller.a', @@ -121,6 +122,7 @@ '<(libchromiumcontent_dir)/libfx_lcms2.a', '<(libchromiumcontent_dir)/libfx_libopenjpeg.a', '<(libchromiumcontent_dir)/libfx_zlib.a', + '-Wl,--no-whole-archive', ], }, }, { @@ -178,7 +180,7 @@ '<(libchromiumcontent_dir)/libpdf.a', '<(libchromiumcontent_dir)/libppapi_cpp_objects.a', '<(libchromiumcontent_dir)/libppapi_internal_module.a', - '<(libchromiumcontent_dir)/liblibjpeg.a', + '<(libchromiumcontent_dir)/libjpeg.a', '<(libchromiumcontent_dir)/libpdfium.a', '<(libchromiumcontent_dir)/libfdrm.a', '<(libchromiumcontent_dir)/libformfiller.a', From 26081d5a11360934e44d4edf8c6f35cb043c5af5 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Wed, 1 Feb 2017 15:05:53 +0100 Subject: [PATCH 0954/1195] Link libfx_freetype.a on Mac OS. --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 66eea978927..19d92f76d15 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -195,6 +195,7 @@ '<(libchromiumcontent_dir)/libjavascript.a', '<(libchromiumcontent_dir)/libpdfwindow.a', '<(libchromiumcontent_dir)/libfx_agg.a', + '<(libchromiumcontent_dir)/libfx_freetype.a', '<(libchromiumcontent_dir)/libfx_lcms2.a', '<(libchromiumcontent_dir)/libfx_libopenjpeg.a', '<(libchromiumcontent_dir)/libfx_zlib.a', From 80de70bf6690e26c659d56f6772235756aac018d Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 1 Feb 2017 20:25:33 +0530 Subject: [PATCH 0955/1195] address review comments --- brightray/brightray.gyp | 3 +++ brightray/common/main_delegate.cc | 7 ++++--- brightray/common/main_delegate_mac.mm | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 19d92f76d15..10a25191d12 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -100,6 +100,9 @@ '<(libchromiumcontent_dir)/librenderer.a', '<(libchromiumcontent_dir)/libsecurity_state.a', # Friends of libpdf.a: + # On Linux we have to use "--whole-archive" to include + # all symbols, otherwise there will be plenty of + # unresolved symbols errors. '-Wl,--whole-archive', '<(libchromiumcontent_dir)/libpdf.a', '<(libchromiumcontent_dir)/libppapi_cpp_objects.a', diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index f14415e681d..3645f53f478 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -52,11 +52,12 @@ void InitializeResourceBundle(const std::string& locale) { #if defined(OS_MACOSX) LoadCommonResources(); #else - base::FilePath path, pak_dir; + base::FilePath pak_dir; ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); PathService::Get(base::DIR_MODULE, &pak_dir); - path = pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")); - bundle.AddDataPackFromPath(path, ui::GetSupportedScaleFactors()[0]); + bundle.AddDataPackFromPath( + pak_dir.Append(FILE_PATH_LITERAL("content_shell.pak")), + ui::GetSupportedScaleFactors()[0]); bundle.AddDataPackFromPath( pak_dir.Append(FILE_PATH_LITERAL("pdf_viewer_resources.pak")), ui::GetSupportedScaleFactors()[0]); diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm index 191b39ff6a1..29040840ce3 100644 --- a/brightray/common/main_delegate_mac.mm +++ b/brightray/common/main_delegate_mac.mm @@ -26,13 +26,13 @@ base::FilePath GetFrameworksPath() { return MainApplicationBundlePath().Append("Contents").Append("Frameworks"); } -} - base::FilePath GetResourcesPakFilePath(NSString* name) { auto path = [base::mac::FrameworkBundle() pathForResource:name ofType:@"pak"]; return base::mac::NSStringToFilePath(path); } +} // namespace + void LoadCommonResources() { ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); bundle.AddDataPackFromPath(GetResourcesPakFilePath(@"content_shell"), @@ -56,4 +56,4 @@ void MainDelegate::OverrideChildProcessPath() { PathService::Override(content::CHILD_PROCESS_EXE, helper_path); } -} +} // namespace brightray From 9a321d2479373f38deb9e02b95b8da799e5f1613 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 9 Feb 2017 16:38:11 +0530 Subject: [PATCH 0956/1195] dont link libfxcrt.a on linux It causes multiple definition error --- brightray/brightray.gyp | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 10a25191d12..e60d17a1585 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -115,7 +115,6 @@ '<(libchromiumcontent_dir)/libfpdfdoc.a', '<(libchromiumcontent_dir)/libfpdftext.a', '<(libchromiumcontent_dir)/libfxcodec.a', - '<(libchromiumcontent_dir)/libfxcrt.a', '<(libchromiumcontent_dir)/libfxedit.a', '<(libchromiumcontent_dir)/libfxge.a', '<(libchromiumcontent_dir)/libfxjs.a', From 07c4f3563ecf15bb16857b776182d17faee46908 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Tue, 14 Mar 2017 21:04:29 +0530 Subject: [PATCH 0957/1195] close devtools web contents when available to trigger cleanup --- brightray/browser/inspectable_web_contents_impl.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 4f4100eb678..f95cc091c23 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -235,6 +235,8 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( } InspectableWebContentsImpl::~InspectableWebContentsImpl() { + if (devtools_web_contents_) + devtools_web_contents_->Close(); Observe(nullptr); } From 1499ba83d95967c028910c8cb6b392c6cbe50752 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 17 Mar 2017 09:11:28 -0700 Subject: [PATCH 0958/1195] Upgrade libcc to latest --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index e0da1e9caa7..44448acf6a2 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit e0da1e9caa7c8f3da3519963a9ea32abba43c7c8 +Subproject commit 44448acf6a21024b9adb7140ffef6402a509f8bf From 8877d78e797e0703d20e08f9a83ea31833f840a7 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 17 Mar 2017 09:35:01 -0700 Subject: [PATCH 0959/1195] Revert "close devtools web contents when available to trigger cleanup" --- brightray/browser/inspectable_web_contents_impl.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index f95cc091c23..4f4100eb678 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -235,8 +235,6 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( } InspectableWebContentsImpl::~InspectableWebContentsImpl() { - if (devtools_web_contents_) - devtools_web_contents_->Close(); Observe(nullptr); } From 99fd1394e4d3f5bccabf13ad7ca8aa791633c8f1 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Sun, 19 Mar 2017 01:25:22 +0530 Subject: [PATCH 0960/1195] Revert "Revert "close devtools web contents when available to trigger cleanup"" This reverts commit 7f01bf4e73c188db2406ded1286b661c61c78bba. --- brightray/browser/inspectable_web_contents_impl.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 4f4100eb678..f95cc091c23 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -235,6 +235,8 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( } InspectableWebContentsImpl::~InspectableWebContentsImpl() { + if (devtools_web_contents_) + devtools_web_contents_->Close(); Observe(nullptr); } From f7935b429a71f0cd23ced7fac7f3bf4c24eb24e6 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 17:12:25 +0900 Subject: [PATCH 0961/1195] Add WebContentsPreferences::IsNativeWindowOpenEnabled --- atom/browser/web_contents_preferences.cc | 15 +++++++++++++++ atom/browser/web_contents_preferences.h | 1 + 2 files changed, 16 insertions(+) diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index c6527dd6f6d..8346d664170 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -208,6 +208,21 @@ bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) { return sandboxed; } +bool WebContentsPreferences::IsNativeWindowOpenEnabled(content::WebContents* web_contents) { + WebContentsPreferences* self; + if (!web_contents) + return false; + + self = FromWebContents(web_contents); + if (!self) + return false; + + base::DictionaryValue& web_preferences = self->web_preferences_; + bool use = false; + web_preferences.GetBoolean("nativeWindowOpen", &use); + return use; +} + // static void WebContentsPreferences::OverrideWebkitPrefs( content::WebContents* web_contents, content::WebPreferences* prefs) { diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index f6e44c51b10..37a88dd552f 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -38,6 +38,7 @@ class WebContentsPreferences content::WebContents* web_contents, base::CommandLine* command_line); static bool IsSandboxed(content::WebContents* web_contents); + static bool IsNativeWindowOpenEnabled(content::WebContents* web_contents); // Modify the WebPreferences according to |web_contents|'s preferences. static void OverrideWebkitPrefs( From 054ba7a964f86ee17a3feae9377a20e16652438e Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 17:25:45 +0900 Subject: [PATCH 0962/1195] Add AtomBrowserClient::IsRendererUsesNativeWindowOpen --- atom/browser/atom_browser_client.cc | 36 ++++++++++++++++++----------- atom/browser/atom_browser_client.h | 16 ++++++++----- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index d0bbf4ad535..7de71cc7fce 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -109,19 +109,26 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( content::SiteInstance::GetSiteForURL(browser_context, url) != src_url; } -void AtomBrowserClient::AddSandboxedRendererId(int process_id) { - base::AutoLock auto_lock(sandboxed_renderers_lock_); - sandboxed_renderers_.insert(process_id); +void AtomBrowserClient::AddProcessPreferences(int process_id, AtomBrowserClient::ProcessPreferences prefs) { + base::AutoLock auto_lock(process_preferences_lock_); + process_preferences_[process_id] = prefs; } -void AtomBrowserClient::RemoveSandboxedRendererId(int process_id) { - base::AutoLock auto_lock(sandboxed_renderers_lock_); - sandboxed_renderers_.erase(process_id); +void AtomBrowserClient::RemoveProcessPreferences(int process_id) { + base::AutoLock auto_lock(process_preferences_lock_); + process_preferences_.erase(process_id); } bool AtomBrowserClient::IsRendererSandboxed(int process_id) { - base::AutoLock auto_lock(sandboxed_renderers_lock_); - return sandboxed_renderers_.count(process_id); + base::AutoLock auto_lock(process_preferences_lock_); + auto it = process_preferences_.find(process_id); + return it != process_preferences_.end() && it->second.sandbox; +} + +bool AtomBrowserClient::IsRendererUsesNativeWindowOpen(int process_id) { + base::AutoLock auto_lock(process_preferences_lock_); + auto it = process_preferences_.find(process_id); + return it != process_preferences_.end() && it->second.native_window_open; } void AtomBrowserClient::RenderProcessWillLaunch( @@ -133,11 +140,12 @@ void AtomBrowserClient::RenderProcessWillLaunch( new WidevineCdmMessageFilter(process_id, host->GetBrowserContext())); content::WebContents* web_contents = GetWebContentsFromProcessID(process_id); - if (WebContentsPreferences::IsSandboxed(web_contents)) { - AddSandboxedRendererId(host->GetID()); - // ensure the sandboxed renderer id is removed later - host->AddObserver(this); - } + ProcessPreferences process_prefs; + process_prefs.sandbox = WebContentsPreferences::IsSandboxed(web_contents); + process_prefs.native_window_open = WebContentsPreferences::IsNativeWindowOpenEnabled(web_contents); + AddProcessPreferences(host->GetID(), process_prefs); + // ensure the ProcessPreferences is removed later + host->AddObserver(this); } content::SpeechRecognitionManagerDelegate* @@ -375,7 +383,7 @@ void AtomBrowserClient::RenderProcessHostDestroyed( break; } } - RemoveSandboxedRendererId(process_id); + RemoveProcessPreferences(process_id); } } // namespace atom diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index c2a7d5edd0f..6ceb49a99c8 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -114,16 +114,20 @@ class AtomBrowserClient : public brightray::BrowserClient, bool ShouldCreateNewSiteInstance(content::BrowserContext* browser_context, content::SiteInstance* current_instance, const GURL& dest_url); - // Add/remove a process id to `sandboxed_renderers_`. - void AddSandboxedRendererId(int process_id); - void RemoveSandboxedRendererId(int process_id); + struct ProcessPreferences { + bool sandbox; + bool native_window_open; + }; + void AddProcessPreferences(int process_id, ProcessPreferences prefs); + void RemoveProcessPreferences(int process_id); bool IsRendererSandboxed(int process_id); + bool IsRendererUsesNativeWindowOpen(int process_id); // pending_render_process => current_render_process. std::map pending_processes_; - // Set that contains the process ids of all sandboxed renderers - std::set sandboxed_renderers_; - base::Lock sandboxed_renderers_lock_; + + std::map process_preferences_; + base::Lock process_preferences_lock_; std::unique_ptr resource_dispatcher_host_delegate_; From a1f9a45276e15f96d89869a3dbb73028e5e9ac21 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 17:41:20 +0900 Subject: [PATCH 0963/1195] Use native window.open implementation --- atom/browser/atom_browser_client.cc | 2 +- atom/browser/web_contents_preferences.cc | 4 +++- atom/browser/web_contents_preferences.h | 2 +- atom/common/options_switches.cc | 1 + atom/common/options_switches.h | 1 + lib/renderer/override.js | 3 ++- lib/renderer/window-setup.js | 24 +++++++++++++----------- 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 7de71cc7fce..79787d26fee 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -142,7 +142,7 @@ void AtomBrowserClient::RenderProcessWillLaunch( content::WebContents* web_contents = GetWebContentsFromProcessID(process_id); ProcessPreferences process_prefs; process_prefs.sandbox = WebContentsPreferences::IsSandboxed(web_contents); - process_prefs.native_window_open = WebContentsPreferences::IsNativeWindowOpenEnabled(web_contents); + process_prefs.native_window_open = WebContentsPreferences::UsesNativeWindowOpen(web_contents); AddProcessPreferences(host->GetID(), process_prefs); // ensure the ProcessPreferences is removed later host->AddObserver(this); diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 8346d664170..55067334715 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -102,6 +102,8 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( // integration. if (IsSandboxed(web_contents)) command_line->AppendSwitch(switches::kEnableSandbox); + if (UsesNativeWindowOpen(web_contents)) + command_line->AppendSwitch(switches::kNativeWindowOpen); // The preload script. base::FilePath::StringType preload; @@ -208,7 +210,7 @@ bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) { return sandboxed; } -bool WebContentsPreferences::IsNativeWindowOpenEnabled(content::WebContents* web_contents) { +bool WebContentsPreferences::UsesNativeWindowOpen(content::WebContents* web_contents) { WebContentsPreferences* self; if (!web_contents) return false; diff --git a/atom/browser/web_contents_preferences.h b/atom/browser/web_contents_preferences.h index 37a88dd552f..f046cdfc99a 100644 --- a/atom/browser/web_contents_preferences.h +++ b/atom/browser/web_contents_preferences.h @@ -38,7 +38,7 @@ class WebContentsPreferences content::WebContents* web_contents, base::CommandLine* command_line); static bool IsSandboxed(content::WebContents* web_contents); - static bool IsNativeWindowOpenEnabled(content::WebContents* web_contents); + static bool UsesNativeWindowOpen(content::WebContents* web_contents); // Modify the WebPreferences according to |web_contents|'s preferences. static void OverrideWebkitPrefs( diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 6db479ceb75..b0099a42550 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -163,6 +163,7 @@ const char kGuestInstanceID[] = "guest-instance-id"; const char kOpenerID[] = "opener-id"; const char kScrollBounce[] = "scroll-bounce"; const char kHiddenPage[] = "hidden-page"; +const char kNativeWindowOpen[] = "native-window-open"; // Widevine options // Path to Widevine CDM binaries. diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index abe3856cd87..8d0de3d372f 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -89,6 +89,7 @@ extern const char kGuestInstanceID[]; extern const char kOpenerID[]; extern const char kScrollBounce[]; extern const char kHiddenPage[]; +extern const char kNativeWindowOpen[]; extern const char kWidevineCdmPath[]; extern const char kWidevineCdmVersion[]; diff --git a/lib/renderer/override.js b/lib/renderer/override.js index f31e9c0e8cd..fdeb6605a5c 100644 --- a/lib/renderer/override.js +++ b/lib/renderer/override.js @@ -4,5 +4,6 @@ const {ipcRenderer} = require('electron') const {guestInstanceId, openerId} = process const hiddenPage = process.argv.includes('--hidden-page') +const usesNativeWindowOpen = process.argv.includes('--native-window-open') -require('./window-setup')(ipcRenderer, guestInstanceId, openerId, hiddenPage) +require('./window-setup')(ipcRenderer, guestInstanceId, openerId, hiddenPage, usesNativeWindowOpen) diff --git a/lib/renderer/window-setup.js b/lib/renderer/window-setup.js index 21f0741a22a..510c46e3e0a 100644 --- a/lib/renderer/window-setup.js +++ b/lib/renderer/window-setup.js @@ -99,7 +99,7 @@ const getHistoryOperation = function (ipcRenderer, ...args) { return ipcRenderer.sendSync('ELECTRON_SYNC_NAVIGATION_CONTROLLER', ...args) } -module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage) => { +module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage, usesNativeWindowOpen) => { if (guestInstanceId == null) { // Override default window.close. window.close = function () { @@ -107,16 +107,18 @@ module.exports = (ipcRenderer, guestInstanceId, openerId, hiddenPage) => { } } - // Make the browser window or guest view emit "new-window" event. - window.open = function (url, frameName, features) { - if (url != null && url !== '') { - url = resolveURL(url) - } - const guestId = ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, features) - if (guestId != null) { - return getOrCreateProxy(ipcRenderer, guestId) - } else { - return null + if (!usesNativeWindowOpen) { + // Make the browser window or guest view emit "new-window" event. + window.open = function (url, frameName, features) { + if (url != null && url !== '') { + url = resolveURL(url) + } + const guestId = ipcRenderer.sendSync('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, features) + if (guestId != null) { + return getOrCreateProxy(ipcRenderer, guestId) + } else { + return null + } } } From 2c7343293a8489fd067ff0e12b1b71a6b0546c94 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 17:47:26 +0900 Subject: [PATCH 0964/1195] Allow window.open on native-window-open enabled --- atom/browser/atom_browser_client.cc | 7 ++++--- atom/browser/atom_browser_client.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 79787d26fee..3515fa32412 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -95,7 +95,8 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( // "javacript:" scheme should always use same SiteInstance return false; - if (!IsRendererSandboxed(current_instance->GetProcess()->GetID())) + int process_id = current_instance->GetProcess()->GetID(); + if (!(IsRendererSandboxed(process_id) || RendererUsesNativeWindowOpen(process_id))) // non-sandboxed renderers should always create a new SiteInstance return true; @@ -125,7 +126,7 @@ bool AtomBrowserClient::IsRendererSandboxed(int process_id) { return it != process_preferences_.end() && it->second.sandbox; } -bool AtomBrowserClient::IsRendererUsesNativeWindowOpen(int process_id) { +bool AtomBrowserClient::RendererUsesNativeWindowOpen(int process_id) { base::AutoLock auto_lock(process_preferences_lock_); auto it = process_preferences_.find(process_id); return it != process_preferences_.end() && it->second.native_window_open; @@ -318,7 +319,7 @@ bool AtomBrowserClient::CanCreateWindow( bool* no_javascript_access) { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - if (IsRendererSandboxed(render_process_id)) { + if (IsRendererSandboxed(render_process_id) || RendererUsesNativeWindowOpen(render_process_id)) { *no_javascript_access = false; return true; } diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index 6ceb49a99c8..f60e72bc612 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -121,7 +121,7 @@ class AtomBrowserClient : public brightray::BrowserClient, void AddProcessPreferences(int process_id, ProcessPreferences prefs); void RemoveProcessPreferences(int process_id); bool IsRendererSandboxed(int process_id); - bool IsRendererUsesNativeWindowOpen(int process_id); + bool RendererUsesNativeWindowOpen(int process_id); // pending_render_process => current_render_process. std::map pending_processes_; From 319a7759d0610eb507e4e5a5544c922625645ac7 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 17:52:39 +0900 Subject: [PATCH 0965/1195] Fix ELECTRON_GUEST_WINDOW_MANAGER_INTERNAL_WINDOW_OPEN handler --- lib/browser/guest-window-manager.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index e5bfa741238..f6e43c33b8c 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -242,12 +242,16 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_INTERNAL_WINDOW_OPEN', function (event disposition, options, additionalFeatures, postData) { options = mergeBrowserWindowOptions(event.sender, options) - event.sender.emit('new-window', event, url, frameName, disposition, options, additionalFeatures) - const newGuest = event.newGuest - if ((event.sender.isGuest() && !event.sender.allowPopups) || event.defaultPrevented) { + const newWindowEvent = { + preventDefault: () => newWindowEvent.defaultPrevented = true + } + event.sender.emit('new-window', newWindowEvent, url, frameName, disposition, options, additionalFeatures) + const newGuest = newWindowEvent.newGuest + if ((event.sender.isGuest() && !event.sender.allowPopups) || newWindowEvent.defaultPrevented) { if (newGuest !== undefined && newGuest !== null) { event.returnValue = setupGuest(event.sender, frameName, newGuest, options) } else { + event.preventDefault() event.returnValue = null } } else { From 6bbfe89f96bc418bd7cd26d4168763df123ec94e Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 18:11:20 +0900 Subject: [PATCH 0966/1195] Add spec for useNativeWindowOpen --- spec/api-browser-window-spec.js | 17 +++++++++++++++++ spec/fixtures/api/native-window-open.html | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 spec/fixtures/api/native-window-open.html diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index b5985e4b740..69f9c78d52b 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1069,6 +1069,23 @@ describe('BrowserWindow module', function () { w.loadURL('file://' + path.join(fixtures, 'pages', 'window-open.html')) }) }) + + describe('useNativeWindowOpen option', () => { + it('allows synchronous access to window opened by window.open()', (done) => { + ipcMain.once('answer', function (event, content) { + assert.equal(content, 'Hello') + done() + }) + w.destroy() + w = new BrowserWindow({ + show: false, + webPreferences: { + nativeWindowOpen: true + } + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html')) + }) + }) }) describe('beforeunload handler', function () { diff --git a/spec/fixtures/api/native-window-open.html b/spec/fixtures/api/native-window-open.html new file mode 100644 index 00000000000..630c4faa41b --- /dev/null +++ b/spec/fixtures/api/native-window-open.html @@ -0,0 +1,11 @@ + + + + + From 076427673e5b2126668defe51a0a68824cc043ac Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 18:20:10 +0900 Subject: [PATCH 0967/1195] Fix JavaScript style --- lib/browser/guest-window-manager.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index f6e43c33b8c..c75e3388239 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -243,7 +243,9 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_INTERNAL_WINDOW_OPEN', function (event additionalFeatures, postData) { options = mergeBrowserWindowOptions(event.sender, options) const newWindowEvent = { - preventDefault: () => newWindowEvent.defaultPrevented = true + preventDefault: function () { + this.defaultPrevented = true + } } event.sender.emit('new-window', newWindowEvent, url, frameName, disposition, options, additionalFeatures) const newGuest = newWindowEvent.newGuest From f3ce93f1bb1ac38aa68d0d2673a5502bafde043e Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 18:24:05 +0900 Subject: [PATCH 0968/1195] Fix C++ style --- atom/browser/atom_browser_client.cc | 12 ++++++++---- atom/browser/web_contents_preferences.cc | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 3515fa32412..d06f27b9c27 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -96,7 +96,8 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( return false; int process_id = current_instance->GetProcess()->GetID(); - if (!(IsRendererSandboxed(process_id) || RendererUsesNativeWindowOpen(process_id))) + if (!(IsRendererSandboxed(process_id) + || RendererUsesNativeWindowOpen(process_id))) // non-sandboxed renderers should always create a new SiteInstance return true; @@ -110,7 +111,8 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( content::SiteInstance::GetSiteForURL(browser_context, url) != src_url; } -void AtomBrowserClient::AddProcessPreferences(int process_id, AtomBrowserClient::ProcessPreferences prefs) { +void AtomBrowserClient::AddProcessPreferences( + int process_id, AtomBrowserClient::ProcessPreferences prefs) { base::AutoLock auto_lock(process_preferences_lock_); process_preferences_[process_id] = prefs; } @@ -143,7 +145,8 @@ void AtomBrowserClient::RenderProcessWillLaunch( content::WebContents* web_contents = GetWebContentsFromProcessID(process_id); ProcessPreferences process_prefs; process_prefs.sandbox = WebContentsPreferences::IsSandboxed(web_contents); - process_prefs.native_window_open = WebContentsPreferences::UsesNativeWindowOpen(web_contents); + process_prefs.native_window_open + = WebContentsPreferences::UsesNativeWindowOpen(web_contents); AddProcessPreferences(host->GetID(), process_prefs); // ensure the ProcessPreferences is removed later host->AddObserver(this); @@ -319,7 +322,8 @@ bool AtomBrowserClient::CanCreateWindow( bool* no_javascript_access) { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - if (IsRendererSandboxed(render_process_id) || RendererUsesNativeWindowOpen(render_process_id)) { + if (IsRendererSandboxed(render_process_id) + || RendererUsesNativeWindowOpen(render_process_id)) { *no_javascript_access = false; return true; } diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 55067334715..ab72114e2be 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -210,7 +210,8 @@ bool WebContentsPreferences::IsSandboxed(content::WebContents* web_contents) { return sandboxed; } -bool WebContentsPreferences::UsesNativeWindowOpen(content::WebContents* web_contents) { +bool WebContentsPreferences::UsesNativeWindowOpen( + content::WebContents* web_contents) { WebContentsPreferences* self; if (!web_contents) return false; From afdf52b05369aafdf2132f72639de065da5e6884 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 18:35:12 +0900 Subject: [PATCH 0969/1195] Add docs for useNativeWindowOpen --- docs/api/browser-window.md | 1 + docs/api/window-open.md | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 3bdc4deddaa..75135d55e94 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -295,6 +295,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. 'Electron Isolated Context' entry in the combo box at the top of the Console tab. **Note:** This option is currently experimental and may change or be removed in future Electron releases. + * `useNativeWindowOpen` Boolean (optional) - Whether to use native `window.open()`. When setting minimum or maximum window size with `minWidth`/`maxWidth`/ `minHeight`/`maxHeight`, it only constrains the users. It won't prevent you from diff --git a/docs/api/window-open.md b/docs/api/window-open.md index 56216f551a0..7bc6b3ef2a7 100644 --- a/docs/api/window-open.md +++ b/docs/api/window-open.md @@ -41,3 +41,27 @@ has to be a field of `BrowserWindow`'s options. Sends a message to the parent window with the specified origin or `*` for no origin preference. + +### Use Native `window.open()` + +If you want to use native `window.open()` implementation, pass `useNativeWindowOpen: true` in `webPreferences` option. +Native `window.open()` allows synchronous access to opened windows so it is convenient choise if you need to open a dialog or a preferences window. + +The creation of the `BrowserWindow` is customizable in `WebContents`'s `new-window` event. + +```javascript +mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => { + if (url.endsWith("modal.html")) { + // open window as modal + event.preventDefault() + Object.assign(options, { + modal: true, + parent: mainWindow, + width: 100, + height: 100 + }) + modal = new BrowserWindow(options) + modal.loadURL(url) + event.newGuest = modal + } +``` From 2c21d3b3fa82865f0ec1906f1fe55369401ea903 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 20:09:52 +0900 Subject: [PATCH 0970/1195] Fix JavaScript in docs --- docs/api/window-open.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/window-open.md b/docs/api/window-open.md index 7bc6b3ef2a7..19c746737a9 100644 --- a/docs/api/window-open.md +++ b/docs/api/window-open.md @@ -51,7 +51,7 @@ The creation of the `BrowserWindow` is customizable in `WebContents`'s `new-wind ```javascript mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => { - if (url.endsWith("modal.html")) { + if (url.endsWith('modal.html')) { // open window as modal event.preventDefault() Object.assign(options, { @@ -61,7 +61,7 @@ mainWindow.webContents.on('new-window', (event, url, frameName, disposition, opt height: 100 }) modal = new BrowserWindow(options) - modal.loadURL(url) event.newGuest = modal } +}) ``` From 3af9f572ac952dc2ff6327e350d66ee858ad3217 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 20:10:25 +0900 Subject: [PATCH 0971/1195] Fix spec description --- spec/api-browser-window-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 69f9c78d52b..c5c1bb28594 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1070,7 +1070,7 @@ describe('BrowserWindow module', function () { }) }) - describe('useNativeWindowOpen option', () => { + describe('nativeWindowOpen option', () => { it('allows synchronous access to window opened by window.open()', (done) => { ipcMain.once('answer', function (event, content) { assert.equal(content, 'Hello') From 88f062958f420dd610be265e77c3a281444a9b0a Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 20:21:03 +0900 Subject: [PATCH 0972/1195] Fix option doc --- docs/api/browser-window.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 75135d55e94..fcb792fe4d3 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -295,7 +295,7 @@ It creates a new `BrowserWindow` with native properties as set by the `options`. 'Electron Isolated Context' entry in the combo box at the top of the Console tab. **Note:** This option is currently experimental and may change or be removed in future Electron releases. - * `useNativeWindowOpen` Boolean (optional) - Whether to use native `window.open()`. + * `nativeWindowOpen` Boolean (optional) - Whether to use native `window.open()`. Defaults to `false`. When setting minimum or maximum window size with `minWidth`/`maxWidth`/ `minHeight`/`maxHeight`, it only constrains the users. It won't prevent you from From c3c67f78c1c57cd15c455d7210acc4f5c4f76f08 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 19 Mar 2017 20:30:07 +0900 Subject: [PATCH 0973/1195] Improve docs on window.open --- docs/api/window-open.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/api/window-open.md b/docs/api/window-open.md index 19c746737a9..b0cd0e25011 100644 --- a/docs/api/window-open.md +++ b/docs/api/window-open.md @@ -50,8 +50,16 @@ Native `window.open()` allows synchronous access to opened windows so it is conv The creation of the `BrowserWindow` is customizable in `WebContents`'s `new-window` event. ```javascript +// main process +const mainWindow = new BrowserWindow({ + width: 800, + height: 600, + webPreferences: { + nativeWindowOpen: true + } +}) mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => { - if (url.endsWith('modal.html')) { + if (frameName === 'modal') { // open window as modal event.preventDefault() Object.assign(options, { @@ -65,3 +73,9 @@ mainWindow.webContents.on('new-window', (event, url, frameName, disposition, opt } }) ``` + +```javascript +// renderer process (mainWindow) +let modal = window.open('', 'modal') +modal.document.write('

Hello

') +``` From 4d61d071b253c9bf8a7ad2583a2e10153fb65cc1 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Tue, 21 Mar 2017 10:41:49 +0900 Subject: [PATCH 0974/1195] Reuse site instance only on window.open --- atom/browser/api/atom_api_web_contents.cc | 1 + atom/browser/atom_browser_client.cc | 33 ++++++++++++++++------- atom/browser/atom_browser_client.h | 2 ++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 6ba23b3c9af..4e9315c6cb3 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -468,6 +468,7 @@ void WebContents::AddNewContents(content::WebContents* source, if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture, initial_rect.x(), initial_rect.y(), initial_rect.width(), initial_rect.height())) { + AtomBrowserClient::CancelReuseRendererProcessForNewWindow(); api_web_contents->DestroyWebContents(); } } diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index d06f27b9c27..10cf4f95973 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -51,6 +51,10 @@ namespace { // Next navigation should not restart renderer process. bool g_suppress_renderer_process_restart = false; +// Next navigation is caused by native window.open and +// the renderer process may be reused. +bool g_reuse_renderer_process_for_new_window = false; + // Custom schemes to be registered to handle service worker. std::string g_custom_service_worker_schemes = ""; @@ -64,6 +68,10 @@ void AtomBrowserClient::SuppressRendererProcessRestartForOnce() { g_suppress_renderer_process_restart = true; } +void AtomBrowserClient::CancelReuseRendererProcessForNewWindow() { + g_reuse_renderer_process_for_new_window = false; +} + void AtomBrowserClient::SetCustomServiceWorkerSchemes( const std::vector& schemes) { g_custom_service_worker_schemes = base::JoinString(schemes, ","); @@ -90,16 +98,22 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( content::BrowserContext* browser_context, content::SiteInstance* current_instance, const GURL& url) { - + if (g_suppress_renderer_process_restart) { + g_suppress_renderer_process_restart = false; + return false; + } if (url.SchemeIs(url::kJavaScriptScheme)) // "javacript:" scheme should always use same SiteInstance return false; int process_id = current_instance->GetProcess()->GetID(); - if (!(IsRendererSandboxed(process_id) - || RendererUsesNativeWindowOpen(process_id))) + if (g_reuse_renderer_process_for_new_window) { + // native window.open can reuse renderer process + g_reuse_renderer_process_for_new_window = false; + } else if (!IsRendererSandboxed(process_id)) { // non-sandboxed renderers should always create a new SiteInstance return true; + } // Create new a SiteInstance if navigating to a different site. auto src_url = current_instance->GetSiteURL(); @@ -188,11 +202,6 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation( content::SiteInstance* current_instance, const GURL& url, content::SiteInstance** new_instance) { - if (g_suppress_renderer_process_restart) { - g_suppress_renderer_process_restart = false; - return; - } - if (!ShouldCreateNewSiteInstance(browser_context, current_instance, url)) return; @@ -322,8 +331,12 @@ bool AtomBrowserClient::CanCreateWindow( bool* no_javascript_access) { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - if (IsRendererSandboxed(render_process_id) - || RendererUsesNativeWindowOpen(render_process_id)) { + if (IsRendererSandboxed(render_process_id)) { + *no_javascript_access = false; + return true; + } + if (RendererUsesNativeWindowOpen(render_process_id)) { + g_reuse_renderer_process_for_new_window = true; *no_javascript_access = false; return true; } diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index f60e72bc612..d3029073cb0 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -40,6 +40,8 @@ class AtomBrowserClient : public brightray::BrowserClient, // Don't force renderer process to restart for once. static void SuppressRendererProcessRestartForOnce(); + // Cancel reusing renderer process for new window. + static void CancelReuseRendererProcessForNewWindow(); // Custom schemes to be registered to handle service worker. static void SetCustomServiceWorkerSchemes( From d3252e0eb11a40b1abeacca290934d0fc8baeb40 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Tue, 21 Mar 2017 16:09:53 +0900 Subject: [PATCH 0975/1195] Reuse existing event --- lib/browser/guest-window-manager.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index c75e3388239..a9c9e20a36f 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -242,18 +242,13 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_INTERNAL_WINDOW_OPEN', function (event disposition, options, additionalFeatures, postData) { options = mergeBrowserWindowOptions(event.sender, options) - const newWindowEvent = { - preventDefault: function () { - this.defaultPrevented = true - } - } - event.sender.emit('new-window', newWindowEvent, url, frameName, disposition, options, additionalFeatures) - const newGuest = newWindowEvent.newGuest - if ((event.sender.isGuest() && !event.sender.allowPopups) || newWindowEvent.defaultPrevented) { + event.sender.emit('new-window', event, url, frameName, disposition, options, additionalFeatures) + const newGuest = event.newGuest + if ((event.sender.isGuest() && !event.sender.allowPopups) || event.defaultPrevented) { if (newGuest !== undefined && newGuest !== null) { + event.defaultPrevented = false event.returnValue = setupGuest(event.sender, frameName, newGuest, options) } else { - event.preventDefault() event.returnValue = null } } else { From deba6553f58683d950749bd58b987925f6848e3f Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 23 Mar 2017 22:43:06 +0900 Subject: [PATCH 0976/1195] Better preventDefault for ELECTRON_GUEST_WINDOW_MANAGER_INTERNAL_WINDOW_OPEN --- lib/browser/guest-window-manager.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index a9c9e20a36f..7649547f942 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -242,11 +242,14 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_INTERNAL_WINDOW_OPEN', function (event disposition, options, additionalFeatures, postData) { options = mergeBrowserWindowOptions(event.sender, options) + const {webContents} = options event.sender.emit('new-window', event, url, frameName, disposition, options, additionalFeatures) const newGuest = event.newGuest if ((event.sender.isGuest() && !event.sender.allowPopups) || event.defaultPrevented) { if (newGuest !== undefined && newGuest !== null) { - event.defaultPrevented = false + if (webContents == newGuest.webContents) { + event.defaultPrevented = false + } event.returnValue = setupGuest(event.sender, frameName, newGuest, options) } else { event.returnValue = null From 96de22ba5f95192f91627fcafbd3bf6ad52cbd3c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 22 Mar 2017 12:53:55 -0700 Subject: [PATCH 0977/1195] Use cpplint from depot_tools --- brightray/.gitmodules | 3 --- brightray/script/cpplint | 2 +- brightray/vendor/google-styleguide | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) delete mode 160000 brightray/vendor/google-styleguide diff --git a/brightray/.gitmodules b/brightray/.gitmodules index 719488608b5..54ed18cf53b 100644 --- a/brightray/.gitmodules +++ b/brightray/.gitmodules @@ -4,6 +4,3 @@ [submodule "vendor/gyp"] path = vendor/gyp url = https://github.com/electron/gyp -[submodule "vendor/google-styleguide"] - path = vendor/google-styleguide - url = https://github.com/svn2github/sgss-mirror-google-styleguide diff --git a/brightray/script/cpplint b/brightray/script/cpplint index ff09db9e7d0..f3a871d6e3d 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -7,7 +7,7 @@ import sys SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) -CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'google-styleguide', 'trunk', 'cpplint', 'cpplint.py') +CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'libchromiumcontent', 'vendor', 'depot_tools', 'cpplint.py') LINE_LENGTH = 100 IGNORED_FILES = [ diff --git a/brightray/vendor/google-styleguide b/brightray/vendor/google-styleguide deleted file mode 160000 index ba88c8a53f1..00000000000 --- a/brightray/vendor/google-styleguide +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ba88c8a53f1b563c43fc063cc048e5efdc238c18 From 97ced7fb077f8995685a76919a9ca5f6bb2f04ec Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 22 Mar 2017 13:07:52 -0700 Subject: [PATCH 0978/1195] Move cpplint config to CPPLINT.cfg file --- brightray/CPPLINT.cfg | 2 ++ brightray/script/cpplint | 12 +----------- 2 files changed, 3 insertions(+), 11 deletions(-) create mode 100644 brightray/CPPLINT.cfg diff --git a/brightray/CPPLINT.cfg b/brightray/CPPLINT.cfg new file mode 100644 index 00000000000..3ca9f82ea82 --- /dev/null +++ b/brightray/CPPLINT.cfg @@ -0,0 +1,2 @@ +filter=-build/header_guard,-build/include_what_you_use,-legal/copyright,-runtime/references +linelength=100 diff --git a/brightray/script/cpplint b/brightray/script/cpplint index f3a871d6e3d..8956857a679 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -8,21 +8,11 @@ import sys SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'libchromiumcontent', 'vendor', 'depot_tools', 'cpplint.py') -LINE_LENGTH = 100 IGNORED_FILES = [ os.path.join('browser', 'mac', 'bry_inspectable_web_contents_view.h'), ] -FILTERS = [ - '-build/header_guard', - '-build/include_what_you_use', - '-legal/copyright', - # cpplint doesn't like the BOOL& parameters that ui::WindowImpl uses. - '-runtime/references', -] - - def main(): os.chdir(SOURCE_ROOT) files = list_files(['browser', 'common'], @@ -41,7 +31,7 @@ def list_files(directories, filters): def cpplint(files): - return subprocess.call([sys.executable, CPPLINT, '--linelength=%d' % LINE_LENGTH, '--filter=' + ','.join(FILTERS)] + list(files)) + return subprocess.call([sys.executable, CPPLINT] + list(files)) if __name__ == '__main__': From ece7698b6ac655616d02c0ff7a1f975df0bfbc14 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 23 Mar 2017 08:21:18 -0700 Subject: [PATCH 0979/1195] Add .clang-format file --- brightray/.clang-format | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 brightray/.clang-format diff --git a/brightray/.clang-format b/brightray/.clang-format new file mode 100644 index 00000000000..6fdf1dc888c --- /dev/null +++ b/brightray/.clang-format @@ -0,0 +1,8 @@ +# Defines the Chromium style for automatic reformatting. +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html +BasedOnStyle: Chromium +# This defaults to 'Auto'. Explicitly set it for a while, so that +# 'vector >' in existing files gets formatted to +# 'vector>'. ('Auto' means that clang-format will only use +# 'int>>' if the file already contains at least one such instance.) +Standard: Cpp11 From 31cd7a28d8b71455b56885535a085f969809826b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 23 Mar 2017 08:21:41 -0700 Subject: [PATCH 0980/1195] Ignore more Objective-C headers --- brightray/script/cpplint | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/script/cpplint b/brightray/script/cpplint index 8956857a679..964f2009fc3 100755 --- a/brightray/script/cpplint +++ b/brightray/script/cpplint @@ -11,6 +11,8 @@ CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'libchromiumcontent', 'vendor', 'd IGNORED_FILES = [ os.path.join('browser', 'mac', 'bry_inspectable_web_contents_view.h'), + os.path.join('browser', 'mac', 'event_dispatching_window.h'), + os.path.join('browser', 'mac', 'notification_center_delegate.h'), ] def main(): From 1d42073ceb493f2c592d1e461f57dad70a58cb14 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 23 Mar 2017 09:58:59 -0700 Subject: [PATCH 0981/1195] Run cpplint on CI build --- brightray/script/cibuild | 2 ++ 1 file changed, 2 insertions(+) diff --git a/brightray/script/cibuild b/brightray/script/cibuild index b16f69b1c54..c4477368514 100755 --- a/brightray/script/cibuild +++ b/brightray/script/cibuild @@ -2,6 +2,8 @@ set -ex +script/cpplint + # Make cloned repository complete git fetch --unshallow origin HEAD From be0c0e278a36487fd991ef9678c60235c975d246 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 23 Mar 2017 12:48:22 -0700 Subject: [PATCH 0982/1195] Remove cpplint errors --- brightray/browser/linux/libnotify_loader.h | 4 +- .../devtools_network_upload_data_stream.cc | 2 +- .../browser/url_request_context_getter.cc | 6 +- .../inspectable_web_contents_view_views.h | 2 +- .../browser/win/notification_presenter_win.cc | 3 +- .../browser/win/notification_presenter_win.h | 9 +- brightray/browser/win/scoped_hstring.h | 8 +- .../browser/win/windows_toast_notification.cc | 103 ++++++++++-------- .../browser/win/windows_toast_notification.h | 75 ++++++++----- 9 files changed, 128 insertions(+), 84 deletions(-) diff --git a/brightray/browser/linux/libnotify_loader.h b/brightray/browser/linux/libnotify_loader.h index 825a349b39f..48fda0b632a 100644 --- a/brightray/browser/linux/libnotify_loader.h +++ b/brightray/browser/linux/libnotify_loader.h @@ -4,10 +4,10 @@ #ifndef BRIGHTRAY_BROWSER_LINUX_LIBNOTIFY_LOADER_H_ #define BRIGHTRAY_BROWSER_LINUX_LIBNOTIFY_LOADER_H_ -#include - #include +#include + class LibNotifyLoader { public: LibNotifyLoader(); diff --git a/brightray/browser/net/devtools_network_upload_data_stream.cc b/brightray/browser/net/devtools_network_upload_data_stream.cc index c6369dcb458..6687038b097 100644 --- a/brightray/browser/net/devtools_network_upload_data_stream.cc +++ b/brightray/browser/net/devtools_network_upload_data_stream.cc @@ -81,7 +81,7 @@ int DevToolsNetworkUploadDataStream::ThrottleRead(int result) { } void DevToolsNetworkUploadDataStream::ThrottleCallback( - int result, int64_t bytes) { + int result, int64_t bytes) { throttled_byte_count_ = bytes; OnReadCompleted(result); } diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index e3e7dca5435..3510d00b844 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -200,7 +200,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { net::HttpUtil::GenerateAcceptLanguageHeader(accept_lang), user_agent_))); - std::unique_ptr host_resolver(net::HostResolver::CreateDefaultResolver(nullptr)); + std::unique_ptr host_resolver( + net::HostResolver::CreateDefaultResolver(nullptr)); // --host-resolver-rules if (command_line.HasSwitch(::switches::kHostResolverRules)) { @@ -301,7 +302,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { // --host-rules if (command_line.HasSwitch(switches::kHostRules)) { host_mapping_rules_.reset(new net::HostMappingRules); - host_mapping_rules_->SetRulesFromString(command_line.GetSwitchValueASCII(switches::kHostRules)); + host_mapping_rules_->SetRulesFromString( + command_line.GetSwitchValueASCII(switches::kHostRules)); network_session_params.host_mapping_rules = host_mapping_rules_.get(); } diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index 8205cc5f06e..1af53e92fdf 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -14,7 +14,7 @@ class Widget; namespace brightray { -namespace { +namespace { // NOLINT class DevToolsWindowDelegate; } diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 018fa3212a4..6e913ea37ff 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -1,5 +1,6 @@ // Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. +// Copyright (c) 2015 Felix Rieseberg and +// Jason Poon . All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index 7bcf1a9909d..69b89f4ae5d 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -1,12 +1,13 @@ // Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. +// Copyright (c) 2015 Felix Rieseberg and +// Jason Poon . All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. // Usage Example (JavaScript: // var windowsNotification = new Notification("Test Title", { -// body: "Hi, I'm an example body. How are you?", -// icon: "file:///C:/Path/To/Your/Image.png" +// body: "Hi, I'm an example body. How are you?", +// icon: "file:///C:/Path/To/Your/Image.png" // }); // windowsNotification.onshow = function () { console.log("Notification shown") }; @@ -40,6 +41,6 @@ class NotificationPresenterWin : public NotificationPresenter { DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin); }; -} // namespace +} // namespace brightray #endif // BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ diff --git a/brightray/browser/win/scoped_hstring.h b/brightray/browser/win/scoped_hstring.h index 67e4fe67fd0..879e62cd39b 100644 --- a/brightray/browser/win/scoped_hstring.h +++ b/brightray/browser/win/scoped_hstring.h @@ -5,18 +5,18 @@ #ifndef BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_ #define BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_ -#include - #include #include +#include + #include "base/macros.h" class ScopedHString { public: // Copy from |source|. - ScopedHString(const wchar_t* source); - ScopedHString(const std::wstring& source); + explicit ScopedHString(const wchar_t* source); + explicit ScopedHString(const std::wstring& source); // Create empty string. ScopedHString(); ~ScopedHString(); diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 4d4b5bfc341..4a3a5a6f678 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -1,6 +1,9 @@ -// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. -// Copyright (c) 2015 Ryan McShane and Brandon Smith -// Thanks to both of those folks mentioned above who first thought up a bunch of this code +// Copyright (c) 2015 Felix Rieseberg and Jason Poon +// . All rights reserved. +// Copyright (c) 2015 Ryan McShane and Brandon Smith +// +// Thanks to both of those folks mentioned above who first thought up a bunch of +// this code // and released it as MIT to the world. #include "browser/win/windows_toast_notification.h" @@ -14,7 +17,13 @@ #include "common/application_info.h" #include "content/public/browser/browser_thread.h" -using namespace ABI::Windows::Data::Xml::Dom; +using ABI::Windows::Data::Xml::Dom::IXmlAttribute; +using ABI::Windows::Data::Xml::Dom::IXmlDocument; +using ABI::Windows::Data::Xml::Dom::IXmlElement; +using ABI::Windows::Data::Xml::Dom::IXmlNamedNodeMap; +using ABI::Windows::Data::Xml::Dom::IXmlNode; +using ABI::Windows::Data::Xml::Dom::IXmlNodeList; +using ABI::Windows::Data::Xml::Dom::IXmlText; namespace brightray { @@ -71,8 +80,7 @@ bool WindowsToastNotification::Initialize() { WindowsToastNotification::WindowsToastNotification( NotificationDelegate* delegate, NotificationPresenter* presenter) - : Notification(delegate, presenter) { -} + : Notification(delegate, presenter) {} WindowsToastNotification::~WindowsToastNotification() { // Remove the notification on exit. @@ -82,18 +90,18 @@ WindowsToastNotification::~WindowsToastNotification() { } } -void WindowsToastNotification::Show( - const base::string16& title, - const base::string16& msg, - const std::string& tag, - const GURL& icon_url, - const SkBitmap& icon, - const bool silent) { +void WindowsToastNotification::Show(const base::string16& title, + const base::string16& msg, + const std::string& tag, + const GURL& icon_url, + const SkBitmap& icon, + const bool silent) { auto presenter_win = static_cast(presenter()); std::wstring icon_path = presenter_win->SaveIconToFilesystem(icon, icon_url); ComPtr toast_xml; - if(FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, silent, &toast_xml))) { + if (FAILED(GetToastXml(toast_manager_.Get(), title, msg, icon_path, silent, + &toast_xml))) { NotificationFailed(); return; } @@ -105,7 +113,8 @@ void WindowsToastNotification::Show( return; } - ComPtr toast_factory; + ComPtr + toast_factory; if (FAILED(Windows::Foundation::GetActivationFactory(toast_str, &toast_factory))) { NotificationFailed(); @@ -136,7 +145,8 @@ void WindowsToastNotification::Dismiss() { } bool WindowsToastNotification::GetToastXml( - ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager, + ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* + toastManager, const std::wstring& title, const std::wstring& msg, const std::wstring& icon_path, @@ -145,16 +155,22 @@ bool WindowsToastNotification::GetToastXml( ABI::Windows::UI::Notifications::ToastTemplateType template_type; if (title.empty() || msg.empty()) { // Single line toast. - template_type = icon_path.empty() ? ABI::Windows::UI::Notifications::ToastTemplateType_ToastText01 : - ABI::Windows::UI::Notifications::ToastTemplateType_ToastImageAndText01; + template_type = + icon_path.empty() + ? ABI::Windows::UI::Notifications::ToastTemplateType_ToastText01 + : ABI::Windows::UI::Notifications:: + ToastTemplateType_ToastImageAndText01; if (FAILED(toast_manager_->GetTemplateContent(template_type, toast_xml))) return false; if (!SetXmlText(*toast_xml, title.empty() ? msg : title)) return false; } else { // Title and body toast. - template_type = icon_path.empty() ? ABI::Windows::UI::Notifications::ToastTemplateType_ToastText02 : - ABI::Windows::UI::Notifications::ToastTemplateType_ToastImageAndText02; + template_type = + icon_path.empty() + ? ABI::Windows::UI::Notifications::ToastTemplateType_ToastText02 + : ABI::Windows::UI::Notifications:: + ToastTemplateType_ToastImageAndText02; if (FAILED(toastManager->GetTemplateContent(template_type, toast_xml))) return false; if (!SetXmlText(*toast_xml, title, msg)) @@ -174,9 +190,8 @@ bool WindowsToastNotification::GetToastXml( return true; } -bool WindowsToastNotification::SetXmlAudioSilent( - IXmlDocument* doc) { - ScopedHString tag(L"toast"); +bool WindowsToastNotification::SetXmlAudioSilent(IXmlDocument* doc) { + ScopedHString tag(L"toast"); if (!tag.success()) return false; @@ -230,15 +245,17 @@ bool WindowsToastNotification::SetXmlAudioSilent( return false; ComPtr child_node; - if (FAILED(silent_attribute_node->AppendChild(silent_node.Get(), &child_node))) + if (FAILED( + silent_attribute_node->AppendChild(silent_node.Get(), &child_node))) return false; ComPtr silent_attribute_pnode; - return SUCCEEDED(attributes.Get()->SetNamedItem(silent_attribute_node.Get(), &silent_attribute_pnode)); + return SUCCEEDED(attributes.Get()->SetNamedItem(silent_attribute_node.Get(), + &silent_attribute_pnode)); } -bool WindowsToastNotification::SetXmlText( - IXmlDocument* doc, const std::wstring& text) { +bool WindowsToastNotification::SetXmlText(IXmlDocument* doc, + const std::wstring& text) { ScopedHString tag; ComPtr node_list; if (!GetTextNodeList(&tag, doc, &node_list, 1)) @@ -251,8 +268,9 @@ bool WindowsToastNotification::SetXmlText( return AppendTextToXml(doc, node.Get(), text); } -bool WindowsToastNotification::SetXmlText( - IXmlDocument* doc, const std::wstring& title, const std::wstring& body) { +bool WindowsToastNotification::SetXmlText(IXmlDocument* doc, + const std::wstring& title, + const std::wstring& body) { ScopedHString tag; ComPtr node_list; if (!GetTextNodeList(&tag, doc, &node_list, 2)) @@ -271,8 +289,8 @@ bool WindowsToastNotification::SetXmlText( return AppendTextToXml(doc, node.Get(), body); } -bool WindowsToastNotification::SetXmlImage( - IXmlDocument* doc, const std::wstring& icon_path) { +bool WindowsToastNotification::SetXmlImage(IXmlDocument* doc, + const std::wstring& icon_path) { ScopedHString tag(L"image"); if (!tag.success()) return false; @@ -313,11 +331,10 @@ bool WindowsToastNotification::SetXmlImage( return SUCCEEDED(src_attr->AppendChild(src_node.Get(), &child_node)); } -bool WindowsToastNotification::GetTextNodeList( - ScopedHString* tag, - IXmlDocument* doc, - IXmlNodeList** node_list, - uint32_t req_length) { +bool WindowsToastNotification::GetTextNodeList(ScopedHString* tag, + IXmlDocument* doc, + IXmlNodeList** node_list, + uint32_t req_length) { tag->Reset(L"text"); if (!tag->success()) return false; @@ -332,8 +349,9 @@ bool WindowsToastNotification::GetTextNodeList( return node_length >= req_length; } -bool WindowsToastNotification::AppendTextToXml( - IXmlDocument* doc, IXmlNode* node, const std::wstring& text) { +bool WindowsToastNotification::AppendTextToXml(IXmlDocument* doc, + IXmlNode* node, + const std::wstring& text) { ScopedHString str(text); if (!str.success()) return false; @@ -377,14 +395,13 @@ bool WindowsToastNotification::RemoveCallbacks( / Toast Event Handler */ ToastEventHandler::ToastEventHandler(Notification* notification) - : notification_(notification->GetWeakPtr()) { -} + : notification_(notification->GetWeakPtr()) {} -ToastEventHandler::~ToastEventHandler() { -} +ToastEventHandler::~ToastEventHandler() {} IFACEMETHODIMP ToastEventHandler::Invoke( - ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args) { + ABI::Windows::UI::Notifications::IToastNotification* sender, + IInspectable* args) { content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, base::Bind(&Notification::NotificationClicked, notification_)); diff --git a/brightray/browser/win/windows_toast_notification.h b/brightray/browser/win/windows_toast_notification.h index fcbe78faa4d..47c7d596a88 100644 --- a/brightray/browser/win/windows_toast_notification.h +++ b/brightray/browser/win/windows_toast_notification.h @@ -1,6 +1,9 @@ -// Copyright (c) 2015 Felix Rieseberg and Jason Poon . All rights reserved. -// Copyright (c) 2015 Ryan McShane and Brandon Smith -// Thanks to both of those folks mentioned above who first thought up a bunch of this code +// Copyright (c) 2015 Felix Rieseberg and Jason Poon +// . All rights reserved. +// Copyright (c) 2015 Ryan McShane and Brandon Smith +// +// Thanks to both of those folks mentioned above who first thought up a bunch of +// this code // and released it as MIT to the world. #ifndef BRIGHTRAY_BROWSER_WIN_WINDOWS_TOAST_NOTIFICATION_H_ @@ -12,21 +15,28 @@ #include "browser/notification.h" -using namespace Microsoft::WRL; +using Microsoft::WRL::ClassicCom; +using Microsoft::WRL::ComPtr; +using Microsoft::WRL::Make; +using Microsoft::WRL::RuntimeClass; +using Microsoft::WRL::RuntimeClassFlags; class ScopedHString; namespace brightray { using DesktopToastActivatedEventHandler = - ABI::Windows::Foundation::ITypedEventHandler; + ABI::Windows::Foundation::ITypedEventHandler< + ABI::Windows::UI::Notifications::ToastNotification*, + IInspectable*>; using DesktopToastDismissedEventHandler = - ABI::Windows::Foundation::ITypedEventHandler; + ABI::Windows::Foundation::ITypedEventHandler< + ABI::Windows::UI::Notifications::ToastNotification*, + ABI::Windows::UI::Notifications::ToastDismissedEventArgs*>; using DesktopToastFailedEventHandler = - ABI::Windows::Foundation::ITypedEventHandler; + ABI::Windows::Foundation::ITypedEventHandler< + ABI::Windows::UI::Notifications::ToastNotification*, + ABI::Windows::UI::Notifications::ToastFailedEventArgs*>; class WindowsToastNotification : public Notification { public: @@ -50,12 +60,14 @@ class WindowsToastNotification : public Notification { private: friend class ToastEventHandler; - bool GetToastXml(ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* toastManager, - const std::wstring& title, - const std::wstring& msg, - const std::wstring& icon_path, - const bool silent, - ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); + bool GetToastXml( + ABI::Windows::UI::Notifications::IToastNotificationManagerStatics* + toastManager, + const std::wstring& title, + const std::wstring& msg, + const std::wstring& icon_path, + const bool silent, + ABI::Windows::Data::Xml::Dom::IXmlDocument** toastXml); bool SetXmlAudioSilent(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc); bool SetXmlText(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, const std::wstring& text); @@ -71,34 +83,45 @@ class WindowsToastNotification : public Notification { bool AppendTextToXml(ABI::Windows::Data::Xml::Dom::IXmlDocument* doc, ABI::Windows::Data::Xml::Dom::IXmlNode* node, const std::wstring& text); - bool SetupCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast); - bool RemoveCallbacks(ABI::Windows::UI::Notifications::IToastNotification* toast); + bool SetupCallbacks( + ABI::Windows::UI::Notifications::IToastNotification* toast); + bool RemoveCallbacks( + ABI::Windows::UI::Notifications::IToastNotification* toast); - static ComPtr toast_manager_; - static ComPtr toast_notifier_; + static ComPtr< + ABI::Windows::UI::Notifications::IToastNotificationManagerStatics> + toast_manager_; + static ComPtr + toast_notifier_; EventRegistrationToken activated_token_; EventRegistrationToken dismissed_token_; EventRegistrationToken failed_token_; ComPtr event_handler_; - ComPtr toast_notification_; + ComPtr + toast_notification_; DISALLOW_COPY_AND_ASSIGN(WindowsToastNotification); }; - class ToastEventHandler : public RuntimeClass, DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler, DesktopToastFailedEventHandler> { public: - ToastEventHandler(Notification* notification); + explicit ToastEventHandler(Notification* notification); ~ToastEventHandler(); - IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, IInspectable* args); - IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e); - IFACEMETHODIMP Invoke(ABI::Windows::UI::Notifications::IToastNotification* sender, ABI::Windows::UI::Notifications::IToastFailedEventArgs* e); + IFACEMETHODIMP Invoke( + ABI::Windows::UI::Notifications::IToastNotification* sender, + IInspectable* args); + IFACEMETHODIMP Invoke( + ABI::Windows::UI::Notifications::IToastNotification* sender, + ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e); + IFACEMETHODIMP Invoke( + ABI::Windows::UI::Notifications::IToastNotification* sender, + ABI::Windows::UI::Notifications::IToastFailedEventArgs* e); private: base::WeakPtr notification_; // weak ref. From 2ece711c2e3a880950164d3a1680ed909a3f3751 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 23 Mar 2017 15:47:30 -0700 Subject: [PATCH 0983/1195] Format line length to 80 instead of 100 --- brightray/CPPLINT.cfg | 1 - brightray/browser/browser_client.cc | 3 +- brightray/browser/browser_client.h | 3 +- brightray/browser/browser_context.cc | 10 ++- brightray/browser/inspectable_web_contents.h | 3 +- .../browser/inspectable_web_contents_impl.cc | 74 +++++++++++-------- .../browser/inspectable_web_contents_impl.h | 3 +- brightray/browser/linux/libnotify_loader.cc | 9 ++- brightray/browser/linux/libnotify_loader.h | 9 ++- .../browser/linux/libnotify_notification.cc | 3 +- .../media/media_stream_devices_controller.cc | 6 +- .../browser/net/devtools_network_controller.h | 5 +- .../net/devtools_network_controller_handle.h | 5 +- .../net/devtools_network_protocol_handler.cc | 3 +- .../devtools_network_transaction_factory.h | 7 +- brightray/browser/net_log.cc | 3 +- brightray/browser/network_delegate.cc | 3 +- brightray/browser/permission_manager.h | 11 ++- .../browser/platform_notification_service.cc | 6 +- .../browser/url_request_context_getter.cc | 27 ++++--- .../browser/url_request_context_getter.h | 6 +- .../inspectable_web_contents_view_views.cc | 29 +++++--- brightray/browser/views/views_delegate.cc | 3 +- .../browser/win/notification_presenter_win.cc | 3 +- .../browser/win/notification_presenter_win.h | 12 ++- brightray/common/main_delegate.cc | 7 +- brightray/common/switches.cc | 3 +- 27 files changed, 161 insertions(+), 96 deletions(-) diff --git a/brightray/CPPLINT.cfg b/brightray/CPPLINT.cfg index 3ca9f82ea82..01e99482f2b 100644 --- a/brightray/CPPLINT.cfg +++ b/brightray/CPPLINT.cfg @@ -1,2 +1 @@ filter=-build/header_guard,-build/include_what_you_use,-legal/copyright,-runtime/references -linelength=100 diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index c34b6613d38..8c39df65cc0 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -68,7 +68,8 @@ content::MediaObserver* BrowserClient::GetMediaObserver() { return MediaCaptureDevicesDispatcher::GetInstance(); } -content::PlatformNotificationService* BrowserClient::GetPlatformNotificationService() { +content::PlatformNotificationService* +BrowserClient::GetPlatformNotificationService() { if (!notification_service_) notification_service_.reset(new PlatformNotificationService(this)); return notification_service_.get(); diff --git a/brightray/browser/browser_client.h b/brightray/browser/browser_client.h index e810a44fadc..574103b91ca 100644 --- a/brightray/browser/browser_client.h +++ b/brightray/browser/browser_client.h @@ -39,7 +39,8 @@ class BrowserClient : public content::ContentBrowserClient { content::BrowserMainParts* CreateBrowserMainParts( const content::MainFunctionParams&) override; content::MediaObserver* GetMediaObserver() override; - content::PlatformNotificationService* GetPlatformNotificationService() override; + content::PlatformNotificationService* GetPlatformNotificationService() + override; void GetAdditionalAllowedSchemesForFileSystem( std::vector* additional_schemes) override; net::NetLog* GetNetLog() override; diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 2a17e327453..46f76302d74 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -94,7 +94,8 @@ BrowserContext::BrowserContext(const std::string& partition, bool in_memory) if (!in_memory_ && !partition.empty()) path_ = path_.Append(FILE_PATH_LITERAL("Partitions")) - .Append(base::FilePath::FromUTF8Unsafe(MakePartitionName(partition))); + .Append(base::FilePath::FromUTF8Unsafe( + MakePartitionName(partition))); content::BrowserContext::Initialize(this, path_); @@ -168,8 +169,8 @@ base::FilePath BrowserContext::GetPath() const { return path_; } -std::unique_ptr BrowserContext::CreateZoomLevelDelegate( - const base::FilePath& partition_path) { +std::unique_ptr +BrowserContext::CreateZoomLevelDelegate(const base::FilePath& partition_path) { if (!IsOffTheRecord()) { return base::MakeUnique(prefs(), partition_path); } @@ -210,7 +211,8 @@ content::PermissionManager* BrowserContext::GetPermissionManager() { return permission_manager_.get(); } -content::BackgroundSyncController* BrowserContext::GetBackgroundSyncController() { +content::BackgroundSyncController* +BrowserContext::GetBackgroundSyncController() { return nullptr; } diff --git a/brightray/browser/inspectable_web_contents.h b/brightray/browser/inspectable_web_contents.h index a862344e2fb..44c0c22ec64 100644 --- a/brightray/browser/inspectable_web_contents.h +++ b/brightray/browser/inspectable_web_contents.h @@ -18,7 +18,8 @@ class InspectableWebContentsView; class InspectableWebContents { public: - static InspectableWebContents* Create(const content::WebContents::CreateParams&); + static InspectableWebContents* Create( + const content::WebContents::CreateParams&); // The returned InspectableWebContents takes ownership of the passed-in // WebContents. diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 4f4100eb678..540cb2feb77 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -136,7 +136,8 @@ GURL GetDevToolsURL(bool can_dock) { class ResponseWriter : public net::URLFetcherResponseWriter { public: - ResponseWriter(base::WeakPtr bindings, int stream_id); + ResponseWriter(base::WeakPtr bindings, + int stream_id); ~ResponseWriter() override; // URLFetcherResponseWriter overrides: @@ -153,8 +154,9 @@ class ResponseWriter : public net::URLFetcherResponseWriter { DISALLOW_COPY_AND_ASSIGN(ResponseWriter); }; -ResponseWriter::ResponseWriter(base::WeakPtr bindings, - int stream_id) +ResponseWriter::ResponseWriter( + base::WeakPtr bindings, + int stream_id) : bindings_(bindings), stream_id_(stream_id) { } @@ -207,7 +209,8 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( delegate_(nullptr), web_contents_(web_contents), weak_factory_(this) { - auto context = static_cast(web_contents_->GetBrowserContext()); + auto context = + static_cast(web_contents_->GetBrowserContext()); pref_service_ = context->prefs(); auto bounds_dict = pref_service_->GetDictionary(kDevToolsBoundsPref); if (bounds_dict) { @@ -226,8 +229,10 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( display = display::Screen::GetScreen()->GetPrimaryDisplay().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); + devtools_bounds_.set_x(display.x() + + (display.width() - devtools_bounds_.width()) / 2); + devtools_bounds_.set_y( + display.y() + (display.height() - devtools_bounds_.height()) / 2); } } @@ -246,7 +251,8 @@ content::WebContents* InspectableWebContentsImpl::GetWebContents() const { return web_contents_.get(); } -content::WebContents* InspectableWebContentsImpl::GetDevToolsWebContents() const { +content::WebContents* InspectableWebContentsImpl::GetDevToolsWebContents() + const { return devtools_web_contents_.get(); } @@ -255,11 +261,13 @@ void InspectableWebContentsImpl::InspectElement(int x, int y) { agent_host_->InspectElement(this, x, y); } -void InspectableWebContentsImpl::SetDelegate(InspectableWebContentsDelegate* delegate) { +void InspectableWebContentsImpl::SetDelegate( + InspectableWebContentsDelegate* delegate) { delegate_ = delegate; } -InspectableWebContentsDelegate* InspectableWebContentsImpl::GetDelegate() const { +InspectableWebContentsDelegate* InspectableWebContentsImpl::GetDelegate() + const { return delegate_; } @@ -279,7 +287,8 @@ void InspectableWebContentsImpl::ShowDevTools() { embedder_message_dispatcher_.reset( DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend(this)); - content::WebContents::CreateParams create_params(web_contents_->GetBrowserContext()); + content::WebContents::CreateParams create_params( + web_contents_->GetBrowserContext()); devtools_web_contents_.reset(content::WebContents::Create(create_params)); Observe(devtools_web_contents_.get()); @@ -324,10 +333,11 @@ void InspectableWebContentsImpl::Detach() { agent_host_ = nullptr; } -void InspectableWebContentsImpl::CallClientFunction(const std::string& function_name, - const base::Value* arg1, - const base::Value* arg2, - const base::Value* arg3) { +void InspectableWebContentsImpl::CallClientFunction( + const std::string& function_name, + const base::Value* arg1, + const base::Value* arg2, + const base::Value* arg3) { if (!devtools_web_contents_) return; @@ -433,15 +443,17 @@ void InspectableWebContentsImpl::LoadNetworkResource( return; } - auto browser_context = static_cast(devtools_web_contents_->GetBrowserContext()); + auto browser_context = + static_cast(devtools_web_contents_->GetBrowserContext()); net::URLFetcher* fetcher = (net::URLFetcher::Create(gurl, net::URLFetcher::GET, this)).release(); pending_requests_[fetcher] = callback; fetcher->SetRequestContext(browser_context->url_request_context_getter()); fetcher->SetExtraRequestHeaders(headers); - fetcher->SaveResponseWithWriter(std::unique_ptr( - new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id))); + fetcher->SaveResponseWithWriter( + std::unique_ptr( + new ResponseWriter(weak_factory_.GetWeakPtr(), stream_id))); fetcher->Start(); } @@ -509,7 +521,8 @@ void InspectableWebContentsImpl::SearchInPath( delegate_->DevToolsSearchInPath(request_id, file_system_path, query); } -void InspectableWebContentsImpl::SetWhitelistedShortcuts(const std::string& message) { +void InspectableWebContentsImpl::SetWhitelistedShortcuts( + const std::string& message) { } void InspectableWebContentsImpl::ZoomIn() { @@ -548,16 +561,18 @@ void InspectableWebContentsImpl::DispatchProtocolMessageFromDevToolsFrontend( agent_host_->DispatchProtocolMessage(this, message); } -void InspectableWebContentsImpl::RecordActionUMA(const std::string& name, int action) { +void InspectableWebContentsImpl::RecordActionUMA(const std::string& name, + int action) { if (name == kDevToolsActionTakenHistogram) UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsActionTakenBoundary); else if (name == kDevToolsPanelShownHistogram) UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsPanelShownBoundary); } -void InspectableWebContentsImpl::SendJsonRequest(const DispatchCallback& callback, - const std::string& browser_id, - const std::string& url) { +void InspectableWebContentsImpl::SendJsonRequest( + const DispatchCallback& callback, + const std::string& browser_id, + const std::string& url) { callback.Run(nullptr); } @@ -584,7 +599,8 @@ void InspectableWebContentsImpl::ClearPreferences() { update.Get()->Clear(); } -void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(const std::string& message) { +void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend( + const std::string& message) { std::string method; base::ListValue empty_params; base::ListValue* params = &empty_params; @@ -728,14 +744,14 @@ void InspectableWebContentsImpl::OnWebContentsFocused() { void InspectableWebContentsImpl::DidStartNavigationToPendingEntry( const GURL& url, content::ReloadType reload_type) { - frontend_host_.reset( - content::DevToolsFrontendHost::Create( - web_contents()->GetMainFrame(), - base::Bind(&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend, - base::Unretained(this)))); + frontend_host_.reset(content::DevToolsFrontendHost::Create( + web_contents()->GetMainFrame(), + base::Bind(&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend, + base::Unretained(this)))); } -void InspectableWebContentsImpl::OnURLFetchComplete(const net::URLFetcher* source) { +void InspectableWebContentsImpl::OnURLFetchComplete( + const net::URLFetcher* source) { DCHECK(source); auto it = pending_requests_.find(source); DCHECK(it != pending_requests_.end()); diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 9b565f0f2dd..2f000c21022 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -173,7 +173,8 @@ class InspectableWebContentsImpl : bool frontend_loaded_; scoped_refptr agent_host_; std::unique_ptr frontend_host_; - std::unique_ptr embedder_message_dispatcher_; + std::unique_ptr + embedder_message_dispatcher_; DevToolsContentsResizingStrategy contents_resizing_strategy_; gfx::Rect devtools_bounds_; diff --git a/brightray/browser/linux/libnotify_loader.cc b/brightray/browser/linux/libnotify_loader.cc index 747108529ae..5510bc23cf3 100644 --- a/brightray/browser/linux/libnotify_loader.cc +++ b/brightray/browser/linux/libnotify_loader.cc @@ -1,5 +1,6 @@ // This is generated file. Do not modify directly. -// Path to the code generator: tools/generate_library_loader/generate_library_loader.py . +// Path to the code generator: +// tools/generate_library_loader/generate_library_loader.py . #include "browser/linux/libnotify_loader.h" @@ -68,9 +69,9 @@ bool LibNotifyLoader::Load(const std::string& library_name) { return false; } - notify_notification_set_image_from_pixbuf = - reinterpret_castnotify_notification_set_image_from_pixbuf)>( - dlsym(library_, "notify_notification_set_image_from_pixbuf")); + notify_notification_set_image_from_pixbuf = reinterpret_castnotify_notification_set_image_from_pixbuf)>( + dlsym(library_, "notify_notification_set_image_from_pixbuf")); if (!notify_notification_set_image_from_pixbuf) { CleanUp(true); return false; diff --git a/brightray/browser/linux/libnotify_loader.h b/brightray/browser/linux/libnotify_loader.h index 48fda0b632a..a48f4794147 100644 --- a/brightray/browser/linux/libnotify_loader.h +++ b/brightray/browser/linux/libnotify_loader.h @@ -1,5 +1,6 @@ // This is generated file. Do not modify directly. -// Path to the code generator: tools/generate_library_loader/generate_library_loader.py . +// Path to the code generator: +// tools/generate_library_loader/generate_library_loader.py . #ifndef BRIGHTRAY_BROWSER_LINUX_LIBNOTIFY_LOADER_H_ #define BRIGHTRAY_BROWSER_LINUX_LIBNOTIFY_LOADER_H_ @@ -24,9 +25,11 @@ class LibNotifyLoader { decltype(&::notify_get_server_info) notify_get_server_info; decltype(&::notify_notification_new) notify_notification_new; decltype(&::notify_notification_add_action) notify_notification_add_action; - decltype(&::notify_notification_set_image_from_pixbuf) notify_notification_set_image_from_pixbuf; + decltype(&::notify_notification_set_image_from_pixbuf) + notify_notification_set_image_from_pixbuf; decltype(&::notify_notification_set_timeout) notify_notification_set_timeout; - decltype(&::notify_notification_set_hint_string) notify_notification_set_hint_string; + decltype(&::notify_notification_set_hint_string) + notify_notification_set_hint_string; decltype(&::notify_notification_show) notify_notification_show; decltype(&::notify_notification_close) notify_notification_close; diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index ab296e21831..aea7b7cc42d 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -22,7 +22,8 @@ bool HasCapability(const std::string& capability) { bool result = false; GList* capabilities = libnotify_loader_.notify_get_server_caps(); - if (g_list_find_custom(capabilities, capability.c_str(), (GCompareFunc) g_strcmp0) != NULL) + if (g_list_find_custom(capabilities, capability.c_str(), + (GCompareFunc)g_strcmp0) != NULL) result = true; g_list_free_full(capabilities, g_free); diff --git a/brightray/browser/media/media_stream_devices_controller.cc b/brightray/browser/media/media_stream_devices_controller.cc index a744a08ae4d..c01749ab43d 100644 --- a/brightray/browser/media/media_stream_devices_controller.cc +++ b/brightray/browser/media/media_stream_devices_controller.cc @@ -142,10 +142,12 @@ void MediaStreamDevicesController::Accept() { content::MediaResponseCallback cb = callback_; callback_.Reset(); - cb.Run(devices, content::MEDIA_DEVICE_OK, std::unique_ptr()); + cb.Run(devices, content::MEDIA_DEVICE_OK, + std::unique_ptr()); } -void MediaStreamDevicesController::Deny(content::MediaStreamRequestResult result) { +void MediaStreamDevicesController::Deny( + content::MediaStreamRequestResult result) { content::MediaResponseCallback cb = callback_; callback_.Reset(); cb.Run(content::MediaStreamDevices(), diff --git a/brightray/browser/net/devtools_network_controller.h b/brightray/browser/net/devtools_network_controller.h index 02bb6985594..7e6c948b42b 100644 --- a/brightray/browser/net/devtools_network_controller.h +++ b/brightray/browser/net/devtools_network_controller.h @@ -24,8 +24,9 @@ class DevToolsNetworkController { DevToolsNetworkInterceptor* GetInterceptor(const std::string& client_id); private: - using InterceptorMap = base::ScopedPtrHashMap>; + using InterceptorMap = + base::ScopedPtrHashMap>; std::unique_ptr appcache_interceptor_; InterceptorMap interceptors_; diff --git a/brightray/browser/net/devtools_network_controller_handle.h b/brightray/browser/net/devtools_network_controller_handle.h index b5c861f5cd6..2d038e837f8 100644 --- a/brightray/browser/net/devtools_network_controller_handle.h +++ b/brightray/browser/net/devtools_network_controller_handle.h @@ -31,8 +31,9 @@ class DevToolsNetworkControllerHandle { private: void LazyInitialize(); - void SetNetworkStateOnIO(const std::string& client_id, - std::unique_ptr conditions); + void SetNetworkStateOnIO( + const std::string& client_id, + std::unique_ptr conditions); std::unique_ptr controller_; diff --git a/brightray/browser/net/devtools_network_protocol_handler.cc b/brightray/browser/net/devtools_network_protocol_handler.cc index 584840533be..58988577b43 100644 --- a/brightray/browser/net/devtools_network_protocol_handler.cc +++ b/brightray/browser/net/devtools_network_protocol_handler.cc @@ -30,7 +30,8 @@ const char kErrorMessage[] = "message"; } // namespace params const char kEmulateNetworkConditions[] = "Network.emulateNetworkConditions"; -const char kCanEmulateNetworkConditions[] = "Network.canEmulateNetworkConditions"; +const char kCanEmulateNetworkConditions[] = + "Network.canEmulateNetworkConditions"; const char kId[] = "id"; const char kMethod[] = "method"; const char kParams[] = "params"; diff --git a/brightray/browser/net/devtools_network_transaction_factory.h b/brightray/browser/net/devtools_network_transaction_factory.h index a6c8f6a3c2d..49286a04742 100644 --- a/brightray/browser/net/devtools_network_transaction_factory.h +++ b/brightray/browser/net/devtools_network_transaction_factory.h @@ -21,13 +21,14 @@ class DevToolsNetworkTransactionFactory : public net::HttpTransactionFactory { ~DevToolsNetworkTransactionFactory() override; // net::HttpTransactionFactory: - int CreateTransaction(net::RequestPriority priority, - std::unique_ptr* transaction) override; + int CreateTransaction( + net::RequestPriority priority, + std::unique_ptr* transaction) override; net::HttpCache* GetCache() override; net::HttpNetworkSession* GetSession() override; private: - DevToolsNetworkController* controller_; + DevToolsNetworkController* controller_; std::unique_ptr network_layer_; DISALLOW_COPY_AND_ASSIGN(DevToolsNetworkTransactionFactory); diff --git a/brightray/browser/net_log.cc b/brightray/browser/net_log.cc index f141c7ef2e4..6b41eb738c1 100644 --- a/brightray/browser/net_log.cc +++ b/brightray/browser/net_log.cc @@ -40,7 +40,8 @@ void NetLog::StartLogging(net::URLRequestContext* url_request_context) { if (!command_line->HasSwitch(switches::kLogNetLog)) return; - base::FilePath log_path = command_line->GetSwitchValuePath(switches::kLogNetLog); + 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) diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index e0ef20bb57b..2af03e0f959 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -25,7 +25,8 @@ const char kIgnoreConnectionsLimit[] = "ignore-connections-limit"; NetworkDelegate::NetworkDelegate() { auto command_line = base::CommandLine::ForCurrentProcess(); if (command_line->HasSwitch(kIgnoreConnectionsLimit)) { - std::string value = command_line->GetSwitchValueASCII(kIgnoreConnectionsLimit); + std::string value = + command_line->GetSwitchValueASCII(kIgnoreConnectionsLimit); ignore_connections_limit_domains_ = base::SplitString( value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); } diff --git a/brightray/browser/permission_manager.h b/brightray/browser/permission_manager.h index 67168ed2b31..7e9a283913f 100644 --- a/brightray/browser/permission_manager.h +++ b/brightray/browser/permission_manager.h @@ -22,14 +22,16 @@ class PermissionManager : public content::PermissionManager { content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, bool user_gesture, - const base::Callback& callback) override; + const base::Callback& callback) + override; int RequestPermissions( const std::vector& permissions, content::RenderFrameHost* render_frame_host, const GURL& requesting_origin, bool user_gesture, - const base::Callback&)>& callback) override; + const base::Callback< + void(const std::vector&)>& callback) + override; void CancelPermissionRequest(int request_id) override; void ResetPermission(content::PermissionType permission, const GURL& requesting_origin, @@ -45,7 +47,8 @@ class PermissionManager : public content::PermissionManager { content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin, - const base::Callback& callback) override; + const base::Callback& callback) + override; void UnsubscribePermissionStatusChange(int subscription_id) override; private: diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 3fa04e0814c..8f9f16a2c17 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -45,7 +45,8 @@ PlatformNotificationService::PlatformNotificationService( PlatformNotificationService::~PlatformNotificationService() {} -blink::mojom::PermissionStatus PlatformNotificationService::CheckPermissionOnUIThread( +blink::mojom::PermissionStatus +PlatformNotificationService::CheckPermissionOnUIThread( content::BrowserContext* browser_context, const GURL& origin, int render_process_id) { @@ -53,7 +54,8 @@ blink::mojom::PermissionStatus PlatformNotificationService::CheckPermissionOnUIT return blink::mojom::PermissionStatus::GRANTED; } -blink::mojom::PermissionStatus PlatformNotificationService::CheckPermissionOnIOThread( +blink::mojom::PermissionStatus +PlatformNotificationService::CheckPermissionOnIOThread( content::ResourceContext* resource_context, const GURL& origin, int render_process_id) { diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 3510d00b844..a9e0a22756b 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -69,7 +69,8 @@ std::string URLRequestContextGetter::Delegate::GetUserAgent() { std::unique_ptr URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( content::ProtocolHandlerMap* protocol_handlers) { - std::unique_ptr job_factory(new net::URLRequestJobFactoryImpl); + std::unique_ptr job_factory( + new net::URLRequestJobFactoryImpl); for (auto& it : *protocol_handlers) { job_factory->SetProtocolHandler( @@ -89,7 +90,8 @@ URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( } net::HttpCache::BackendFactory* -URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory(const base::FilePath& base_path) { +URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory( + const base::FilePath& base_path) { base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache")); return new net::HttpCache::DefaultBackend( net::DISK_CACHE, @@ -104,11 +106,13 @@ URLRequestContextGetter::Delegate::CreateCertVerifier() { return net::CertVerifier::CreateDefault(); } -net::SSLConfigService* URLRequestContextGetter::Delegate::CreateSSLConfigService() { +net::SSLConfigService* +URLRequestContextGetter::Delegate::CreateSSLConfigService() { return new net::SSLConfigServiceDefaults; } -std::vector URLRequestContextGetter::Delegate::GetCookieableSchemes() { +std::vector +URLRequestContextGetter::Delegate::GetCookieableSchemes() { return { "http", "https", "ws", "wss" }; } @@ -177,7 +181,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_delegate_.reset(delegate_->CreateNetworkDelegate()); url_request_context_->set_network_delegate(network_delegate_.get()); - storage_.reset(new net::URLRequestContextStorage(url_request_context_.get())); + storage_.reset( + new net::URLRequestContextStorage(url_request_context_.get())); auto cookie_path = in_memory_ ? base::FilePath() : base_path_.Append(FILE_PATH_LITERAL("Cookies")); @@ -261,7 +266,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { // --auth-negotiate-delegate-whitelist if (command_line.HasSwitch(switches::kAuthNegotiateDelegateWhitelist)) { http_auth_preferences_->set_delegate_whitelist( - command_line.GetSwitchValueASCII(switches::kAuthNegotiateDelegateWhitelist)); + command_line.GetSwitchValueASCII( + switches::kAuthNegotiateDelegateWhitelist)); } auto auth_handler_factory = @@ -309,7 +315,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { // Give |storage_| ownership at the end in case it's |mapped_host_resolver|. storage_->set_host_resolver(std::move(host_resolver)); - network_session_params.host_resolver = url_request_context_->host_resolver(); + network_session_params.host_resolver = + url_request_context_->host_resolver(); http_network_session_.reset( new net::HttpNetworkSession(network_session_params)); @@ -324,7 +331,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { storage_->set_http_transaction_factory(base::WrapUnique( new net::HttpCache( base::WrapUnique(new DevToolsNetworkTransactionFactory( - network_controller_handle_->GetController(), http_network_session_.get())), + network_controller_handle_->GetController(), + http_network_session_.get())), std::move(backend), false))); } else { @@ -356,7 +364,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { return url_request_context_.get(); } -scoped_refptr URLRequestContextGetter::GetNetworkTaskRunner() const { +scoped_refptr +URLRequestContextGetter::GetNetworkTaskRunner() const { return BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); } diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index e08189d862d..c09824d44be 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -47,8 +47,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { } virtual std::string GetUserAgent(); virtual std::unique_ptr - CreateURLRequestJobFactory( - content::ProtocolHandlerMap* protocol_handlers); + CreateURLRequestJobFactory(content::ProtocolHandlerMap* protocol_handlers); virtual net::HttpCache::BackendFactory* CreateHttpCacheBackendFactory( const base::FilePath& base_path); virtual std::unique_ptr CreateCertVerifier(); @@ -75,7 +74,8 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { // net::URLRequestContextGetter: net::URLRequestContext* GetURLRequestContext() override; - scoped_refptr GetNetworkTaskRunner() const override; + scoped_refptr GetNetworkTaskRunner() + const override; net::HostResolver* host_resolver(); net::URLRequestJobFactory* job_factory() const { return job_factory_; } diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index fb1f8493cd9..13efd4be752 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -48,7 +48,9 @@ class DevToolsWindowDelegate : public views::ClientView, views::Widget* GetWidget() override { return widget_; } const views::Widget* GetWidget() const override { return widget_; } views::View* GetContentsView() override { return view_; } - views::ClientView* CreateClientView(views::Widget* widget) override { return this; } + views::ClientView* CreateClientView(views::Widget* widget) override { + return this; + } // views::ClientView: bool CanClose() override { @@ -85,10 +87,12 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews( if (inspectable_web_contents_->GetWebContents()->GetNativeView()) { views::WebView* contents_web_view = new views::WebView(nullptr); - contents_web_view->SetWebContents(inspectable_web_contents_->GetWebContents()); + contents_web_view->SetWebContents( + inspectable_web_contents_->GetWebContents()); contents_web_view_ = contents_web_view; } else { - contents_web_view_ = new views::Label(base::ASCIIToUTF16("No content under offscreen mode")); + contents_web_view_ = new views::Label( + base::ASCIIToUTF16("No content under offscreen mode")); } devtools_web_view_->SetVisible(false); @@ -98,7 +102,8 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews( InspectableWebContentsViewViews::~InspectableWebContentsViewViews() { if (devtools_window_) - inspectable_web_contents()->SaveDevToolsBounds(devtools_window_->GetWindowBoundsInScreen()); + inspectable_web_contents()->SaveDevToolsBounds( + devtools_window_->GetWindowBoundsInScreen()); } views::View* InspectableWebContentsViewViews::GetView() { @@ -117,7 +122,8 @@ void InspectableWebContentsViewViews::ShowDevTools() { if (devtools_window_) { devtools_window_web_view_->SetWebContents( inspectable_web_contents_->GetDevToolsWebContents()); - devtools_window_->SetBounds(inspectable_web_contents()->GetDevToolsBounds()); + devtools_window_->SetBounds( + inspectable_web_contents()->GetDevToolsBounds()); devtools_window_->Show(); } else { devtools_web_view_->SetVisible(true); @@ -134,7 +140,8 @@ void InspectableWebContentsViewViews::CloseDevTools() { devtools_visible_ = false; if (devtools_window_) { - inspectable_web_contents()->SaveDevToolsBounds(devtools_window_->GetWindowBoundsInScreen()); + inspectable_web_contents()->SaveDevToolsBounds( + devtools_window_->GetWindowBoundsInScreen()); devtools_window_.reset(); devtools_window_web_view_ = nullptr; devtools_window_delegate_ = nullptr; @@ -164,9 +171,10 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { if (!docked) { devtools_window_.reset(new views::Widget); devtools_window_web_view_ = new views::WebView(NULL); - devtools_window_delegate_ = new DevToolsWindowDelegate(this, - devtools_window_web_view_, - devtools_window_.get()); + devtools_window_delegate_ = new DevToolsWindowDelegate( + this, + devtools_window_web_view_ + devtools_window_.get()); views::Widget::InitParams params; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; @@ -176,7 +184,8 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { #if defined(USE_X11) params.wm_role_name = "devtools"; if (GetDelegate()) - GetDelegate()->GetDevToolsWindowWMClass(¶ms.wm_class_name, ¶ms.wm_class_class); + GetDelegate()->GetDevToolsWindowWMClass(¶ms.wm_class_name, + ¶ms.wm_class_class); #endif devtools_window_->Init(params); diff --git a/brightray/browser/views/views_delegate.cc b/brightray/browser/views/views_delegate.cc index 8dcbe38ae20..99797dea4ad 100644 --- a/brightray/browser/views/views_delegate.cc +++ b/brightray/browser/views/views_delegate.cc @@ -48,7 +48,8 @@ void ViewsDelegate::NotifyMenuItemFocused( #if defined(OS_WIN) HICON ViewsDelegate::GetDefaultWindowIcon() const { // Use current exe's icon as default window icon. - return LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(1 /* IDR_MAINFRAME */)); + return LoadIcon(GetModuleHandle(NULL), + MAKEINTRESOURCE(1 /* IDR_MAINFRAME */)); } HICON ViewsDelegate::GetSmallWindowIcon() const { diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 6e913ea37ff..c185246809e 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -38,7 +38,8 @@ bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) { NotificationPresenter* NotificationPresenter::Create() { if (!WindowsToastNotification::Initialize()) return nullptr; - std::unique_ptr presenter(new NotificationPresenterWin); + std::unique_ptr presenter( + new NotificationPresenterWin); if (!presenter->Init()) return nullptr; return presenter.release(); diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index 69b89f4ae5d..c3e6a9ad43f 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -10,9 +10,15 @@ // icon: "file:///C:/Path/To/Your/Image.png" // }); -// windowsNotification.onshow = function () { console.log("Notification shown") }; -// windowsNotification.onclick = function () { console.log("Notification clicked") }; -// windowsNotification.onclose = function () { console.log("Notification dismissed") }; +// windowsNotification.onshow = function () { +// console.log("Notification shown") +// }; +// windowsNotification.onclick = function () { +// console.log("Notification clicked") +// }; +// windowsNotification.onclose = function () { +// console.log("Notification dismissed") +// }; #ifndef BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ #define BRIGHTRAY_BROWSER_WIN_NOTIFICATION_PRESENTER_WIN_H_ diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc index 3645f53f478..4551ddfa0aa 100644 --- a/brightray/common/main_delegate.cc +++ b/brightray/common/main_delegate.cc @@ -61,9 +61,9 @@ void InitializeResourceBundle(const std::string& locale) { bundle.AddDataPackFromPath( pak_dir.Append(FILE_PATH_LITERAL("pdf_viewer_resources.pak")), ui::GetSupportedScaleFactors()[0]); - bundle.AddDataPackFromPath( - pak_dir.Append(FILE_PATH_LITERAL("blink_image_resources_200_percent.pak")), - ui::SCALE_FACTOR_200P); + bundle.AddDataPackFromPath(pak_dir.Append(FILE_PATH_LITERAL( + "blink_image_resources_200_percent.pak")), + ui::SCALE_FACTOR_200P); bundle.AddDataPackFromPath( pak_dir.Append(FILE_PATH_LITERAL("content_resources_200_percent.pak")), ui::SCALE_FACTOR_200P); @@ -76,7 +76,6 @@ void InitializeResourceBundle(const std::string& locale) { #endif } - MainDelegate::MainDelegate() { } diff --git a/brightray/common/switches.cc b/brightray/common/switches.cc index c46fe3bda97..1f0da2adfdd 100644 --- a/brightray/common/switches.cc +++ b/brightray/common/switches.cc @@ -47,7 +47,8 @@ const char kDisableHttp2[] = "disable-http2"; const char kAuthServerWhitelist[] = "auth-server-whitelist"; // Whitelist containing servers for which Kerberos delegation is allowed. -const char kAuthNegotiateDelegateWhitelist[] = "auth-negotiate-delegate-whitelist"; +const char kAuthNegotiateDelegateWhitelist[] = + "auth-negotiate-delegate-whitelist"; // Ignores certificate-related errors. const char kIgnoreCertificateErrors[] = "ignore-certificate-errors"; From 4e473897b7dd168996d951c8d45c15c21ec5ffbe Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Fri, 24 Mar 2017 11:08:08 +0900 Subject: [PATCH 0984/1195] Use === --- lib/browser/guest-window-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index 7649547f942..dc51ce105df 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -247,7 +247,7 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_INTERNAL_WINDOW_OPEN', function (event const newGuest = event.newGuest if ((event.sender.isGuest() && !event.sender.allowPopups) || event.defaultPrevented) { if (newGuest !== undefined && newGuest !== null) { - if (webContents == newGuest.webContents) { + if (webContents === newGuest.webContents) { event.defaultPrevented = false } event.returnValue = setupGuest(event.sender, frameName, newGuest, options) From 49ef4e326f602564e9d1b2c10075b5284ffbce81 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 23 Mar 2017 15:51:25 -0700 Subject: [PATCH 0985/1195] Initialize submodules in appveyor build --- brightray/appveyor.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/appveyor.yml b/brightray/appveyor.yml index 46a91007e6e..d623fdc8c64 100644 --- a/brightray/appveyor.yml +++ b/brightray/appveyor.yml @@ -13,6 +13,7 @@ platform: install: - cmd: SET PATH=C:\Program Files (x86)\MSBuild\14.0\bin\;%PATH% - cmd: SET PATH=C:\python27;%PATH% + - cmd: git submodule update --init --recursive - cmd: bash script/cibuild branches: From 21956071e63013788b7aa2294ee20e79f202ebcd Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 24 Mar 2017 09:52:37 -0700 Subject: [PATCH 0986/1195] Fix compilation issue --- brightray/browser/views/inspectable_web_contents_view_views.cc | 2 +- 1 file changed, 1 insertion(+), 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 13efd4be752..6a9997f2324 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -173,7 +173,7 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { devtools_window_web_view_ = new views::WebView(NULL); devtools_window_delegate_ = new DevToolsWindowDelegate( this, - devtools_window_web_view_ + devtools_window_web_view_, devtools_window_.get()); views::Widget::InitParams params; From e885e33b75799f7cc338d7604374efb35b08e2a3 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Tue, 28 Mar 2017 19:50:00 +0900 Subject: [PATCH 0987/1195] Fix choise -> choice --- docs/api/window-open.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/window-open.md b/docs/api/window-open.md index b0cd0e25011..308ab9c73a1 100644 --- a/docs/api/window-open.md +++ b/docs/api/window-open.md @@ -45,7 +45,7 @@ origin preference. ### Use Native `window.open()` If you want to use native `window.open()` implementation, pass `useNativeWindowOpen: true` in `webPreferences` option. -Native `window.open()` allows synchronous access to opened windows so it is convenient choise if you need to open a dialog or a preferences window. +Native `window.open()` allows synchronous access to opened windows so it is convenient choice if you need to open a dialog or a preferences window. The creation of the `BrowserWindow` is customizable in `WebContents`'s `new-window` event. From 87565f4c8452486195a6582f4721532a2f82e6d9 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Tue, 28 Mar 2017 19:50:45 +0900 Subject: [PATCH 0988/1195] Simplify example code --- docs/api/window-open.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/api/window-open.md b/docs/api/window-open.md index 308ab9c73a1..79158b292a7 100644 --- a/docs/api/window-open.md +++ b/docs/api/window-open.md @@ -68,8 +68,7 @@ mainWindow.webContents.on('new-window', (event, url, frameName, disposition, opt width: 100, height: 100 }) - modal = new BrowserWindow(options) - event.newGuest = modal + event.newGuest = new BrowserWindow(options) } }) ``` From de2019f6b8e75dddbf1da569e87f2dfe7e03aea2 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Tue, 28 Mar 2017 19:58:23 +0900 Subject: [PATCH 0989/1195] Change webContents -> options.webContents --- lib/browser/guest-window-manager.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index dc51ce105df..77777ae211d 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -242,12 +242,11 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_INTERNAL_WINDOW_OPEN', function (event disposition, options, additionalFeatures, postData) { options = mergeBrowserWindowOptions(event.sender, options) - const {webContents} = options event.sender.emit('new-window', event, url, frameName, disposition, options, additionalFeatures) const newGuest = event.newGuest if ((event.sender.isGuest() && !event.sender.allowPopups) || event.defaultPrevented) { if (newGuest !== undefined && newGuest !== null) { - if (webContents === newGuest.webContents) { + if (options.webContents === newGuest.webContents) { event.defaultPrevented = false } event.returnValue = setupGuest(event.sender, frameName, newGuest, options) From 9edfbab89fc3e369d08331a0df9dae1e72e95979 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Tue, 28 Mar 2017 19:58:58 +0900 Subject: [PATCH 0990/1195] Add comment why defaultPrevented = false --- lib/browser/guest-window-manager.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index 77777ae211d..e06dd27d203 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -247,6 +247,8 @@ ipcMain.on('ELECTRON_GUEST_WINDOW_MANAGER_INTERNAL_WINDOW_OPEN', function (event if ((event.sender.isGuest() && !event.sender.allowPopups) || event.defaultPrevented) { if (newGuest !== undefined && newGuest !== null) { if (options.webContents === newGuest.webContents) { + // the webContents is not changed, so set defaultPrevented to false to + // stop the callers of this event from destroying the webContents. event.defaultPrevented = false } event.returnValue = setupGuest(event.sender, frameName, newGuest, options) From 37c4569982365db5299f6e9852d3cee509bd3893 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Tue, 28 Mar 2017 20:00:33 +0900 Subject: [PATCH 0991/1195] Use GetBoolean directly --- atom/browser/web_contents_preferences.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index aa760a83d28..adab0bf85ac 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -106,7 +106,7 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( // integration. if (IsSandboxed(web_contents)) command_line->AppendSwitch(switches::kEnableSandbox); - if (UsesNativeWindowOpen(web_contents)) + if (web_preferences.GetBoolean("nativeWindowOpen", &b) && b) command_line->AppendSwitch(switches::kNativeWindowOpen); // The preload script. From 424078cfdba3d36dae3df4428014e2c6402eb2d3 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Tue, 28 Mar 2017 21:06:02 +0200 Subject: [PATCH 0992/1195] Fix namespace comments. --- brightray/browser/browser_client.cc | 2 +- brightray/browser/browser_main_parts_mac.mm | 2 +- brightray/browser/inspectable_web_contents_view_mac.mm | 2 +- brightray/browser/web_ui_controller_factory.cc | 2 +- brightray/common/application_info_mac.mm | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index 8c39df65cc0..fdf66593770 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -23,7 +23,7 @@ namespace { BrowserClient* g_browser_client; -} +} // namespace BrowserClient* BrowserClient::Get() { return g_browser_client; diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm index 19d0262a101..20d7df5529d 100644 --- a/brightray/browser/browser_main_parts_mac.mm +++ b/brightray/browser/browser_main_parts_mac.mm @@ -19,4 +19,4 @@ void BrowserMainParts::InitializeMainNib() { [mainNib release]; } -} +} // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index e708a686802..a74c52456ae 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -56,4 +56,4 @@ void InspectableWebContentsViewMac::SetTitle(const base::string16& title) { [view_ setTitle:base::SysUTF16ToNSString(title)]; } -} +} // namespace brightray diff --git a/brightray/browser/web_ui_controller_factory.cc b/brightray/browser/web_ui_controller_factory.cc index c59e5bb0c66..63e4a3aba41 100644 --- a/brightray/browser/web_ui_controller_factory.cc +++ b/brightray/browser/web_ui_controller_factory.cc @@ -16,7 +16,7 @@ namespace { const char kChromeUIDevToolsBundledHost[] = "devtools"; -} +} // namespace // static WebUIControllerFactory* WebUIControllerFactory::GetInstance() { diff --git a/brightray/common/application_info_mac.mm b/brightray/common/application_info_mac.mm index ee9f9bbf4c5..a8f0e354dbf 100644 --- a/brightray/common/application_info_mac.mm +++ b/brightray/common/application_info_mac.mm @@ -17,7 +17,7 @@ std::string ApplicationInfoDictionaryValue(CFStringRef key) { return ApplicationInfoDictionaryValue(base::mac::CFToNSCast(key)); } -} +} // namespace std::string GetApplicationName() { return ApplicationInfoDictionaryValue(kCFBundleNameKey); @@ -27,4 +27,4 @@ std::string GetApplicationVersion() { return ApplicationInfoDictionaryValue(@"CFBundleShortVersionString"); } -} +} // namespace brightray From e4c571fc683f8cd435814491beafdc6b5ff97297 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 30 Mar 2017 21:30:13 +0200 Subject: [PATCH 0993/1195] Remove unused using namespace declaration. --- brightray/browser/mac/bry_inspectable_web_contents_view.mm | 2 -- 1 file changed, 2 deletions(-) diff --git a/brightray/browser/mac/bry_inspectable_web_contents_view.mm b/brightray/browser/mac/bry_inspectable_web_contents_view.mm index 16174ed3617..25e7083948b 100644 --- a/brightray/browser/mac/bry_inspectable_web_contents_view.mm +++ b/brightray/browser/mac/bry_inspectable_web_contents_view.mm @@ -8,8 +8,6 @@ #include "content/public/browser/render_widget_host_view.h" #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" -using namespace brightray; - @implementation BRYInspectableWebContentsView - (instancetype)initWithInspectableWebContentsViewMac:(InspectableWebContentsViewMac*)view { From d18b34d55f784d157e1bc013718183b63ab6789c Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Thu, 30 Mar 2017 21:44:15 +0200 Subject: [PATCH 0994/1195] Replace size() method with empty() when possible. There is no guaranteed that size() is a constant-time function. --- brightray/browser/browser_main_parts.cc | 3 +-- brightray/browser/devtools_file_system_indexer.cc | 2 +- brightray/browser/net/devtools_network_controller.cc | 2 +- brightray/browser/net/devtools_network_interceptor.cc | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index c37100a76e9..57f4f9d1fff 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -54,7 +54,6 @@ #include "device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h" #endif -using content::BrowserThread; namespace brightray { @@ -107,7 +106,7 @@ NOINLINE void WaitingForUIThreadToHandleIOError() { } int BrowserX11IOErrorHandler(Display* d) { - if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { + if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { // Wait for the UI thread (which has a different connection to the X server) // to get the error. We can't call shutdown from this thread without // tripping an error. Doing it through a function so that we'll be able diff --git a/brightray/browser/devtools_file_system_indexer.cc b/brightray/browser/devtools_file_system_indexer.cc index 1700ff0eb99..e41830258fd 100644 --- a/brightray/browser/devtools_file_system_indexer.cc +++ b/brightray/browser/devtools_file_system_indexer.cc @@ -205,7 +205,7 @@ vector Index::Search(string query) { vector result; FileIdsMap::const_iterator ids_it = file_ids_.begin(); for (; ids_it != file_ids_.end(); ++ids_it) { - if (trigrams.size() == 0 || + if (trigrams.empty() || file_ids.find(ids_it->second) != file_ids.end()) { result.push_back(ids_it->first); } diff --git a/brightray/browser/net/devtools_network_controller.cc b/brightray/browser/net/devtools_network_controller.cc index cfa4e234712..07b469b1f77 100644 --- a/brightray/browser/net/devtools_network_controller.cc +++ b/brightray/browser/net/devtools_network_controller.cc @@ -67,7 +67,7 @@ DevToolsNetworkInterceptor* DevToolsNetworkController::GetInterceptor(const std::string& client_id) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - if (!interceptors_.size() || client_id.empty()) + if (interceptors_.empty() || client_id.empty()) return nullptr; DevToolsNetworkInterceptor* interceptor = interceptors_.get(client_id); diff --git a/brightray/browser/net/devtools_network_interceptor.cc b/brightray/browser/net/devtools_network_interceptor.cc index f0e3e0e488d..73e8538310d 100644 --- a/brightray/browser/net/devtools_network_interceptor.cc +++ b/brightray/browser/net/devtools_network_interceptor.cc @@ -108,7 +108,7 @@ uint64_t DevToolsNetworkInterceptor::UpdateThrottledRecords( uint64_t last_tick, base::TimeDelta tick_length) { if (tick_length.is_zero()) { - DCHECK(!records->size()); + DCHECK(records->empty()); return last_tick; } @@ -195,7 +195,7 @@ base::TimeTicks DevToolsNetworkInterceptor::CalculateDesiredTime( void DevToolsNetworkInterceptor::ArmTimer(base::TimeTicks now) { size_t suspend_count = suspended_.size(); - if (!download_.size() && !upload_.size() && !suspend_count) { + if (download_.empty() && upload_.empty() && !suspend_count) { timer_.Stop(); return; } From 22035e2d6d2b3d1132ea26719d9165e52fc81054 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 31 Mar 2017 20:18:20 +0200 Subject: [PATCH 0995/1195] Fix cpplint: at least two spaces between code and comments. --- brightray/browser/browser_client.cc | 2 +- brightray/browser/browser_main_parts_mac.mm | 2 +- brightray/browser/inspectable_web_contents_view_mac.mm | 2 +- brightray/browser/web_ui_controller_factory.cc | 2 +- brightray/common/application_info_mac.mm | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index fdf66593770..e425b7a83b1 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -23,7 +23,7 @@ namespace { BrowserClient* g_browser_client; -} // namespace +} // namespace BrowserClient* BrowserClient::Get() { return g_browser_client; diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm index 20d7df5529d..1df09f20e79 100644 --- a/brightray/browser/browser_main_parts_mac.mm +++ b/brightray/browser/browser_main_parts_mac.mm @@ -19,4 +19,4 @@ void BrowserMainParts::InitializeMainNib() { [mainNib release]; } -} // namespace brightray +} // namespace brightray diff --git a/brightray/browser/inspectable_web_contents_view_mac.mm b/brightray/browser/inspectable_web_contents_view_mac.mm index a74c52456ae..94edc1c1a71 100644 --- a/brightray/browser/inspectable_web_contents_view_mac.mm +++ b/brightray/browser/inspectable_web_contents_view_mac.mm @@ -56,4 +56,4 @@ void InspectableWebContentsViewMac::SetTitle(const base::string16& title) { [view_ setTitle:base::SysUTF16ToNSString(title)]; } -} // namespace brightray +} // namespace brightray diff --git a/brightray/browser/web_ui_controller_factory.cc b/brightray/browser/web_ui_controller_factory.cc index 63e4a3aba41..565c0258883 100644 --- a/brightray/browser/web_ui_controller_factory.cc +++ b/brightray/browser/web_ui_controller_factory.cc @@ -16,7 +16,7 @@ namespace { const char kChromeUIDevToolsBundledHost[] = "devtools"; -} // namespace +} // namespace // static WebUIControllerFactory* WebUIControllerFactory::GetInstance() { diff --git a/brightray/common/application_info_mac.mm b/brightray/common/application_info_mac.mm index a8f0e354dbf..6898b6376de 100644 --- a/brightray/common/application_info_mac.mm +++ b/brightray/common/application_info_mac.mm @@ -17,7 +17,7 @@ std::string ApplicationInfoDictionaryValue(CFStringRef key) { return ApplicationInfoDictionaryValue(base::mac::CFToNSCast(key)); } -} // namespace +} // namespace std::string GetApplicationName() { return ApplicationInfoDictionaryValue(kCFBundleNameKey); @@ -27,4 +27,4 @@ std::string GetApplicationVersion() { return ApplicationInfoDictionaryValue(@"CFBundleShortVersionString"); } -} // namespace brightray +} // namespace brightray From f506047a9b720f6d61987ea9f1f0277bdf384376 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 31 Mar 2017 21:56:19 +0200 Subject: [PATCH 0996/1195] Remove an extra blank line. --- brightray/browser/browser_main_parts.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 57f4f9d1fff..93afed487f0 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -54,7 +54,6 @@ #include "device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h" #endif - namespace brightray { namespace { From ee1f3acf7b7e15a58425d071e56f25a845d61a56 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 31 Mar 2017 21:27:06 +0200 Subject: [PATCH 0997/1195] Don't use anonymous namespace in header file. Anonymous namespace should be forbidden in header files even for the forward declarations: * As declarations defined in anonymous namespace are internal linkage, each translation unit which includes this header will get unique copy, which wastes space. * It is easy to violate C++ ODR rule. Consider the following "foo.h": ```cpp namespace { class Foo; } class Bar { public: Foo* getFoo(); Foo* foo; } ``` If the 'foo.h' is included in multiple `.cc` files, the compiler will put `Foo` into a different anonymous namespace in each `.cc`, which means there are different definitions of `Foo` in the program (a violation of the ODR). --- .../views/inspectable_web_contents_view_views.cc | 5 +++-- .../views/inspectable_web_contents_view_views.h | 11 ++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 6a9997f2324..073da870e56 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -178,7 +178,7 @@ void InspectableWebContentsViewViews::SetIsDocked(bool docked) { views::Widget::InitParams params; params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; - params.delegate = GetDevToolsWindowDelegate(); + params.delegate = devtools_window_delegate_; params.bounds = inspectable_web_contents()->GetDevToolsBounds(); #if defined(USE_X11) @@ -203,7 +203,8 @@ void InspectableWebContentsViewViews::SetContentsResizingStrategy( void InspectableWebContentsViewViews::SetTitle(const base::string16& title) { if (devtools_window_) { - GetDevToolsWindowDelegate()->SetWindowTitle(title); + static_cast(devtools_window_delegate_) + ->SetWindowTitle(title); devtools_window_->UpdateWindowTitle(); } } diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index 1af53e92fdf..1d2963fd19e 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -10,14 +10,11 @@ namespace views { class WebView; class Widget; +class WidgetDelegate; } namespace brightray { -namespace { // NOLINT -class DevToolsWindowDelegate; -} - class InspectableWebContentsImpl; class InspectableWebContentsViewViews : public InspectableWebContentsView, @@ -27,10 +24,6 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, InspectableWebContentsImpl* inspectable_web_contents_impl); ~InspectableWebContentsViewViews(); - DevToolsWindowDelegate* GetDevToolsWindowDelegate() const { - return devtools_window_delegate_; - } - // InspectableWebContentsView: views::View* GetView() override; views::View* GetWebView() override; @@ -61,7 +54,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, DevToolsContentsResizingStrategy strategy_; bool devtools_visible_; - DevToolsWindowDelegate* devtools_window_delegate_; + views::WidgetDelegate* devtools_window_delegate_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewViews); }; From e80a9bbb932c552b030d082060a32bc81d33eefe Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Sat, 1 Apr 2017 14:56:51 +0200 Subject: [PATCH 0998/1195] Move title_ to InspectableWebContentsViewVies to get rid of cast. --- .../views/inspectable_web_contents_view_views.cc | 14 +++++--------- .../views/inspectable_web_contents_view_views.h | 3 +++ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/brightray/browser/views/inspectable_web_contents_view_views.cc b/brightray/browser/views/inspectable_web_contents_view_views.cc index 073da870e56..8f52ca56995 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.cc +++ b/brightray/browser/views/inspectable_web_contents_view_views.cc @@ -24,8 +24,7 @@ class DevToolsWindowDelegate : public views::ClientView, : views::ClientView(widget, view), shell_(shell), view_(view), - widget_(widget), - title_(base::ASCIIToUTF16("Developer Tools")) { + widget_(widget) { // A WidgetDelegate should be deleted on DeleteDelegate. set_owned_by_client(); @@ -34,15 +33,13 @@ class DevToolsWindowDelegate : public views::ClientView, } virtual ~DevToolsWindowDelegate() {} - void SetWindowTitle(const base::string16& title) { title_ = title; } - // views::WidgetDelegate: void DeleteDelegate() override { delete this; } views::View* GetInitiallyFocusedView() override { return view_; } bool CanResize() const override { return true; } bool CanMaximize() const override { return true; } bool CanMinimize() const override { return true; } - base::string16 GetWindowTitle() const override { return title_; } + base::string16 GetWindowTitle() const override { return shell_->GetTitle(); } gfx::ImageSkia GetWindowAppIcon() override { return GetWindowIcon(); } gfx::ImageSkia GetWindowIcon() override { return icon_; } views::Widget* GetWidget() override { return widget_; } @@ -62,7 +59,6 @@ class DevToolsWindowDelegate : public views::ClientView, InspectableWebContentsViewViews* shell_; views::View* view_; views::Widget* widget_; - base::string16 title_; gfx::ImageSkia icon_; DISALLOW_COPY_AND_ASSIGN(DevToolsWindowDelegate); @@ -82,7 +78,8 @@ InspectableWebContentsViewViews::InspectableWebContentsViewViews( contents_web_view_(nullptr), devtools_web_view_(new views::WebView(nullptr)), devtools_visible_(false), - devtools_window_delegate_(nullptr) { + devtools_window_delegate_(nullptr), + title_(base::ASCIIToUTF16("Developer Tools")) { set_owned_by_client(); if (inspectable_web_contents_->GetWebContents()->GetNativeView()) { @@ -203,8 +200,7 @@ void InspectableWebContentsViewViews::SetContentsResizingStrategy( void InspectableWebContentsViewViews::SetTitle(const base::string16& title) { if (devtools_window_) { - static_cast(devtools_window_delegate_) - ->SetWindowTitle(title); + title_ = title; devtools_window_->UpdateWindowTitle(); } } diff --git a/brightray/browser/views/inspectable_web_contents_view_views.h b/brightray/browser/views/inspectable_web_contents_view_views.h index 1d2963fd19e..9094b9f35dc 100644 --- a/brightray/browser/views/inspectable_web_contents_view_views.h +++ b/brightray/browser/views/inspectable_web_contents_view_views.h @@ -40,6 +40,8 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, return inspectable_web_contents_; } + const base::string16& GetTitle() const { return title_; } + private: // views::View: void Layout() override; @@ -55,6 +57,7 @@ class InspectableWebContentsViewViews : public InspectableWebContentsView, DevToolsContentsResizingStrategy strategy_; bool devtools_visible_; views::WidgetDelegate* devtools_window_delegate_; + base::string16 title_; DISALLOW_COPY_AND_ASSIGN(InspectableWebContentsViewViews); }; From 3eab5df4a41b12b5f29d11eb3d942eca2f061c6e Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Tue, 4 Apr 2017 13:48:17 +0900 Subject: [PATCH 0999/1195] Revert "Reuse site instance only on window.open" This reverts commit 4d61d071b253c9bf8a7ad2583a2e10153fb65cc1. --- atom/browser/api/atom_api_web_contents.cc | 1 - atom/browser/atom_browser_client.cc | 33 +++++++---------------- atom/browser/atom_browser_client.h | 2 -- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 4e9315c6cb3..6ba23b3c9af 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -468,7 +468,6 @@ void WebContents::AddNewContents(content::WebContents* source, if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture, initial_rect.x(), initial_rect.y(), initial_rect.width(), initial_rect.height())) { - AtomBrowserClient::CancelReuseRendererProcessForNewWindow(); api_web_contents->DestroyWebContents(); } } diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 10cf4f95973..d06f27b9c27 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -51,10 +51,6 @@ namespace { // Next navigation should not restart renderer process. bool g_suppress_renderer_process_restart = false; -// Next navigation is caused by native window.open and -// the renderer process may be reused. -bool g_reuse_renderer_process_for_new_window = false; - // Custom schemes to be registered to handle service worker. std::string g_custom_service_worker_schemes = ""; @@ -68,10 +64,6 @@ void AtomBrowserClient::SuppressRendererProcessRestartForOnce() { g_suppress_renderer_process_restart = true; } -void AtomBrowserClient::CancelReuseRendererProcessForNewWindow() { - g_reuse_renderer_process_for_new_window = false; -} - void AtomBrowserClient::SetCustomServiceWorkerSchemes( const std::vector& schemes) { g_custom_service_worker_schemes = base::JoinString(schemes, ","); @@ -98,22 +90,16 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( content::BrowserContext* browser_context, content::SiteInstance* current_instance, const GURL& url) { - if (g_suppress_renderer_process_restart) { - g_suppress_renderer_process_restart = false; - return false; - } + if (url.SchemeIs(url::kJavaScriptScheme)) // "javacript:" scheme should always use same SiteInstance return false; int process_id = current_instance->GetProcess()->GetID(); - if (g_reuse_renderer_process_for_new_window) { - // native window.open can reuse renderer process - g_reuse_renderer_process_for_new_window = false; - } else if (!IsRendererSandboxed(process_id)) { + if (!(IsRendererSandboxed(process_id) + || RendererUsesNativeWindowOpen(process_id))) // non-sandboxed renderers should always create a new SiteInstance return true; - } // Create new a SiteInstance if navigating to a different site. auto src_url = current_instance->GetSiteURL(); @@ -202,6 +188,11 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation( content::SiteInstance* current_instance, const GURL& url, content::SiteInstance** new_instance) { + if (g_suppress_renderer_process_restart) { + g_suppress_renderer_process_restart = false; + return; + } + if (!ShouldCreateNewSiteInstance(browser_context, current_instance, url)) return; @@ -331,12 +322,8 @@ bool AtomBrowserClient::CanCreateWindow( bool* no_javascript_access) { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - if (IsRendererSandboxed(render_process_id)) { - *no_javascript_access = false; - return true; - } - if (RendererUsesNativeWindowOpen(render_process_id)) { - g_reuse_renderer_process_for_new_window = true; + if (IsRendererSandboxed(render_process_id) + || RendererUsesNativeWindowOpen(render_process_id)) { *no_javascript_access = false; return true; } diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index d3029073cb0..f60e72bc612 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -40,8 +40,6 @@ class AtomBrowserClient : public brightray::BrowserClient, // Don't force renderer process to restart for once. static void SuppressRendererProcessRestartForOnce(); - // Cancel reusing renderer process for new window. - static void CancelReuseRendererProcessForNewWindow(); // Custom schemes to be registered to handle service worker. static void SetCustomServiceWorkerSchemes( From 051e133ce33e3c1f6be625f65b7a4774182cc394 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Tue, 4 Apr 2017 19:05:13 +0900 Subject: [PATCH 1000/1195] Add test for opeing HTML file --- spec/api-browser-window-spec.js | 23 +++++++++++++------ .../api/native-window-open-child.html | 1 + spec/fixtures/api/native-window-open.html | 23 +++++++++++++++---- 3 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 spec/fixtures/api/native-window-open-child.html diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index c5c1bb28594..04c3be453cc 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1071,19 +1071,28 @@ describe('BrowserWindow module', function () { }) describe('nativeWindowOpen option', () => { - it('allows synchronous access to window opened by window.open()', (done) => { - ipcMain.once('answer', function (event, content) { - assert.equal(content, 'Hello') - done() - }) + beforeEach(() => { w.destroy() w = new BrowserWindow({ - show: false, + show: true, webPreferences: { nativeWindowOpen: true } }) - w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html')) + }) + it('opens window of about:blank with cross-scripting enabled', (done) => { + ipcMain.once('answer', function (event, content) { + assert.equal(content, 'Hello') + done() + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#blank')) + }) + it('opens window of same domain with cross-scripting enabled', (done) => { + ipcMain.once('answer', function (event, content) { + assert.equal(content, 'Hello') + done() + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#file')) }) }) }) diff --git a/spec/fixtures/api/native-window-open-child.html b/spec/fixtures/api/native-window-open-child.html new file mode 100644 index 00000000000..986a4a1a25b --- /dev/null +++ b/spec/fixtures/api/native-window-open-child.html @@ -0,0 +1 @@ +

Hello

diff --git a/spec/fixtures/api/native-window-open.html b/spec/fixtures/api/native-window-open.html index 630c4faa41b..49c9352265e 100644 --- a/spec/fixtures/api/native-window-open.html +++ b/spec/fixtures/api/native-window-open.html @@ -2,10 +2,25 @@ From e7b9b4b1a562b7f15c2ddf49a5124a2baeda6fbc Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Tue, 4 Apr 2017 20:54:10 +0900 Subject: [PATCH 1001/1195] Always create new site instance --- atom/browser/atom_browser_client.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index d06f27b9c27..4f0f3da45a3 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -96,8 +96,7 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( return false; int process_id = current_instance->GetProcess()->GetID(); - if (!(IsRendererSandboxed(process_id) - || RendererUsesNativeWindowOpen(process_id))) + if (!IsRendererSandboxed(process_id)) // non-sandboxed renderers should always create a new SiteInstance return true; From 90852c665de4d6b62f6d9f6b3baf410e7a40c0d5 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Wed, 5 Apr 2017 13:47:02 +0900 Subject: [PATCH 1002/1195] Pass RenderFrameHost to ShouldCreateNewSiteInstance --- atom/browser/atom_browser_client.cc | 6 ++++-- atom/browser/atom_browser_client.h | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 4f0f3da45a3..7c7e6cded29 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -87,10 +87,10 @@ content::WebContents* AtomBrowserClient::GetWebContentsFromProcessID( } bool AtomBrowserClient::ShouldCreateNewSiteInstance( + content::RenderFrameHost* render_frame_host, content::BrowserContext* browser_context, content::SiteInstance* current_instance, const GURL& url) { - if (url.SchemeIs(url::kJavaScriptScheme)) // "javacript:" scheme should always use same SiteInstance return false; @@ -183,6 +183,7 @@ std::string AtomBrowserClient::GetApplicationLocale() { } void AtomBrowserClient::OverrideSiteInstanceForNavigation( + content::RenderFrameHost* render_frame_host, content::BrowserContext* browser_context, content::SiteInstance* current_instance, const GURL& url, @@ -192,7 +193,8 @@ void AtomBrowserClient::OverrideSiteInstanceForNavigation( return; } - if (!ShouldCreateNewSiteInstance(browser_context, current_instance, url)) + if (!ShouldCreateNewSiteInstance(render_frame_host, browser_context, + current_instance, url)) return; scoped_refptr site_instance = diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index f60e72bc612..cd73b559e60 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -54,6 +54,7 @@ class AtomBrowserClient : public brightray::BrowserClient, content::WebPreferences* prefs) override; std::string GetApplicationLocale() override; void OverrideSiteInstanceForNavigation( + content::RenderFrameHost* render_frame_host, content::BrowserContext* browser_context, content::SiteInstance* current_instance, const GURL& dest_url, @@ -111,7 +112,8 @@ class AtomBrowserClient : public brightray::BrowserClient, void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; private: - bool ShouldCreateNewSiteInstance(content::BrowserContext* browser_context, + bool ShouldCreateNewSiteInstance(content::RenderFrameHost* render_frame_host, + content::BrowserContext* browser_context, content::SiteInstance* current_instance, const GURL& dest_url); struct ProcessPreferences { From cbdd52e43bbd89dcae01bb3d8e7660163d14fc58 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Wed, 5 Apr 2017 17:51:17 +0900 Subject: [PATCH 1003/1195] Always create new SiteInstance on root WebContents --- atom/browser/atom_browser_client.cc | 31 ++++++++++++++++++++++++++--- atom/browser/atom_browser_client.h | 13 ++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 7c7e6cded29..14d71b55175 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -96,9 +96,20 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( return false; int process_id = current_instance->GetProcess()->GetID(); - if (!IsRendererSandboxed(process_id)) - // non-sandboxed renderers should always create a new SiteInstance - return true; + if (!IsRendererSandboxed(process_id)) { + if (!RendererUsesNativeWindowOpen(process_id)) { + // non-sandboxed renderers without native window.open should always create + // a new SiteInstance + return true; + } + auto web_contents = + content::WebContents::FromRenderFrameHost(render_frame_host); + if (root_web_contents_.find(web_contents) != root_web_contents_.end()) { + // non-sandboxed renderers with native.window.open always create a new + // SiteInstance in the root webcontents. + return true; + } + } // Create new a SiteInstance if navigating to a different site. auto src_url = current_instance->GetSiteURL(); @@ -149,6 +160,8 @@ void AtomBrowserClient::RenderProcessWillLaunch( AddProcessPreferences(host->GetID(), process_prefs); // ensure the ProcessPreferences is removed later host->AddObserver(this); + + new RootWebContentsTracker(web_contents, this); } content::SpeechRecognitionManagerDelegate* @@ -392,4 +405,16 @@ void AtomBrowserClient::RenderProcessHostDestroyed( RemoveProcessPreferences(process_id); } +AtomBrowserClient::RootWebContentsTracker::RootWebContentsTracker( + content::WebContents* web_contents, + AtomBrowserClient* client) + : content::WebContentsObserver(web_contents), client_(client) { + client->root_web_contents_.insert(web_contents); +} + +void AtomBrowserClient::RootWebContentsTracker::WebContentsDestroyed() { + client_->root_web_contents_.erase(web_contents()); + delete this; +} + } // namespace atom diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index cd73b559e60..c1a229edae8 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -12,6 +12,7 @@ #include "brightray/browser/browser_client.h" #include "content/public/browser/render_process_host_observer.h" +#include "content/public/browser/web_contents_observer.h" namespace content { class QuotaPermissionContext; @@ -136,6 +137,18 @@ class AtomBrowserClient : public brightray::BrowserClient, Delegate* delegate_; + class RootWebContentsTracker : public content::WebContentsObserver { + public: + RootWebContentsTracker(content::WebContents* web_contents, + AtomBrowserClient* client); + void WebContentsDestroyed() override; + + private: + AtomBrowserClient* client_; + }; + + std::set root_web_contents_; + DISALLOW_COPY_AND_ASSIGN(AtomBrowserClient); }; From b683584859c95c8f34208bd4b11886563ecff639 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Wed, 5 Apr 2017 18:16:10 +0900 Subject: [PATCH 1004/1195] Add better comments to ShouldCreateNewSiteInstance --- atom/browser/atom_browser_client.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 14d71b55175..3a9bef9f87d 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -105,8 +105,10 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( auto web_contents = content::WebContents::FromRenderFrameHost(render_frame_host); if (root_web_contents_.find(web_contents) != root_web_contents_.end()) { - // non-sandboxed renderers with native.window.open always create a new - // SiteInstance in the root webcontents. + // Root WebContents should always create new process + // to make sure native addons are loaded correctly after reload / navigation. + // (Non-root WebContents opened by window.open() should try to reuse process + // to allow synchronous cross-window scripting.) return true; } } From e6a30388da571cb8f1dcaad32e7c8b1db79edbd0 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Tue, 10 Jan 2017 16:34:41 +0100 Subject: [PATCH 1005/1195] Make `Notification` factory function a member of `NotificationPresenter` so that we can create different types of notifications based on runtime conditions. --- brightray/browser/linux/libnotify_notification.cc | 6 ------ brightray/browser/linux/notification_presenter_linux.cc | 4 ++++ brightray/browser/linux/notification_presenter_linux.h | 2 ++ brightray/browser/mac/cocoa_notification.mm | 6 ------ brightray/browser/mac/notification_presenter_mac.h | 2 ++ brightray/browser/mac/notification_presenter_mac.mm | 4 ++++ brightray/browser/notification.h | 8 +------- brightray/browser/notification_presenter.cc | 3 ++- brightray/browser/notification_presenter.h | 1 + brightray/browser/win/notification_presenter_win.cc | 4 ++++ brightray/browser/win/notification_presenter_win.h | 2 ++ brightray/browser/win/windows_toast_notification.cc | 6 ------ 12 files changed, 22 insertions(+), 26 deletions(-) diff --git a/brightray/browser/linux/libnotify_notification.cc b/brightray/browser/linux/libnotify_notification.cc index aea7b7cc42d..dad3acb4335 100644 --- a/brightray/browser/linux/libnotify_notification.cc +++ b/brightray/browser/linux/libnotify_notification.cc @@ -55,12 +55,6 @@ void log_and_clear_error(GError* error, const char* context) { } // namespace -// static -Notification* Notification::Create(NotificationDelegate* delegate, - NotificationPresenter* presenter) { - return new LibnotifyNotification(delegate, presenter); -} - // static bool LibnotifyNotification::Initialize() { if (!libnotify_loader_.Load("libnotify.so.4") && // most common one diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index c846fca6659..25d1b6d982b 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -22,4 +22,8 @@ NotificationPresenterLinux::NotificationPresenterLinux() { NotificationPresenterLinux::~NotificationPresenterLinux() { } +Notification* NotificationPresenterLinux::CreateNotificationObject(NotificationDelegate* delegate) { + return new LibnotifyNotification(delegate, this); +} + } // namespace brightray diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index ef436799484..b8adcd1348d 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -16,6 +16,8 @@ class NotificationPresenterLinux : public NotificationPresenter { ~NotificationPresenterLinux(); private: + Notification* CreateNotificationObject(NotificationDelegate* delegate) override; + DISALLOW_COPY_AND_ASSIGN(NotificationPresenterLinux); }; diff --git a/brightray/browser/mac/cocoa_notification.mm b/brightray/browser/mac/cocoa_notification.mm index 4e9ee3238b8..f4599487c84 100644 --- a/brightray/browser/mac/cocoa_notification.mm +++ b/brightray/browser/mac/cocoa_notification.mm @@ -12,12 +12,6 @@ namespace brightray { -// static -Notification* Notification::Create(NotificationDelegate* delegate, - NotificationPresenter* presenter) { - return new CocoaNotification(delegate, presenter); -} - CocoaNotification::CocoaNotification(NotificationDelegate* delegate, NotificationPresenter* presenter) : Notification(delegate, presenter) { diff --git a/brightray/browser/mac/notification_presenter_mac.h b/brightray/browser/mac/notification_presenter_mac.h index 825a1dada23..f6e5f7959c8 100644 --- a/brightray/browser/mac/notification_presenter_mac.h +++ b/brightray/browser/mac/notification_presenter_mac.h @@ -22,6 +22,8 @@ class NotificationPresenterMac : public NotificationPresenter { ~NotificationPresenterMac(); private: + Notification* CreateNotificationObject(NotificationDelegate* delegate) override; + base::scoped_nsobject notification_center_delegate_; diff --git a/brightray/browser/mac/notification_presenter_mac.mm b/brightray/browser/mac/notification_presenter_mac.mm index a37e9182fc6..a1fb2e77893 100644 --- a/brightray/browser/mac/notification_presenter_mac.mm +++ b/brightray/browser/mac/notification_presenter_mac.mm @@ -35,4 +35,8 @@ NotificationPresenterMac::~NotificationPresenterMac() { NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil; } +Notification* NotificationPresenterMac::CreateNotificationObject(NotificationDelegate* delegate) { + return new CocoaNotification(delegate, this); +} + } // namespace brightray diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index 87096bbe263..76e3ba4320f 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -47,16 +47,10 @@ class Notification { protected: Notification(NotificationDelegate* delegate, NotificationPresenter* presenter); + public: virtual ~Notification(); private: - friend class NotificationPresenter; - - // Can only be called by NotificationPresenter, the caller is responsible of - // freeing the returned instance. - static Notification* Create(NotificationDelegate* delegate, - NotificationPresenter* presenter); - NotificationDelegate* delegate_; NotificationPresenter* presenter_; diff --git a/brightray/browser/notification_presenter.cc b/brightray/browser/notification_presenter.cc index ad46e292a27..39c3efd7ddf 100644 --- a/brightray/browser/notification_presenter.cc +++ b/brightray/browser/notification_presenter.cc @@ -18,7 +18,8 @@ NotificationPresenter::~NotificationPresenter() { base::WeakPtr NotificationPresenter::CreateNotification( NotificationDelegate* delegate) { - Notification* notification = Notification::Create(delegate, this); + Notification* notification = CreateNotificationObject(delegate); + if (!notification) return {}; notifications_.insert(notification); return notification->GetWeakPtr(); } diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index b3dac3005dc..f88a9a6449a 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -27,6 +27,7 @@ class NotificationPresenter { protected: NotificationPresenter(); + virtual Notification* CreateNotificationObject(NotificationDelegate* delegate) = 0; private: friend class Notification; diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index c185246809e..5fc961008c9 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -66,4 +66,8 @@ base::string16 NotificationPresenterWin::SaveIconToFilesystem( return base::UTF8ToUTF16(origin.spec()); } +Notification* NotificationPresenterWin::CreateNotificationObject(NotificationDelegate* delegate) { + return new WindowsToastNotification(delegate, this); +} + } // namespace brightray diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index c3e6a9ad43f..1e1186c500b 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -42,6 +42,8 @@ class NotificationPresenterWin : public NotificationPresenter { base::string16 SaveIconToFilesystem(const SkBitmap& icon, const GURL& origin); private: + Notification* CreateNotificationObject(NotificationDelegate* delegate) override; + base::ScopedTempDir temp_dir_; DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin); diff --git a/brightray/browser/win/windows_toast_notification.cc b/brightray/browser/win/windows_toast_notification.cc index 4a3a5a6f678..0e0c9249c11 100644 --- a/brightray/browser/win/windows_toast_notification.cc +++ b/brightray/browser/win/windows_toast_notification.cc @@ -42,12 +42,6 @@ bool GetAppUserModelId(ScopedHString* app_id) { } // namespace -// static -Notification* Notification::Create(NotificationDelegate* delegate, - NotificationPresenter* presenter) { - return new WindowsToastNotification(delegate, presenter); -} - // static ComPtr WindowsToastNotification::toast_manager_; From fe05b66a6c599cdbdfe88d5b3977dd10f98d3488 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 15 Mar 2017 13:56:06 +0100 Subject: [PATCH 1006/1195] Added desktop notifications implementation for Windows 7 (and earlier) --- .../win/notification_presenter_win7.cc | 47 + .../browser/win/notification_presenter_win7.h | 28 + .../win/win32_desktop_notifications/common.h | 57 ++ .../desktop_notification_controller.cc | 426 +++++++++ .../desktop_notification_controller.h | 103 +++ .../win/win32_desktop_notifications/toast.cc | 811 ++++++++++++++++++ .../win/win32_desktop_notifications/toast.h | 99 +++ brightray/browser/win/win32_notification.cc | 60 ++ brightray/browser/win/win32_notification.h | 30 + brightray/filenames.gypi | 17 +- 10 files changed, 1674 insertions(+), 4 deletions(-) create mode 100644 brightray/browser/win/notification_presenter_win7.cc create mode 100644 brightray/browser/win/notification_presenter_win7.h create mode 100644 brightray/browser/win/win32_desktop_notifications/common.h create mode 100644 brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc create mode 100644 brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h create mode 100644 brightray/browser/win/win32_desktop_notifications/toast.cc create mode 100644 brightray/browser/win/win32_desktop_notifications/toast.h create mode 100644 brightray/browser/win/win32_notification.cc create mode 100644 brightray/browser/win/win32_notification.h diff --git a/brightray/browser/win/notification_presenter_win7.cc b/brightray/browser/win/notification_presenter_win7.cc new file mode 100644 index 00000000000..0203e2e85d3 --- /dev/null +++ b/brightray/browser/win/notification_presenter_win7.cc @@ -0,0 +1,47 @@ +#include "notification_presenter_win7.h" +#include "win32_notification.h" + +namespace brightray { + +brightray::Notification* NotificationPresenterWin7::CreateNotificationObject(NotificationDelegate* delegate) +{ + return new Win32Notification(delegate, this); +} + +Win32Notification* NotificationPresenterWin7::GetNotificationObjectByRef(const DesktopNotificationController::Notification& ref) +{ + for(auto n : this->notifications()) + { + auto w32n = static_cast(n); + if(w32n->GetRef() == ref) + return w32n; + } + + return nullptr; +} + +Win32Notification* NotificationPresenterWin7::GetNotificationObjectByTag(const std::string& tag) +{ + for(auto n : this->notifications()) + { + auto w32n = static_cast(n); + if(w32n->GetTag() == tag) + return w32n; + } + + return nullptr; +} + +void NotificationPresenterWin7::OnNotificationClicked(Notification& notification) +{ + auto n = GetNotificationObjectByRef(notification); + if(n) n->NotificationClicked(); +} + +void NotificationPresenterWin7::OnNotificationDismissed(Notification& notification) +{ + auto n = GetNotificationObjectByRef(notification); + if(n) n->NotificationDismissed(); +} + +} diff --git a/brightray/browser/win/notification_presenter_win7.h b/brightray/browser/win/notification_presenter_win7.h new file mode 100644 index 00000000000..cebef5438ff --- /dev/null +++ b/brightray/browser/win/notification_presenter_win7.h @@ -0,0 +1,28 @@ +#pragma once +#include "browser/notification_presenter.h" +#include "browser/win/win32_desktop_notifications/desktop_notification_controller.h" + +namespace brightray { + +class Win32Notification; + +class NotificationPresenterWin7 : + public NotificationPresenter, + public DesktopNotificationController +{ +public: + NotificationPresenterWin7() = default; + + Win32Notification* GetNotificationObjectByRef(const DesktopNotificationController::Notification& ref); + Win32Notification* GetNotificationObjectByTag(const std::string& tag); + +private: + DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7); + + brightray::Notification* CreateNotificationObject(NotificationDelegate* delegate) override; + + void OnNotificationClicked(Notification& notification) override; + void OnNotificationDismissed(Notification& notification) override; +}; + +} // namespace diff --git a/brightray/browser/win/win32_desktop_notifications/common.h b/brightray/browser/win/win32_desktop_notifications/common.h new file mode 100644 index 00000000000..5f44debf312 --- /dev/null +++ b/brightray/browser/win/win32_desktop_notifications/common.h @@ -0,0 +1,57 @@ +#pragma once +#include + +namespace brightray { + +struct NotificationData +{ + DesktopNotificationController* controller = nullptr; + + std::wstring caption; + std::wstring bodyText; + HBITMAP image = NULL; + + + NotificationData() = default; + + ~NotificationData() + { + if(image) DeleteObject(image); + } + + NotificationData(const NotificationData& other) = delete; + NotificationData& operator=(const NotificationData& other) = delete; +}; + +template +inline T ScaleForDpi(T value, unsigned dpi) +{ + return value * dpi / 96; +} + +struct ScreenMetrics +{ + UINT dpiX, dpiY; + + ScreenMetrics() + { + typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*); + auto GetDpiForMonitor = (GetDpiForMonitor_t*)GetProcAddress(GetModuleHandle(TEXT("shcore")), "GetDpiForMonitor"); + if(GetDpiForMonitor) + { + auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); + if(GetDpiForMonitor(monitor, 0, &dpiX, &dpiY) == S_OK) + return; + } + + HDC hdc = GetDC(NULL); + dpiX = GetDeviceCaps(hdc, LOGPIXELSX); + dpiY = GetDeviceCaps(hdc, LOGPIXELSY); + ReleaseDC(NULL, hdc); + } + + template T X(T value) const { return ScaleForDpi(value, dpiX); } + template T Y(T value) const { return ScaleForDpi(value, dpiY); } +}; + +} diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc new file mode 100644 index 00000000000..e79c6e5be56 --- /dev/null +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -0,0 +1,426 @@ +#define NOMINMAX +#define WIN32_LEAN_AND_MEAN +#include "desktop_notification_controller.h" +#include "common.h" +#include "toast.h" +#include +#include +#include + +using namespace std; + +namespace brightray { + +HBITMAP CopyBitmap(HBITMAP bitmap) +{ + HBITMAP ret = NULL; + + BITMAP bm; + if(bitmap && GetObject(bitmap, sizeof(bm), &bm)) + { + HDC hdcScreen = GetDC(NULL); + ret = CreateCompatibleBitmap(hdcScreen, bm.bmWidth, bm.bmHeight); + ReleaseDC(NULL, hdcScreen); + + if(ret) + { + HDC hdcSrc = CreateCompatibleDC(NULL); + HDC hdcDst = CreateCompatibleDC(NULL); + SelectBitmap(hdcSrc, bitmap); + SelectBitmap(hdcDst, ret); + BitBlt(hdcDst, 0, 0, bm.bmWidth, bm.bmHeight, hdcSrc, 0, 0, SRCCOPY); + DeleteDC(hdcDst); + DeleteDC(hdcSrc); + } + } + + return ret; +} + +HINSTANCE DesktopNotificationController::RegisterWndClasses() +{ + // We keep a static `module` variable which serves a dual purpose: + // 1. Stores the HINSTANCE where the window classes are registered, which can be passed to `CreateWindow` + // 2. Indicates whether we already attempted the registration so that we don't do it twice (we don't retry + // even if registration fails, as there is no point. + static HMODULE module = NULL; + + if(!module) + { + if(GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(&RegisterWndClasses), &module)) + { + Toast::Register(module); + + WNDCLASSEX wc = { sizeof(wc) }; + wc.lpfnWndProc = &WndProc; + wc.lpszClassName = className; + wc.cbWndExtra = sizeof(DesktopNotificationController*); + wc.hInstance = module; + + RegisterClassEx(&wc); + } + } + + return module; +} + +DesktopNotificationController::DesktopNotificationController(unsigned maximumToasts) +{ + instances.reserve(maximumToasts); +} + +DesktopNotificationController::~DesktopNotificationController() +{ + for(auto&& inst : instances) DestroyToast(inst); + if(hwndController) DestroyWindow(hwndController); + ClearAssets(); +} + +LRESULT CALLBACK DesktopNotificationController::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_CREATE: + { + auto& cs = reinterpret_cast(lParam); + SetWindowLongPtr(hWnd, 0, (LONG_PTR)cs->lpCreateParams); + } + break; + + case WM_TIMER: + if(wParam == TimerID_Animate) + { + Get(hWnd)->AnimateAll(); + } + return 0; + + case WM_DISPLAYCHANGE: + { + auto inst = Get(hWnd); + inst->ClearAssets(); + inst->AnimateAll(); + } + break; + + case WM_SETTINGCHANGE: + if(wParam == SPI_SETWORKAREA) + { + Get(hWnd)->AnimateAll(); + } + break; + } + + return DefWindowProc(hWnd, message, wParam, lParam); +} + +void DesktopNotificationController::StartAnimation() +{ + _ASSERT(hwndController); + + if(!isAnimating && hwndController) + { + // 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 to get at least 60 + + SetTimer(hwndController, TimerID_Animate, 15, nullptr); + isAnimating = true; + } +} + +HFONT DesktopNotificationController::GetCaptionFont() +{ + InitializeFonts(); + return captionFont; +} + +HFONT DesktopNotificationController::GetBodyFont() +{ + InitializeFonts(); + return bodyFont; +} + +void DesktopNotificationController::InitializeFonts() +{ + if(!bodyFont) + { + NONCLIENTMETRICS metrics = { sizeof(metrics) }; + if(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) + { + auto baseHeight = metrics.lfMessageFont.lfHeight; + + HDC hdc = GetDC(NULL); + auto dpiY = GetDeviceCaps(hdc, LOGPIXELSY); + ReleaseDC(NULL, hdc); + + metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.1f, dpiY); + bodyFont = CreateFontIndirect(&metrics.lfMessageFont); + + if(captionFont) DeleteFont(captionFont); + metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.4f, dpiY); + captionFont = CreateFontIndirect(&metrics.lfMessageFont); + } + } +} + +void DesktopNotificationController::ClearAssets() +{ + if(captionFont) { DeleteFont(captionFont); captionFont = NULL; } + if(bodyFont) { DeleteFont(bodyFont); bodyFont = NULL; } +} + +void DesktopNotificationController::AnimateAll() +{ + // NOTE: This function refreshes position and size of all toasts according + // to all current conditions. Animation time is only one of the variables + // influencing them. Screen resolution is another. + + bool keepAnimating = false; + + if(!instances.empty()) + { + RECT workArea; + if(SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0)) + { + ScreenMetrics metrics; + POINT origin = { workArea.right, + workArea.bottom - metrics.Y(toastMargin) }; + + auto hdwp = BeginDeferWindowPos((int)instances.size()); + for(auto&& inst : instances) + { + if(!inst.hwnd) continue; + + auto notification = Toast::Get(inst.hwnd); + hdwp = notification->Animate(hdwp, origin); + if(!hdwp) break; + keepAnimating |= notification->IsAnimationActive(); + } + if(hdwp) EndDeferWindowPos(hdwp); + } + } + + if(!keepAnimating) + { + _ASSERT(hwndController); + if(hwndController) KillTimer(hwndController, TimerID_Animate); + isAnimating = false; + } + + // Purge dismissed notifications and collapse the stack between + // items which are highlighted + if(!instances.empty()) + { + auto isAlive = [](ToastInstance& inst) { + return inst.hwnd && IsWindowVisible(inst.hwnd); + }; + + auto isHighlighted = [](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(), isHighlighted); + + // collapse the stack in front of the highlighted item + it = stable_partition(it, it2, isAlive); + + // 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 + if(!instances.empty()) + { + ScreenMetrics metrics; + auto margin = metrics.Y(toastMargin); + + int targetPos = 0; + for(auto&& inst : instances) + { + if(inst.hwnd) + { + auto toast = Toast::Get(inst.hwnd); + + if(toast->IsHighlighted()) + targetPos = toast->GetVerticalPosition(); + else + toast->SetVerticalPosition(targetPos); + + targetPos += toast->GetHeight() + margin; + } + } + } + + // Create new toasts from the queue + CheckQueue(); +} + +DesktopNotificationController::Notification DesktopNotificationController::AddNotification(std::wstring caption, std::wstring bodyText, HBITMAP image) +{ + NotificationLink data(this); + + data->caption = move(caption); + data->bodyText = move(bodyText); + data->image = CopyBitmap(image); + + // Enqueue new notification + Notification ret = *queue.insert(queue.end(), move(data)); + CheckQueue(); + return ret; +} + +void DesktopNotificationController::CloseNotification(Notification& notification) +{ + // Remove it from the queue + auto it = find(queue.begin(), queue.end(), notification.data); + if(it != queue.end()) + { + queue.erase(it); + this->OnNotificationClosed(notification); + return; + } + + // Dismiss active toast + auto hwnd = GetToast(notification.data.get()); + if(hwnd) + { + auto toast = Toast::Get(hwnd); + toast->Dismiss(); + } +} + +void DesktopNotificationController::CheckQueue() +{ + while(instances.size() < instances.capacity() && !queue.empty()) + { + CreateToast(move(queue.front())); + queue.pop_front(); + } +} + +void DesktopNotificationController::CreateToast(NotificationLink&& data) +{ + auto hInstance = RegisterWndClasses(); + auto hwnd = Toast::Create(hInstance, data); + if(hwnd) + { + int toastPos = 0; + if(!instances.empty()) + { + auto& item = instances.back(); + _ASSERT(item.hwnd); + + ScreenMetrics scr; + auto toast = Toast::Get(item.hwnd); + toastPos = toast->GetVerticalPosition() + toast->GetHeight() + scr.Y(toastMargin); + } + + instances.push_back({ hwnd, move(data) }); + + if(!hwndController) + { + // NOTE: We cannot use a message-only window because we need to receive system notifications + hwndController = CreateWindow(className, nullptr, 0, 0, 0, 0, 0, NULL, NULL, hInstance, this); + } + + auto toast = Toast::Get(hwnd); + toast->PopUp(toastPos); + } +} + +HWND DesktopNotificationController::GetToast(const NotificationData* data) const +{ + auto it = find_if(instances.cbegin(), instances.cend(), [data](auto&& inst) { + auto toast = Toast::Get(inst.hwnd); + return data == toast->GetNotification().get(); + }); + + return (it != instances.cend()) ? it->hwnd : NULL; +} + +void DesktopNotificationController::DestroyToast(ToastInstance& inst) +{ + if(inst.hwnd) + { + auto data = Toast::Get(inst.hwnd)->GetNotification(); + + DestroyWindow(inst.hwnd); + inst.hwnd = NULL; + + Notification notification(data); + OnNotificationClosed(notification); + } +} + + +DesktopNotificationController::Notification::Notification(const shared_ptr& data) : + data(data) +{ + _ASSERT(data != nullptr); +} + +bool DesktopNotificationController::Notification::operator==(const Notification& other) const +{ + return data == other.data; +} + +void DesktopNotificationController::Notification::Close() +{ + // No business calling this when not pointing to a valid instance + _ASSERT(data); + + if(data->controller) + data->controller->CloseNotification(*this); +} + +void DesktopNotificationController::Notification::Set(std::wstring caption, std::wstring bodyText, HBITMAP image) +{ + // No business calling this when not pointing to a valid instance + _ASSERT(data); + + // Do nothing when the notification has been closed + if(!data->controller) + return; + + if(data->image) DeleteBitmap(data->image); + + data->caption = move(caption); + data->bodyText = move(bodyText); + data->image = CopyBitmap(image); + + auto hwnd = data->controller->GetToast(data.get()); + if(hwnd) + { + auto toast = Toast::Get(hwnd); + toast->ResetContents(); + } + + // Change of contents can affect size and position of all toasts + data->controller->StartAnimation(); +} + + +DesktopNotificationController::NotificationLink::NotificationLink(DesktopNotificationController* controller) : + shared_ptr(make_shared()) +{ + get()->controller = controller; +} + +DesktopNotificationController::NotificationLink::~NotificationLink() +{ + auto p = get(); + if(p) p->controller = nullptr; +} + +} diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h new file mode 100644 index 00000000000..1d93591f60d --- /dev/null +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h @@ -0,0 +1,103 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace brightray { + +struct NotificationData; + +class DesktopNotificationController +{ +public: + DesktopNotificationController(unsigned maximumToasts = 3); + ~DesktopNotificationController(); + + class Notification; + Notification AddNotification(std::wstring caption, std::wstring bodyText, HBITMAP image); + void CloseNotification(Notification& notification); + + // Event handlers -- override to receive the events +private: + virtual void OnNotificationClosed(Notification& notification) {} + virtual void OnNotificationClicked(Notification& notification) {} + virtual void OnNotificationDismissed(Notification& notification) {} + +private: + static HINSTANCE RegisterWndClasses(); + void StartAnimation(); + HFONT GetCaptionFont(); + HFONT GetBodyFont(); + +private: + enum TimerID { + TimerID_Animate = 1 + }; + + template + static constexpr T toastMargin = 20; + + // Wrapper around `NotificationData` which makes sure that + // the `controller` member is cleared when the controller object + // stops tracking the notification + struct NotificationLink : std::shared_ptr { + NotificationLink(DesktopNotificationController* controller); + ~NotificationLink(); + + NotificationLink(NotificationLink&&) = default; + NotificationLink(const NotificationLink&) = delete; + NotificationLink& operator=(NotificationLink&&) = default; + }; + + struct ToastInstance { + HWND hwnd; + NotificationLink data; + }; + + class Toast; + + static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + static DesktopNotificationController* Get(HWND hWnd) + { + return reinterpret_cast(GetWindowLongPtr(hWnd, 0)); + } + + DesktopNotificationController(const DesktopNotificationController&) = delete; + + void InitializeFonts(); + void ClearAssets(); + void AnimateAll(); + void CheckQueue(); + void CreateToast(NotificationLink&& data); + HWND GetToast(const NotificationData* data) const; + void DestroyToast(ToastInstance& inst); + +private: + static constexpr const TCHAR className[] = TEXT("DesktopNotificationController"); + HWND hwndController = NULL; + HFONT captionFont = NULL, bodyFont = NULL; + std::vector instances; + std::deque queue; + bool isAnimating = false; +}; + +class DesktopNotificationController::Notification +{ +public: + Notification() = default; + Notification(const std::shared_ptr& data); + + bool operator==(const Notification& other) const; + + void Close(); + void Set(std::wstring caption, std::wstring bodyText, HBITMAP image); + +private: + std::shared_ptr data; + + friend class DesktopNotificationController; +}; + +} diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc new file mode 100644 index 00000000000..f6cb8d06cef --- /dev/null +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -0,0 +1,811 @@ +#define NOMINMAX +#include "toast.h" +#include "common.h" +#include +#include +#include + +#pragma comment(lib, "msimg32.lib") +#pragma comment(lib, "uxtheme.lib") + +using namespace std; + +namespace brightray { + +static COLORREF GetAccentColor() +{ + bool success = false; + if(IsAppThemed()) + { + HKEY hkey; + if(RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows\\DWM"), 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) + { + COLORREF color; + DWORD type, size; + if(RegQueryValueEx(hkey, TEXT("AccentColor"), nullptr, &type, (BYTE*)&color, &(size = sizeof(color))) == ERROR_SUCCESS && type == REG_DWORD) + { + // convert from RGBA + color = RGB(GetRValue(color), GetGValue(color), GetBValue(color)); + success = true; + } + else if(RegQueryValueEx(hkey, TEXT("ColorizationColor"), nullptr, &type, (BYTE*)&color, &(size = sizeof(color))) == ERROR_SUCCESS && type == REG_DWORD) + { + // convert from BGRA + color = RGB(GetBValue(color), GetGValue(color), GetRValue(color)); + success = true; + } + + RegCloseKey(hkey); + + if(success) return color; + } + } + + return GetSysColor(COLOR_ACTIVECAPTION); +} + +// Stretches a bitmap to the specified size, preserves alpha channel +static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) +{ + // We use StretchBlt for the scaling, but that discards the alpha channel. + // Therefore we first create a separate grayscale bitmap from the alpha channel, + // scale that separately and copy it back to the scaled color bitmap. + + BITMAP bm; + if(!GetObject(bitmap, sizeof(bm), &bm)) + return NULL; + + if(width == 0 || height == 0) + return NULL; + + HBITMAP resultBitmap = NULL; + + HDC hdcScreen = GetDC(NULL); + + HBITMAP alphaSrcBitmap; + { + BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) }; + bmi.biWidth = bm.bmWidth; + bmi.biHeight = bm.bmHeight; + bmi.biPlanes = bm.bmPlanes; + bmi.biBitCount = bm.bmBitsPixel; + bmi.biCompression = BI_RGB; + + void* alphaSrcBits; + alphaSrcBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, DIB_RGB_COLORS, &alphaSrcBits, NULL, 0); + + if(alphaSrcBitmap) + { + if(GetDIBits(hdcScreen, bitmap, 0, 0, 0, (BITMAPINFO*)&bmi, DIB_RGB_COLORS) && + bmi.biSizeImage > 0 && + (bmi.biSizeImage % 4) == 0) + { + auto buf = (DWORD*)_aligned_malloc(bmi.biSizeImage, sizeof(DWORD)); + if(buf) + { + GetDIBits(hdcScreen, bitmap, 0, bm.bmHeight, buf, (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + + BYTE* dest = (BYTE*)alphaSrcBits; + for(const DWORD *src = buf, *end = (DWORD*)((BYTE*)buf + bmi.biSizeImage); + src != end; + ++src, ++dest) + { + BYTE a = *src >> 24; + *dest++ = a; + *dest++ = a; + *dest++ = a; + } + + _aligned_free(buf); + } + } + } + } + + if(alphaSrcBitmap) + { + BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) }; + bmi.biWidth = width; + bmi.biHeight = height; + bmi.biPlanes = 1; + bmi.biBitCount = 32; + bmi.biCompression = BI_RGB; + + void* colorBits; + auto colorBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, DIB_RGB_COLORS, &colorBits, NULL, 0); + + void* alphaBits; + auto alphaBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, DIB_RGB_COLORS, &alphaBits, NULL, 0); + + HDC hdc = CreateCompatibleDC(NULL); + HDC hdcSrc = CreateCompatibleDC(NULL); + + if(colorBitmap && alphaBitmap && hdc && hdcSrc) + { + SetStretchBltMode(hdc, HALFTONE); + + // resize color channels + SelectObject(hdc, colorBitmap); + SelectObject(hdcSrc, bitmap); + StretchBlt(hdc, 0, 0, width, height, hdcSrc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); + + // resize alpha channel + SelectObject(hdc, alphaBitmap); + SelectObject(hdcSrc, alphaSrcBitmap); + StretchBlt(hdc, 0, 0, width, height, hdcSrc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); + + // flush before touching the bits + GdiFlush(); + + // apply the alpha channel + auto dest = (BYTE*)colorBits; + auto src = (const BYTE*)alphaBits; + auto end = src + (width * height * 4); + while(src != end) + { + dest[3] = src[0]; + dest += 4; + src += 4; + } + + // create the resulting bitmap + resultBitmap = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, colorBits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + } + + if(hdcSrc) DeleteDC(hdcSrc); + if(hdc) DeleteDC(hdc); + + if(alphaBitmap) DeleteObject(alphaBitmap); + if(colorBitmap) DeleteObject(colorBitmap); + + DeleteObject(alphaSrcBitmap); + } + + ReleaseDC(NULL, hdcScreen); + + return resultBitmap; +} + +DesktopNotificationController::Toast::Toast(HWND hWnd, shared_ptr* data) : + hWnd(hWnd), data(*data) +{ + HDC hdcScreen = GetDC(NULL); + hdc = CreateCompatibleDC(hdcScreen); + ReleaseDC(NULL, hdcScreen); +} + +DesktopNotificationController::Toast::~Toast() +{ + DeleteDC(hdc); + if(bitmap) DeleteBitmap(bitmap); + if(scaledImage) DeleteBitmap(scaledImage); +} + +void DesktopNotificationController::Toast::Register(HINSTANCE hInstance) +{ + WNDCLASSEX wc = { sizeof(wc) }; + wc.lpfnWndProc = &Toast::WndProc; + wc.lpszClassName = className; + wc.cbWndExtra = sizeof(Toast*); + wc.hInstance = hInstance; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + + RegisterClassEx(&wc); +} + +LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch(message) + { + case WM_CREATE: + { + auto& cs = reinterpret_cast(lParam); + auto inst = new Toast(hWnd, static_cast*>(cs->lpCreateParams)); + SetWindowLongPtr(hWnd, 0, (LONG_PTR)inst); + } + break; + + case WM_NCDESTROY: + delete Get(hWnd); + SetWindowLongPtr(hWnd, 0, 0); + return 0; + + case WM_MOUSEACTIVATE: + return MA_NOACTIVATE; + + case WM_TIMER: + if(wParam == TimerID_AutoDismiss) + { + Get(hWnd)->AutoDismiss(); + } + return 0; + + case WM_LBUTTONDOWN: + { + auto inst = Get(hWnd); + + inst->Dismiss(); + + Notification notification(inst->data); + if(inst->isCloseHot) + inst->data->controller->OnNotificationDismissed(notification); + else + inst->data->controller->OnNotificationClicked(notification); + } + return 0; + + case WM_MOUSEMOVE: + { + auto inst = Get(hWnd); + if(!inst->isHighlighted) + { + inst->isHighlighted = true; + + TRACKMOUSEEVENT tme = { sizeof(tme), TME_LEAVE, hWnd }; + TrackMouseEvent(&tme); + } + + POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + inst->isCloseHot = (PtInRect(&inst->closeButtonRect, cursor) != FALSE); + + if(!inst->isNonInteractive) + inst->CancelDismiss(); + + inst->UpdateContents(); + } + return 0; + + case WM_MOUSELEAVE: + { + auto inst = Get(hWnd); + inst->isHighlighted = false; + inst->isCloseHot = false; + inst->UpdateContents(); + + if(!inst->easeOutActive && inst->easeInPos == 1.0f) + inst->ScheduleDismissal(); + + // Make sure stack collapse happens if needed + inst->data->controller->StartAnimation(); + } + return 0; + + case WM_WINDOWPOSCHANGED: + { + auto& wp = reinterpret_cast(lParam); + if(wp->flags & SWP_HIDEWINDOW) + { + if(!IsWindowVisible(hWnd)) + Get(hWnd)->isHighlighted = false; + } + } + break; + } + + return DefWindowProc(hWnd, message, wParam, lParam); +} + +HWND DesktopNotificationController::Toast::Create(HINSTANCE hInstance, shared_ptr& data) +{ + return CreateWindowEx(WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOPMOST, className, nullptr, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, &data); +} + +void DesktopNotificationController::Toast::Draw() +{ + const COLORREF accent = GetAccentColor(); + + COLORREF backColor; + { + // base background color is 2/3 of accent + // highlighted adds a bit of intensity to every channel + + int h = isHighlighted ? (0xff / 20) : 0; + + backColor = RGB(min(0xff, (GetRValue(accent) * 2 / 3) + h), + min(0xff, (GetGValue(accent) * 2 / 3) + h), + min(0xff, (GetBValue(accent) * 2 / 3) + h)); + } + + const float backLuma = + (GetRValue(backColor) * 0.299f / 255) + + (GetGValue(backColor) * 0.587f / 255) + + (GetBValue(backColor) * 0.114f / 255); + + const struct { float r, g, b; } backF = { + GetRValue(backColor) / 255.0f, + GetGValue(backColor) / 255.0f, + GetBValue(backColor) / 255.0f, + }; + + COLORREF foreColor, dimmedColor; + { + // based on the lightness of background, we draw foreground in light or dark + // shades of gray blended onto the background with slight transparency + // to avoid sharp contrast + + constexpr float alpha = 0.9f; + constexpr float intensityLight[] = { (1.0f * alpha), (0.8f * alpha) }; + constexpr float intensityDark[] = { (0.1f * alpha), (0.3f * alpha) }; + + // select foreground intensity values (light or dark) + auto& i = (backLuma < 0.6f) ? intensityLight : intensityDark; + + float r, g, b; + + r = i[0] + backF.r * (1 - alpha); + g = i[0] + backF.g * (1 - alpha); + b = i[0] + backF.b * (1 - alpha); + foreColor = RGB(r * 0xff, g * 0xff, b * 0xff); + + r = i[1] + backF.r * (1 - alpha); + g = i[1] + backF.g * (1 - alpha); + b = i[1] + backF.b * (1 - alpha); + dimmedColor = RGB(r * 0xff, g * 0xff, b * 0xff); + } + + // Draw background + { + auto brush = CreateSolidBrush(backColor); + + RECT rc = { 0, 0, toastSize.cx, toastSize.cy }; + FillRect(hdc, &rc, brush); + + DeleteBrush(brush); + } + + SetBkMode(hdc, TRANSPARENT); + + const auto close = L'\x2715'; + auto captionFont = data->controller->GetCaptionFont(); + auto bodyFont = data->controller->GetBodyFont(); + + TEXTMETRIC tmCap; + SelectFont(hdc, captionFont); + GetTextMetrics(hdc, &tmCap); + + auto textOffsetX = margin.cx; + + BITMAP imageInfo = {}; + if(scaledImage) + { + GetObject(scaledImage, sizeof(imageInfo), &imageInfo); + + textOffsetX += margin.cx + imageInfo.bmWidth; + } + + // calculate close button rect + POINT closePos; + { + SIZE extent = {}; + GetTextExtentPoint32W(hdc, &close, 1, &extent); + + closeButtonRect.right = toastSize.cx; + closeButtonRect.top = 0; + + closePos.x = closeButtonRect.right - margin.cy - extent.cx; + closePos.y = closeButtonRect.top + margin.cy; + + closeButtonRect.left = closePos.x - margin.cy; + closeButtonRect.bottom = closePos.y + extent.cy + margin.cy; + } + + // image + if(scaledImage) + { + HDC hdcImage = CreateCompatibleDC(NULL); + SelectBitmap(hdcImage, scaledImage); + BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; + AlphaBlend(hdc, margin.cx, margin.cy, imageInfo.bmWidth, imageInfo.bmHeight, hdcImage, 0, 0, imageInfo.bmWidth, imageInfo.bmHeight, blend); + DeleteDC(hdcImage); + } + + // caption + { + RECT rc = { + textOffsetX, + margin.cy, + closeButtonRect.left, + toastSize.cy + }; + + SelectFont(hdc, captionFont); + SetTextColor(hdc, foreColor); + DrawText(hdc, data->caption.data(), (UINT)data->caption.length(), &rc, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX); + } + + // body text + if(!data->bodyText.empty()) + { + RECT rc = { + textOffsetX, + 2 * margin.cy + tmCap.tmAscent, + toastSize.cx - margin.cx, + toastSize.cy - margin.cy + }; + + SelectFont(hdc, bodyFont); + SetTextColor(hdc, dimmedColor); + DrawText(hdc, data->bodyText.data(), (UINT)data->bodyText.length(), &rc, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_END_ELLIPSIS | DT_EDITCONTROL); + } + + // close button + { + SelectFont(hdc, captionFont); + SetTextColor(hdc, isCloseHot ? foreColor : dimmedColor); + ExtTextOut(hdc, closePos.x, closePos.y, 0, nullptr, &close, 1, nullptr); + } + + isContentUpdated = true; +} + +void DesktopNotificationController::Toast::Invalidate() +{ + isContentUpdated = false; +} + +bool DesktopNotificationController::Toast::IsRedrawNeeded() const +{ + return !isContentUpdated; +} + +void DesktopNotificationController::Toast::UpdateBufferSize() +{ + if(hdc) + { + SIZE newSize; + { + TEXTMETRIC tmCap = {}; + HFONT font = data->controller->GetCaptionFont(); + if(font) + { + SelectFont(hdc, font); + if(!GetTextMetrics(hdc, &tmCap)) return; + } + + TEXTMETRIC tmBody = {}; + font = data->controller->GetBodyFont(); + if(font) + { + SelectFont(hdc, font); + if(!GetTextMetrics(hdc, &tmBody)) return; + } + + this->margin = { tmCap.tmAveCharWidth * 2, tmCap.tmAscent / 2 }; + + newSize.cx = margin.cx + (32 * tmCap.tmAveCharWidth) + margin.cx; + newSize.cy = margin.cy + (tmCap.tmHeight) + margin.cy; + + if(!data->bodyText.empty()) + newSize.cy += margin.cy + (3 * tmBody.tmHeight); + + if(data->image) + { + BITMAP bm; + if(GetObject(data->image, sizeof(bm), &bm)) + { + // cap the image size + const int maxDimSize = 80; + + auto width = bm.bmWidth; + auto height = bm.bmHeight; + if(width < height) + { + if(height > maxDimSize) + { + width = width * maxDimSize / height; + height = maxDimSize; + } + } + else + { + if(width > maxDimSize) + { + height = height * maxDimSize / width; + width = maxDimSize; + } + } + + ScreenMetrics scr; + SIZE imageDrawSize = { scr.X(width), scr.Y(height) }; + + newSize.cx += imageDrawSize.cx + margin.cx; + + auto heightWithImage = margin.cy + (imageDrawSize.cy) + margin.cy; + if(newSize.cy < heightWithImage) newSize.cy = heightWithImage; + + UpdateScaledImage(imageDrawSize); + } + } + } + + if(newSize.cx != this->toastSize.cx || newSize.cy != this->toastSize.cy) + { + HDC hdcScreen = GetDC(NULL); + auto newBitmap = CreateCompatibleBitmap(hdcScreen, newSize.cx, newSize.cy); + ReleaseDC(NULL, hdcScreen); + + if(newBitmap) + { + if(SelectBitmap(hdc, newBitmap)) + { + RECT dirty1 = {}, dirty2 = {}; + if(toastSize.cx < newSize.cx) dirty1 = { toastSize.cx, 0, newSize.cx, toastSize.cy }; + if(toastSize.cy < newSize.cy) dirty2 = { 0, toastSize.cy, newSize.cx, newSize.cy }; + + if(this->bitmap) DeleteBitmap(this->bitmap); + this->bitmap = newBitmap; + this->toastSize = newSize; + + Invalidate(); + + // Resize also the DWM buffer to prevent flicker during window resizing. + // Make sure any existing data is not overwritten by marking the dirty region. + { + POINT origin = { 0, 0 }; + + UPDATELAYEREDWINDOWINFO ulw; + ulw.cbSize = sizeof(ulw); + ulw.hdcDst = NULL; + ulw.pptDst = nullptr; + ulw.psize = &toastSize; + ulw.hdcSrc = hdc; + ulw.pptSrc = &origin; + ulw.crKey = 0; + ulw.pblend = nullptr; + ulw.dwFlags = 0; + ulw.prcDirty = &dirty1; + auto b1 = UpdateLayeredWindowIndirect(hWnd, &ulw); + ulw.prcDirty = &dirty2; + auto b2 = UpdateLayeredWindowIndirect(hWnd, &ulw); + _ASSERT(b1 && b2); + } + + return; + } + + DeleteBitmap(newBitmap); + } + } + } +} + +void DesktopNotificationController::Toast::UpdateScaledImage(const SIZE& size) +{ + BITMAP bm; + if(!GetObject(scaledImage, sizeof(bm), &bm) || + bm.bmWidth != size.cx || + bm.bmHeight != size.cy) + { + if(scaledImage) DeleteBitmap(scaledImage); + scaledImage = StretchBitmap(data->image, size.cx, size.cy); + } +} + +void DesktopNotificationController::Toast::UpdateContents() +{ + Draw(); + + if(IsWindowVisible(hWnd)) + { + RECT rc; + GetWindowRect(hWnd, &rc); + POINT origin = { 0, 0 }; + SIZE size = { rc.right - rc.left, rc.bottom - rc.top }; + UpdateLayeredWindow(hWnd, NULL, nullptr, &size, hdc, &origin, 0, nullptr, 0); + } +} + +void DesktopNotificationController::Toast::Dismiss() +{ + if(!isNonInteractive) + { + // Set a flag to prevent further interaction. We don't disable the HWND because + // we still want to receive mouse move messages in order to keep the toast under + // the cursor and not collapse it while dismissing. + isNonInteractive = true; + + AutoDismiss(); + } +} + +void DesktopNotificationController::Toast::AutoDismiss() +{ + KillTimer(hWnd, TimerID_AutoDismiss); + StartEaseOut(); +} + +void DesktopNotificationController::Toast::CancelDismiss() +{ + KillTimer(hWnd, TimerID_AutoDismiss); + easeOutActive = false; + easeOutPos = 0; +} + +void DesktopNotificationController::Toast::ScheduleDismissal() +{ + SetTimer(hWnd, TimerID_AutoDismiss, 4000, nullptr); +} + +void DesktopNotificationController::Toast::ResetContents() +{ + if(scaledImage) + { + DeleteBitmap(scaledImage); + scaledImage = NULL; + } + + Invalidate(); +} + +void DesktopNotificationController::Toast::PopUp(int y) +{ + verticalPosTarget = verticalPos = y; + StartEaseIn(); +} + +void DesktopNotificationController::Toast::SetVerticalPosition(int y) +{ + // Don't restart animation if current target is the same + if(y == verticalPosTarget) + return; + + // Make sure the new animation's origin is at the current position + verticalPos += (int)((verticalPosTarget - verticalPos) * stackCollapsePos); + + // Set new target position and start the animation + verticalPosTarget = y; + stackCollapseStart = GetTickCount(); + data->controller->StartAnimation(); +} + +HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origin) +{ + UpdateBufferSize(); + + if(IsRedrawNeeded()) + Draw(); + + POINT srcOrigin = { 0, 0 }; + + UPDATELAYEREDWINDOWINFO ulw; + ulw.cbSize = sizeof(ulw); + ulw.hdcDst = NULL; + ulw.pptDst = nullptr; + ulw.psize = nullptr; + ulw.hdcSrc = hdc; + ulw.pptSrc = &srcOrigin; + ulw.crKey = 0; + ulw.pblend = nullptr; + ulw.dwFlags = 0; + ulw.prcDirty = nullptr; + + POINT pt = { 0, 0 }; + SIZE size = { 0, 0 }; + BLENDFUNCTION blend; + UINT dwpFlags = SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOREDRAW | SWP_NOCOPYBITS; + + auto easeInPos = AnimateEaseIn(); + auto easeOutPos = AnimateEaseOut(); + auto stackCollapsePos = AnimateStackCollapse(); + + auto yOffset = (verticalPosTarget - verticalPos) * stackCollapsePos; + + size.cx = (int)(toastSize.cx * easeInPos); + size.cy = toastSize.cy; + + pt.x = origin.x - size.cx; + pt.y = (int)(origin.y - verticalPos - yOffset - size.cy); + + ulw.pptDst = &pt; + ulw.psize = &size; + + if(easeInActive && easeInPos == 1.0f) + { + easeInActive = false; + ScheduleDismissal(); + } + + this->easeInPos = easeInPos; + this->stackCollapsePos = stackCollapsePos; + + if(easeOutPos != this->easeOutPos) + { + blend.BlendOp = AC_SRC_OVER; + blend.BlendFlags = 0; + blend.SourceConstantAlpha = (BYTE)(255 * (1.0f - easeOutPos)); + blend.AlphaFormat = 0; + + ulw.pblend = &blend; + ulw.dwFlags = ULW_ALPHA; + + this->easeOutPos = easeOutPos; + + if(easeOutPos == 1.0f) + { + easeOutActive = false; + + dwpFlags &= ~SWP_SHOWWINDOW; + dwpFlags |= SWP_HIDEWINDOW; + } + } + + if(stackCollapsePos == 1.0f) + { + verticalPos = verticalPosTarget; + } + + // `UpdateLayeredWindowIndirect` updates position, size, and transparency. + // `DeferWindowPos` updates z-order, and also position and size in case ULWI fails, + // which can happen when one of the dimensions is zero (e.g. at the beginning of ease-in). + + auto ulwResult = UpdateLayeredWindowIndirect(hWnd, &ulw); + hdwp = DeferWindowPos(hdwp, hWnd, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, dwpFlags); + return hdwp; +} + +void DesktopNotificationController::Toast::StartEaseIn() +{ + _ASSERT(!easeInActive); + easeInStart = GetTickCount(); + easeInActive = true; + data->controller->StartAnimation(); +} + +void DesktopNotificationController::Toast::StartEaseOut() +{ + _ASSERT(!easeOutActive); + easeOutStart = GetTickCount(); + easeOutActive = true; + data->controller->StartAnimation(); +} + +bool DesktopNotificationController::Toast::IsStackCollapseActive() const +{ + return (verticalPos != verticalPosTarget); +} + +float DesktopNotificationController::Toast::AnimateEaseIn() +{ + if(!easeInActive) + return easeInPos; + + constexpr float duration = 500.0f; + float time = std::min(duration, (float)(GetTickCount() - easeInStart)) / duration; + + // decelerating exponential ease + const float a = -8.0f; + auto pos = (std::exp(a * time) - 1.0f) / (std::exp(a) - 1.0f); + + return pos; +} + +float DesktopNotificationController::Toast::AnimateEaseOut() +{ + if(!easeOutActive) + return easeOutPos; + + constexpr float duration = 120.0f; + float time = std::min(duration, (float)(GetTickCount() - easeOutStart)) / duration; + + // accelerating circle ease + auto pos = 1.0f - std::sqrt(1 - time * time); + + return pos; +} + +float DesktopNotificationController::Toast::AnimateStackCollapse() +{ + if(!IsStackCollapseActive()) + return stackCollapsePos; + + constexpr float duration = 500.0f; + float time = std::min(duration, (float)(GetTickCount() - stackCollapseStart)) / duration; + + // decelerating exponential ease + const float a = -8.0f; + auto pos = (std::exp(a * time) - 1.0f) / (std::exp(a) - 1.0f); + + return pos; +} + +} diff --git a/brightray/browser/win/win32_desktop_notifications/toast.h b/brightray/browser/win/win32_desktop_notifications/toast.h new file mode 100644 index 00000000000..bdf3ce383b3 --- /dev/null +++ b/brightray/browser/win/win32_desktop_notifications/toast.h @@ -0,0 +1,99 @@ +#pragma once +#include "desktop_notification_controller.h" + +namespace brightray { + +class DesktopNotificationController::Toast +{ +public: + static void Register(HINSTANCE hInstance); + static HWND Create(HINSTANCE hInstance, std::shared_ptr& data); + static Toast* Get(HWND hWnd) + { + return reinterpret_cast(GetWindowLongPtr(hWnd, 0)); + } + + static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + + const std::shared_ptr& GetNotification() const + { + return data; + } + + void ResetContents(); + + void Dismiss(); + + void PopUp(int y); + void SetVerticalPosition(int y); + int GetVerticalPosition() const + { + return verticalPosTarget; + } + int GetHeight() const + { + return toastSize.cy; + } + HDWP Animate(HDWP hdwp, const POINT& origin); + bool IsAnimationActive() const + { + return easeInActive || easeOutActive || IsStackCollapseActive(); + } + bool IsHighlighted() const + { + _ASSERT(!(isHighlighted && !IsWindowVisible(hWnd))); + return isHighlighted; + } + +private: + enum TimerID { + TimerID_AutoDismiss = 1 + }; + + Toast(HWND hWnd, std::shared_ptr* data); + ~Toast(); + + void UpdateBufferSize(); + void UpdateScaledImage(const SIZE& size); + void Draw(); + void Invalidate(); + bool IsRedrawNeeded() const; + void UpdateContents(); + + void AutoDismiss(); + void CancelDismiss(); + void ScheduleDismissal(); + + void StartEaseIn(); + void StartEaseOut(); + bool IsStackCollapseActive() const; + + float AnimateEaseIn(); + float AnimateEaseOut(); + float AnimateStackCollapse(); + +private: + static constexpr const TCHAR className[] = TEXT("DesktopNotificationToast"); + + const HWND hWnd; + HDC hdc; + HBITMAP bitmap = NULL; + + const std::shared_ptr data; // never null + + SIZE toastSize = {}; + SIZE margin = {}; + RECT closeButtonRect = {}; + HBITMAP scaledImage = NULL; + + int verticalPos = 0; + int verticalPosTarget = 0; + bool isNonInteractive = false; + bool easeInActive = false; + bool easeOutActive = false; + bool isContentUpdated = false, isHighlighted = false, isCloseHot = false; + DWORD easeInStart, easeOutStart, stackCollapseStart; + float easeInPos = 0, easeOutPos = 0, stackCollapsePos = 0; +}; + +} diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc new file mode 100644 index 00000000000..fcff85cd30e --- /dev/null +++ b/brightray/browser/win/win32_notification.cc @@ -0,0 +1,60 @@ +#define WIN32_LEAN_AND_MEAN +#include "win32_notification.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include + +namespace brightray { + +void Win32Notification::Show(const base::string16& title, const base::string16& msg, const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) +{ + auto presenter = static_cast(this->presenter()); + if(!presenter) return; + + HBITMAP image = NULL; + + if(!icon.drawsNothing()) + { + if(icon.colorType() == kBGRA_8888_SkColorType) + { + icon.lockPixels(); + + BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) }; + bmi.biWidth = icon.width(); + bmi.biHeight = -icon.height(); + bmi.biPlanes = 1; + bmi.biBitCount = 32; + bmi.biCompression = BI_RGB; + + HDC hdcScreen = GetDC(NULL); + image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, icon.getPixels(), (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + ReleaseDC(NULL, hdcScreen); + + icon.unlockPixels(); + } + } + + Win32Notification* existing = nullptr; + if(!tag.empty()) existing = presenter->GetNotificationObjectByTag(tag); + + if(existing) + { + existing->tag.clear(); + this->notificationRef = std::move(existing->notificationRef); + this->notificationRef.Set(title, msg, image); + } + else + { + this->notificationRef = presenter->AddNotification(title, msg, image); + } + + this->tag = tag; + + if(image) DeleteObject(image); +} + +void Win32Notification::Dismiss() +{ + notificationRef.Close(); +} + +} diff --git a/brightray/browser/win/win32_notification.h b/brightray/browser/win/win32_notification.h new file mode 100644 index 00000000000..95089268ba4 --- /dev/null +++ b/brightray/browser/win/win32_notification.h @@ -0,0 +1,30 @@ +#pragma once +#include "browser/notification.h" +#include "browser/win/notification_presenter_win7.h" + +namespace brightray { + +class Win32Notification : public brightray::Notification +{ +public: + Win32Notification(NotificationDelegate* delegate, NotificationPresenterWin7* presenter) : Notification(delegate, presenter) {} + void Show(const base::string16& title, const base::string16& msg, const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) override; + void Dismiss() override; + + const DesktopNotificationController::Notification& GetRef() const + { + return notificationRef; + } + + const std::string& GetTag() const + { + return tag; + } + +private: + DISALLOW_COPY_AND_ASSIGN(Win32Notification); + DesktopNotificationController::Notification notificationRef; + std::string tag; +}; + +} diff --git a/brightray/filenames.gypi b/brightray/filenames.gypi index a0858ea926c..b7d44013b84 100644 --- a/brightray/filenames.gypi +++ b/brightray/filenames.gypi @@ -84,12 +84,21 @@ 'browser/linux/libnotify_notification.cc', 'browser/linux/notification_presenter_linux.h', 'browser/linux/notification_presenter_linux.cc', - 'browser/win/notification_presenter_win.h', 'browser/win/notification_presenter_win.cc', - 'browser/win/windows_toast_notification.h', - 'browser/win/windows_toast_notification.cc', - 'browser/win/scoped_hstring.h', + 'browser/win/notification_presenter_win.h', + 'browser/win/notification_presenter_win7.cc', + 'browser/win/notification_presenter_win7.h', 'browser/win/scoped_hstring.cc', + 'browser/win/scoped_hstring.h', + 'browser/win/win32_desktop_notifications/common.h', + 'browser/win/win32_desktop_notifications/desktop_notification_controller.cc', + 'browser/win/win32_desktop_notifications/desktop_notification_controller.h', + 'browser/win/win32_desktop_notifications/toast.cc', + 'browser/win/win32_desktop_notifications/toast.h', + 'browser/win/win32_notification.cc', + 'browser/win/win32_notification.h', + 'browser/win/windows_toast_notification.cc', + 'browser/win/windows_toast_notification.h', 'browser/special_storage_policy.cc', 'browser/special_storage_policy.h', 'browser/url_request_context_getter.cc', From 0fa6c82b3f60526f55c894b3184823a35967c67e Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 15 Mar 2017 13:58:53 +0100 Subject: [PATCH 1007/1195] Use `NotificationPresenterWin7` on Windows 7 --- brightray/browser/browser_client.cc | 10 ---------- brightray/browser/win/notification_presenter_win.cc | 6 ++++++ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/brightray/browser/browser_client.cc b/brightray/browser/browser_client.cc index e425b7a83b1..7b25c6a7858 100644 --- a/brightray/browser/browser_client.cc +++ b/brightray/browser/browser_client.cc @@ -13,10 +13,6 @@ #include "browser/platform_notification_service.h" #include "content/public/common/url_constants.h" -#if defined(OS_WIN) -#include "base/win/windows_version.h" -#endif - namespace brightray { namespace { @@ -39,12 +35,6 @@ BrowserClient::~BrowserClient() { } NotificationPresenter* BrowserClient::GetNotificationPresenter() { - #if defined(OS_WIN) - // Bail out if on Windows 7 or even lower, no operating will follow - if (base::win::GetVersion() < base::win::VERSION_WIN8) - return nullptr; - #endif - if (!notification_presenter_) { // Create a new presenter if on OS X, Linux, or Windows 8+ notification_presenter_.reset(NotificationPresenter::Create()); diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 5fc961008c9..faa95cc7e4b 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -10,6 +10,7 @@ #include "base/md5.h" #include "base/strings/utf_string_conversions.h" #include "base/win/windows_version.h" +#include "browser/win/notification_presenter_win7.h" #include "browser/win/windows_toast_notification.h" #include "content/public/browser/desktop_notification_delegate.h" #include "content/public/common/platform_notification_data.h" @@ -36,6 +37,11 @@ bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) { // static NotificationPresenter* NotificationPresenter::Create() { + auto version = base::win::GetVersion(); + if (version < base::win::VERSION_WIN7) + return nullptr; + if (version < base::win::VERSION_WIN8) + return new NotificationPresenterWin7; if (!WindowsToastNotification::Initialize()) return nullptr; std::unique_ptr presenter( From 392d606848e00aa6a7f77bafb39499fec8d8b05f Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Fri, 17 Mar 2017 14:41:22 +0100 Subject: [PATCH 1008/1195] Changed member variable naming style to snake case --- .../win/win32_desktop_notifications/common.h | 14 +- .../desktop_notification_controller.cc | 122 ++++---- .../desktop_notification_controller.h | 16 +- .../win/win32_desktop_notifications/toast.cc | 284 +++++++++--------- .../win/win32_desktop_notifications/toast.h | 46 +-- brightray/browser/win/win32_notification.cc | 12 +- brightray/browser/win/win32_notification.h | 8 +- 7 files changed, 251 insertions(+), 251 deletions(-) diff --git a/brightray/browser/win/win32_desktop_notifications/common.h b/brightray/browser/win/win32_desktop_notifications/common.h index 5f44debf312..9df81bb1194 100644 --- a/brightray/browser/win/win32_desktop_notifications/common.h +++ b/brightray/browser/win/win32_desktop_notifications/common.h @@ -8,7 +8,7 @@ struct NotificationData DesktopNotificationController* controller = nullptr; std::wstring caption; - std::wstring bodyText; + std::wstring body_text; HBITMAP image = NULL; @@ -31,7 +31,7 @@ inline T ScaleForDpi(T value, unsigned dpi) struct ScreenMetrics { - UINT dpiX, dpiY; + UINT dpi_x, dpi_y; ScreenMetrics() { @@ -40,18 +40,18 @@ struct ScreenMetrics if(GetDpiForMonitor) { auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); - if(GetDpiForMonitor(monitor, 0, &dpiX, &dpiY) == S_OK) + if(GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK) return; } HDC hdc = GetDC(NULL); - dpiX = GetDeviceCaps(hdc, LOGPIXELSX); - dpiY = GetDeviceCaps(hdc, LOGPIXELSY); + dpi_x = GetDeviceCaps(hdc, LOGPIXELSX); + dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); } - template T X(T value) const { return ScaleForDpi(value, dpiX); } - template T Y(T value) const { return ScaleForDpi(value, dpiY); } + template T X(T value) const { return ScaleForDpi(value, dpi_x); } + template T Y(T value) const { return ScaleForDpi(value, dpi_y); } }; } diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index e79c6e5be56..262d19ceb18 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -53,7 +53,7 @@ HINSTANCE DesktopNotificationController::RegisterWndClasses() WNDCLASSEX wc = { sizeof(wc) }; wc.lpfnWndProc = &WndProc; - wc.lpszClassName = className; + wc.lpszClassName = class_name_; wc.cbWndExtra = sizeof(DesktopNotificationController*); wc.hInstance = module; @@ -66,13 +66,13 @@ HINSTANCE DesktopNotificationController::RegisterWndClasses() DesktopNotificationController::DesktopNotificationController(unsigned maximumToasts) { - instances.reserve(maximumToasts); + instances_.reserve(maximumToasts); } DesktopNotificationController::~DesktopNotificationController() { - for(auto&& inst : instances) DestroyToast(inst); - if(hwndController) DestroyWindow(hwndController); + for(auto&& inst : instances_) DestroyToast(inst); + if(hwnd_controller_) DestroyWindow(hwnd_controller_); ClearAssets(); } @@ -115,33 +115,33 @@ LRESULT CALLBACK DesktopNotificationController::WndProc(HWND hWnd, UINT message, void DesktopNotificationController::StartAnimation() { - _ASSERT(hwndController); + _ASSERT(hwnd_controller_); - if(!isAnimating && hwndController) + if(!is_animating_ && hwnd_controller_) { // 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 to get at least 60 - SetTimer(hwndController, TimerID_Animate, 15, nullptr); - isAnimating = true; + SetTimer(hwnd_controller_, TimerID_Animate, 15, nullptr); + is_animating_ = true; } } HFONT DesktopNotificationController::GetCaptionFont() { InitializeFonts(); - return captionFont; + return caption_font_; } HFONT DesktopNotificationController::GetBodyFont() { InitializeFonts(); - return bodyFont; + return body_font_; } void DesktopNotificationController::InitializeFonts() { - if(!bodyFont) + if(!body_font_) { NONCLIENTMETRICS metrics = { sizeof(metrics) }; if(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) @@ -153,19 +153,19 @@ void DesktopNotificationController::InitializeFonts() ReleaseDC(NULL, hdc); metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.1f, dpiY); - bodyFont = CreateFontIndirect(&metrics.lfMessageFont); + body_font_ = CreateFontIndirect(&metrics.lfMessageFont); - if(captionFont) DeleteFont(captionFont); + if(caption_font_) DeleteFont(caption_font_); metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.4f, dpiY); - captionFont = CreateFontIndirect(&metrics.lfMessageFont); + caption_font_ = CreateFontIndirect(&metrics.lfMessageFont); } } } void DesktopNotificationController::ClearAssets() { - if(captionFont) { DeleteFont(captionFont); captionFont = NULL; } - if(bodyFont) { DeleteFont(bodyFont); bodyFont = NULL; } + if(caption_font_) { DeleteFont(caption_font_); caption_font_ = NULL; } + if(body_font_) { DeleteFont(body_font_); body_font_ = NULL; } } void DesktopNotificationController::AnimateAll() @@ -176,17 +176,17 @@ void DesktopNotificationController::AnimateAll() bool keepAnimating = false; - if(!instances.empty()) + if(!instances_.empty()) { RECT workArea; if(SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0)) { ScreenMetrics metrics; POINT origin = { workArea.right, - workArea.bottom - metrics.Y(toastMargin) }; + workArea.bottom - metrics.Y(toast_margin_) }; - auto hdwp = BeginDeferWindowPos((int)instances.size()); - for(auto&& inst : instances) + auto hdwp = BeginDeferWindowPos((int)instances_.size()); + for(auto&& inst : instances_) { if(!inst.hwnd) continue; @@ -201,14 +201,14 @@ void DesktopNotificationController::AnimateAll() if(!keepAnimating) { - _ASSERT(hwndController); - if(hwndController) KillTimer(hwndController, TimerID_Animate); - isAnimating = false; + _ASSERT(hwnd_controller_); + if(hwnd_controller_) KillTimer(hwnd_controller_, TimerID_Animate); + is_animating_ = false; } // Purge dismissed notifications and collapse the stack between // items which are highlighted - if(!instances.empty()) + if(!instances_.empty()) { auto isAlive = [](ToastInstance& inst) { return inst.hwnd && IsWindowVisible(inst.hwnd); @@ -218,10 +218,10 @@ void DesktopNotificationController::AnimateAll() return inst.hwnd && Toast::Get(inst.hwnd)->IsHighlighted(); }; - for(auto it = instances.begin();; ++it) + for(auto it = instances_.begin();; ++it) { // find next highlighted item - auto it2 = find_if(it, instances.end(), isHighlighted); + auto it2 = find_if(it, instances_.end(), isHighlighted); // collapse the stack in front of the highlighted item it = stable_partition(it, it2, isAlive); @@ -229,9 +229,9 @@ void DesktopNotificationController::AnimateAll() // purge the dead items for_each(it, it2, [this](auto&& inst) { DestroyToast(inst); }); - if(it2 == instances.end()) + if(it2 == instances_.end()) { - instances.erase(it, it2); + instances_.erase(it, it2); break; } @@ -240,13 +240,13 @@ void DesktopNotificationController::AnimateAll() } // Set new toast positions - if(!instances.empty()) + if(!instances_.empty()) { ScreenMetrics metrics; - auto margin = metrics.Y(toastMargin); + auto margin = metrics.Y(toast_margin_); int targetPos = 0; - for(auto&& inst : instances) + for(auto&& inst : instances_) { if(inst.hwnd) { @@ -271,11 +271,11 @@ DesktopNotificationController::Notification DesktopNotificationController::AddNo NotificationLink data(this); data->caption = move(caption); - data->bodyText = move(bodyText); + data->body_text = move(bodyText); data->image = CopyBitmap(image); // Enqueue new notification - Notification ret = *queue.insert(queue.end(), move(data)); + Notification ret = *queue_.insert(queue_.end(), move(data)); CheckQueue(); return ret; } @@ -283,16 +283,16 @@ DesktopNotificationController::Notification DesktopNotificationController::AddNo void DesktopNotificationController::CloseNotification(Notification& notification) { // Remove it from the queue - auto it = find(queue.begin(), queue.end(), notification.data); - if(it != queue.end()) + auto it = find(queue_.begin(), queue_.end(), notification.data_); + if(it != queue_.end()) { - queue.erase(it); + queue_.erase(it); this->OnNotificationClosed(notification); return; } // Dismiss active toast - auto hwnd = GetToast(notification.data.get()); + auto hwnd = GetToast(notification.data_.get()); if(hwnd) { auto toast = Toast::Get(hwnd); @@ -302,10 +302,10 @@ void DesktopNotificationController::CloseNotification(Notification& notification void DesktopNotificationController::CheckQueue() { - while(instances.size() < instances.capacity() && !queue.empty()) + while(instances_.size() < instances_.capacity() && !queue_.empty()) { - CreateToast(move(queue.front())); - queue.pop_front(); + CreateToast(move(queue_.front())); + queue_.pop_front(); } } @@ -316,22 +316,22 @@ void DesktopNotificationController::CreateToast(NotificationLink&& data) if(hwnd) { int toastPos = 0; - if(!instances.empty()) + if(!instances_.empty()) { - auto& item = instances.back(); + auto& item = instances_.back(); _ASSERT(item.hwnd); ScreenMetrics scr; auto toast = Toast::Get(item.hwnd); - toastPos = toast->GetVerticalPosition() + toast->GetHeight() + scr.Y(toastMargin); + toastPos = toast->GetVerticalPosition() + toast->GetHeight() + scr.Y(toast_margin_); } - instances.push_back({ hwnd, move(data) }); + instances_.push_back({ hwnd, move(data) }); - if(!hwndController) + if(!hwnd_controller_) { // NOTE: We cannot use a message-only window because we need to receive system notifications - hwndController = CreateWindow(className, nullptr, 0, 0, 0, 0, 0, NULL, NULL, hInstance, this); + hwnd_controller_ = CreateWindow(class_name_, nullptr, 0, 0, 0, 0, 0, NULL, NULL, hInstance, this); } auto toast = Toast::Get(hwnd); @@ -341,12 +341,12 @@ void DesktopNotificationController::CreateToast(NotificationLink&& data) HWND DesktopNotificationController::GetToast(const NotificationData* data) const { - auto it = find_if(instances.cbegin(), instances.cend(), [data](auto&& inst) { + auto it = find_if(instances_.cbegin(), instances_.cend(), [data](auto&& inst) { 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) @@ -365,41 +365,41 @@ void DesktopNotificationController::DestroyToast(ToastInstance& inst) DesktopNotificationController::Notification::Notification(const shared_ptr& data) : - data(data) + data_(data) { _ASSERT(data != nullptr); } bool DesktopNotificationController::Notification::operator==(const Notification& other) const { - return data == other.data; + return data_ == other.data_; } void DesktopNotificationController::Notification::Close() { // No business calling this when not pointing to a valid instance - _ASSERT(data); + _ASSERT(data_); - if(data->controller) - data->controller->CloseNotification(*this); + if(data_->controller) + data_->controller->CloseNotification(*this); } void DesktopNotificationController::Notification::Set(std::wstring caption, std::wstring bodyText, HBITMAP image) { // No business calling this when not pointing to a valid instance - _ASSERT(data); + _ASSERT(data_); // Do nothing when the notification has been closed - if(!data->controller) + if(!data_->controller) return; - if(data->image) DeleteBitmap(data->image); + if(data_->image) DeleteBitmap(data_->image); - data->caption = move(caption); - data->bodyText = move(bodyText); - data->image = CopyBitmap(image); + data_->caption = move(caption); + data_->body_text = move(bodyText); + data_->image = CopyBitmap(image); - auto hwnd = data->controller->GetToast(data.get()); + auto hwnd = data_->controller->GetToast(data_.get()); if(hwnd) { auto toast = Toast::Get(hwnd); @@ -407,7 +407,7 @@ void DesktopNotificationController::Notification::Set(std::wstring caption, std: } // Change of contents can affect size and position of all toasts - data->controller->StartAnimation(); + data_->controller->StartAnimation(); } diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h index 1d93591f60d..8b5b160b0e8 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h @@ -37,7 +37,7 @@ private: }; template - static constexpr T toastMargin = 20; + static constexpr T toast_margin_ = 20; // Wrapper around `NotificationData` which makes sure that // the `controller` member is cleared when the controller object @@ -75,12 +75,12 @@ private: void DestroyToast(ToastInstance& inst); private: - static constexpr const TCHAR className[] = TEXT("DesktopNotificationController"); - HWND hwndController = NULL; - HFONT captionFont = NULL, bodyFont = NULL; - std::vector instances; - std::deque queue; - bool isAnimating = false; + static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationController"); + HWND hwnd_controller_ = NULL; + HFONT caption_font_ = NULL, body_font_ = NULL; + std::vector instances_; + std::deque queue_; + bool is_animating_ = false; }; class DesktopNotificationController::Notification @@ -95,7 +95,7 @@ public: void Set(std::wstring caption, std::wstring bodyText, HBITMAP image); private: - std::shared_ptr data; + std::shared_ptr data_; friend class DesktopNotificationController; }; diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index f6cb8d06cef..4f90c37d97f 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -167,25 +167,25 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) } DesktopNotificationController::Toast::Toast(HWND hWnd, shared_ptr* data) : - hWnd(hWnd), data(*data) + hwnd_(hWnd), data_(*data) { HDC hdcScreen = GetDC(NULL); - hdc = CreateCompatibleDC(hdcScreen); + hdc_ = CreateCompatibleDC(hdcScreen); ReleaseDC(NULL, hdcScreen); } DesktopNotificationController::Toast::~Toast() { - DeleteDC(hdc); - if(bitmap) DeleteBitmap(bitmap); - if(scaledImage) DeleteBitmap(scaledImage); + DeleteDC(hdc_); + if(bitmap_) DeleteBitmap(bitmap_); + if(scaled_image_) DeleteBitmap(scaled_image_); } void DesktopNotificationController::Toast::Register(HINSTANCE hInstance) { WNDCLASSEX wc = { sizeof(wc) }; wc.lpfnWndProc = &Toast::WndProc; - wc.lpszClassName = className; + wc.lpszClassName = class_name_; wc.cbWndExtra = sizeof(Toast*); wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); @@ -226,29 +226,29 @@ LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, W inst->Dismiss(); - Notification notification(inst->data); - if(inst->isCloseHot) - inst->data->controller->OnNotificationDismissed(notification); + Notification notification(inst->data_); + if(inst->is_close_hot_) + inst->data_->controller->OnNotificationDismissed(notification); else - inst->data->controller->OnNotificationClicked(notification); + inst->data_->controller->OnNotificationClicked(notification); } return 0; case WM_MOUSEMOVE: { auto inst = Get(hWnd); - if(!inst->isHighlighted) + if(!inst->is_highlighted_) { - inst->isHighlighted = true; + inst->is_highlighted_ = true; TRACKMOUSEEVENT tme = { sizeof(tme), TME_LEAVE, hWnd }; TrackMouseEvent(&tme); } POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - inst->isCloseHot = (PtInRect(&inst->closeButtonRect, cursor) != FALSE); + inst->is_close_hot_ = (PtInRect(&inst->close_button_rect_, cursor) != FALSE); - if(!inst->isNonInteractive) + if(!inst->is_non_interactive_) inst->CancelDismiss(); inst->UpdateContents(); @@ -258,15 +258,15 @@ LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, W case WM_MOUSELEAVE: { auto inst = Get(hWnd); - inst->isHighlighted = false; - inst->isCloseHot = false; + inst->is_highlighted_ = false; + inst->is_close_hot_ = false; inst->UpdateContents(); - if(!inst->easeOutActive && inst->easeInPos == 1.0f) + if(!inst->ease_out_active_ && inst->ease_in_pos_ == 1.0f) inst->ScheduleDismissal(); // Make sure stack collapse happens if needed - inst->data->controller->StartAnimation(); + inst->data_->controller->StartAnimation(); } return 0; @@ -276,7 +276,7 @@ LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, W if(wp->flags & SWP_HIDEWINDOW) { if(!IsWindowVisible(hWnd)) - Get(hWnd)->isHighlighted = false; + Get(hWnd)->is_highlighted_ = false; } } break; @@ -287,7 +287,7 @@ LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, W HWND DesktopNotificationController::Toast::Create(HINSTANCE hInstance, shared_ptr& data) { - return CreateWindowEx(WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOPMOST, className, nullptr, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, &data); + return CreateWindowEx(WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOPMOST, class_name_, nullptr, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, &data); } void DesktopNotificationController::Toast::Draw() @@ -299,7 +299,7 @@ void DesktopNotificationController::Toast::Draw() // base background color is 2/3 of accent // highlighted adds a bit of intensity to every channel - int h = isHighlighted ? (0xff / 20) : 0; + int h = is_highlighted_ ? (0xff / 20) : 0; backColor = RGB(min(0xff, (GetRValue(accent) * 2 / 3) + h), min(0xff, (GetGValue(accent) * 2 / 3) + h), @@ -347,55 +347,55 @@ void DesktopNotificationController::Toast::Draw() { auto brush = CreateSolidBrush(backColor); - RECT rc = { 0, 0, toastSize.cx, toastSize.cy }; - FillRect(hdc, &rc, brush); + RECT rc = { 0, 0, toast_size_.cx, toast_size_.cy }; + FillRect(hdc_, &rc, brush); DeleteBrush(brush); } - SetBkMode(hdc, TRANSPARENT); + SetBkMode(hdc_, TRANSPARENT); const auto close = L'\x2715'; - auto captionFont = data->controller->GetCaptionFont(); - auto bodyFont = data->controller->GetBodyFont(); + auto captionFont = data_->controller->GetCaptionFont(); + auto bodyFont = data_->controller->GetBodyFont(); TEXTMETRIC tmCap; - SelectFont(hdc, captionFont); - GetTextMetrics(hdc, &tmCap); + SelectFont(hdc_, captionFont); + GetTextMetrics(hdc_, &tmCap); - auto textOffsetX = margin.cx; + auto textOffsetX = margin_.cx; BITMAP imageInfo = {}; - if(scaledImage) + if(scaled_image_) { - GetObject(scaledImage, sizeof(imageInfo), &imageInfo); + GetObject(scaled_image_, sizeof(imageInfo), &imageInfo); - textOffsetX += margin.cx + imageInfo.bmWidth; + textOffsetX += margin_.cx + imageInfo.bmWidth; } // calculate close button rect POINT closePos; { SIZE extent = {}; - GetTextExtentPoint32W(hdc, &close, 1, &extent); + GetTextExtentPoint32W(hdc_, &close, 1, &extent); - closeButtonRect.right = toastSize.cx; - closeButtonRect.top = 0; + close_button_rect_.right = toast_size_.cx; + close_button_rect_.top = 0; - closePos.x = closeButtonRect.right - margin.cy - extent.cx; - closePos.y = closeButtonRect.top + margin.cy; + closePos.x = close_button_rect_.right - margin_.cy - extent.cx; + closePos.y = close_button_rect_.top + margin_.cy; - closeButtonRect.left = closePos.x - margin.cy; - closeButtonRect.bottom = closePos.y + extent.cy + margin.cy; + close_button_rect_.left = closePos.x - margin_.cy; + close_button_rect_.bottom = closePos.y + extent.cy + margin_.cy; } // image - if(scaledImage) + if(scaled_image_) { HDC hdcImage = CreateCompatibleDC(NULL); - SelectBitmap(hdcImage, scaledImage); + SelectBitmap(hdcImage, scaled_image_); BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; - AlphaBlend(hdc, margin.cx, margin.cy, imageInfo.bmWidth, imageInfo.bmHeight, hdcImage, 0, 0, imageInfo.bmWidth, imageInfo.bmHeight, blend); + AlphaBlend(hdc_, margin_.cx, margin_.cy, imageInfo.bmWidth, imageInfo.bmHeight, hdcImage, 0, 0, imageInfo.bmWidth, imageInfo.bmHeight, blend); DeleteDC(hdcImage); } @@ -403,85 +403,85 @@ void DesktopNotificationController::Toast::Draw() { RECT rc = { textOffsetX, - margin.cy, - closeButtonRect.left, - toastSize.cy + margin_.cy, + close_button_rect_.left, + toast_size_.cy }; - SelectFont(hdc, captionFont); - SetTextColor(hdc, foreColor); - DrawText(hdc, data->caption.data(), (UINT)data->caption.length(), &rc, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX); + SelectFont(hdc_, captionFont); + SetTextColor(hdc_, foreColor); + DrawText(hdc_, data_->caption.data(), (UINT)data_->caption.length(), &rc, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX); } // body text - if(!data->bodyText.empty()) + if(!data_->body_text.empty()) { RECT rc = { textOffsetX, - 2 * margin.cy + tmCap.tmAscent, - toastSize.cx - margin.cx, - toastSize.cy - margin.cy + 2 * margin_.cy + tmCap.tmAscent, + toast_size_.cx - margin_.cx, + toast_size_.cy - margin_.cy }; - SelectFont(hdc, bodyFont); - SetTextColor(hdc, dimmedColor); - DrawText(hdc, data->bodyText.data(), (UINT)data->bodyText.length(), &rc, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_END_ELLIPSIS | DT_EDITCONTROL); + SelectFont(hdc_, bodyFont); + SetTextColor(hdc_, dimmedColor); + DrawText(hdc_, data_->body_text.data(), (UINT)data_->body_text.length(), &rc, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_END_ELLIPSIS | DT_EDITCONTROL); } // close button { - SelectFont(hdc, captionFont); - SetTextColor(hdc, isCloseHot ? foreColor : dimmedColor); - ExtTextOut(hdc, closePos.x, closePos.y, 0, nullptr, &close, 1, nullptr); + SelectFont(hdc_, captionFont); + SetTextColor(hdc_, is_close_hot_ ? foreColor : dimmedColor); + ExtTextOut(hdc_, closePos.x, closePos.y, 0, nullptr, &close, 1, nullptr); } - isContentUpdated = true; + is_content_updated_ = true; } void DesktopNotificationController::Toast::Invalidate() { - isContentUpdated = false; + is_content_updated_ = false; } bool DesktopNotificationController::Toast::IsRedrawNeeded() const { - return !isContentUpdated; + return !is_content_updated_; } void DesktopNotificationController::Toast::UpdateBufferSize() { - if(hdc) + if(hdc_) { SIZE newSize; { TEXTMETRIC tmCap = {}; - HFONT font = data->controller->GetCaptionFont(); + HFONT font = data_->controller->GetCaptionFont(); if(font) { - SelectFont(hdc, font); - if(!GetTextMetrics(hdc, &tmCap)) return; + SelectFont(hdc_, font); + if(!GetTextMetrics(hdc_, &tmCap)) return; } TEXTMETRIC tmBody = {}; - font = data->controller->GetBodyFont(); + font = data_->controller->GetBodyFont(); if(font) { - SelectFont(hdc, font); - if(!GetTextMetrics(hdc, &tmBody)) return; + SelectFont(hdc_, font); + if(!GetTextMetrics(hdc_, &tmBody)) return; } - this->margin = { tmCap.tmAveCharWidth * 2, tmCap.tmAscent / 2 }; + this->margin_ = { tmCap.tmAveCharWidth * 2, tmCap.tmAscent / 2 }; - newSize.cx = margin.cx + (32 * tmCap.tmAveCharWidth) + margin.cx; - newSize.cy = margin.cy + (tmCap.tmHeight) + margin.cy; + newSize.cx = margin_.cx + (32 * tmCap.tmAveCharWidth) + margin_.cx; + newSize.cy = margin_.cy + (tmCap.tmHeight) + margin_.cy; - if(!data->bodyText.empty()) - newSize.cy += margin.cy + (3 * tmBody.tmHeight); + if(!data_->body_text.empty()) + newSize.cy += margin_.cy + (3 * tmBody.tmHeight); - if(data->image) + if(data_->image) { BITMAP bm; - if(GetObject(data->image, sizeof(bm), &bm)) + if(GetObject(data_->image, sizeof(bm), &bm)) { // cap the image size const int maxDimSize = 80; @@ -508,9 +508,9 @@ void DesktopNotificationController::Toast::UpdateBufferSize() ScreenMetrics scr; SIZE imageDrawSize = { scr.X(width), scr.Y(height) }; - newSize.cx += imageDrawSize.cx + margin.cx; + newSize.cx += imageDrawSize.cx + margin_.cx; - auto heightWithImage = margin.cy + (imageDrawSize.cy) + margin.cy; + auto heightWithImage = margin_.cy + (imageDrawSize.cy) + margin_.cy; if(newSize.cy < heightWithImage) newSize.cy = heightWithImage; UpdateScaledImage(imageDrawSize); @@ -518,7 +518,7 @@ void DesktopNotificationController::Toast::UpdateBufferSize() } } - if(newSize.cx != this->toastSize.cx || newSize.cy != this->toastSize.cy) + if(newSize.cx != this->toast_size_.cx || newSize.cy != this->toast_size_.cy) { HDC hdcScreen = GetDC(NULL); auto newBitmap = CreateCompatibleBitmap(hdcScreen, newSize.cx, newSize.cy); @@ -526,15 +526,15 @@ void DesktopNotificationController::Toast::UpdateBufferSize() if(newBitmap) { - if(SelectBitmap(hdc, newBitmap)) + if(SelectBitmap(hdc_, newBitmap)) { RECT dirty1 = {}, dirty2 = {}; - if(toastSize.cx < newSize.cx) dirty1 = { toastSize.cx, 0, newSize.cx, toastSize.cy }; - if(toastSize.cy < newSize.cy) dirty2 = { 0, toastSize.cy, newSize.cx, newSize.cy }; + if(toast_size_.cx < newSize.cx) dirty1 = { toast_size_.cx, 0, newSize.cx, toast_size_.cy }; + if(toast_size_.cy < newSize.cy) dirty2 = { 0, toast_size_.cy, newSize.cx, newSize.cy }; - if(this->bitmap) DeleteBitmap(this->bitmap); - this->bitmap = newBitmap; - this->toastSize = newSize; + if(this->bitmap_) DeleteBitmap(this->bitmap_); + this->bitmap_ = newBitmap; + this->toast_size_ = newSize; Invalidate(); @@ -547,16 +547,16 @@ void DesktopNotificationController::Toast::UpdateBufferSize() ulw.cbSize = sizeof(ulw); ulw.hdcDst = NULL; ulw.pptDst = nullptr; - ulw.psize = &toastSize; - ulw.hdcSrc = hdc; + ulw.psize = &toast_size_; + ulw.hdcSrc = hdc_; ulw.pptSrc = &origin; ulw.crKey = 0; ulw.pblend = nullptr; ulw.dwFlags = 0; ulw.prcDirty = &dirty1; - auto b1 = UpdateLayeredWindowIndirect(hWnd, &ulw); + auto b1 = UpdateLayeredWindowIndirect(hwnd_, &ulw); ulw.prcDirty = &dirty2; - auto b2 = UpdateLayeredWindowIndirect(hWnd, &ulw); + auto b2 = UpdateLayeredWindowIndirect(hwnd_, &ulw); _ASSERT(b1 && b2); } @@ -572,12 +572,12 @@ void DesktopNotificationController::Toast::UpdateBufferSize() void DesktopNotificationController::Toast::UpdateScaledImage(const SIZE& size) { BITMAP bm; - if(!GetObject(scaledImage, sizeof(bm), &bm) || + if(!GetObject(scaled_image_, sizeof(bm), &bm) || bm.bmWidth != size.cx || bm.bmHeight != size.cy) { - if(scaledImage) DeleteBitmap(scaledImage); - scaledImage = StretchBitmap(data->image, size.cx, size.cy); + if(scaled_image_) DeleteBitmap(scaled_image_); + scaled_image_ = StretchBitmap(data_->image, size.cx, size.cy); } } @@ -585,24 +585,24 @@ void DesktopNotificationController::Toast::UpdateContents() { Draw(); - if(IsWindowVisible(hWnd)) + if(IsWindowVisible(hwnd_)) { RECT rc; - GetWindowRect(hWnd, &rc); + GetWindowRect(hwnd_, &rc); POINT origin = { 0, 0 }; SIZE size = { rc.right - rc.left, rc.bottom - rc.top }; - UpdateLayeredWindow(hWnd, NULL, nullptr, &size, hdc, &origin, 0, nullptr, 0); + UpdateLayeredWindow(hwnd_, NULL, nullptr, &size, hdc_, &origin, 0, nullptr, 0); } } void DesktopNotificationController::Toast::Dismiss() { - if(!isNonInteractive) + if(!is_non_interactive_) { // Set a flag to prevent further interaction. We don't disable the HWND because // we still want to receive mouse move messages in order to keep the toast under // the cursor and not collapse it while dismissing. - isNonInteractive = true; + is_non_interactive_ = true; AutoDismiss(); } @@ -610,28 +610,28 @@ void DesktopNotificationController::Toast::Dismiss() void DesktopNotificationController::Toast::AutoDismiss() { - KillTimer(hWnd, TimerID_AutoDismiss); + KillTimer(hwnd_, TimerID_AutoDismiss); StartEaseOut(); } void DesktopNotificationController::Toast::CancelDismiss() { - KillTimer(hWnd, TimerID_AutoDismiss); - easeOutActive = false; - easeOutPos = 0; + KillTimer(hwnd_, TimerID_AutoDismiss); + ease_out_active_ = false; + ease_out_pos_ = 0; } void DesktopNotificationController::Toast::ScheduleDismissal() { - SetTimer(hWnd, TimerID_AutoDismiss, 4000, nullptr); + SetTimer(hwnd_, TimerID_AutoDismiss, 4000, nullptr); } void DesktopNotificationController::Toast::ResetContents() { - if(scaledImage) + if(scaled_image_) { - DeleteBitmap(scaledImage); - scaledImage = NULL; + DeleteBitmap(scaled_image_); + scaled_image_ = NULL; } Invalidate(); @@ -639,23 +639,23 @@ void DesktopNotificationController::Toast::ResetContents() void DesktopNotificationController::Toast::PopUp(int y) { - verticalPosTarget = verticalPos = y; + vertical_pos_target_ = vertical_pos_ = y; StartEaseIn(); } void DesktopNotificationController::Toast::SetVerticalPosition(int y) { // Don't restart animation if current target is the same - if(y == verticalPosTarget) + if(y == vertical_pos_target_) return; // Make sure the new animation's origin is at the current position - verticalPos += (int)((verticalPosTarget - verticalPos) * stackCollapsePos); + vertical_pos_ += (int)((vertical_pos_target_ - vertical_pos_) * stack_collapse_pos_); // Set new target position and start the animation - verticalPosTarget = y; - stackCollapseStart = GetTickCount(); - data->controller->StartAnimation(); + vertical_pos_target_ = y; + stack_collapse_start_ = GetTickCount(); + data_->controller->StartAnimation(); } HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origin) @@ -672,7 +672,7 @@ HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origi ulw.hdcDst = NULL; ulw.pptDst = nullptr; ulw.psize = nullptr; - ulw.hdcSrc = hdc; + ulw.hdcSrc = hdc_; ulw.pptSrc = &srcOrigin; ulw.crKey = 0; ulw.pblend = nullptr; @@ -688,27 +688,27 @@ HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origi auto easeOutPos = AnimateEaseOut(); auto stackCollapsePos = AnimateStackCollapse(); - auto yOffset = (verticalPosTarget - verticalPos) * stackCollapsePos; + auto yOffset = (vertical_pos_target_ - vertical_pos_) * stackCollapsePos; - size.cx = (int)(toastSize.cx * easeInPos); - size.cy = toastSize.cy; + size.cx = (int)(toast_size_.cx * easeInPos); + size.cy = toast_size_.cy; pt.x = origin.x - size.cx; - pt.y = (int)(origin.y - verticalPos - yOffset - size.cy); + pt.y = (int)(origin.y - vertical_pos_ - yOffset - size.cy); ulw.pptDst = &pt; ulw.psize = &size; - if(easeInActive && easeInPos == 1.0f) + if(ease_in_active_ && easeInPos == 1.0f) { - easeInActive = false; + ease_in_active_ = false; ScheduleDismissal(); } - this->easeInPos = easeInPos; - this->stackCollapsePos = stackCollapsePos; + this->ease_in_pos_ = easeInPos; + this->stack_collapse_pos_ = stackCollapsePos; - if(easeOutPos != this->easeOutPos) + if(easeOutPos != this->ease_out_pos_) { blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; @@ -718,11 +718,11 @@ HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origi ulw.pblend = &blend; ulw.dwFlags = ULW_ALPHA; - this->easeOutPos = easeOutPos; + this->ease_out_pos_ = easeOutPos; if(easeOutPos == 1.0f) { - easeOutActive = false; + ease_out_active_ = false; dwpFlags &= ~SWP_SHOWWINDOW; dwpFlags |= SWP_HIDEWINDOW; @@ -731,46 +731,46 @@ HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origi if(stackCollapsePos == 1.0f) { - verticalPos = verticalPosTarget; + vertical_pos_ = vertical_pos_target_; } // `UpdateLayeredWindowIndirect` updates position, size, and transparency. // `DeferWindowPos` updates z-order, and also position and size in case ULWI fails, // which can happen when one of the dimensions is zero (e.g. at the beginning of ease-in). - auto ulwResult = UpdateLayeredWindowIndirect(hWnd, &ulw); - hdwp = DeferWindowPos(hdwp, hWnd, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, dwpFlags); + auto ulwResult = UpdateLayeredWindowIndirect(hwnd_, &ulw); + hdwp = DeferWindowPos(hdwp, hwnd_, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, dwpFlags); return hdwp; } void DesktopNotificationController::Toast::StartEaseIn() { - _ASSERT(!easeInActive); - easeInStart = GetTickCount(); - easeInActive = true; - data->controller->StartAnimation(); + _ASSERT(!ease_in_active_); + ease_in_start_ = GetTickCount(); + ease_in_active_ = true; + data_->controller->StartAnimation(); } void DesktopNotificationController::Toast::StartEaseOut() { - _ASSERT(!easeOutActive); - easeOutStart = GetTickCount(); - easeOutActive = true; - data->controller->StartAnimation(); + _ASSERT(!ease_out_active_); + ease_out_start_ = GetTickCount(); + ease_out_active_ = true; + data_->controller->StartAnimation(); } bool DesktopNotificationController::Toast::IsStackCollapseActive() const { - return (verticalPos != verticalPosTarget); + return (vertical_pos_ != vertical_pos_target_); } float DesktopNotificationController::Toast::AnimateEaseIn() { - if(!easeInActive) - return easeInPos; + if(!ease_in_active_) + return ease_in_pos_; constexpr float duration = 500.0f; - float time = std::min(duration, (float)(GetTickCount() - easeInStart)) / duration; + float time = std::min(duration, (float)(GetTickCount() - ease_in_start_)) / duration; // decelerating exponential ease const float a = -8.0f; @@ -781,11 +781,11 @@ float DesktopNotificationController::Toast::AnimateEaseIn() float DesktopNotificationController::Toast::AnimateEaseOut() { - if(!easeOutActive) - return easeOutPos; + if(!ease_out_active_) + return ease_out_pos_; constexpr float duration = 120.0f; - float time = std::min(duration, (float)(GetTickCount() - easeOutStart)) / duration; + float time = std::min(duration, (float)(GetTickCount() - ease_out_start_)) / duration; // accelerating circle ease auto pos = 1.0f - std::sqrt(1 - time * time); @@ -796,10 +796,10 @@ float DesktopNotificationController::Toast::AnimateEaseOut() float DesktopNotificationController::Toast::AnimateStackCollapse() { if(!IsStackCollapseActive()) - return stackCollapsePos; + return stack_collapse_pos_; constexpr float duration = 500.0f; - float time = std::min(duration, (float)(GetTickCount() - stackCollapseStart)) / duration; + float time = std::min(duration, (float)(GetTickCount() - stack_collapse_start_)) / duration; // decelerating exponential ease const float a = -8.0f; diff --git a/brightray/browser/win/win32_desktop_notifications/toast.h b/brightray/browser/win/win32_desktop_notifications/toast.h index bdf3ce383b3..64ea7d1e99b 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.h +++ b/brightray/browser/win/win32_desktop_notifications/toast.h @@ -17,7 +17,7 @@ public: const std::shared_ptr& GetNotification() const { - return data; + return data_; } void ResetContents(); @@ -28,21 +28,21 @@ public: void SetVerticalPosition(int y); int GetVerticalPosition() const { - return verticalPosTarget; + return vertical_pos_target_; } int GetHeight() const { - return toastSize.cy; + return toast_size_.cy; } HDWP Animate(HDWP hdwp, const POINT& origin); bool IsAnimationActive() const { - return easeInActive || easeOutActive || IsStackCollapseActive(); + return ease_in_active_ || ease_out_active_ || IsStackCollapseActive(); } bool IsHighlighted() const { - _ASSERT(!(isHighlighted && !IsWindowVisible(hWnd))); - return isHighlighted; + _ASSERT(!(is_highlighted_ && !IsWindowVisible(hwnd_))); + return is_highlighted_; } private: @@ -73,27 +73,27 @@ private: float AnimateStackCollapse(); private: - static constexpr const TCHAR className[] = TEXT("DesktopNotificationToast"); + static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationToast"); - const HWND hWnd; - HDC hdc; - HBITMAP bitmap = NULL; + const HWND hwnd_; + HDC hdc_; + HBITMAP bitmap_ = NULL; - const std::shared_ptr data; // never null + const std::shared_ptr data_; // never null - SIZE toastSize = {}; - SIZE margin = {}; - RECT closeButtonRect = {}; - HBITMAP scaledImage = NULL; + SIZE toast_size_ = {}; + SIZE margin_ = {}; + RECT close_button_rect_ = {}; + HBITMAP scaled_image_ = NULL; - int verticalPos = 0; - int verticalPosTarget = 0; - bool isNonInteractive = false; - bool easeInActive = false; - bool easeOutActive = false; - bool isContentUpdated = false, isHighlighted = false, isCloseHot = false; - DWORD easeInStart, easeOutStart, stackCollapseStart; - float easeInPos = 0, easeOutPos = 0, stackCollapsePos = 0; + int vertical_pos_ = 0; + int vertical_pos_target_ = 0; + bool is_non_interactive_ = false; + bool ease_in_active_ = false; + bool ease_out_active_ = false; + bool is_content_updated_ = false, is_highlighted_ = false, is_close_hot_ = false; + DWORD ease_in_start_, ease_out_start_, stack_collapse_start_; + float ease_in_pos_ = 0, ease_out_pos_ = 0, stack_collapse_pos_ = 0; }; } diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc index fcff85cd30e..86b42cf768f 100644 --- a/brightray/browser/win/win32_notification.cc +++ b/brightray/browser/win/win32_notification.cc @@ -38,23 +38,23 @@ void Win32Notification::Show(const base::string16& title, const base::string16& if(existing) { - existing->tag.clear(); - this->notificationRef = std::move(existing->notificationRef); - this->notificationRef.Set(title, msg, image); + existing->tag_.clear(); + this->notification_ref_ = std::move(existing->notification_ref_); + this->notification_ref_.Set(title, msg, image); } else { - this->notificationRef = presenter->AddNotification(title, msg, image); + this->notification_ref_ = presenter->AddNotification(title, msg, image); } - this->tag = tag; + this->tag_ = tag; if(image) DeleteObject(image); } void Win32Notification::Dismiss() { - notificationRef.Close(); + notification_ref_.Close(); } } diff --git a/brightray/browser/win/win32_notification.h b/brightray/browser/win/win32_notification.h index 95089268ba4..79919354332 100644 --- a/brightray/browser/win/win32_notification.h +++ b/brightray/browser/win/win32_notification.h @@ -13,18 +13,18 @@ public: const DesktopNotificationController::Notification& GetRef() const { - return notificationRef; + return notification_ref_; } const std::string& GetTag() const { - return tag; + return tag_; } private: DISALLOW_COPY_AND_ASSIGN(Win32Notification); - DesktopNotificationController::Notification notificationRef; - std::string tag; + DesktopNotificationController::Notification notification_ref_; + std::string tag_; }; } From 0bba5b9b4199842646ba2b94cca05774705cc543 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Mon, 3 Apr 2017 10:38:21 +0200 Subject: [PATCH 1009/1195] Address cpplint issue "Lines should be <= 80 characters long [whitespace/line_length] [2]" --- .../linux/notification_presenter_linux.cc | 3 +- .../linux/notification_presenter_linux.h | 3 +- .../browser/mac/notification_presenter_mac.h | 3 +- .../browser/mac/notification_presenter_mac.mm | 3 +- brightray/browser/notification_presenter.h | 3 +- .../browser/win/notification_presenter_win.cc | 3 +- .../browser/win/notification_presenter_win.h | 3 +- .../win/notification_presenter_win7.cc | 15 +- .../browser/win/notification_presenter_win7.h | 7 +- .../win/win32_desktop_notifications/common.h | 8 +- .../desktop_notification_controller.cc | 75 +++++--- .../desktop_notification_controller.h | 16 +- .../win/win32_desktop_notifications/toast.cc | 171 ++++++++++++------ .../win/win32_desktop_notifications/toast.h | 13 +- brightray/browser/win/win32_notification.cc | 8 +- brightray/browser/win/win32_notification.h | 10 +- 16 files changed, 238 insertions(+), 106 deletions(-) diff --git a/brightray/browser/linux/notification_presenter_linux.cc b/brightray/browser/linux/notification_presenter_linux.cc index 25d1b6d982b..6df5ebaaec9 100644 --- a/brightray/browser/linux/notification_presenter_linux.cc +++ b/brightray/browser/linux/notification_presenter_linux.cc @@ -22,7 +22,8 @@ NotificationPresenterLinux::NotificationPresenterLinux() { NotificationPresenterLinux::~NotificationPresenterLinux() { } -Notification* NotificationPresenterLinux::CreateNotificationObject(NotificationDelegate* delegate) { +Notification* NotificationPresenterLinux::CreateNotificationObject( + NotificationDelegate* delegate) { return new LibnotifyNotification(delegate, this); } diff --git a/brightray/browser/linux/notification_presenter_linux.h b/brightray/browser/linux/notification_presenter_linux.h index b8adcd1348d..a90f31ea60e 100644 --- a/brightray/browser/linux/notification_presenter_linux.h +++ b/brightray/browser/linux/notification_presenter_linux.h @@ -16,7 +16,8 @@ class NotificationPresenterLinux : public NotificationPresenter { ~NotificationPresenterLinux(); private: - Notification* CreateNotificationObject(NotificationDelegate* delegate) override; + Notification* CreateNotificationObject( + NotificationDelegate* delegate) override; DISALLOW_COPY_AND_ASSIGN(NotificationPresenterLinux); }; diff --git a/brightray/browser/mac/notification_presenter_mac.h b/brightray/browser/mac/notification_presenter_mac.h index f6e5f7959c8..514a27625ea 100644 --- a/brightray/browser/mac/notification_presenter_mac.h +++ b/brightray/browser/mac/notification_presenter_mac.h @@ -22,7 +22,8 @@ class NotificationPresenterMac : public NotificationPresenter { ~NotificationPresenterMac(); private: - Notification* CreateNotificationObject(NotificationDelegate* delegate) override; + Notification* CreateNotificationObject( + NotificationDelegate* delegate) override; base::scoped_nsobject notification_center_delegate_; diff --git a/brightray/browser/mac/notification_presenter_mac.mm b/brightray/browser/mac/notification_presenter_mac.mm index a1fb2e77893..fec4c1a0539 100644 --- a/brightray/browser/mac/notification_presenter_mac.mm +++ b/brightray/browser/mac/notification_presenter_mac.mm @@ -35,7 +35,8 @@ NotificationPresenterMac::~NotificationPresenterMac() { NSUserNotificationCenter.defaultUserNotificationCenter.delegate = nil; } -Notification* NotificationPresenterMac::CreateNotificationObject(NotificationDelegate* delegate) { +Notification* NotificationPresenterMac::CreateNotificationObject( + NotificationDelegate* delegate) { return new CocoaNotification(delegate, this); } diff --git a/brightray/browser/notification_presenter.h b/brightray/browser/notification_presenter.h index f88a9a6449a..721ba92ace4 100644 --- a/brightray/browser/notification_presenter.h +++ b/brightray/browser/notification_presenter.h @@ -27,7 +27,8 @@ class NotificationPresenter { protected: NotificationPresenter(); - virtual Notification* CreateNotificationObject(NotificationDelegate* delegate) = 0; + virtual Notification* CreateNotificationObject( + NotificationDelegate* delegate) = 0; private: friend class Notification; diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index faa95cc7e4b..42819eada71 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -72,7 +72,8 @@ base::string16 NotificationPresenterWin::SaveIconToFilesystem( return base::UTF8ToUTF16(origin.spec()); } -Notification* NotificationPresenterWin::CreateNotificationObject(NotificationDelegate* delegate) { +Notification* NotificationPresenterWin::CreateNotificationObject( + NotificationDelegate* delegate) { return new WindowsToastNotification(delegate, this); } diff --git a/brightray/browser/win/notification_presenter_win.h b/brightray/browser/win/notification_presenter_win.h index 1e1186c500b..679490c1852 100644 --- a/brightray/browser/win/notification_presenter_win.h +++ b/brightray/browser/win/notification_presenter_win.h @@ -42,7 +42,8 @@ class NotificationPresenterWin : public NotificationPresenter { base::string16 SaveIconToFilesystem(const SkBitmap& icon, const GURL& origin); private: - Notification* CreateNotificationObject(NotificationDelegate* delegate) override; + Notification* CreateNotificationObject( + NotificationDelegate* delegate) override; base::ScopedTempDir temp_dir_; diff --git a/brightray/browser/win/notification_presenter_win7.cc b/brightray/browser/win/notification_presenter_win7.cc index 0203e2e85d3..9e80b5c1c1e 100644 --- a/brightray/browser/win/notification_presenter_win7.cc +++ b/brightray/browser/win/notification_presenter_win7.cc @@ -3,12 +3,14 @@ namespace brightray { -brightray::Notification* NotificationPresenterWin7::CreateNotificationObject(NotificationDelegate* delegate) +brightray::Notification* NotificationPresenterWin7::CreateNotificationObject( + NotificationDelegate* delegate) { return new Win32Notification(delegate, this); } -Win32Notification* NotificationPresenterWin7::GetNotificationObjectByRef(const DesktopNotificationController::Notification& ref) +Win32Notification* NotificationPresenterWin7::GetNotificationObjectByRef( + const DesktopNotificationController::Notification& ref) { for(auto n : this->notifications()) { @@ -20,7 +22,8 @@ Win32Notification* NotificationPresenterWin7::GetNotificationObjectByRef(const D return nullptr; } -Win32Notification* NotificationPresenterWin7::GetNotificationObjectByTag(const std::string& tag) +Win32Notification* NotificationPresenterWin7::GetNotificationObjectByTag( + const std::string& tag) { for(auto n : this->notifications()) { @@ -32,13 +35,15 @@ Win32Notification* NotificationPresenterWin7::GetNotificationObjectByTag(const s return nullptr; } -void NotificationPresenterWin7::OnNotificationClicked(Notification& notification) +void NotificationPresenterWin7::OnNotificationClicked( + Notification& notification) { auto n = GetNotificationObjectByRef(notification); if(n) n->NotificationClicked(); } -void NotificationPresenterWin7::OnNotificationDismissed(Notification& notification) +void NotificationPresenterWin7::OnNotificationDismissed( + Notification& notification) { auto n = GetNotificationObjectByRef(notification); if(n) n->NotificationDismissed(); diff --git a/brightray/browser/win/notification_presenter_win7.h b/brightray/browser/win/notification_presenter_win7.h index cebef5438ff..bdc5afdb2af 100644 --- a/brightray/browser/win/notification_presenter_win7.h +++ b/brightray/browser/win/notification_presenter_win7.h @@ -13,13 +13,16 @@ class NotificationPresenterWin7 : public: NotificationPresenterWin7() = default; - Win32Notification* GetNotificationObjectByRef(const DesktopNotificationController::Notification& ref); + Win32Notification* GetNotificationObjectByRef( + const DesktopNotificationController::Notification& ref); + Win32Notification* GetNotificationObjectByTag(const std::string& tag); private: DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7); - brightray::Notification* CreateNotificationObject(NotificationDelegate* delegate) override; + brightray::Notification* CreateNotificationObject( + NotificationDelegate* delegate) override; void OnNotificationClicked(Notification& notification) override; void OnNotificationDismissed(Notification& notification) override; diff --git a/brightray/browser/win/win32_desktop_notifications/common.h b/brightray/browser/win/win32_desktop_notifications/common.h index 9df81bb1194..d6611bf4205 100644 --- a/brightray/browser/win/win32_desktop_notifications/common.h +++ b/brightray/browser/win/win32_desktop_notifications/common.h @@ -36,7 +36,9 @@ struct ScreenMetrics ScreenMetrics() { typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*); - auto GetDpiForMonitor = (GetDpiForMonitor_t*)GetProcAddress(GetModuleHandle(TEXT("shcore")), "GetDpiForMonitor"); + auto GetDpiForMonitor = + (GetDpiForMonitor_t*)GetProcAddress(GetModuleHandle(TEXT("shcore")), + "GetDpiForMonitor"); if(GetDpiForMonitor) { auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); @@ -50,8 +52,8 @@ struct ScreenMetrics ReleaseDC(NULL, hdc); } - template T X(T value) const { return ScaleForDpi(value, dpi_x); } - template T Y(T value) const { return ScaleForDpi(value, dpi_y); } + template T X(T value) const { return ScaleForDpi(value, dpi_x); } + template T Y(T value) const { return ScaleForDpi(value, dpi_y); } }; } diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index 262d19ceb18..f6ea2e8071e 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -28,7 +28,8 @@ HBITMAP CopyBitmap(HBITMAP bitmap) HDC hdcDst = CreateCompatibleDC(NULL); SelectBitmap(hdcSrc, bitmap); SelectBitmap(hdcDst, ret); - BitBlt(hdcDst, 0, 0, bm.bmWidth, bm.bmHeight, hdcSrc, 0, 0, SRCCOPY); + BitBlt(hdcDst, 0, 0, bm.bmWidth, bm.bmHeight, + hdcSrc, 0, 0, SRCCOPY); DeleteDC(hdcDst); DeleteDC(hdcSrc); } @@ -40,14 +41,19 @@ HBITMAP CopyBitmap(HBITMAP bitmap) HINSTANCE DesktopNotificationController::RegisterWndClasses() { // We keep a static `module` variable which serves a dual purpose: - // 1. Stores the HINSTANCE where the window classes are registered, which can be passed to `CreateWindow` - // 2. Indicates whether we already attempted the registration so that we don't do it twice (we don't retry - // even if registration fails, as there is no point. + // 1. Stores the HINSTANCE where the window classes are registered, + // which can be passed to `CreateWindow` + // 2. Indicates whether we already attempted the registration so that + // we don't do it twice (we don't retry even if registration fails, + // as there is no point). static HMODULE module = NULL; if(!module) { - if(GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(&RegisterWndClasses), &module)) + if(GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast(&RegisterWndClasses), + &module)) { Toast::Register(module); @@ -64,7 +70,8 @@ HINSTANCE DesktopNotificationController::RegisterWndClasses() return module; } -DesktopNotificationController::DesktopNotificationController(unsigned maximumToasts) +DesktopNotificationController::DesktopNotificationController( + unsigned maximumToasts) { instances_.reserve(maximumToasts); } @@ -76,7 +83,8 @@ DesktopNotificationController::~DesktopNotificationController() ClearAssets(); } -LRESULT CALLBACK DesktopNotificationController::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK DesktopNotificationController::WndProc( + HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { @@ -119,8 +127,9 @@ void DesktopNotificationController::StartAnimation() if(!is_animating_ && hwnd_controller_) { - // 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 to get at least 60 + // 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 + // to get at least 60 SetTimer(hwnd_controller_, TimerID_Animate, 15, nullptr); is_animating_ = true; @@ -152,11 +161,13 @@ void DesktopNotificationController::InitializeFonts() auto dpiY = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); - metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.1f, dpiY); + metrics.lfMessageFont.lfHeight = + (LONG)ScaleForDpi(baseHeight * 1.1f, dpiY); body_font_ = CreateFontIndirect(&metrics.lfMessageFont); if(caption_font_) DeleteFont(caption_font_); - metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.4f, dpiY); + metrics.lfMessageFont.lfHeight = + (LONG)ScaleForDpi(baseHeight * 1.4f, dpiY); caption_font_ = CreateFontIndirect(&metrics.lfMessageFont); } } @@ -266,7 +277,9 @@ void DesktopNotificationController::AnimateAll() CheckQueue(); } -DesktopNotificationController::Notification DesktopNotificationController::AddNotification(std::wstring caption, std::wstring bodyText, HBITMAP image) +DesktopNotificationController::Notification + DesktopNotificationController::AddNotification( + std::wstring caption, std::wstring bodyText, HBITMAP image) { NotificationLink data(this); @@ -280,7 +293,8 @@ DesktopNotificationController::Notification DesktopNotificationController::AddNo return ret; } -void DesktopNotificationController::CloseNotification(Notification& notification) +void DesktopNotificationController::CloseNotification( + Notification& notification) { // Remove it from the queue auto it = find(queue_.begin(), queue_.end(), notification.data_); @@ -323,15 +337,20 @@ void DesktopNotificationController::CreateToast(NotificationLink&& data) ScreenMetrics scr; auto toast = Toast::Get(item.hwnd); - toastPos = toast->GetVerticalPosition() + toast->GetHeight() + scr.Y(toast_margin_); + toastPos = toast->GetVerticalPosition() + + toast->GetHeight() + + 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); + // 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); @@ -339,12 +358,14 @@ void DesktopNotificationController::CreateToast(NotificationLink&& data) } } -HWND DesktopNotificationController::GetToast(const NotificationData* data) const +HWND DesktopNotificationController::GetToast( + const NotificationData* data) const { - auto it = find_if(instances_.cbegin(), instances_.cend(), [data](auto&& inst) { - auto toast = Toast::Get(inst.hwnd); - return data == toast->GetNotification().get(); - }); + auto it = find_if(instances_.cbegin(), instances_.cend(), + [data](auto&& inst) { + auto toast = Toast::Get(inst.hwnd); + return data == toast->GetNotification().get(); + }); return (it != instances_.cend()) ? it->hwnd : NULL; } @@ -364,13 +385,15 @@ void DesktopNotificationController::DestroyToast(ToastInstance& inst) } -DesktopNotificationController::Notification::Notification(const shared_ptr& data) : +DesktopNotificationController::Notification::Notification( + const shared_ptr& data) : data_(data) { _ASSERT(data != nullptr); } -bool DesktopNotificationController::Notification::operator==(const Notification& other) const +bool DesktopNotificationController::Notification::operator==( + const Notification& other) const { return data_ == other.data_; } @@ -384,7 +407,8 @@ void DesktopNotificationController::Notification::Close() data_->controller->CloseNotification(*this); } -void DesktopNotificationController::Notification::Set(std::wstring caption, std::wstring bodyText, HBITMAP image) +void DesktopNotificationController::Notification::Set( + std::wstring caption, std::wstring bodyText, HBITMAP image) { // No business calling this when not pointing to a valid instance _ASSERT(data_); @@ -411,7 +435,8 @@ void DesktopNotificationController::Notification::Set(std::wstring caption, std: } -DesktopNotificationController::NotificationLink::NotificationLink(DesktopNotificationController* controller) : +DesktopNotificationController::NotificationLink::NotificationLink( + DesktopNotificationController* controller) : shared_ptr(make_shared()) { get()->controller = controller; diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h index 8b5b160b0e8..62a85c9c9dd 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h @@ -16,7 +16,8 @@ public: ~DesktopNotificationController(); class Notification; - Notification AddNotification(std::wstring caption, std::wstring bodyText, HBITMAP image); + Notification AddNotification(std::wstring caption, std::wstring bodyText, + HBITMAP image); void CloseNotification(Notification& notification); // Event handlers -- override to receive the events @@ -58,13 +59,16 @@ private: class Toast; - static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, + WPARAM wParam, LPARAM lParam); static DesktopNotificationController* Get(HWND hWnd) { - return reinterpret_cast(GetWindowLongPtr(hWnd, 0)); + return reinterpret_cast( + GetWindowLongPtr(hWnd, 0)); } - DesktopNotificationController(const DesktopNotificationController&) = delete; + DesktopNotificationController( + const DesktopNotificationController&) = delete; void InitializeFonts(); void ClearAssets(); @@ -75,7 +79,9 @@ private: void DestroyToast(ToastInstance& inst); private: - static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationController"); + static constexpr const TCHAR class_name_[] = + TEXT("DesktopNotificationController"); + HWND hwnd_controller_ = NULL; HFONT caption_font_ = NULL, body_font_ = NULL; std::vector instances_; diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index 4f90c37d97f..be2b04502bd 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -18,20 +18,34 @@ static COLORREF GetAccentColor() if(IsAppThemed()) { HKEY hkey; - if(RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows\\DWM"), 0, KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) + if(RegOpenKeyEx(HKEY_CURRENT_USER, + TEXT("SOFTWARE\\Microsoft\\Windows\\DWM"), 0, + KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) { COLORREF color; DWORD type, size; - if(RegQueryValueEx(hkey, TEXT("AccentColor"), nullptr, &type, (BYTE*)&color, &(size = sizeof(color))) == ERROR_SUCCESS && type == REG_DWORD) + if(RegQueryValueEx(hkey, TEXT("AccentColor"), nullptr, + &type, + (BYTE*)&color, + &(size = sizeof(color))) == ERROR_SUCCESS && + type == REG_DWORD) { // convert from RGBA - color = RGB(GetRValue(color), GetGValue(color), GetBValue(color)); + color = RGB(GetRValue(color), + GetGValue(color), + GetBValue(color)); success = true; } - else if(RegQueryValueEx(hkey, TEXT("ColorizationColor"), nullptr, &type, (BYTE*)&color, &(size = sizeof(color))) == ERROR_SUCCESS && type == REG_DWORD) + else if(RegQueryValueEx(hkey, TEXT("ColorizationColor"), nullptr, + &type, + (BYTE*)&color, + &(size = sizeof(color))) == ERROR_SUCCESS && + type == REG_DWORD) { // convert from BGRA - color = RGB(GetBValue(color), GetGValue(color), GetRValue(color)); + color = RGB(GetBValue(color), + GetGValue(color), + GetRValue(color)); success = true; } @@ -48,8 +62,8 @@ static COLORREF GetAccentColor() static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { // We use StretchBlt for the scaling, but that discards the alpha channel. - // Therefore we first create a separate grayscale bitmap from the alpha channel, - // scale that separately and copy it back to the scaled color bitmap. + // So we first create a separate grayscale bitmap from the alpha channel, + // scale that separately, and copy it back to the scaled color bitmap. BITMAP bm; if(!GetObject(bitmap, sizeof(bm), &bm)) @@ -72,21 +86,27 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) bmi.biCompression = BI_RGB; void* alphaSrcBits; - alphaSrcBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, DIB_RGB_COLORS, &alphaSrcBits, NULL, 0); + alphaSrcBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, + DIB_RGB_COLORS, &alphaSrcBits, + NULL, 0); if(alphaSrcBitmap) { - if(GetDIBits(hdcScreen, bitmap, 0, 0, 0, (BITMAPINFO*)&bmi, DIB_RGB_COLORS) && + if(GetDIBits(hdcScreen, bitmap, 0, 0, 0, + (BITMAPINFO*)&bmi, DIB_RGB_COLORS) && bmi.biSizeImage > 0 && (bmi.biSizeImage % 4) == 0) { - auto buf = (DWORD*)_aligned_malloc(bmi.biSizeImage, sizeof(DWORD)); + auto buf = (BYTE*)_aligned_malloc(bmi.biSizeImage, + sizeof(DWORD)); if(buf) { - GetDIBits(hdcScreen, bitmap, 0, bm.bmHeight, buf, (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + GetDIBits(hdcScreen, bitmap, 0, bm.bmHeight, buf, + (BITMAPINFO*)&bmi, DIB_RGB_COLORS); BYTE* dest = (BYTE*)alphaSrcBits; - for(const DWORD *src = buf, *end = (DWORD*)((BYTE*)buf + bmi.biSizeImage); + for(const DWORD *src = (DWORD*)buf, + *end = (DWORD*)(buf + bmi.biSizeImage); src != end; ++src, ++dest) { @@ -112,10 +132,14 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) bmi.biCompression = BI_RGB; void* colorBits; - auto colorBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, DIB_RGB_COLORS, &colorBits, NULL, 0); + auto colorBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, + DIB_RGB_COLORS, &colorBits, + NULL, 0); void* alphaBits; - auto alphaBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, DIB_RGB_COLORS, &alphaBits, NULL, 0); + auto alphaBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, + DIB_RGB_COLORS, &alphaBits, + NULL, 0); HDC hdc = CreateCompatibleDC(NULL); HDC hdcSrc = CreateCompatibleDC(NULL); @@ -127,12 +151,16 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) // resize color channels SelectObject(hdc, colorBitmap); SelectObject(hdcSrc, bitmap); - StretchBlt(hdc, 0, 0, width, height, hdcSrc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); + StretchBlt(hdc, 0, 0, width, height, + hdcSrc, 0, 0, bm.bmWidth, bm.bmHeight, + SRCCOPY); // resize alpha channel SelectObject(hdc, alphaBitmap); SelectObject(hdcSrc, alphaSrcBitmap); - StretchBlt(hdc, 0, 0, width, height, hdcSrc, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); + StretchBlt(hdc, 0, 0, width, height, + hdcSrc, 0, 0, bm.bmWidth, bm.bmHeight, + SRCCOPY); // flush before touching the bits GdiFlush(); @@ -149,7 +177,9 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) } // create the resulting bitmap - resultBitmap = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, colorBits, (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + resultBitmap = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, + colorBits, (BITMAPINFO*)&bmi, + DIB_RGB_COLORS); } if(hdcSrc) DeleteDC(hdcSrc); @@ -166,7 +196,8 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) return resultBitmap; } -DesktopNotificationController::Toast::Toast(HWND hWnd, shared_ptr* data) : +DesktopNotificationController::Toast::Toast( + HWND hWnd, shared_ptr* data) : hwnd_(hWnd), data_(*data) { HDC hdcScreen = GetDC(NULL); @@ -193,14 +224,17 @@ void DesktopNotificationController::Toast::Register(HINSTANCE hInstance) RegisterClassEx(&wc); } -LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +LRESULT DesktopNotificationController::Toast::WndProc( + HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_CREATE: { auto& cs = reinterpret_cast(lParam); - auto inst = new Toast(hWnd, static_cast*>(cs->lpCreateParams)); + auto data = + static_cast*>(cs->lpCreateParams); + auto inst = new Toast(hWnd, data); SetWindowLongPtr(hWnd, 0, (LONG_PTR)inst); } break; @@ -246,7 +280,8 @@ LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, W } POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - inst->is_close_hot_ = (PtInRect(&inst->close_button_rect_, cursor) != FALSE); + inst->is_close_hot_ = + (PtInRect(&inst->close_button_rect_, cursor) != FALSE); if(!inst->is_non_interactive_) inst->CancelDismiss(); @@ -285,9 +320,12 @@ LRESULT DesktopNotificationController::Toast::WndProc(HWND hWnd, UINT message, W return DefWindowProc(hWnd, message, wParam, lParam); } -HWND DesktopNotificationController::Toast::Create(HINSTANCE hInstance, shared_ptr& data) +HWND DesktopNotificationController::Toast::Create( + HINSTANCE hInstance, shared_ptr& data) { - return CreateWindowEx(WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOPMOST, class_name_, nullptr, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, &data); + return CreateWindowEx(WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOPMOST, + class_name_, nullptr, WS_POPUP, 0, 0, 0, 0, + NULL, NULL, hInstance, &data); } void DesktopNotificationController::Toast::Draw() @@ -319,9 +357,9 @@ void DesktopNotificationController::Toast::Draw() COLORREF foreColor, dimmedColor; { - // based on the lightness of background, we draw foreground in light or dark - // shades of gray blended onto the background with slight transparency - // to avoid sharp contrast + // based on the lightness of background, we draw foreground in light + // or dark shades of gray blended onto the background with slight + // transparency to avoid sharp contrast constexpr float alpha = 0.9f; constexpr float intensityLight[] = { (1.0f * alpha), (0.8f * alpha) }; @@ -395,7 +433,11 @@ void DesktopNotificationController::Toast::Draw() HDC hdcImage = CreateCompatibleDC(NULL); SelectBitmap(hdcImage, scaled_image_); BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; - AlphaBlend(hdc_, margin_.cx, margin_.cy, imageInfo.bmWidth, imageInfo.bmHeight, hdcImage, 0, 0, imageInfo.bmWidth, imageInfo.bmHeight, blend); + AlphaBlend(hdc_, margin_.cx, margin_.cy, + imageInfo.bmWidth, imageInfo.bmHeight, + hdcImage, 0, 0, + imageInfo.bmWidth, imageInfo.bmHeight, + blend); DeleteDC(hdcImage); } @@ -410,7 +452,8 @@ void DesktopNotificationController::Toast::Draw() SelectFont(hdc_, captionFont); SetTextColor(hdc_, foreColor); - DrawText(hdc_, data_->caption.data(), (UINT)data_->caption.length(), &rc, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX); + DrawText(hdc_, data_->caption.data(), (UINT)data_->caption.length(), + &rc, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX); } // body text @@ -425,14 +468,18 @@ void DesktopNotificationController::Toast::Draw() SelectFont(hdc_, bodyFont); SetTextColor(hdc_, dimmedColor); - DrawText(hdc_, data_->body_text.data(), (UINT)data_->body_text.length(), &rc, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | DT_END_ELLIPSIS | DT_EDITCONTROL); + DrawText(hdc_, data_->body_text.data(), (UINT)data_->body_text.length(), + &rc, + DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | + DT_END_ELLIPSIS | DT_EDITCONTROL); } // close button { SelectFont(hdc_, captionFont); SetTextColor(hdc_, is_close_hot_ ? foreColor : dimmedColor); - ExtTextOut(hdc_, closePos.x, closePos.y, 0, nullptr, &close, 1, nullptr); + ExtTextOut(hdc_, closePos.x, closePos.y, 0, nullptr, + &close, 1, nullptr); } is_content_updated_ = true; @@ -510,18 +557,22 @@ void DesktopNotificationController::Toast::UpdateBufferSize() newSize.cx += imageDrawSize.cx + margin_.cx; - auto heightWithImage = margin_.cy + (imageDrawSize.cy) + margin_.cy; - if(newSize.cy < heightWithImage) newSize.cy = heightWithImage; + auto heightWithImage = + margin_.cy + (imageDrawSize.cy) + margin_.cy; + if(newSize.cy < heightWithImage) + newSize.cy = heightWithImage; UpdateScaledImage(imageDrawSize); } } } - if(newSize.cx != this->toast_size_.cx || newSize.cy != this->toast_size_.cy) + if(newSize.cx != this->toast_size_.cx || + newSize.cy != this->toast_size_.cy) { HDC hdcScreen = GetDC(NULL); - auto newBitmap = CreateCompatibleBitmap(hdcScreen, newSize.cx, newSize.cy); + auto newBitmap = CreateCompatibleBitmap(hdcScreen, + newSize.cx, newSize.cy); ReleaseDC(NULL, hdcScreen); if(newBitmap) @@ -529,8 +580,16 @@ void DesktopNotificationController::Toast::UpdateBufferSize() if(SelectBitmap(hdc_, newBitmap)) { RECT dirty1 = {}, dirty2 = {}; - if(toast_size_.cx < newSize.cx) dirty1 = { toast_size_.cx, 0, newSize.cx, toast_size_.cy }; - if(toast_size_.cy < newSize.cy) dirty2 = { 0, toast_size_.cy, newSize.cx, newSize.cy }; + if(toast_size_.cx < newSize.cx) + { + dirty1 = { toast_size_.cx, 0, + newSize.cx, toast_size_.cy }; + } + if(toast_size_.cy < newSize.cy) + { + dirty2 = { 0, toast_size_.cy, + newSize.cx, newSize.cy }; + } if(this->bitmap_) DeleteBitmap(this->bitmap_); this->bitmap_ = newBitmap; @@ -538,8 +597,9 @@ void DesktopNotificationController::Toast::UpdateBufferSize() Invalidate(); - // Resize also the DWM buffer to prevent flicker during window resizing. - // Make sure any existing data is not overwritten by marking the dirty region. + // Resize also the DWM buffer to prevent flicker during + // window resizing. Make sure any existing data is not + // overwritten by marking the dirty region. { POINT origin = { 0, 0 }; @@ -591,7 +651,8 @@ void DesktopNotificationController::Toast::UpdateContents() GetWindowRect(hwnd_, &rc); POINT origin = { 0, 0 }; SIZE size = { rc.right - rc.left, rc.bottom - rc.top }; - UpdateLayeredWindow(hwnd_, NULL, nullptr, &size, hdc_, &origin, 0, nullptr, 0); + UpdateLayeredWindow(hwnd_, NULL, nullptr, &size, + hdc_, &origin, 0, nullptr, 0); } } @@ -599,9 +660,9 @@ void DesktopNotificationController::Toast::Dismiss() { if(!is_non_interactive_) { - // Set a flag to prevent further interaction. We don't disable the HWND because - // we still want to receive mouse move messages in order to keep the toast under - // the cursor and not collapse it while dismissing. + // Set a flag to prevent further interaction. We don't disable the HWND + // because we still want to receive mouse move messages in order to keep + // the toast under the cursor and not collapse it while dismissing. is_non_interactive_ = true; AutoDismiss(); @@ -650,7 +711,8 @@ void DesktopNotificationController::Toast::SetVerticalPosition(int y) return; // Make sure the new animation's origin is at the current position - vertical_pos_ += (int)((vertical_pos_target_ - vertical_pos_) * stack_collapse_pos_); + vertical_pos_ += + (int)((vertical_pos_target_ - vertical_pos_) * stack_collapse_pos_); // Set new target position and start the animation vertical_pos_target_ = y; @@ -658,7 +720,8 @@ void DesktopNotificationController::Toast::SetVerticalPosition(int y) data_->controller->StartAnimation(); } -HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origin) +HDWP DesktopNotificationController::Toast::Animate( + HDWP hdwp, const POINT& origin) { UpdateBufferSize(); @@ -682,7 +745,8 @@ HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origi POINT pt = { 0, 0 }; SIZE size = { 0, 0 }; BLENDFUNCTION blend; - UINT dwpFlags = SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOREDRAW | SWP_NOCOPYBITS; + UINT dwpFlags = SWP_NOACTIVATE | SWP_SHOWWINDOW | + SWP_NOREDRAW | SWP_NOCOPYBITS; auto easeInPos = AnimateEaseIn(); auto easeOutPos = AnimateEaseOut(); @@ -735,11 +799,13 @@ HDWP DesktopNotificationController::Toast::Animate(HDWP hdwp, const POINT& origi } // `UpdateLayeredWindowIndirect` updates position, size, and transparency. - // `DeferWindowPos` updates z-order, and also position and size in case ULWI fails, - // which can happen when one of the dimensions is zero (e.g. at the beginning of ease-in). + // `DeferWindowPos` updates z-order, and also position and size in case + // ULWI fails, which can happen when one of the dimensions is zero (e.g. + // at the beginning of ease-in). auto ulwResult = UpdateLayeredWindowIndirect(hwnd_, &ulw); - hdwp = DeferWindowPos(hdwp, hwnd_, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, dwpFlags); + hdwp = DeferWindowPos(hdwp, hwnd_, HWND_TOPMOST, + pt.x, pt.y, size.cx, size.cy, dwpFlags); return hdwp; } @@ -770,7 +836,8 @@ float DesktopNotificationController::Toast::AnimateEaseIn() return ease_in_pos_; constexpr float duration = 500.0f; - float time = std::min(duration, (float)(GetTickCount() - ease_in_start_)) / duration; + float elapsed = GetTickCount() - ease_in_start_; + float time = std::min(duration, elapsed) / duration; // decelerating exponential ease const float a = -8.0f; @@ -785,7 +852,8 @@ float DesktopNotificationController::Toast::AnimateEaseOut() return ease_out_pos_; constexpr float duration = 120.0f; - float time = std::min(duration, (float)(GetTickCount() - ease_out_start_)) / duration; + float elapsed = GetTickCount() - ease_out_start_; + float time = std::min(duration, elapsed) / duration; // accelerating circle ease auto pos = 1.0f - std::sqrt(1 - time * time); @@ -799,7 +867,8 @@ float DesktopNotificationController::Toast::AnimateStackCollapse() return stack_collapse_pos_; constexpr float duration = 500.0f; - float time = std::min(duration, (float)(GetTickCount() - stack_collapse_start_)) / duration; + float elapsed = GetTickCount() - stack_collapse_start_; + float time = std::min(duration, elapsed) / duration; // decelerating exponential ease const float a = -8.0f; diff --git a/brightray/browser/win/win32_desktop_notifications/toast.h b/brightray/browser/win/win32_desktop_notifications/toast.h index 64ea7d1e99b..6505b5e01af 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.h +++ b/brightray/browser/win/win32_desktop_notifications/toast.h @@ -7,13 +7,15 @@ class DesktopNotificationController::Toast { public: static void Register(HINSTANCE hInstance); - static HWND Create(HINSTANCE hInstance, std::shared_ptr& data); + static HWND Create(HINSTANCE hInstance, + std::shared_ptr& data); static Toast* Get(HWND hWnd) { return reinterpret_cast(GetWindowLongPtr(hWnd, 0)); } - static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, + WPARAM wParam, LPARAM lParam); const std::shared_ptr& GetNotification() const { @@ -73,7 +75,8 @@ private: float AnimateStackCollapse(); private: - static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationToast"); + static constexpr const TCHAR class_name_[] = + TEXT("DesktopNotificationToast"); const HWND hwnd_; HDC hdc_; @@ -91,7 +94,9 @@ private: bool is_non_interactive_ = false; bool ease_in_active_ = false; bool ease_out_active_ = false; - bool is_content_updated_ = false, is_highlighted_ = false, is_close_hot_ = false; + bool is_content_updated_ = false; + bool is_highlighted_ = false; + bool is_close_hot_ = false; DWORD ease_in_start_, ease_out_start_, stack_collapse_start_; float ease_in_pos_ = 0, ease_out_pos_ = 0, stack_collapse_pos_ = 0; }; diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc index 86b42cf768f..c9e29b127b2 100644 --- a/brightray/browser/win/win32_notification.cc +++ b/brightray/browser/win/win32_notification.cc @@ -5,7 +5,10 @@ namespace brightray { -void Win32Notification::Show(const base::string16& title, const base::string16& msg, const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) +void Win32Notification::Show( + const base::string16& title, const base::string16& msg, + const std::string& tag, const GURL& icon_url, + const SkBitmap& icon, const bool silent) { auto presenter = static_cast(this->presenter()); if(!presenter) return; @@ -26,7 +29,8 @@ void Win32Notification::Show(const base::string16& title, const base::string16& bmi.biCompression = BI_RGB; HDC hdcScreen = GetDC(NULL); - image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, icon.getPixels(), (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, icon.getPixels(), + (BITMAPINFO*)&bmi, DIB_RGB_COLORS); ReleaseDC(NULL, hdcScreen); icon.unlockPixels(); diff --git a/brightray/browser/win/win32_notification.h b/brightray/browser/win/win32_notification.h index 79919354332..b1fe7e764b1 100644 --- a/brightray/browser/win/win32_notification.h +++ b/brightray/browser/win/win32_notification.h @@ -7,8 +7,14 @@ namespace brightray { class Win32Notification : public brightray::Notification { public: - Win32Notification(NotificationDelegate* delegate, NotificationPresenterWin7* presenter) : Notification(delegate, presenter) {} - void Show(const base::string16& title, const base::string16& msg, const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) override; + Win32Notification(NotificationDelegate* delegate, + NotificationPresenterWin7* presenter) : + Notification(delegate, presenter) + { + } + void Show(const base::string16& title, const base::string16& msg, + const std::string& tag, const GURL& icon_url, + const SkBitmap& icon, const bool silent) override; void Dismiss() override; const DesktopNotificationController::Notification& GetRef() const From 33b4936a680ae9c92d45fb0a51da76e003c7c4d8 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Mon, 3 Apr 2017 10:42:26 +0200 Subject: [PATCH 1010/1195] Address cpplint issue "Include the directory when naming .h files [build/include] [4]" --- brightray/browser/win/notification_presenter_win7.cc | 4 ++-- .../desktop_notification_controller.cc | 6 +++--- brightray/browser/win/win32_desktop_notifications/toast.cc | 4 ++-- brightray/browser/win/win32_desktop_notifications/toast.h | 2 +- brightray/browser/win/win32_notification.cc | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win7.cc b/brightray/browser/win/notification_presenter_win7.cc index 9e80b5c1c1e..3ce59901069 100644 --- a/brightray/browser/win/notification_presenter_win7.cc +++ b/brightray/browser/win/notification_presenter_win7.cc @@ -1,5 +1,5 @@ -#include "notification_presenter_win7.h" -#include "win32_notification.h" +#include "browser/win/notification_presenter_win7.h" +#include "browser/win/win32_notification.h" namespace brightray { diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index f6ea2e8071e..1559e73ea47 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -1,8 +1,8 @@ #define NOMINMAX #define WIN32_LEAN_AND_MEAN -#include "desktop_notification_controller.h" -#include "common.h" -#include "toast.h" +#include "browser/win/win32_desktop_notifications/desktop_notification_controller.h" +#include "browser/win/win32_desktop_notifications/common.h" +#include "browser/win/win32_desktop_notifications/toast.h" #include #include #include diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index be2b04502bd..6c4614de7c6 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -1,6 +1,6 @@ #define NOMINMAX -#include "toast.h" -#include "common.h" +#include "browser/win/win32_desktop_notifications/toast.h" +#include "browser/win/win32_desktop_notifications/common.h" #include #include #include diff --git a/brightray/browser/win/win32_desktop_notifications/toast.h b/brightray/browser/win/win32_desktop_notifications/toast.h index 6505b5e01af..2e0a1032114 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.h +++ b/brightray/browser/win/win32_desktop_notifications/toast.h @@ -1,5 +1,5 @@ #pragma once -#include "desktop_notification_controller.h" +#include "browser/win/win32_desktop_notifications/desktop_notification_controller.h" namespace brightray { diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc index c9e29b127b2..17382c449be 100644 --- a/brightray/browser/win/win32_notification.cc +++ b/brightray/browser/win/win32_notification.cc @@ -1,5 +1,5 @@ #define WIN32_LEAN_AND_MEAN -#include "win32_notification.h" +#include "browser/win/win32_notification.h" #include "third_party/skia/include/core/SkBitmap.h" #include From 20d0bda538f848261a23fc42fd39ac7464d1c881 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Mon, 3 Apr 2017 10:48:18 +0200 Subject: [PATCH 1011/1195] Address cpplint issue "Found C++ system header after other header. Should be: toast.h, c system, c++ system, other. [build/include_order] [4]" --- .../desktop_notification_controller.cc | 6 +++--- brightray/browser/win/win32_desktop_notifications/toast.cc | 4 ++-- brightray/browser/win/win32_notification.cc | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index 1559e73ea47..a56f6000e4a 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -1,11 +1,11 @@ #define NOMINMAX #define WIN32_LEAN_AND_MEAN #include "browser/win/win32_desktop_notifications/desktop_notification_controller.h" -#include "browser/win/win32_desktop_notifications/common.h" -#include "browser/win/win32_desktop_notifications/toast.h" +#include #include #include -#include +#include "browser/win/win32_desktop_notifications/common.h" +#include "browser/win/win32_desktop_notifications/toast.h" using namespace std; diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index 6c4614de7c6..62aacdb1d00 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -1,9 +1,9 @@ #define NOMINMAX #include "browser/win/win32_desktop_notifications/toast.h" -#include "browser/win/win32_desktop_notifications/common.h" -#include #include #include +#include +#include "browser/win/win32_desktop_notifications/common.h" #pragma comment(lib, "msimg32.lib") #pragma comment(lib, "uxtheme.lib") diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc index 17382c449be..beb13754486 100644 --- a/brightray/browser/win/win32_notification.cc +++ b/brightray/browser/win/win32_notification.cc @@ -1,7 +1,7 @@ #define WIN32_LEAN_AND_MEAN #include "browser/win/win32_notification.h" -#include "third_party/skia/include/core/SkBitmap.h" #include +#include "third_party/skia/include/core/SkBitmap.h" namespace brightray { From 63eeb96e710d9786c6704b243097ee7ddb97afff Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Mon, 3 Apr 2017 11:23:36 +0200 Subject: [PATCH 1012/1195] Address cpplint issue "Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5]" --- .../desktop_notification_controller.cc | 3 ++- brightray/browser/win/win32_desktop_notifications/toast.cc | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index a56f6000e4a..7213f4382c9 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -7,7 +7,8 @@ #include "browser/win/win32_desktop_notifications/common.h" #include "browser/win/win32_desktop_notifications/toast.h" -using namespace std; +using std::make_shared; +using std::shared_ptr; namespace brightray { diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index 62aacdb1d00..e11eea5f4d6 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -8,7 +8,8 @@ #pragma comment(lib, "msimg32.lib") #pragma comment(lib, "uxtheme.lib") -using namespace std; +using std::min; +using std::shared_ptr; namespace brightray { From 29f333227638c36485faa2e891dabbac2f64e56c Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Mon, 3 Apr 2017 12:11:39 +0200 Subject: [PATCH 1013/1195] Address cpplint issue "{ should almost always be at the end of the previous line [whitespace/braces] [4]" --- .../win/notification_presenter_win7.cc | 21 +- .../browser/win/notification_presenter_win7.h | 3 +- .../win/win32_desktop_notifications/common.h | 18 +- .../desktop_notification_controller.cc | 153 +++++-------- .../desktop_notification_controller.h | 9 +- .../win/win32_desktop_notifications/toast.cc | 201 ++++++------------ .../win/win32_desktop_notifications/toast.h | 21 +- brightray/browser/win/win32_notification.cc | 18 +- brightray/browser/win/win32_notification.h | 12 +- 9 files changed, 152 insertions(+), 304 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win7.cc b/brightray/browser/win/notification_presenter_win7.cc index 3ce59901069..cdbdfc803d4 100644 --- a/brightray/browser/win/notification_presenter_win7.cc +++ b/brightray/browser/win/notification_presenter_win7.cc @@ -4,16 +4,13 @@ namespace brightray { brightray::Notification* NotificationPresenterWin7::CreateNotificationObject( - NotificationDelegate* delegate) -{ + NotificationDelegate* delegate) { return new Win32Notification(delegate, this); } Win32Notification* NotificationPresenterWin7::GetNotificationObjectByRef( - const DesktopNotificationController::Notification& ref) -{ - for(auto n : this->notifications()) - { + const DesktopNotificationController::Notification& ref) { + for(auto n : this->notifications()) { auto w32n = static_cast(n); if(w32n->GetRef() == ref) return w32n; @@ -23,10 +20,8 @@ Win32Notification* NotificationPresenterWin7::GetNotificationObjectByRef( } Win32Notification* NotificationPresenterWin7::GetNotificationObjectByTag( - const std::string& tag) -{ - for(auto n : this->notifications()) - { + const std::string& tag) { + for(auto n : this->notifications()) { auto w32n = static_cast(n); if(w32n->GetTag() == tag) return w32n; @@ -36,15 +31,13 @@ Win32Notification* NotificationPresenterWin7::GetNotificationObjectByTag( } void NotificationPresenterWin7::OnNotificationClicked( - Notification& notification) -{ + Notification& notification) { auto n = GetNotificationObjectByRef(notification); if(n) n->NotificationClicked(); } void NotificationPresenterWin7::OnNotificationDismissed( - Notification& notification) -{ + Notification& notification) { auto n = GetNotificationObjectByRef(notification); if(n) n->NotificationDismissed(); } diff --git a/brightray/browser/win/notification_presenter_win7.h b/brightray/browser/win/notification_presenter_win7.h index bdc5afdb2af..2b352aad8af 100644 --- a/brightray/browser/win/notification_presenter_win7.h +++ b/brightray/browser/win/notification_presenter_win7.h @@ -8,8 +8,7 @@ class Win32Notification; class NotificationPresenterWin7 : public NotificationPresenter, - public DesktopNotificationController -{ + public DesktopNotificationController { public: NotificationPresenterWin7() = default; diff --git a/brightray/browser/win/win32_desktop_notifications/common.h b/brightray/browser/win/win32_desktop_notifications/common.h index d6611bf4205..f68ca396086 100644 --- a/brightray/browser/win/win32_desktop_notifications/common.h +++ b/brightray/browser/win/win32_desktop_notifications/common.h @@ -3,8 +3,7 @@ namespace brightray { -struct NotificationData -{ +struct NotificationData { DesktopNotificationController* controller = nullptr; std::wstring caption; @@ -14,8 +13,7 @@ struct NotificationData NotificationData() = default; - ~NotificationData() - { + ~NotificationData() { if(image) DeleteObject(image); } @@ -24,23 +22,19 @@ struct NotificationData }; template -inline T ScaleForDpi(T value, unsigned dpi) -{ +inline T ScaleForDpi(T value, unsigned dpi) { return value * dpi / 96; } -struct ScreenMetrics -{ +struct ScreenMetrics { UINT dpi_x, dpi_y; - ScreenMetrics() - { + ScreenMetrics() { typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*); auto GetDpiForMonitor = (GetDpiForMonitor_t*)GetProcAddress(GetModuleHandle(TEXT("shcore")), "GetDpiForMonitor"); - if(GetDpiForMonitor) - { + if(GetDpiForMonitor) { auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); if(GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK) return; diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index 7213f4382c9..072be506534 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -12,19 +12,16 @@ using std::shared_ptr; namespace brightray { -HBITMAP CopyBitmap(HBITMAP bitmap) -{ +HBITMAP CopyBitmap(HBITMAP bitmap) { HBITMAP ret = NULL; BITMAP bm; - if(bitmap && GetObject(bitmap, sizeof(bm), &bm)) - { + if(bitmap && GetObject(bitmap, sizeof(bm), &bm)) { HDC hdcScreen = GetDC(NULL); ret = CreateCompatibleBitmap(hdcScreen, bm.bmWidth, bm.bmHeight); ReleaseDC(NULL, hdcScreen); - if(ret) - { + if(ret) { HDC hdcSrc = CreateCompatibleDC(NULL); HDC hdcDst = CreateCompatibleDC(NULL); SelectBitmap(hdcSrc, bitmap); @@ -39,8 +36,7 @@ HBITMAP CopyBitmap(HBITMAP bitmap) return ret; } -HINSTANCE DesktopNotificationController::RegisterWndClasses() -{ +HINSTANCE DesktopNotificationController::RegisterWndClasses() { // We keep a static `module` variable which serves a dual purpose: // 1. Stores the HINSTANCE where the window classes are registered, // which can be passed to `CreateWindow` @@ -49,13 +45,11 @@ HINSTANCE DesktopNotificationController::RegisterWndClasses() // as there is no point). static HMODULE module = NULL; - if(!module) - { + if(!module) { if(GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(&RegisterWndClasses), - &module)) - { + &module)) { Toast::Register(module); WNDCLASSEX wc = { sizeof(wc) }; @@ -72,23 +66,19 @@ HINSTANCE DesktopNotificationController::RegisterWndClasses() } DesktopNotificationController::DesktopNotificationController( - unsigned maximumToasts) -{ + unsigned maximumToasts) { instances_.reserve(maximumToasts); } -DesktopNotificationController::~DesktopNotificationController() -{ +DesktopNotificationController::~DesktopNotificationController() { for(auto&& inst : instances_) DestroyToast(inst); if(hwnd_controller_) DestroyWindow(hwnd_controller_); ClearAssets(); } LRESULT CALLBACK DesktopNotificationController::WndProc( - HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch(message) - { + HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + switch(message) { case WM_CREATE: { auto& cs = reinterpret_cast(lParam); @@ -97,8 +87,7 @@ LRESULT CALLBACK DesktopNotificationController::WndProc( break; case WM_TIMER: - if(wParam == TimerID_Animate) - { + if(wParam == TimerID_Animate) { Get(hWnd)->AnimateAll(); } return 0; @@ -112,8 +101,7 @@ LRESULT CALLBACK DesktopNotificationController::WndProc( break; case WM_SETTINGCHANGE: - if(wParam == SPI_SETWORKAREA) - { + if(wParam == SPI_SETWORKAREA) { Get(hWnd)->AnimateAll(); } break; @@ -122,12 +110,10 @@ LRESULT CALLBACK DesktopNotificationController::WndProc( return DefWindowProc(hWnd, message, wParam, lParam); } -void DesktopNotificationController::StartAnimation() -{ +void DesktopNotificationController::StartAnimation() { _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 // the timer is not accurate we must request a higher frame rate // to get at least 60 @@ -137,25 +123,20 @@ void DesktopNotificationController::StartAnimation() } } -HFONT DesktopNotificationController::GetCaptionFont() -{ +HFONT DesktopNotificationController::GetCaptionFont() { InitializeFonts(); return caption_font_; } -HFONT DesktopNotificationController::GetBodyFont() -{ +HFONT DesktopNotificationController::GetBodyFont() { InitializeFonts(); return body_font_; } -void DesktopNotificationController::InitializeFonts() -{ - if(!body_font_) - { +void DesktopNotificationController::InitializeFonts() { + if(!body_font_) { NONCLIENTMETRICS metrics = { sizeof(metrics) }; - if(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) - { + if(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) { auto baseHeight = metrics.lfMessageFont.lfHeight; HDC hdc = GetDC(NULL); @@ -174,32 +155,27 @@ void DesktopNotificationController::InitializeFonts() } } -void DesktopNotificationController::ClearAssets() -{ +void DesktopNotificationController::ClearAssets() { if(caption_font_) { 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 // to all current conditions. Animation time is only one of the variables // influencing them. Screen resolution is another. bool keepAnimating = false; - if(!instances_.empty()) - { + if(!instances_.empty()) { RECT workArea; - if(SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0)) - { + if(SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0)) { ScreenMetrics metrics; POINT origin = { workArea.right, workArea.bottom - metrics.Y(toast_margin_) }; auto hdwp = BeginDeferWindowPos((int)instances_.size()); - for(auto&& inst : instances_) - { + for(auto&& inst : instances_) { if(!inst.hwnd) continue; auto notification = Toast::Get(inst.hwnd); @@ -211,8 +187,7 @@ void DesktopNotificationController::AnimateAll() } } - if(!keepAnimating) - { + if(!keepAnimating) { _ASSERT(hwnd_controller_); if(hwnd_controller_) KillTimer(hwnd_controller_, TimerID_Animate); is_animating_ = false; @@ -220,8 +195,7 @@ void DesktopNotificationController::AnimateAll() // Purge dismissed notifications and collapse the stack between // items which are highlighted - if(!instances_.empty()) - { + if(!instances_.empty()) { auto isAlive = [](ToastInstance& inst) { return inst.hwnd && IsWindowVisible(inst.hwnd); }; @@ -230,8 +204,7 @@ void DesktopNotificationController::AnimateAll() return inst.hwnd && Toast::Get(inst.hwnd)->IsHighlighted(); }; - for(auto it = instances_.begin();; ++it) - { + for(auto it = instances_.begin();; ++it) { // find next highlighted item auto it2 = find_if(it, instances_.end(), isHighlighted); @@ -241,8 +214,7 @@ void DesktopNotificationController::AnimateAll() // purge the dead items for_each(it, it2, [this](auto&& inst) { DestroyToast(inst); }); - if(it2 == instances_.end()) - { + if(it2 == instances_.end()) { instances_.erase(it, it2); break; } @@ -252,16 +224,13 @@ void DesktopNotificationController::AnimateAll() } // Set new toast positions - if(!instances_.empty()) - { + if(!instances_.empty()) { ScreenMetrics metrics; auto margin = metrics.Y(toast_margin_); int targetPos = 0; - for(auto&& inst : instances_) - { - if(inst.hwnd) - { + for(auto&& inst : instances_) { + if(inst.hwnd) { auto toast = Toast::Get(inst.hwnd); if(toast->IsHighlighted()) @@ -280,8 +249,7 @@ void DesktopNotificationController::AnimateAll() DesktopNotificationController::Notification DesktopNotificationController::AddNotification( - std::wstring caption, std::wstring bodyText, HBITMAP image) -{ + std::wstring caption, std::wstring bodyText, HBITMAP image) { NotificationLink data(this); data->caption = move(caption); @@ -295,12 +263,10 @@ DesktopNotificationController::Notification } void DesktopNotificationController::CloseNotification( - Notification& notification) -{ + Notification& notification) { // Remove it from the queue auto it = find(queue_.begin(), queue_.end(), notification.data_); - if(it != queue_.end()) - { + if(it != queue_.end()) { queue_.erase(it); this->OnNotificationClosed(notification); return; @@ -308,31 +274,25 @@ void DesktopNotificationController::CloseNotification( // Dismiss active toast auto hwnd = GetToast(notification.data_.get()); - if(hwnd) - { + if(hwnd) { auto toast = Toast::Get(hwnd); toast->Dismiss(); } } -void DesktopNotificationController::CheckQueue() -{ - while(instances_.size() < instances_.capacity() && !queue_.empty()) - { +void DesktopNotificationController::CheckQueue() { + while(instances_.size() < instances_.capacity() && !queue_.empty()) { CreateToast(move(queue_.front())); queue_.pop_front(); } } -void DesktopNotificationController::CreateToast(NotificationLink&& data) -{ +void DesktopNotificationController::CreateToast(NotificationLink&& data) { auto hInstance = RegisterWndClasses(); auto hwnd = Toast::Create(hInstance, data); - if(hwnd) - { + if(hwnd) { int toastPos = 0; - if(!instances_.empty()) - { + if(!instances_.empty()) { auto& item = instances_.back(); _ASSERT(item.hwnd); @@ -345,8 +305,7 @@ void DesktopNotificationController::CreateToast(NotificationLink&& data) instances_.push_back({ hwnd, move(data) }); - if(!hwnd_controller_) - { + 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, @@ -360,8 +319,7 @@ void DesktopNotificationController::CreateToast(NotificationLink&& data) } HWND DesktopNotificationController::GetToast( - const NotificationData* data) const -{ + const NotificationData* data) const { auto it = find_if(instances_.cbegin(), instances_.cend(), [data](auto&& inst) { auto toast = Toast::Get(inst.hwnd); @@ -371,10 +329,8 @@ HWND DesktopNotificationController::GetToast( return (it != instances_.cend()) ? it->hwnd : NULL; } -void DesktopNotificationController::DestroyToast(ToastInstance& inst) -{ - if(inst.hwnd) - { +void DesktopNotificationController::DestroyToast(ToastInstance& inst) { + if(inst.hwnd) { auto data = Toast::Get(inst.hwnd)->GetNotification(); DestroyWindow(inst.hwnd); @@ -388,19 +344,16 @@ void DesktopNotificationController::DestroyToast(ToastInstance& inst) DesktopNotificationController::Notification::Notification( const shared_ptr& data) : - data_(data) -{ + data_(data) { _ASSERT(data != nullptr); } bool DesktopNotificationController::Notification::operator==( - const Notification& other) const -{ + const Notification& other) const { return data_ == other.data_; } -void DesktopNotificationController::Notification::Close() -{ +void DesktopNotificationController::Notification::Close() { // No business calling this when not pointing to a valid instance _ASSERT(data_); @@ -409,8 +362,7 @@ void DesktopNotificationController::Notification::Close() } void DesktopNotificationController::Notification::Set( - std::wstring caption, std::wstring bodyText, HBITMAP image) -{ + std::wstring caption, std::wstring bodyText, HBITMAP image) { // No business calling this when not pointing to a valid instance _ASSERT(data_); @@ -425,8 +377,7 @@ void DesktopNotificationController::Notification::Set( data_->image = CopyBitmap(image); auto hwnd = data_->controller->GetToast(data_.get()); - if(hwnd) - { + if(hwnd) { auto toast = Toast::Get(hwnd); toast->ResetContents(); } @@ -438,13 +389,11 @@ void DesktopNotificationController::Notification::Set( DesktopNotificationController::NotificationLink::NotificationLink( DesktopNotificationController* controller) : - shared_ptr(make_shared()) -{ + shared_ptr(make_shared()) { get()->controller = controller; } -DesktopNotificationController::NotificationLink::~NotificationLink() -{ +DesktopNotificationController::NotificationLink::~NotificationLink() { auto p = get(); if(p) p->controller = nullptr; } diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h index 62a85c9c9dd..a15d6b1b354 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h @@ -9,8 +9,7 @@ namespace brightray { struct NotificationData; -class DesktopNotificationController -{ +class DesktopNotificationController { public: DesktopNotificationController(unsigned maximumToasts = 3); ~DesktopNotificationController(); @@ -61,8 +60,7 @@ private: static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - static DesktopNotificationController* Get(HWND hWnd) - { + static DesktopNotificationController* Get(HWND hWnd) { return reinterpret_cast( GetWindowLongPtr(hWnd, 0)); } @@ -89,8 +87,7 @@ private: bool is_animating_ = false; }; -class DesktopNotificationController::Notification -{ +class DesktopNotificationController::Notification { public: Notification() = default; Notification(const std::shared_ptr& data); diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index e11eea5f4d6..4f71dad9370 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -13,24 +13,20 @@ using std::shared_ptr; namespace brightray { -static COLORREF GetAccentColor() -{ +static COLORREF GetAccentColor() { bool success = false; - if(IsAppThemed()) - { + if(IsAppThemed()) { HKEY hkey; if(RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Windows\\DWM"), 0, - KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) - { + KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) { COLORREF color; DWORD type, size; if(RegQueryValueEx(hkey, TEXT("AccentColor"), nullptr, &type, (BYTE*)&color, &(size = sizeof(color))) == ERROR_SUCCESS && - type == REG_DWORD) - { + type == REG_DWORD) { // convert from RGBA color = RGB(GetRValue(color), GetGValue(color), @@ -41,8 +37,7 @@ static COLORREF GetAccentColor() &type, (BYTE*)&color, &(size = sizeof(color))) == ERROR_SUCCESS && - type == REG_DWORD) - { + type == REG_DWORD) { // convert from BGRA color = RGB(GetBValue(color), GetGValue(color), @@ -60,8 +55,7 @@ static COLORREF GetAccentColor() } // Stretches a bitmap to the specified size, preserves alpha channel -static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) -{ +static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { // We use StretchBlt for the scaling, but that discards the alpha channel. // So we first create a separate grayscale bitmap from the alpha channel, // scale that separately, and copy it back to the scaled color bitmap. @@ -91,17 +85,14 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) DIB_RGB_COLORS, &alphaSrcBits, NULL, 0); - if(alphaSrcBitmap) - { + if(alphaSrcBitmap) { if(GetDIBits(hdcScreen, bitmap, 0, 0, 0, (BITMAPINFO*)&bmi, DIB_RGB_COLORS) && bmi.biSizeImage > 0 && - (bmi.biSizeImage % 4) == 0) - { + (bmi.biSizeImage % 4) == 0) { auto buf = (BYTE*)_aligned_malloc(bmi.biSizeImage, sizeof(DWORD)); - if(buf) - { + if(buf) { GetDIBits(hdcScreen, bitmap, 0, bm.bmHeight, buf, (BITMAPINFO*)&bmi, DIB_RGB_COLORS); @@ -109,8 +100,7 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) for(const DWORD *src = (DWORD*)buf, *end = (DWORD*)(buf + bmi.biSizeImage); src != end; - ++src, ++dest) - { + ++src, ++dest) { BYTE a = *src >> 24; *dest++ = a; *dest++ = a; @@ -123,8 +113,7 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) } } - if(alphaSrcBitmap) - { + if(alphaSrcBitmap) { BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) }; bmi.biWidth = width; bmi.biHeight = height; @@ -145,8 +134,7 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) HDC hdc = CreateCompatibleDC(NULL); HDC hdcSrc = CreateCompatibleDC(NULL); - if(colorBitmap && alphaBitmap && hdc && hdcSrc) - { + if(colorBitmap && alphaBitmap && hdc && hdcSrc) { SetStretchBltMode(hdc, HALFTONE); // resize color channels @@ -170,8 +158,7 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) auto dest = (BYTE*)colorBits; auto src = (const BYTE*)alphaBits; auto end = src + (width * height * 4); - while(src != end) - { + while(src != end) { dest[3] = src[0]; dest += 4; src += 4; @@ -199,22 +186,19 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) DesktopNotificationController::Toast::Toast( HWND hWnd, shared_ptr* data) : - hwnd_(hWnd), data_(*data) -{ + hwnd_(hWnd), data_(*data) { HDC hdcScreen = GetDC(NULL); hdc_ = CreateCompatibleDC(hdcScreen); ReleaseDC(NULL, hdcScreen); } -DesktopNotificationController::Toast::~Toast() -{ +DesktopNotificationController::Toast::~Toast() { DeleteDC(hdc_); if(bitmap_) DeleteBitmap(bitmap_); if(scaled_image_) DeleteBitmap(scaled_image_); } -void DesktopNotificationController::Toast::Register(HINSTANCE hInstance) -{ +void DesktopNotificationController::Toast::Register(HINSTANCE hInstance) { WNDCLASSEX wc = { sizeof(wc) }; wc.lpfnWndProc = &Toast::WndProc; wc.lpszClassName = class_name_; @@ -226,10 +210,8 @@ void DesktopNotificationController::Toast::Register(HINSTANCE hInstance) } LRESULT DesktopNotificationController::Toast::WndProc( - HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - switch(message) - { + HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + switch(message) { case WM_CREATE: { auto& cs = reinterpret_cast(lParam); @@ -249,8 +231,7 @@ LRESULT DesktopNotificationController::Toast::WndProc( return MA_NOACTIVATE; case WM_TIMER: - if(wParam == TimerID_AutoDismiss) - { + if(wParam == TimerID_AutoDismiss) { Get(hWnd)->AutoDismiss(); } return 0; @@ -272,8 +253,7 @@ LRESULT DesktopNotificationController::Toast::WndProc( case WM_MOUSEMOVE: { auto inst = Get(hWnd); - if(!inst->is_highlighted_) - { + if(!inst->is_highlighted_) { inst->is_highlighted_ = true; TRACKMOUSEEVENT tme = { sizeof(tme), TME_LEAVE, hWnd }; @@ -309,8 +289,7 @@ LRESULT DesktopNotificationController::Toast::WndProc( case WM_WINDOWPOSCHANGED: { auto& wp = reinterpret_cast(lParam); - if(wp->flags & SWP_HIDEWINDOW) - { + if(wp->flags & SWP_HIDEWINDOW) { if(!IsWindowVisible(hWnd)) Get(hWnd)->is_highlighted_ = false; } @@ -322,15 +301,13 @@ LRESULT DesktopNotificationController::Toast::WndProc( } HWND DesktopNotificationController::Toast::Create( - HINSTANCE hInstance, shared_ptr& data) -{ + HINSTANCE hInstance, shared_ptr& data) { return CreateWindowEx(WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOPMOST, class_name_, nullptr, WS_POPUP, 0, 0, 0, 0, NULL, NULL, hInstance, &data); } -void DesktopNotificationController::Toast::Draw() -{ +void DesktopNotificationController::Toast::Draw() { const COLORREF accent = GetAccentColor(); COLORREF backColor; @@ -405,8 +382,7 @@ void DesktopNotificationController::Toast::Draw() auto textOffsetX = margin_.cx; BITMAP imageInfo = {}; - if(scaled_image_) - { + if(scaled_image_) { GetObject(scaled_image_, sizeof(imageInfo), &imageInfo); textOffsetX += margin_.cx + imageInfo.bmWidth; @@ -429,8 +405,7 @@ void DesktopNotificationController::Toast::Draw() } // image - if(scaled_image_) - { + if(scaled_image_) { HDC hdcImage = CreateCompatibleDC(NULL); SelectBitmap(hdcImage, scaled_image_); BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; @@ -458,8 +433,7 @@ void DesktopNotificationController::Toast::Draw() } // body text - if(!data_->body_text.empty()) - { + if(!data_->body_text.empty()) { RECT rc = { textOffsetX, 2 * margin_.cy + tmCap.tmAscent, @@ -486,34 +460,28 @@ void DesktopNotificationController::Toast::Draw() is_content_updated_ = true; } -void DesktopNotificationController::Toast::Invalidate() -{ +void DesktopNotificationController::Toast::Invalidate() { is_content_updated_ = false; } -bool DesktopNotificationController::Toast::IsRedrawNeeded() const -{ +bool DesktopNotificationController::Toast::IsRedrawNeeded() const { return !is_content_updated_; } -void DesktopNotificationController::Toast::UpdateBufferSize() -{ - if(hdc_) - { +void DesktopNotificationController::Toast::UpdateBufferSize() { + if(hdc_) { SIZE newSize; { TEXTMETRIC tmCap = {}; HFONT font = data_->controller->GetCaptionFont(); - if(font) - { + if(font) { SelectFont(hdc_, font); if(!GetTextMetrics(hdc_, &tmCap)) return; } TEXTMETRIC tmBody = {}; font = data_->controller->GetBodyFont(); - if(font) - { + if(font) { SelectFont(hdc_, font); if(!GetTextMetrics(hdc_, &tmBody)) return; } @@ -526,28 +494,22 @@ void DesktopNotificationController::Toast::UpdateBufferSize() if(!data_->body_text.empty()) newSize.cy += margin_.cy + (3 * tmBody.tmHeight); - if(data_->image) - { + if(data_->image) { BITMAP bm; - if(GetObject(data_->image, sizeof(bm), &bm)) - { + if(GetObject(data_->image, sizeof(bm), &bm)) { // cap the image size const int maxDimSize = 80; auto width = bm.bmWidth; auto height = bm.bmHeight; - if(width < height) - { - if(height > maxDimSize) - { + if(width < height) { + if(height > maxDimSize) { width = width * maxDimSize / height; height = maxDimSize; } } - else - { - if(width > maxDimSize) - { + else { + if(width > maxDimSize) { height = height * maxDimSize / width; width = maxDimSize; } @@ -569,25 +531,20 @@ void DesktopNotificationController::Toast::UpdateBufferSize() } if(newSize.cx != this->toast_size_.cx || - newSize.cy != this->toast_size_.cy) - { + newSize.cy != this->toast_size_.cy) { HDC hdcScreen = GetDC(NULL); auto newBitmap = CreateCompatibleBitmap(hdcScreen, newSize.cx, newSize.cy); ReleaseDC(NULL, hdcScreen); - if(newBitmap) - { - if(SelectBitmap(hdc_, newBitmap)) - { + if(newBitmap) { + if(SelectBitmap(hdc_, newBitmap)) { RECT dirty1 = {}, dirty2 = {}; - if(toast_size_.cx < newSize.cx) - { + if(toast_size_.cx < newSize.cx) { dirty1 = { toast_size_.cx, 0, newSize.cx, toast_size_.cy }; } - if(toast_size_.cy < newSize.cy) - { + if(toast_size_.cy < newSize.cy) { dirty2 = { 0, toast_size_.cy, newSize.cx, newSize.cy }; } @@ -630,24 +587,20 @@ void DesktopNotificationController::Toast::UpdateBufferSize() } } -void DesktopNotificationController::Toast::UpdateScaledImage(const SIZE& size) -{ +void DesktopNotificationController::Toast::UpdateScaledImage(const SIZE& size) { BITMAP bm; if(!GetObject(scaled_image_, sizeof(bm), &bm) || bm.bmWidth != size.cx || - bm.bmHeight != size.cy) - { + bm.bmHeight != size.cy) { if(scaled_image_) DeleteBitmap(scaled_image_); scaled_image_ = StretchBitmap(data_->image, size.cx, size.cy); } } -void DesktopNotificationController::Toast::UpdateContents() -{ +void DesktopNotificationController::Toast::UpdateContents() { Draw(); - if(IsWindowVisible(hwnd_)) - { + if(IsWindowVisible(hwnd_)) { RECT rc; GetWindowRect(hwnd_, &rc); POINT origin = { 0, 0 }; @@ -657,10 +610,8 @@ void DesktopNotificationController::Toast::UpdateContents() } } -void DesktopNotificationController::Toast::Dismiss() -{ - if(!is_non_interactive_) - { +void DesktopNotificationController::Toast::Dismiss() { + if(!is_non_interactive_) { // Set a flag to prevent further interaction. We don't disable the HWND // because we still want to receive mouse move messages in order to keep // the toast under the cursor and not collapse it while dismissing. @@ -670,28 +621,23 @@ void DesktopNotificationController::Toast::Dismiss() } } -void DesktopNotificationController::Toast::AutoDismiss() -{ +void DesktopNotificationController::Toast::AutoDismiss() { KillTimer(hwnd_, TimerID_AutoDismiss); StartEaseOut(); } -void DesktopNotificationController::Toast::CancelDismiss() -{ +void DesktopNotificationController::Toast::CancelDismiss() { KillTimer(hwnd_, TimerID_AutoDismiss); ease_out_active_ = false; ease_out_pos_ = 0; } -void DesktopNotificationController::Toast::ScheduleDismissal() -{ +void DesktopNotificationController::Toast::ScheduleDismissal() { SetTimer(hwnd_, TimerID_AutoDismiss, 4000, nullptr); } -void DesktopNotificationController::Toast::ResetContents() -{ - if(scaled_image_) - { +void DesktopNotificationController::Toast::ResetContents() { + if(scaled_image_) { DeleteBitmap(scaled_image_); scaled_image_ = NULL; } @@ -699,14 +645,12 @@ void DesktopNotificationController::Toast::ResetContents() Invalidate(); } -void DesktopNotificationController::Toast::PopUp(int y) -{ +void DesktopNotificationController::Toast::PopUp(int y) { vertical_pos_target_ = vertical_pos_ = y; StartEaseIn(); } -void DesktopNotificationController::Toast::SetVerticalPosition(int y) -{ +void DesktopNotificationController::Toast::SetVerticalPosition(int y) { // Don't restart animation if current target is the same if(y == vertical_pos_target_) return; @@ -722,8 +666,7 @@ void DesktopNotificationController::Toast::SetVerticalPosition(int y) } HDWP DesktopNotificationController::Toast::Animate( - HDWP hdwp, const POINT& origin) -{ + HDWP hdwp, const POINT& origin) { UpdateBufferSize(); if(IsRedrawNeeded()) @@ -764,8 +707,7 @@ HDWP DesktopNotificationController::Toast::Animate( ulw.pptDst = &pt; ulw.psize = &size; - if(ease_in_active_ && easeInPos == 1.0f) - { + if(ease_in_active_ && easeInPos == 1.0f) { ease_in_active_ = false; ScheduleDismissal(); } @@ -773,8 +715,7 @@ HDWP DesktopNotificationController::Toast::Animate( this->ease_in_pos_ = easeInPos; this->stack_collapse_pos_ = stackCollapsePos; - if(easeOutPos != this->ease_out_pos_) - { + if(easeOutPos != this->ease_out_pos_) { blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = (BYTE)(255 * (1.0f - easeOutPos)); @@ -785,8 +726,7 @@ HDWP DesktopNotificationController::Toast::Animate( this->ease_out_pos_ = easeOutPos; - if(easeOutPos == 1.0f) - { + if(easeOutPos == 1.0f) { ease_out_active_ = false; dwpFlags &= ~SWP_SHOWWINDOW; @@ -794,8 +734,7 @@ HDWP DesktopNotificationController::Toast::Animate( } } - if(stackCollapsePos == 1.0f) - { + if(stackCollapsePos == 1.0f) { vertical_pos_ = vertical_pos_target_; } @@ -810,29 +749,25 @@ HDWP DesktopNotificationController::Toast::Animate( return hdwp; } -void DesktopNotificationController::Toast::StartEaseIn() -{ +void DesktopNotificationController::Toast::StartEaseIn() { _ASSERT(!ease_in_active_); ease_in_start_ = GetTickCount(); ease_in_active_ = true; data_->controller->StartAnimation(); } -void DesktopNotificationController::Toast::StartEaseOut() -{ +void DesktopNotificationController::Toast::StartEaseOut() { _ASSERT(!ease_out_active_); ease_out_start_ = GetTickCount(); ease_out_active_ = true; data_->controller->StartAnimation(); } -bool DesktopNotificationController::Toast::IsStackCollapseActive() const -{ +bool DesktopNotificationController::Toast::IsStackCollapseActive() const { return (vertical_pos_ != vertical_pos_target_); } -float DesktopNotificationController::Toast::AnimateEaseIn() -{ +float DesktopNotificationController::Toast::AnimateEaseIn() { if(!ease_in_active_) return ease_in_pos_; @@ -847,8 +782,7 @@ float DesktopNotificationController::Toast::AnimateEaseIn() return pos; } -float DesktopNotificationController::Toast::AnimateEaseOut() -{ +float DesktopNotificationController::Toast::AnimateEaseOut() { if(!ease_out_active_) return ease_out_pos_; @@ -862,8 +796,7 @@ float DesktopNotificationController::Toast::AnimateEaseOut() return pos; } -float DesktopNotificationController::Toast::AnimateStackCollapse() -{ +float DesktopNotificationController::Toast::AnimateStackCollapse() { if(!IsStackCollapseActive()) return stack_collapse_pos_; diff --git a/brightray/browser/win/win32_desktop_notifications/toast.h b/brightray/browser/win/win32_desktop_notifications/toast.h index 2e0a1032114..e77535f86c7 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.h +++ b/brightray/browser/win/win32_desktop_notifications/toast.h @@ -3,22 +3,19 @@ namespace brightray { -class DesktopNotificationController::Toast -{ +class DesktopNotificationController::Toast { public: static void Register(HINSTANCE hInstance); static HWND Create(HINSTANCE hInstance, std::shared_ptr& data); - static Toast* Get(HWND hWnd) - { + static Toast* Get(HWND hWnd) { return reinterpret_cast(GetWindowLongPtr(hWnd, 0)); } static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - const std::shared_ptr& GetNotification() const - { + const std::shared_ptr& GetNotification() const { return data_; } @@ -28,21 +25,17 @@ public: void PopUp(int y); void SetVerticalPosition(int y); - int GetVerticalPosition() const - { + int GetVerticalPosition() const { return vertical_pos_target_; } - int GetHeight() const - { + int GetHeight() const { return toast_size_.cy; } HDWP Animate(HDWP hdwp, const POINT& origin); - bool IsAnimationActive() const - { + bool IsAnimationActive() const { return ease_in_active_ || ease_out_active_ || IsStackCollapseActive(); } - bool IsHighlighted() const - { + bool IsHighlighted() const { _ASSERT(!(is_highlighted_ && !IsWindowVisible(hwnd_))); return is_highlighted_; } diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc index beb13754486..f8830e3ea2d 100644 --- a/brightray/browser/win/win32_notification.cc +++ b/brightray/browser/win/win32_notification.cc @@ -8,17 +8,14 @@ namespace brightray { void Win32Notification::Show( const base::string16& title, const base::string16& msg, const std::string& tag, const GURL& icon_url, - const SkBitmap& icon, const bool silent) -{ + const SkBitmap& icon, const bool silent) { auto presenter = static_cast(this->presenter()); if(!presenter) return; HBITMAP image = NULL; - if(!icon.drawsNothing()) - { - if(icon.colorType() == kBGRA_8888_SkColorType) - { + if(!icon.drawsNothing()) { + if(icon.colorType() == kBGRA_8888_SkColorType) { icon.lockPixels(); BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) }; @@ -40,14 +37,12 @@ void Win32Notification::Show( Win32Notification* existing = nullptr; if(!tag.empty()) existing = presenter->GetNotificationObjectByTag(tag); - if(existing) - { + if(existing) { existing->tag_.clear(); this->notification_ref_ = std::move(existing->notification_ref_); this->notification_ref_.Set(title, msg, image); } - else - { + else { this->notification_ref_ = presenter->AddNotification(title, msg, image); } @@ -56,8 +51,7 @@ void Win32Notification::Show( if(image) DeleteObject(image); } -void Win32Notification::Dismiss() -{ +void Win32Notification::Dismiss() { notification_ref_.Close(); } diff --git a/brightray/browser/win/win32_notification.h b/brightray/browser/win/win32_notification.h index b1fe7e764b1..41f9583bd1f 100644 --- a/brightray/browser/win/win32_notification.h +++ b/brightray/browser/win/win32_notification.h @@ -4,26 +4,22 @@ namespace brightray { -class Win32Notification : public brightray::Notification -{ +class Win32Notification : public brightray::Notification { public: Win32Notification(NotificationDelegate* delegate, NotificationPresenterWin7* presenter) : - Notification(delegate, presenter) - { + Notification(delegate, presenter) { } void Show(const base::string16& title, const base::string16& msg, const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) override; void Dismiss() override; - const DesktopNotificationController::Notification& GetRef() const - { + const DesktopNotificationController::Notification& GetRef() const { return notification_ref_; } - const std::string& GetTag() const - { + const std::string& GetTag() const { return tag_; } From 91cff2e6c794179e3c5485bb1430b172f3b6bff8 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Mon, 3 Apr 2017 13:34:01 +0200 Subject: [PATCH 1014/1195] Address cpplint issue "Missing space before ( in if( [whitespace/parens] [5]" --- .../win/notification_presenter_win7.cc | 12 +- .../win/win32_desktop_notifications/common.h | 6 +- .../desktop_notification_controller.cc | 84 +++++----- .../win/win32_desktop_notifications/toast.cc | 157 +++++++++--------- brightray/browser/win/win32_notification.cc | 12 +- 5 files changed, 136 insertions(+), 135 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win7.cc b/brightray/browser/win/notification_presenter_win7.cc index cdbdfc803d4..e74e212a575 100644 --- a/brightray/browser/win/notification_presenter_win7.cc +++ b/brightray/browser/win/notification_presenter_win7.cc @@ -10,9 +10,9 @@ brightray::Notification* NotificationPresenterWin7::CreateNotificationObject( Win32Notification* NotificationPresenterWin7::GetNotificationObjectByRef( const DesktopNotificationController::Notification& ref) { - for(auto n : this->notifications()) { + for (auto n : this->notifications()) { auto w32n = static_cast(n); - if(w32n->GetRef() == ref) + if (w32n->GetRef() == ref) return w32n; } @@ -21,9 +21,9 @@ Win32Notification* NotificationPresenterWin7::GetNotificationObjectByRef( Win32Notification* NotificationPresenterWin7::GetNotificationObjectByTag( const std::string& tag) { - for(auto n : this->notifications()) { + for (auto n : this->notifications()) { auto w32n = static_cast(n); - if(w32n->GetTag() == tag) + if (w32n->GetTag() == tag) return w32n; } @@ -33,13 +33,13 @@ Win32Notification* NotificationPresenterWin7::GetNotificationObjectByTag( void NotificationPresenterWin7::OnNotificationClicked( Notification& notification) { auto n = GetNotificationObjectByRef(notification); - if(n) n->NotificationClicked(); + if (n) n->NotificationClicked(); } void NotificationPresenterWin7::OnNotificationDismissed( Notification& notification) { auto n = GetNotificationObjectByRef(notification); - if(n) n->NotificationDismissed(); + if (n) n->NotificationDismissed(); } } diff --git a/brightray/browser/win/win32_desktop_notifications/common.h b/brightray/browser/win/win32_desktop_notifications/common.h index f68ca396086..5c7d5ae3764 100644 --- a/brightray/browser/win/win32_desktop_notifications/common.h +++ b/brightray/browser/win/win32_desktop_notifications/common.h @@ -14,7 +14,7 @@ struct NotificationData { NotificationData() = default; ~NotificationData() { - if(image) DeleteObject(image); + if (image) DeleteObject(image); } NotificationData(const NotificationData& other) = delete; @@ -34,9 +34,9 @@ struct ScreenMetrics { auto GetDpiForMonitor = (GetDpiForMonitor_t*)GetProcAddress(GetModuleHandle(TEXT("shcore")), "GetDpiForMonitor"); - if(GetDpiForMonitor) { + if (GetDpiForMonitor) { 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; } diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index 072be506534..b371df608a2 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -16,12 +16,12 @@ HBITMAP CopyBitmap(HBITMAP bitmap) { HBITMAP ret = NULL; BITMAP bm; - if(bitmap && GetObject(bitmap, sizeof(bm), &bm)) { + if (bitmap && GetObject(bitmap, sizeof(bm), &bm)) { HDC hdcScreen = GetDC(NULL); ret = CreateCompatibleBitmap(hdcScreen, bm.bmWidth, bm.bmHeight); ReleaseDC(NULL, hdcScreen); - if(ret) { + if (ret) { HDC hdcSrc = CreateCompatibleDC(NULL); HDC hdcDst = CreateCompatibleDC(NULL); SelectBitmap(hdcSrc, bitmap); @@ -45,8 +45,8 @@ HINSTANCE DesktopNotificationController::RegisterWndClasses() { // as there is no point). static HMODULE module = NULL; - if(!module) { - if(GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + if (!module) { + if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast(&RegisterWndClasses), &module)) { @@ -71,14 +71,14 @@ DesktopNotificationController::DesktopNotificationController( } DesktopNotificationController::~DesktopNotificationController() { - for(auto&& inst : instances_) DestroyToast(inst); - if(hwnd_controller_) DestroyWindow(hwnd_controller_); + for (auto&& inst : instances_) DestroyToast(inst); + if (hwnd_controller_) DestroyWindow(hwnd_controller_); ClearAssets(); } LRESULT CALLBACK DesktopNotificationController::WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) { + switch (message) { case WM_CREATE: { auto& cs = reinterpret_cast(lParam); @@ -87,7 +87,7 @@ LRESULT CALLBACK DesktopNotificationController::WndProc( break; case WM_TIMER: - if(wParam == TimerID_Animate) { + if (wParam == TimerID_Animate) { Get(hWnd)->AnimateAll(); } return 0; @@ -101,7 +101,7 @@ LRESULT CALLBACK DesktopNotificationController::WndProc( break; case WM_SETTINGCHANGE: - if(wParam == SPI_SETWORKAREA) { + if (wParam == SPI_SETWORKAREA) { Get(hWnd)->AnimateAll(); } break; @@ -113,7 +113,7 @@ LRESULT CALLBACK DesktopNotificationController::WndProc( void DesktopNotificationController::StartAnimation() { _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 // the timer is not accurate we must request a higher frame rate // to get at least 60 @@ -134,9 +134,9 @@ HFONT DesktopNotificationController::GetBodyFont() { } void DesktopNotificationController::InitializeFonts() { - if(!body_font_) { + if (!body_font_) { NONCLIENTMETRICS metrics = { sizeof(metrics) }; - if(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) { + if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &metrics, 0)) { auto baseHeight = metrics.lfMessageFont.lfHeight; HDC hdc = GetDC(NULL); @@ -147,7 +147,7 @@ void DesktopNotificationController::InitializeFonts() { (LONG)ScaleForDpi(baseHeight * 1.1f, dpiY); body_font_ = CreateFontIndirect(&metrics.lfMessageFont); - if(caption_font_) DeleteFont(caption_font_); + if (caption_font_) DeleteFont(caption_font_); metrics.lfMessageFont.lfHeight = (LONG)ScaleForDpi(baseHeight * 1.4f, dpiY); caption_font_ = CreateFontIndirect(&metrics.lfMessageFont); @@ -156,8 +156,8 @@ void DesktopNotificationController::InitializeFonts() { } void DesktopNotificationController::ClearAssets() { - if(caption_font_) { DeleteFont(caption_font_); caption_font_ = NULL; } - if(body_font_) { DeleteFont(body_font_); body_font_ = NULL; } + if (caption_font_) { DeleteFont(caption_font_); caption_font_ = NULL; } + if (body_font_) { DeleteFont(body_font_); body_font_ = NULL; } } void DesktopNotificationController::AnimateAll() { @@ -167,35 +167,35 @@ void DesktopNotificationController::AnimateAll() { bool keepAnimating = false; - if(!instances_.empty()) { + if (!instances_.empty()) { RECT workArea; - if(SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0)) { + if (SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0)) { ScreenMetrics metrics; POINT origin = { workArea.right, workArea.bottom - metrics.Y(toast_margin_) }; auto hdwp = BeginDeferWindowPos((int)instances_.size()); - for(auto&& inst : instances_) { - if(!inst.hwnd) continue; + for (auto&& inst : instances_) { + if (!inst.hwnd) continue; auto notification = Toast::Get(inst.hwnd); hdwp = notification->Animate(hdwp, origin); - if(!hdwp) break; + if (!hdwp) break; keepAnimating |= notification->IsAnimationActive(); } - if(hdwp) EndDeferWindowPos(hdwp); + if (hdwp) EndDeferWindowPos(hdwp); } } - if(!keepAnimating) { + if (!keepAnimating) { _ASSERT(hwnd_controller_); - if(hwnd_controller_) KillTimer(hwnd_controller_, TimerID_Animate); + if (hwnd_controller_) KillTimer(hwnd_controller_, TimerID_Animate); is_animating_ = false; } // Purge dismissed notifications and collapse the stack between // items which are highlighted - if(!instances_.empty()) { + if (!instances_.empty()) { auto isAlive = [](ToastInstance& inst) { return inst.hwnd && IsWindowVisible(inst.hwnd); }; @@ -204,7 +204,7 @@ void DesktopNotificationController::AnimateAll() { return inst.hwnd && Toast::Get(inst.hwnd)->IsHighlighted(); }; - for(auto it = instances_.begin();; ++it) { + for (auto it = instances_.begin();; ++it) { // find next highlighted item auto it2 = find_if(it, instances_.end(), isHighlighted); @@ -214,7 +214,7 @@ void DesktopNotificationController::AnimateAll() { // purge the dead items for_each(it, it2, [this](auto&& inst) { DestroyToast(inst); }); - if(it2 == instances_.end()) { + if (it2 == instances_.end()) { instances_.erase(it, it2); break; } @@ -224,16 +224,16 @@ void DesktopNotificationController::AnimateAll() { } // Set new toast positions - if(!instances_.empty()) { + if (!instances_.empty()) { ScreenMetrics metrics; auto margin = metrics.Y(toast_margin_); int targetPos = 0; - for(auto&& inst : instances_) { - if(inst.hwnd) { + for (auto&& inst : instances_) { + if (inst.hwnd) { auto toast = Toast::Get(inst.hwnd); - if(toast->IsHighlighted()) + if (toast->IsHighlighted()) targetPos = toast->GetVerticalPosition(); else toast->SetVerticalPosition(targetPos); @@ -266,7 +266,7 @@ void DesktopNotificationController::CloseNotification( Notification& notification) { // Remove it from the queue auto it = find(queue_.begin(), queue_.end(), notification.data_); - if(it != queue_.end()) { + if (it != queue_.end()) { queue_.erase(it); this->OnNotificationClosed(notification); return; @@ -274,14 +274,14 @@ void DesktopNotificationController::CloseNotification( // Dismiss active toast auto hwnd = GetToast(notification.data_.get()); - if(hwnd) { + if (hwnd) { auto toast = Toast::Get(hwnd); toast->Dismiss(); } } void DesktopNotificationController::CheckQueue() { - while(instances_.size() < instances_.capacity() && !queue_.empty()) { + while (instances_.size() < instances_.capacity() && !queue_.empty()) { CreateToast(move(queue_.front())); queue_.pop_front(); } @@ -290,9 +290,9 @@ void DesktopNotificationController::CheckQueue() { void DesktopNotificationController::CreateToast(NotificationLink&& data) { auto hInstance = RegisterWndClasses(); auto hwnd = Toast::Create(hInstance, data); - if(hwnd) { + if (hwnd) { int toastPos = 0; - if(!instances_.empty()) { + if (!instances_.empty()) { auto& item = instances_.back(); _ASSERT(item.hwnd); @@ -305,7 +305,7 @@ void DesktopNotificationController::CreateToast(NotificationLink&& data) { instances_.push_back({ hwnd, move(data) }); - if(!hwnd_controller_) { + 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, @@ -330,7 +330,7 @@ HWND DesktopNotificationController::GetToast( } void DesktopNotificationController::DestroyToast(ToastInstance& inst) { - if(inst.hwnd) { + if (inst.hwnd) { auto data = Toast::Get(inst.hwnd)->GetNotification(); DestroyWindow(inst.hwnd); @@ -357,7 +357,7 @@ void DesktopNotificationController::Notification::Close() { // No business calling this when not pointing to a valid instance _ASSERT(data_); - if(data_->controller) + if (data_->controller) data_->controller->CloseNotification(*this); } @@ -367,17 +367,17 @@ void DesktopNotificationController::Notification::Set( _ASSERT(data_); // Do nothing when the notification has been closed - if(!data_->controller) + if (!data_->controller) return; - if(data_->image) DeleteBitmap(data_->image); + if (data_->image) DeleteBitmap(data_->image); data_->caption = move(caption); data_->body_text = move(bodyText); data_->image = CopyBitmap(image); auto hwnd = data_->controller->GetToast(data_.get()); - if(hwnd) { + if (hwnd) { auto toast = Toast::Get(hwnd); toast->ResetContents(); } @@ -395,7 +395,7 @@ DesktopNotificationController::NotificationLink::NotificationLink( DesktopNotificationController::NotificationLink::~NotificationLink() { auto p = get(); - if(p) p->controller = nullptr; + if (p) p->controller = nullptr; } } diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index 4f71dad9370..798dd76fba4 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -15,29 +15,30 @@ namespace brightray { static COLORREF GetAccentColor() { bool success = false; - if(IsAppThemed()) { + if (IsAppThemed()) { HKEY hkey; - if(RegOpenKeyEx(HKEY_CURRENT_USER, - TEXT("SOFTWARE\\Microsoft\\Windows\\DWM"), 0, - KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) { + if (RegOpenKeyEx(HKEY_CURRENT_USER, + TEXT("SOFTWARE\\Microsoft\\Windows\\DWM"), 0, + KEY_QUERY_VALUE, &hkey) == ERROR_SUCCESS) { COLORREF color; DWORD type, size; - if(RegQueryValueEx(hkey, TEXT("AccentColor"), nullptr, - &type, - (BYTE*)&color, - &(size = sizeof(color))) == ERROR_SUCCESS && - type == REG_DWORD) { + if (RegQueryValueEx(hkey, TEXT("AccentColor"), nullptr, + &type, + (BYTE*)&color, + &(size = sizeof(color))) == ERROR_SUCCESS && + type == REG_DWORD) { // convert from RGBA color = RGB(GetRValue(color), GetGValue(color), GetBValue(color)); success = true; } - else if(RegQueryValueEx(hkey, TEXT("ColorizationColor"), nullptr, - &type, - (BYTE*)&color, - &(size = sizeof(color))) == ERROR_SUCCESS && - type == REG_DWORD) { + else if ( + RegQueryValueEx(hkey, TEXT("ColorizationColor"), nullptr, + &type, + (BYTE*)&color, + &(size = sizeof(color))) == ERROR_SUCCESS && + type == REG_DWORD) { // convert from BGRA color = RGB(GetBValue(color), GetGValue(color), @@ -47,7 +48,7 @@ static COLORREF GetAccentColor() { RegCloseKey(hkey); - if(success) return color; + if (success) return color; } } @@ -61,10 +62,10 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { // scale that separately, and copy it back to the scaled color bitmap. BITMAP bm; - if(!GetObject(bitmap, sizeof(bm), &bm)) + if (!GetObject(bitmap, sizeof(bm), &bm)) return NULL; - if(width == 0 || height == 0) + if (width == 0 || height == 0) return NULL; HBITMAP resultBitmap = NULL; @@ -85,22 +86,22 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { DIB_RGB_COLORS, &alphaSrcBits, NULL, 0); - if(alphaSrcBitmap) { - if(GetDIBits(hdcScreen, bitmap, 0, 0, 0, + if (alphaSrcBitmap) { + if (GetDIBits(hdcScreen, bitmap, 0, 0, 0, (BITMAPINFO*)&bmi, DIB_RGB_COLORS) && - bmi.biSizeImage > 0 && - (bmi.biSizeImage % 4) == 0) { + bmi.biSizeImage > 0 && + (bmi.biSizeImage % 4) == 0) { auto buf = (BYTE*)_aligned_malloc(bmi.biSizeImage, sizeof(DWORD)); - if(buf) { + if (buf) { GetDIBits(hdcScreen, bitmap, 0, bm.bmHeight, buf, (BITMAPINFO*)&bmi, DIB_RGB_COLORS); BYTE* dest = (BYTE*)alphaSrcBits; - for(const DWORD *src = (DWORD*)buf, - *end = (DWORD*)(buf + bmi.biSizeImage); - src != end; - ++src, ++dest) { + for (const DWORD *src = (DWORD*)buf, + *end = (DWORD*)(buf + bmi.biSizeImage); + src != end; + ++src, ++dest) { BYTE a = *src >> 24; *dest++ = a; *dest++ = a; @@ -113,7 +114,7 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { } } - if(alphaSrcBitmap) { + if (alphaSrcBitmap) { BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) }; bmi.biWidth = width; bmi.biHeight = height; @@ -134,7 +135,7 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { HDC hdc = CreateCompatibleDC(NULL); HDC hdcSrc = CreateCompatibleDC(NULL); - if(colorBitmap && alphaBitmap && hdc && hdcSrc) { + if (colorBitmap && alphaBitmap && hdc && hdcSrc) { SetStretchBltMode(hdc, HALFTONE); // resize color channels @@ -158,7 +159,7 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { auto dest = (BYTE*)colorBits; auto src = (const BYTE*)alphaBits; auto end = src + (width * height * 4); - while(src != end) { + while (src != end) { dest[3] = src[0]; dest += 4; src += 4; @@ -170,11 +171,11 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { DIB_RGB_COLORS); } - if(hdcSrc) DeleteDC(hdcSrc); - if(hdc) DeleteDC(hdc); + if (hdcSrc) DeleteDC(hdcSrc); + if (hdc) DeleteDC(hdc); - if(alphaBitmap) DeleteObject(alphaBitmap); - if(colorBitmap) DeleteObject(colorBitmap); + if (alphaBitmap) DeleteObject(alphaBitmap); + if (colorBitmap) DeleteObject(colorBitmap); DeleteObject(alphaSrcBitmap); } @@ -194,8 +195,8 @@ DesktopNotificationController::Toast::Toast( DesktopNotificationController::Toast::~Toast() { DeleteDC(hdc_); - if(bitmap_) DeleteBitmap(bitmap_); - if(scaled_image_) DeleteBitmap(scaled_image_); + if (bitmap_) DeleteBitmap(bitmap_); + if (scaled_image_) DeleteBitmap(scaled_image_); } void DesktopNotificationController::Toast::Register(HINSTANCE hInstance) { @@ -211,7 +212,7 @@ void DesktopNotificationController::Toast::Register(HINSTANCE hInstance) { LRESULT DesktopNotificationController::Toast::WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - switch(message) { + switch (message) { case WM_CREATE: { auto& cs = reinterpret_cast(lParam); @@ -231,7 +232,7 @@ LRESULT DesktopNotificationController::Toast::WndProc( return MA_NOACTIVATE; case WM_TIMER: - if(wParam == TimerID_AutoDismiss) { + if (wParam == TimerID_AutoDismiss) { Get(hWnd)->AutoDismiss(); } return 0; @@ -243,7 +244,7 @@ LRESULT DesktopNotificationController::Toast::WndProc( inst->Dismiss(); Notification notification(inst->data_); - if(inst->is_close_hot_) + if (inst->is_close_hot_) inst->data_->controller->OnNotificationDismissed(notification); else inst->data_->controller->OnNotificationClicked(notification); @@ -253,7 +254,7 @@ LRESULT DesktopNotificationController::Toast::WndProc( case WM_MOUSEMOVE: { auto inst = Get(hWnd); - if(!inst->is_highlighted_) { + if (!inst->is_highlighted_) { inst->is_highlighted_ = true; TRACKMOUSEEVENT tme = { sizeof(tme), TME_LEAVE, hWnd }; @@ -264,7 +265,7 @@ LRESULT DesktopNotificationController::Toast::WndProc( inst->is_close_hot_ = (PtInRect(&inst->close_button_rect_, cursor) != FALSE); - if(!inst->is_non_interactive_) + if (!inst->is_non_interactive_) inst->CancelDismiss(); inst->UpdateContents(); @@ -278,7 +279,7 @@ LRESULT DesktopNotificationController::Toast::WndProc( inst->is_close_hot_ = false; inst->UpdateContents(); - if(!inst->ease_out_active_ && inst->ease_in_pos_ == 1.0f) + if (!inst->ease_out_active_ && inst->ease_in_pos_ == 1.0f) inst->ScheduleDismissal(); // Make sure stack collapse happens if needed @@ -289,8 +290,8 @@ LRESULT DesktopNotificationController::Toast::WndProc( case WM_WINDOWPOSCHANGED: { auto& wp = reinterpret_cast(lParam); - if(wp->flags & SWP_HIDEWINDOW) { - if(!IsWindowVisible(hWnd)) + if (wp->flags & SWP_HIDEWINDOW) { + if (!IsWindowVisible(hWnd)) Get(hWnd)->is_highlighted_ = false; } } @@ -382,7 +383,7 @@ void DesktopNotificationController::Toast::Draw() { auto textOffsetX = margin_.cx; BITMAP imageInfo = {}; - if(scaled_image_) { + if (scaled_image_) { GetObject(scaled_image_, sizeof(imageInfo), &imageInfo); textOffsetX += margin_.cx + imageInfo.bmWidth; @@ -405,7 +406,7 @@ void DesktopNotificationController::Toast::Draw() { } // image - if(scaled_image_) { + if (scaled_image_) { HDC hdcImage = CreateCompatibleDC(NULL); SelectBitmap(hdcImage, scaled_image_); BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; @@ -433,7 +434,7 @@ void DesktopNotificationController::Toast::Draw() { } // body text - if(!data_->body_text.empty()) { + if (!data_->body_text.empty()) { RECT rc = { textOffsetX, 2 * margin_.cy + tmCap.tmAscent, @@ -469,21 +470,21 @@ bool DesktopNotificationController::Toast::IsRedrawNeeded() const { } void DesktopNotificationController::Toast::UpdateBufferSize() { - if(hdc_) { + if (hdc_) { SIZE newSize; { TEXTMETRIC tmCap = {}; HFONT font = data_->controller->GetCaptionFont(); - if(font) { + if (font) { SelectFont(hdc_, font); - if(!GetTextMetrics(hdc_, &tmCap)) return; + if (!GetTextMetrics(hdc_, &tmCap)) return; } TEXTMETRIC tmBody = {}; font = data_->controller->GetBodyFont(); - if(font) { + if (font) { SelectFont(hdc_, font); - if(!GetTextMetrics(hdc_, &tmBody)) return; + if (!GetTextMetrics(hdc_, &tmBody)) return; } this->margin_ = { tmCap.tmAveCharWidth * 2, tmCap.tmAscent / 2 }; @@ -491,25 +492,25 @@ void DesktopNotificationController::Toast::UpdateBufferSize() { newSize.cx = margin_.cx + (32 * tmCap.tmAveCharWidth) + margin_.cx; newSize.cy = margin_.cy + (tmCap.tmHeight) + margin_.cy; - if(!data_->body_text.empty()) + if (!data_->body_text.empty()) newSize.cy += margin_.cy + (3 * tmBody.tmHeight); - if(data_->image) { + if (data_->image) { BITMAP bm; - if(GetObject(data_->image, sizeof(bm), &bm)) { + if (GetObject(data_->image, sizeof(bm), &bm)) { // cap the image size const int maxDimSize = 80; auto width = bm.bmWidth; auto height = bm.bmHeight; - if(width < height) { - if(height > maxDimSize) { + if (width < height) { + if (height > maxDimSize) { width = width * maxDimSize / height; height = maxDimSize; } } else { - if(width > maxDimSize) { + if (width > maxDimSize) { height = height * maxDimSize / width; width = maxDimSize; } @@ -522,7 +523,7 @@ void DesktopNotificationController::Toast::UpdateBufferSize() { auto heightWithImage = margin_.cy + (imageDrawSize.cy) + margin_.cy; - if(newSize.cy < heightWithImage) + if (newSize.cy < heightWithImage) newSize.cy = heightWithImage; UpdateScaledImage(imageDrawSize); @@ -530,26 +531,26 @@ void DesktopNotificationController::Toast::UpdateBufferSize() { } } - if(newSize.cx != this->toast_size_.cx || + if (newSize.cx != this->toast_size_.cx || newSize.cy != this->toast_size_.cy) { HDC hdcScreen = GetDC(NULL); auto newBitmap = CreateCompatibleBitmap(hdcScreen, newSize.cx, newSize.cy); ReleaseDC(NULL, hdcScreen); - if(newBitmap) { - if(SelectBitmap(hdc_, newBitmap)) { + if (newBitmap) { + if (SelectBitmap(hdc_, newBitmap)) { RECT dirty1 = {}, dirty2 = {}; - if(toast_size_.cx < newSize.cx) { + if (toast_size_.cx < newSize.cx) { dirty1 = { toast_size_.cx, 0, newSize.cx, toast_size_.cy }; } - if(toast_size_.cy < newSize.cy) { + if (toast_size_.cy < newSize.cy) { dirty2 = { 0, toast_size_.cy, newSize.cx, newSize.cy }; } - if(this->bitmap_) DeleteBitmap(this->bitmap_); + if (this->bitmap_) DeleteBitmap(this->bitmap_); this->bitmap_ = newBitmap; this->toast_size_ = newSize; @@ -589,10 +590,10 @@ void DesktopNotificationController::Toast::UpdateBufferSize() { void DesktopNotificationController::Toast::UpdateScaledImage(const SIZE& size) { BITMAP bm; - if(!GetObject(scaled_image_, sizeof(bm), &bm) || + if (!GetObject(scaled_image_, sizeof(bm), &bm) || bm.bmWidth != size.cx || bm.bmHeight != size.cy) { - if(scaled_image_) DeleteBitmap(scaled_image_); + if (scaled_image_) DeleteBitmap(scaled_image_); scaled_image_ = StretchBitmap(data_->image, size.cx, size.cy); } } @@ -600,7 +601,7 @@ void DesktopNotificationController::Toast::UpdateScaledImage(const SIZE& size) { void DesktopNotificationController::Toast::UpdateContents() { Draw(); - if(IsWindowVisible(hwnd_)) { + if (IsWindowVisible(hwnd_)) { RECT rc; GetWindowRect(hwnd_, &rc); POINT origin = { 0, 0 }; @@ -611,7 +612,7 @@ void DesktopNotificationController::Toast::UpdateContents() { } void DesktopNotificationController::Toast::Dismiss() { - if(!is_non_interactive_) { + if (!is_non_interactive_) { // Set a flag to prevent further interaction. We don't disable the HWND // because we still want to receive mouse move messages in order to keep // the toast under the cursor and not collapse it while dismissing. @@ -637,7 +638,7 @@ void DesktopNotificationController::Toast::ScheduleDismissal() { } void DesktopNotificationController::Toast::ResetContents() { - if(scaled_image_) { + if (scaled_image_) { DeleteBitmap(scaled_image_); scaled_image_ = NULL; } @@ -652,7 +653,7 @@ void DesktopNotificationController::Toast::PopUp(int y) { void DesktopNotificationController::Toast::SetVerticalPosition(int y) { // Don't restart animation if current target is the same - if(y == vertical_pos_target_) + if (y == vertical_pos_target_) return; // Make sure the new animation's origin is at the current position @@ -669,7 +670,7 @@ HDWP DesktopNotificationController::Toast::Animate( HDWP hdwp, const POINT& origin) { UpdateBufferSize(); - if(IsRedrawNeeded()) + if (IsRedrawNeeded()) Draw(); POINT srcOrigin = { 0, 0 }; @@ -707,7 +708,7 @@ HDWP DesktopNotificationController::Toast::Animate( ulw.pptDst = &pt; ulw.psize = &size; - if(ease_in_active_ && easeInPos == 1.0f) { + if (ease_in_active_ && easeInPos == 1.0f) { ease_in_active_ = false; ScheduleDismissal(); } @@ -715,7 +716,7 @@ HDWP DesktopNotificationController::Toast::Animate( this->ease_in_pos_ = easeInPos; this->stack_collapse_pos_ = stackCollapsePos; - if(easeOutPos != this->ease_out_pos_) { + if (easeOutPos != this->ease_out_pos_) { blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; blend.SourceConstantAlpha = (BYTE)(255 * (1.0f - easeOutPos)); @@ -726,7 +727,7 @@ HDWP DesktopNotificationController::Toast::Animate( this->ease_out_pos_ = easeOutPos; - if(easeOutPos == 1.0f) { + if (easeOutPos == 1.0f) { ease_out_active_ = false; dwpFlags &= ~SWP_SHOWWINDOW; @@ -734,7 +735,7 @@ HDWP DesktopNotificationController::Toast::Animate( } } - if(stackCollapsePos == 1.0f) { + if (stackCollapsePos == 1.0f) { vertical_pos_ = vertical_pos_target_; } @@ -768,7 +769,7 @@ bool DesktopNotificationController::Toast::IsStackCollapseActive() const { } float DesktopNotificationController::Toast::AnimateEaseIn() { - if(!ease_in_active_) + if (!ease_in_active_) return ease_in_pos_; constexpr float duration = 500.0f; @@ -783,7 +784,7 @@ float DesktopNotificationController::Toast::AnimateEaseIn() { } float DesktopNotificationController::Toast::AnimateEaseOut() { - if(!ease_out_active_) + if (!ease_out_active_) return ease_out_pos_; constexpr float duration = 120.0f; @@ -797,7 +798,7 @@ float DesktopNotificationController::Toast::AnimateEaseOut() { } float DesktopNotificationController::Toast::AnimateStackCollapse() { - if(!IsStackCollapseActive()) + if (!IsStackCollapseActive()) return stack_collapse_pos_; constexpr float duration = 500.0f; diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc index f8830e3ea2d..36242c06a40 100644 --- a/brightray/browser/win/win32_notification.cc +++ b/brightray/browser/win/win32_notification.cc @@ -10,12 +10,12 @@ void Win32Notification::Show( const std::string& tag, const GURL& icon_url, const SkBitmap& icon, const bool silent) { auto presenter = static_cast(this->presenter()); - if(!presenter) return; + if (!presenter) return; HBITMAP image = NULL; - if(!icon.drawsNothing()) { - if(icon.colorType() == kBGRA_8888_SkColorType) { + if (!icon.drawsNothing()) { + if (icon.colorType() == kBGRA_8888_SkColorType) { icon.lockPixels(); BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) }; @@ -35,9 +35,9 @@ void Win32Notification::Show( } Win32Notification* existing = nullptr; - if(!tag.empty()) existing = presenter->GetNotificationObjectByTag(tag); + if (!tag.empty()) existing = presenter->GetNotificationObjectByTag(tag); - if(existing) { + if (existing) { existing->tag_.clear(); this->notification_ref_ = std::move(existing->notification_ref_); this->notification_ref_.Set(title, msg, image); @@ -48,7 +48,7 @@ void Win32Notification::Show( this->tag_ = tag; - if(image) DeleteObject(image); + if (image) DeleteObject(image); } void Win32Notification::Dismiss() { From 9b7fbd4d223a9302a108763b50c7f820f070979c Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 5 Apr 2017 11:53:37 +0200 Subject: [PATCH 1015/1195] Address cpplint issue "Using C-style cast. Use reinterpret_cast(...) instead [readability/casting] [4]" --- .../win/win32_desktop_notifications/common.h | 8 +-- .../desktop_notification_controller.cc | 5 +- .../win/win32_desktop_notifications/toast.cc | 51 +++++++++++-------- brightray/browser/win/win32_notification.cc | 3 +- 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/brightray/browser/win/win32_desktop_notifications/common.h b/brightray/browser/win/win32_desktop_notifications/common.h index 5c7d5ae3764..2785f187fc7 100644 --- a/brightray/browser/win/win32_desktop_notifications/common.h +++ b/brightray/browser/win/win32_desktop_notifications/common.h @@ -31,9 +31,11 @@ struct ScreenMetrics { ScreenMetrics() { typedef HRESULT WINAPI GetDpiForMonitor_t(HMONITOR, int, UINT*, UINT*); - auto GetDpiForMonitor = - (GetDpiForMonitor_t*)GetProcAddress(GetModuleHandle(TEXT("shcore")), - "GetDpiForMonitor"); + + auto GetDpiForMonitor = reinterpret_cast( + GetProcAddress(GetModuleHandle(TEXT("shcore")), + "GetDpiForMonitor")); + if (GetDpiForMonitor) { auto monitor = MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY); if (GetDpiForMonitor(monitor, 0, &dpi_x, &dpi_y) == S_OK) diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index b371df608a2..f0d65469b9d 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -174,7 +174,9 @@ void DesktopNotificationController::AnimateAll() { POINT origin = { workArea.right, workArea.bottom - metrics.Y(toast_margin_) }; - auto hdwp = BeginDeferWindowPos((int)instances_.size()); + auto hdwp = + BeginDeferWindowPos(static_cast(instances_.size())); + for (auto&& inst : instances_) { if (!inst.hwnd) continue; @@ -183,6 +185,7 @@ void DesktopNotificationController::AnimateAll() { if (!hdwp) break; keepAnimating |= notification->IsAnimationActive(); } + if (hdwp) EndDeferWindowPos(hdwp); } } diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index 798dd76fba4..2727bc9ed12 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -24,7 +24,7 @@ static COLORREF GetAccentColor() { DWORD type, size; if (RegQueryValueEx(hkey, TEXT("AccentColor"), nullptr, &type, - (BYTE*)&color, + reinterpret_cast(&color), &(size = sizeof(color))) == ERROR_SUCCESS && type == REG_DWORD) { // convert from RGBA @@ -36,7 +36,7 @@ static COLORREF GetAccentColor() { else if ( RegQueryValueEx(hkey, TEXT("ColorizationColor"), nullptr, &type, - (BYTE*)&color, + reinterpret_cast(&color), &(size = sizeof(color))) == ERROR_SUCCESS && type == REG_DWORD) { // convert from BGRA @@ -82,26 +82,32 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { bmi.biCompression = BI_RGB; void* alphaSrcBits; - alphaSrcBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, + alphaSrcBitmap = CreateDIBSection(NULL, + reinterpret_cast(&bmi), DIB_RGB_COLORS, &alphaSrcBits, NULL, 0); if (alphaSrcBitmap) { if (GetDIBits(hdcScreen, bitmap, 0, 0, 0, - (BITMAPINFO*)&bmi, DIB_RGB_COLORS) && + reinterpret_cast(&bmi), + DIB_RGB_COLORS) && bmi.biSizeImage > 0 && (bmi.biSizeImage % 4) == 0) { - auto buf = (BYTE*)_aligned_malloc(bmi.biSizeImage, - sizeof(DWORD)); + auto buf = reinterpret_cast( + _aligned_malloc(bmi.biSizeImage, sizeof(DWORD))); + if (buf) { GetDIBits(hdcScreen, bitmap, 0, bm.bmHeight, buf, - (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + reinterpret_cast(&bmi), + DIB_RGB_COLORS); - BYTE* dest = (BYTE*)alphaSrcBits; - for (const DWORD *src = (DWORD*)buf, - *end = (DWORD*)(buf + bmi.biSizeImage); - src != end; - ++src, ++dest) { + const DWORD *src = reinterpret_cast(buf); + const DWORD *end = + reinterpret_cast(buf + bmi.biSizeImage); + + BYTE* dest = reinterpret_cast(alphaSrcBits); + + for (; src != end; ++src, ++dest) { BYTE a = *src >> 24; *dest++ = a; *dest++ = a; @@ -123,12 +129,14 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { bmi.biCompression = BI_RGB; void* colorBits; - auto colorBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, + auto colorBitmap = CreateDIBSection(NULL, + reinterpret_cast(&bmi), DIB_RGB_COLORS, &colorBits, NULL, 0); void* alphaBits; - auto alphaBitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmi, + auto alphaBitmap = CreateDIBSection(NULL, + reinterpret_cast(&bmi), DIB_RGB_COLORS, &alphaBits, NULL, 0); @@ -156,8 +164,8 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { GdiFlush(); // apply the alpha channel - auto dest = (BYTE*)colorBits; - auto src = (const BYTE*)alphaBits; + auto dest = reinterpret_cast(colorBits); + auto src = reinterpret_cast(alphaBits); auto end = src + (width * height * 4); while (src != end) { dest[3] = src[0]; @@ -167,7 +175,8 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { // create the resulting bitmap resultBitmap = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, - colorBits, (BITMAPINFO*)&bmi, + colorBits, + reinterpret_cast(&bmi), DIB_RGB_COLORS); } @@ -657,8 +666,8 @@ void DesktopNotificationController::Toast::SetVerticalPosition(int y) { return; // Make sure the new animation's origin is at the current position - vertical_pos_ += - (int)((vertical_pos_target_ - vertical_pos_) * stack_collapse_pos_); + vertical_pos_ += static_cast( + (vertical_pos_target_ - vertical_pos_) * stack_collapse_pos_); // Set new target position and start the animation vertical_pos_target_ = y; @@ -699,11 +708,11 @@ HDWP DesktopNotificationController::Toast::Animate( auto yOffset = (vertical_pos_target_ - vertical_pos_) * stackCollapsePos; - size.cx = (int)(toast_size_.cx * easeInPos); + size.cx = static_cast(toast_size_.cx * easeInPos); size.cy = toast_size_.cy; pt.x = origin.x - size.cx; - pt.y = (int)(origin.y - vertical_pos_ - yOffset - size.cy); + pt.y = static_cast(origin.y - vertical_pos_ - yOffset - size.cy); ulw.pptDst = &pt; ulw.psize = &size; diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc index 36242c06a40..f1ac9598a7f 100644 --- a/brightray/browser/win/win32_notification.cc +++ b/brightray/browser/win/win32_notification.cc @@ -27,7 +27,8 @@ void Win32Notification::Show( HDC hdcScreen = GetDC(NULL); image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, icon.getPixels(), - (BITMAPINFO*)&bmi, DIB_RGB_COLORS); + reinterpret_cast(&bmi), + DIB_RGB_COLORS); ReleaseDC(NULL, hdcScreen); icon.unlockPixels(); From 64bf0d210e51d0984e2eb0bbeff5fe1da3cbddc1 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 5 Apr 2017 12:00:35 +0200 Subject: [PATCH 1016/1195] Address cpplint issue "An else should appear on the same line as the preceding } [whitespace/newline] [4]" --- brightray/browser/win/win32_desktop_notifications/toast.cc | 6 ++---- brightray/browser/win/win32_notification.cc | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index 2727bc9ed12..879163a2629 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -32,8 +32,7 @@ static COLORREF GetAccentColor() { GetGValue(color), GetBValue(color)); success = true; - } - else if ( + } else if ( RegQueryValueEx(hkey, TEXT("ColorizationColor"), nullptr, &type, reinterpret_cast(&color), @@ -517,8 +516,7 @@ void DesktopNotificationController::Toast::UpdateBufferSize() { width = width * maxDimSize / height; height = maxDimSize; } - } - else { + } else { if (width > maxDimSize) { height = height * maxDimSize / width; width = maxDimSize; diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc index f1ac9598a7f..495569b036a 100644 --- a/brightray/browser/win/win32_notification.cc +++ b/brightray/browser/win/win32_notification.cc @@ -42,8 +42,7 @@ void Win32Notification::Show( existing->tag_.clear(); this->notification_ref_ = std::move(existing->notification_ref_); this->notification_ref_.Set(title, msg, image); - } - else { + } else { this->notification_ref_ = presenter->AddNotification(title, msg, image); } From 9d75e9f54c4aad16a5b09169a82e61ea83a93397 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 5 Apr 2017 13:10:28 +0200 Subject: [PATCH 1017/1195] Address cpplint issue "Namespace should be terminated with "// namespace brightray" [readability/namespace] [5]" --- brightray/browser/win/notification_presenter_win7.cc | 2 +- brightray/browser/win/notification_presenter_win7.h | 2 +- brightray/browser/win/win32_desktop_notifications/common.h | 2 +- .../desktop_notification_controller.cc | 2 +- .../desktop_notification_controller.h | 2 +- brightray/browser/win/win32_desktop_notifications/toast.cc | 2 +- brightray/browser/win/win32_desktop_notifications/toast.h | 2 +- brightray/browser/win/win32_notification.cc | 2 +- brightray/browser/win/win32_notification.h | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win7.cc b/brightray/browser/win/notification_presenter_win7.cc index e74e212a575..f002c476d5a 100644 --- a/brightray/browser/win/notification_presenter_win7.cc +++ b/brightray/browser/win/notification_presenter_win7.cc @@ -42,4 +42,4 @@ void NotificationPresenterWin7::OnNotificationDismissed( if (n) n->NotificationDismissed(); } -} +} // namespace brightray diff --git a/brightray/browser/win/notification_presenter_win7.h b/brightray/browser/win/notification_presenter_win7.h index 2b352aad8af..8c7bc9aecaa 100644 --- a/brightray/browser/win/notification_presenter_win7.h +++ b/brightray/browser/win/notification_presenter_win7.h @@ -27,4 +27,4 @@ private: void OnNotificationDismissed(Notification& notification) override; }; -} // namespace +} // namespace brightray diff --git a/brightray/browser/win/win32_desktop_notifications/common.h b/brightray/browser/win/win32_desktop_notifications/common.h index 2785f187fc7..ef364ceb4cc 100644 --- a/brightray/browser/win/win32_desktop_notifications/common.h +++ b/brightray/browser/win/win32_desktop_notifications/common.h @@ -52,4 +52,4 @@ struct ScreenMetrics { template T Y(T value) const { return ScaleForDpi(value, dpi_y); } }; -} +} // namespace brightray diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index f0d65469b9d..e0261054be4 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -401,4 +401,4 @@ DesktopNotificationController::NotificationLink::~NotificationLink() { if (p) p->controller = nullptr; } -} +} // namespace brightray diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h index a15d6b1b354..9320283ea4a 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h @@ -103,4 +103,4 @@ private: friend class DesktopNotificationController; }; -} +} // namespace brightray diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index 879163a2629..5a31cfd9819 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -819,4 +819,4 @@ float DesktopNotificationController::Toast::AnimateStackCollapse() { return pos; } -} +} // namespace brightray diff --git a/brightray/browser/win/win32_desktop_notifications/toast.h b/brightray/browser/win/win32_desktop_notifications/toast.h index e77535f86c7..926427c734b 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.h +++ b/brightray/browser/win/win32_desktop_notifications/toast.h @@ -94,4 +94,4 @@ private: float ease_in_pos_ = 0, ease_out_pos_ = 0, stack_collapse_pos_ = 0; }; -} +} // namespace brightray diff --git a/brightray/browser/win/win32_notification.cc b/brightray/browser/win/win32_notification.cc index 495569b036a..5b6093658aa 100644 --- a/brightray/browser/win/win32_notification.cc +++ b/brightray/browser/win/win32_notification.cc @@ -55,4 +55,4 @@ void Win32Notification::Dismiss() { notification_ref_.Close(); } -} +} // namespace brightray diff --git a/brightray/browser/win/win32_notification.h b/brightray/browser/win/win32_notification.h index 41f9583bd1f..02f15c915f5 100644 --- a/brightray/browser/win/win32_notification.h +++ b/brightray/browser/win/win32_notification.h @@ -29,4 +29,4 @@ private: std::string tag_; }; -} +} // namespace brightray From 161b4e752b4c5f9344f1fc67fa3c52ec6b51c58e Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 5 Apr 2017 13:15:06 +0200 Subject: [PATCH 1018/1195] Address cpplint issue "public: should be indented +1 space inside class NotificationPresenterWin7 [whitespace/indent] [3]" --- .../browser/win/notification_presenter_win7.h | 4 ++-- .../desktop_notification_controller.h | 14 +++++++------- .../win/win32_desktop_notifications/toast.h | 6 +++--- brightray/browser/win/win32_notification.h | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win7.h b/brightray/browser/win/notification_presenter_win7.h index 8c7bc9aecaa..5021d2c41ca 100644 --- a/brightray/browser/win/notification_presenter_win7.h +++ b/brightray/browser/win/notification_presenter_win7.h @@ -9,7 +9,7 @@ class Win32Notification; class NotificationPresenterWin7 : public NotificationPresenter, public DesktopNotificationController { -public: + public: NotificationPresenterWin7() = default; Win32Notification* GetNotificationObjectByRef( @@ -17,7 +17,7 @@ public: Win32Notification* GetNotificationObjectByTag(const std::string& tag); -private: + private: DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7); brightray::Notification* CreateNotificationObject( diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h index 9320283ea4a..88daf5d2ed7 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h @@ -10,7 +10,7 @@ namespace brightray { struct NotificationData; class DesktopNotificationController { -public: + public: DesktopNotificationController(unsigned maximumToasts = 3); ~DesktopNotificationController(); @@ -20,18 +20,18 @@ public: void CloseNotification(Notification& notification); // Event handlers -- override to receive the events -private: + private: virtual void OnNotificationClosed(Notification& notification) {} virtual void OnNotificationClicked(Notification& notification) {} virtual void OnNotificationDismissed(Notification& notification) {} -private: + private: static HINSTANCE RegisterWndClasses(); void StartAnimation(); HFONT GetCaptionFont(); HFONT GetBodyFont(); -private: + private: enum TimerID { TimerID_Animate = 1 }; @@ -76,7 +76,7 @@ private: HWND GetToast(const NotificationData* data) const; void DestroyToast(ToastInstance& inst); -private: + private: static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationController"); @@ -88,7 +88,7 @@ private: }; class DesktopNotificationController::Notification { -public: + public: Notification() = default; Notification(const std::shared_ptr& data); @@ -97,7 +97,7 @@ public: void Close(); void Set(std::wstring caption, std::wstring bodyText, HBITMAP image); -private: + private: std::shared_ptr data_; friend class DesktopNotificationController; diff --git a/brightray/browser/win/win32_desktop_notifications/toast.h b/brightray/browser/win/win32_desktop_notifications/toast.h index 926427c734b..00e5733b6d5 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.h +++ b/brightray/browser/win/win32_desktop_notifications/toast.h @@ -4,7 +4,7 @@ namespace brightray { class DesktopNotificationController::Toast { -public: + public: static void Register(HINSTANCE hInstance); static HWND Create(HINSTANCE hInstance, std::shared_ptr& data); @@ -40,7 +40,7 @@ public: return is_highlighted_; } -private: + private: enum TimerID { TimerID_AutoDismiss = 1 }; @@ -67,7 +67,7 @@ private: float AnimateEaseOut(); float AnimateStackCollapse(); -private: + private: static constexpr const TCHAR class_name_[] = TEXT("DesktopNotificationToast"); diff --git a/brightray/browser/win/win32_notification.h b/brightray/browser/win/win32_notification.h index 02f15c915f5..c45352d145e 100644 --- a/brightray/browser/win/win32_notification.h +++ b/brightray/browser/win/win32_notification.h @@ -5,7 +5,7 @@ namespace brightray { class Win32Notification : public brightray::Notification { -public: + public: Win32Notification(NotificationDelegate* delegate, NotificationPresenterWin7* presenter) : Notification(delegate, presenter) { @@ -23,7 +23,7 @@ public: return tag_; } -private: + private: DISALLOW_COPY_AND_ASSIGN(Win32Notification); DesktopNotificationController::Notification notification_ref_; std::string tag_; From bf86718d610d4df6f7ce96f52484197538a2cd83 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 5 Apr 2017 13:16:41 +0200 Subject: [PATCH 1019/1195] Address cpplint issue "DISALLOW_COPY_AND_ASSIGN should be the last thing in the class [readability/constructors] [3]" --- brightray/browser/win/notification_presenter_win7.h | 4 ++-- brightray/browser/win/win32_notification.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/brightray/browser/win/notification_presenter_win7.h b/brightray/browser/win/notification_presenter_win7.h index 5021d2c41ca..c191439befc 100644 --- a/brightray/browser/win/notification_presenter_win7.h +++ b/brightray/browser/win/notification_presenter_win7.h @@ -18,13 +18,13 @@ class NotificationPresenterWin7 : Win32Notification* GetNotificationObjectByTag(const std::string& tag); private: - DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7); - brightray::Notification* CreateNotificationObject( NotificationDelegate* delegate) override; void OnNotificationClicked(Notification& notification) override; void OnNotificationDismissed(Notification& notification) override; + + DISALLOW_COPY_AND_ASSIGN(NotificationPresenterWin7); }; } // namespace brightray diff --git a/brightray/browser/win/win32_notification.h b/brightray/browser/win/win32_notification.h index c45352d145e..9a418cd5037 100644 --- a/brightray/browser/win/win32_notification.h +++ b/brightray/browser/win/win32_notification.h @@ -24,9 +24,10 @@ class Win32Notification : public brightray::Notification { } private: - DISALLOW_COPY_AND_ASSIGN(Win32Notification); DesktopNotificationController::Notification notification_ref_; std::string tag_; + + DISALLOW_COPY_AND_ASSIGN(Win32Notification); }; } // namespace brightray From 1a7d9a5d204e0c6df8bf464562a9fd6e4993b47c Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 5 Apr 2017 13:19:19 +0200 Subject: [PATCH 1020/1195] Address cpplint issue "At least two spaces is best between code and comments [whitespace/comments] [2]" --- brightray/browser/win/win32_desktop_notifications/toast.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/win/win32_desktop_notifications/toast.h b/brightray/browser/win/win32_desktop_notifications/toast.h index 00e5733b6d5..5700341f7e4 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.h +++ b/brightray/browser/win/win32_desktop_notifications/toast.h @@ -75,7 +75,7 @@ class DesktopNotificationController::Toast { HDC hdc_; HBITMAP bitmap_ = NULL; - const std::shared_ptr data_; // never null + const std::shared_ptr data_; // never null SIZE toast_size_ = {}; SIZE margin_ = {}; From 3336e0276903be530c10b0989219c05c83c04a49 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 5 Apr 2017 13:20:16 +0200 Subject: [PATCH 1021/1195] Address cpplint issue "Constructors callable with one argument should be marked explicit. [runtime/explicit] [5]" --- .../desktop_notification_controller.cc | 2 +- .../desktop_notification_controller.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index e0261054be4..947def20df8 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -260,7 +260,7 @@ DesktopNotificationController::Notification data->image = CopyBitmap(image); // Enqueue new notification - Notification ret = *queue_.insert(queue_.end(), move(data)); + Notification ret { *queue_.insert(queue_.end(), move(data)) }; CheckQueue(); return ret; } diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h index 88daf5d2ed7..db3001028b8 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h @@ -11,7 +11,7 @@ struct NotificationData; class DesktopNotificationController { public: - DesktopNotificationController(unsigned maximumToasts = 3); + explicit DesktopNotificationController(unsigned maximumToasts = 3); ~DesktopNotificationController(); class Notification; @@ -43,7 +43,7 @@ class DesktopNotificationController { // the `controller` member is cleared when the controller object // stops tracking the notification struct NotificationLink : std::shared_ptr { - NotificationLink(DesktopNotificationController* controller); + explicit NotificationLink(DesktopNotificationController* controller); ~NotificationLink(); NotificationLink(NotificationLink&&) = default; @@ -90,7 +90,7 @@ class DesktopNotificationController { class DesktopNotificationController::Notification { public: Notification() = default; - Notification(const std::shared_ptr& data); + explicit Notification(const std::shared_ptr& data); bool operator==(const Notification& other) const; From ba03c544f3beab54a5d804b8e2d82047aa3ac786 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 5 Apr 2017 13:27:46 +0200 Subject: [PATCH 1022/1195] Address cpplint issue ""public:" should be preceded by a blank line [whitespace/blank_line] [3]" --- brightray/browser/notification.h | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/notification.h b/brightray/browser/notification.h index 76e3ba4320f..a330bc25d1b 100644 --- a/brightray/browser/notification.h +++ b/brightray/browser/notification.h @@ -47,6 +47,7 @@ class Notification { protected: Notification(NotificationDelegate* delegate, NotificationPresenter* presenter); + public: virtual ~Notification(); From f73233ee55bb610b7dd302bb59fd0fccba42d9c6 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 5 Apr 2017 14:14:23 +0200 Subject: [PATCH 1023/1195] Changed local variable and parameter names to snake case style --- .../desktop_notification_controller.cc | 104 ++--- .../desktop_notification_controller.h | 14 +- .../win/win32_desktop_notifications/toast.cc | 362 +++++++++--------- .../win/win32_desktop_notifications/toast.h | 14 +- 4 files changed, 247 insertions(+), 247 deletions(-) diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc index 947def20df8..68068a6de26 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.cc @@ -17,19 +17,19 @@ HBITMAP CopyBitmap(HBITMAP bitmap) { BITMAP bm; if (bitmap && GetObject(bitmap, sizeof(bm), &bm)) { - HDC hdcScreen = GetDC(NULL); - ret = CreateCompatibleBitmap(hdcScreen, bm.bmWidth, bm.bmHeight); - ReleaseDC(NULL, hdcScreen); + HDC hdc_screen = GetDC(NULL); + ret = CreateCompatibleBitmap(hdc_screen, bm.bmWidth, bm.bmHeight); + ReleaseDC(NULL, hdc_screen); if (ret) { - HDC hdcSrc = CreateCompatibleDC(NULL); - HDC hdcDst = CreateCompatibleDC(NULL); - SelectBitmap(hdcSrc, bitmap); - SelectBitmap(hdcDst, ret); - BitBlt(hdcDst, 0, 0, bm.bmWidth, bm.bmHeight, - hdcSrc, 0, 0, SRCCOPY); - DeleteDC(hdcDst); - DeleteDC(hdcSrc); + HDC hdc_src = CreateCompatibleDC(NULL); + HDC hdc_dst = CreateCompatibleDC(NULL); + SelectBitmap(hdc_src, bitmap); + SelectBitmap(hdc_dst, ret); + BitBlt(hdc_dst, 0, 0, bm.bmWidth, bm.bmHeight, + hdc_src, 0, 0, SRCCOPY); + DeleteDC(hdc_dst); + DeleteDC(hdc_src); } } @@ -66,8 +66,8 @@ HINSTANCE DesktopNotificationController::RegisterWndClasses() { } DesktopNotificationController::DesktopNotificationController( - unsigned maximumToasts) { - instances_.reserve(maximumToasts); + unsigned maximum_toasts) { + instances_.reserve(maximum_toasts); } DesktopNotificationController::~DesktopNotificationController() { @@ -77,37 +77,37 @@ DesktopNotificationController::~DesktopNotificationController() { } LRESULT CALLBACK DesktopNotificationController::WndProc( - HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { switch (message) { case WM_CREATE: { - auto& cs = reinterpret_cast(lParam); - SetWindowLongPtr(hWnd, 0, (LONG_PTR)cs->lpCreateParams); + auto& cs = reinterpret_cast(lparam); + SetWindowLongPtr(hwnd, 0, (LONG_PTR)cs->lpCreateParams); } break; case WM_TIMER: - if (wParam == TimerID_Animate) { - Get(hWnd)->AnimateAll(); + if (wparam == TimerID_Animate) { + Get(hwnd)->AnimateAll(); } return 0; case WM_DISPLAYCHANGE: { - auto inst = Get(hWnd); + auto inst = Get(hwnd); inst->ClearAssets(); inst->AnimateAll(); } break; case WM_SETTINGCHANGE: - if (wParam == SPI_SETWORKAREA) { - Get(hWnd)->AnimateAll(); + if (wparam == SPI_SETWORKAREA) { + Get(hwnd)->AnimateAll(); } break; } - return DefWindowProc(hWnd, message, wParam, lParam); + return DefWindowProc(hwnd, message, wparam, lparam); } void DesktopNotificationController::StartAnimation() { @@ -140,16 +140,16 @@ void DesktopNotificationController::InitializeFonts() { auto baseHeight = metrics.lfMessageFont.lfHeight; HDC hdc = GetDC(NULL); - auto dpiY = GetDeviceCaps(hdc, LOGPIXELSY); + auto dpi_y = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); metrics.lfMessageFont.lfHeight = - (LONG)ScaleForDpi(baseHeight * 1.1f, dpiY); + (LONG)ScaleForDpi(baseHeight * 1.1f, dpi_y); body_font_ = CreateFontIndirect(&metrics.lfMessageFont); if (caption_font_) DeleteFont(caption_font_); metrics.lfMessageFont.lfHeight = - (LONG)ScaleForDpi(baseHeight * 1.4f, dpiY); + (LONG)ScaleForDpi(baseHeight * 1.4f, dpi_y); caption_font_ = CreateFontIndirect(&metrics.lfMessageFont); } } @@ -165,14 +165,14 @@ void DesktopNotificationController::AnimateAll() { // to all current conditions. Animation time is only one of the variables // influencing them. Screen resolution is another. - bool keepAnimating = false; + bool keep_animating = false; if (!instances_.empty()) { - RECT workArea; - if (SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0)) { + RECT work_area; + if (SystemParametersInfo(SPI_GETWORKAREA, 0, &work_area, 0)) { ScreenMetrics metrics; - POINT origin = { workArea.right, - workArea.bottom - metrics.Y(toast_margin_) }; + POINT origin = { work_area.right, + work_area.bottom - metrics.Y(toast_margin_) }; auto hdwp = BeginDeferWindowPos(static_cast(instances_.size())); @@ -183,14 +183,14 @@ void DesktopNotificationController::AnimateAll() { auto notification = Toast::Get(inst.hwnd); hdwp = notification->Animate(hdwp, origin); if (!hdwp) break; - keepAnimating |= notification->IsAnimationActive(); + keep_animating |= notification->IsAnimationActive(); } if (hdwp) EndDeferWindowPos(hdwp); } } - if (!keepAnimating) { + if (!keep_animating) { _ASSERT(hwnd_controller_); if (hwnd_controller_) KillTimer(hwnd_controller_, TimerID_Animate); is_animating_ = false; @@ -199,20 +199,20 @@ void DesktopNotificationController::AnimateAll() { // Purge dismissed notifications and collapse the stack between // items which are highlighted if (!instances_.empty()) { - auto isAlive = [](ToastInstance& inst) { + auto is_alive = [](ToastInstance& inst) { return inst.hwnd && IsWindowVisible(inst.hwnd); }; - auto isHighlighted = [](ToastInstance& inst) { + 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(), isHighlighted); + auto it2 = find_if(it, instances_.end(), is_highlighted); // collapse the stack in front of the highlighted item - it = stable_partition(it, it2, isAlive); + it = stable_partition(it, it2, is_alive); // purge the dead items for_each(it, it2, [this](auto&& inst) { DestroyToast(inst); }); @@ -231,17 +231,17 @@ void DesktopNotificationController::AnimateAll() { ScreenMetrics metrics; auto margin = metrics.Y(toast_margin_); - int targetPos = 0; + int target_pos = 0; for (auto&& inst : instances_) { if (inst.hwnd) { auto toast = Toast::Get(inst.hwnd); if (toast->IsHighlighted()) - targetPos = toast->GetVerticalPosition(); + target_pos = toast->GetVerticalPosition(); else - toast->SetVerticalPosition(targetPos); + toast->SetVerticalPosition(target_pos); - targetPos += toast->GetHeight() + margin; + target_pos += toast->GetHeight() + margin; } } } @@ -252,11 +252,11 @@ void DesktopNotificationController::AnimateAll() { DesktopNotificationController::Notification DesktopNotificationController::AddNotification( - std::wstring caption, std::wstring bodyText, HBITMAP image) { + std::wstring caption, std::wstring body_text, HBITMAP image) { NotificationLink data(this); data->caption = move(caption); - data->body_text = move(bodyText); + data->body_text = move(body_text); data->image = CopyBitmap(image); // Enqueue new notification @@ -291,19 +291,19 @@ void DesktopNotificationController::CheckQueue() { } void DesktopNotificationController::CreateToast(NotificationLink&& data) { - auto hInstance = RegisterWndClasses(); - auto hwnd = Toast::Create(hInstance, data); + auto hinstance = RegisterWndClasses(); + auto hwnd = Toast::Create(hinstance, data); if (hwnd) { - int toastPos = 0; + int toast_pos = 0; if (!instances_.empty()) { auto& item = instances_.back(); _ASSERT(item.hwnd); ScreenMetrics scr; auto toast = Toast::Get(item.hwnd); - toastPos = toast->GetVerticalPosition() + - toast->GetHeight() + - scr.Y(toast_margin_); + toast_pos = toast->GetVerticalPosition() + + toast->GetHeight() + + scr.Y(toast_margin_); } instances_.push_back({ hwnd, move(data) }); @@ -313,11 +313,11 @@ void DesktopNotificationController::CreateToast(NotificationLink&& data) { // receive system notifications hwnd_controller_ = CreateWindow(class_name_, nullptr, 0, 0, 0, 0, 0, - NULL, NULL, hInstance, this); + NULL, NULL, hinstance, this); } auto toast = Toast::Get(hwnd); - toast->PopUp(toastPos); + toast->PopUp(toast_pos); } } @@ -365,7 +365,7 @@ void DesktopNotificationController::Notification::Close() { } void DesktopNotificationController::Notification::Set( - std::wstring caption, std::wstring bodyText, HBITMAP image) { + std::wstring caption, std::wstring body_text, HBITMAP image) { // No business calling this when not pointing to a valid instance _ASSERT(data_); @@ -376,7 +376,7 @@ void DesktopNotificationController::Notification::Set( if (data_->image) DeleteBitmap(data_->image); data_->caption = move(caption); - data_->body_text = move(bodyText); + data_->body_text = move(body_text); data_->image = CopyBitmap(image); auto hwnd = data_->controller->GetToast(data_.get()); diff --git a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h index db3001028b8..643a61f5331 100644 --- a/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h +++ b/brightray/browser/win/win32_desktop_notifications/desktop_notification_controller.h @@ -11,11 +11,11 @@ struct NotificationData; class DesktopNotificationController { public: - explicit DesktopNotificationController(unsigned maximumToasts = 3); + explicit DesktopNotificationController(unsigned maximum_toasts = 3); ~DesktopNotificationController(); class Notification; - Notification AddNotification(std::wstring caption, std::wstring bodyText, + Notification AddNotification(std::wstring caption, std::wstring body_text, HBITMAP image); void CloseNotification(Notification& notification); @@ -58,11 +58,11 @@ class DesktopNotificationController { class Toast; - static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, - WPARAM wParam, LPARAM lParam); - static DesktopNotificationController* Get(HWND hWnd) { + static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam); + static DesktopNotificationController* Get(HWND hwnd) { return reinterpret_cast( - GetWindowLongPtr(hWnd, 0)); + GetWindowLongPtr(hwnd, 0)); } DesktopNotificationController( @@ -95,7 +95,7 @@ class DesktopNotificationController::Notification { bool operator==(const Notification& other) const; void Close(); - void Set(std::wstring caption, std::wstring bodyText, HBITMAP image); + void Set(std::wstring caption, std::wstring body_text, HBITMAP image); private: std::shared_ptr data_; diff --git a/brightray/browser/win/win32_desktop_notifications/toast.cc b/brightray/browser/win/win32_desktop_notifications/toast.cc index 5a31cfd9819..1ab968c3ef0 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.cc +++ b/brightray/browser/win/win32_desktop_notifications/toast.cc @@ -67,11 +67,11 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { if (width == 0 || height == 0) return NULL; - HBITMAP resultBitmap = NULL; + HBITMAP result_bitmap = NULL; - HDC hdcScreen = GetDC(NULL); + HDC hdc_screen = GetDC(NULL); - HBITMAP alphaSrcBitmap; + HBITMAP alpha_src_bitmap; { BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) }; bmi.biWidth = bm.bmWidth; @@ -80,14 +80,13 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { bmi.biBitCount = bm.bmBitsPixel; bmi.biCompression = BI_RGB; - void* alphaSrcBits; - alphaSrcBitmap = CreateDIBSection(NULL, - reinterpret_cast(&bmi), - DIB_RGB_COLORS, &alphaSrcBits, - NULL, 0); + void* alpha_src_bits; + alpha_src_bitmap = + CreateDIBSection(NULL, reinterpret_cast(&bmi), + DIB_RGB_COLORS, &alpha_src_bits, NULL, 0); - if (alphaSrcBitmap) { - if (GetDIBits(hdcScreen, bitmap, 0, 0, 0, + if (alpha_src_bitmap) { + if (GetDIBits(hdc_screen, bitmap, 0, 0, 0, reinterpret_cast(&bmi), DIB_RGB_COLORS) && bmi.biSizeImage > 0 && @@ -96,7 +95,7 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { _aligned_malloc(bmi.biSizeImage, sizeof(DWORD))); if (buf) { - GetDIBits(hdcScreen, bitmap, 0, bm.bmHeight, buf, + GetDIBits(hdc_screen, bitmap, 0, bm.bmHeight, buf, reinterpret_cast(&bmi), DIB_RGB_COLORS); @@ -104,7 +103,7 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { const DWORD *end = reinterpret_cast(buf + bmi.biSizeImage); - BYTE* dest = reinterpret_cast(alphaSrcBits); + BYTE* dest = reinterpret_cast(alpha_src_bits); for (; src != end; ++src, ++dest) { BYTE a = *src >> 24; @@ -119,7 +118,7 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { } } - if (alphaSrcBitmap) { + if (alpha_src_bitmap) { BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) }; bmi.biWidth = width; bmi.biHeight = height; @@ -127,44 +126,42 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { bmi.biBitCount = 32; bmi.biCompression = BI_RGB; - void* colorBits; - auto colorBitmap = CreateDIBSection(NULL, - reinterpret_cast(&bmi), - DIB_RGB_COLORS, &colorBits, - NULL, 0); + void* color_bits; + auto color_bitmap = + CreateDIBSection(NULL, reinterpret_cast(&bmi), + DIB_RGB_COLORS, &color_bits, NULL, 0); - void* alphaBits; - auto alphaBitmap = CreateDIBSection(NULL, - reinterpret_cast(&bmi), - DIB_RGB_COLORS, &alphaBits, - NULL, 0); + void* alpha_bits; + auto alpha_bitmap = + CreateDIBSection(NULL, reinterpret_cast(&bmi), + DIB_RGB_COLORS, &alpha_bits, NULL, 0); HDC hdc = CreateCompatibleDC(NULL); - HDC hdcSrc = CreateCompatibleDC(NULL); + HDC hdc_src = CreateCompatibleDC(NULL); - if (colorBitmap && alphaBitmap && hdc && hdcSrc) { + if (color_bitmap && alpha_bitmap && hdc && hdc_src) { SetStretchBltMode(hdc, HALFTONE); // resize color channels - SelectObject(hdc, colorBitmap); - SelectObject(hdcSrc, bitmap); + SelectObject(hdc, color_bitmap); + SelectObject(hdc_src, bitmap); StretchBlt(hdc, 0, 0, width, height, - hdcSrc, 0, 0, bm.bmWidth, bm.bmHeight, + hdc_src, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); // resize alpha channel - SelectObject(hdc, alphaBitmap); - SelectObject(hdcSrc, alphaSrcBitmap); + SelectObject(hdc, alpha_bitmap); + SelectObject(hdc_src, alpha_src_bitmap); StretchBlt(hdc, 0, 0, width, height, - hdcSrc, 0, 0, bm.bmWidth, bm.bmHeight, + hdc_src, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); // flush before touching the bits GdiFlush(); // apply the alpha channel - auto dest = reinterpret_cast(colorBits); - auto src = reinterpret_cast(alphaBits); + auto dest = reinterpret_cast(color_bits); + auto src = reinterpret_cast(alpha_bits); auto end = src + (width * height * 4); while (src != end) { dest[3] = src[0]; @@ -173,32 +170,32 @@ static HBITMAP StretchBitmap(HBITMAP bitmap, unsigned width, unsigned height) { } // create the resulting bitmap - resultBitmap = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, - colorBits, - reinterpret_cast(&bmi), - DIB_RGB_COLORS); + result_bitmap = CreateDIBitmap(hdc_screen, &bmi, CBM_INIT, + color_bits, + reinterpret_cast(&bmi), + DIB_RGB_COLORS); } - if (hdcSrc) DeleteDC(hdcSrc); + if (hdc_src) DeleteDC(hdc_src); if (hdc) DeleteDC(hdc); - if (alphaBitmap) DeleteObject(alphaBitmap); - if (colorBitmap) DeleteObject(colorBitmap); + if (alpha_bitmap) DeleteObject(alpha_bitmap); + if (color_bitmap) DeleteObject(color_bitmap); - DeleteObject(alphaSrcBitmap); + DeleteObject(alpha_src_bitmap); } - ReleaseDC(NULL, hdcScreen); + ReleaseDC(NULL, hdc_screen); - return resultBitmap; + return result_bitmap; } DesktopNotificationController::Toast::Toast( - HWND hWnd, shared_ptr* data) : - hwnd_(hWnd), data_(*data) { - HDC hdcScreen = GetDC(NULL); - hdc_ = CreateCompatibleDC(hdcScreen); - ReleaseDC(NULL, hdcScreen); + HWND hwnd, shared_ptr* data) : + hwnd_(hwnd), data_(*data) { + HDC hdc_screen = GetDC(NULL); + hdc_ = CreateCompatibleDC(hdc_screen); + ReleaseDC(NULL, hdc_screen); } DesktopNotificationController::Toast::~Toast() { @@ -207,47 +204,47 @@ DesktopNotificationController::Toast::~Toast() { if (scaled_image_) DeleteBitmap(scaled_image_); } -void DesktopNotificationController::Toast::Register(HINSTANCE hInstance) { +void DesktopNotificationController::Toast::Register(HINSTANCE hinstance) { WNDCLASSEX wc = { sizeof(wc) }; wc.lpfnWndProc = &Toast::WndProc; wc.lpszClassName = class_name_; wc.cbWndExtra = sizeof(Toast*); - wc.hInstance = hInstance; + wc.hInstance = hinstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); RegisterClassEx(&wc); } LRESULT DesktopNotificationController::Toast::WndProc( - HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { switch (message) { case WM_CREATE: { - auto& cs = reinterpret_cast(lParam); + auto& cs = reinterpret_cast(lparam); auto data = static_cast*>(cs->lpCreateParams); - auto inst = new Toast(hWnd, data); - SetWindowLongPtr(hWnd, 0, (LONG_PTR)inst); + auto inst = new Toast(hwnd, data); + SetWindowLongPtr(hwnd, 0, (LONG_PTR)inst); } break; case WM_NCDESTROY: - delete Get(hWnd); - SetWindowLongPtr(hWnd, 0, 0); + delete Get(hwnd); + SetWindowLongPtr(hwnd, 0, 0); return 0; case WM_MOUSEACTIVATE: return MA_NOACTIVATE; case WM_TIMER: - if (wParam == TimerID_AutoDismiss) { - Get(hWnd)->AutoDismiss(); + if (wparam == TimerID_AutoDismiss) { + Get(hwnd)->AutoDismiss(); } return 0; case WM_LBUTTONDOWN: { - auto inst = Get(hWnd); + auto inst = Get(hwnd); inst->Dismiss(); @@ -261,15 +258,15 @@ LRESULT DesktopNotificationController::Toast::WndProc( case WM_MOUSEMOVE: { - auto inst = Get(hWnd); + auto inst = Get(hwnd); if (!inst->is_highlighted_) { inst->is_highlighted_ = true; - TRACKMOUSEEVENT tme = { sizeof(tme), TME_LEAVE, hWnd }; + TRACKMOUSEEVENT tme = { sizeof(tme), TME_LEAVE, hwnd }; TrackMouseEvent(&tme); } - POINT cursor = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + POINT cursor = { GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam) }; inst->is_close_hot_ = (PtInRect(&inst->close_button_rect_, cursor) != FALSE); @@ -282,7 +279,7 @@ LRESULT DesktopNotificationController::Toast::WndProc( case WM_MOUSELEAVE: { - auto inst = Get(hWnd); + auto inst = Get(hwnd); inst->is_highlighted_ = false; inst->is_close_hot_ = false; inst->UpdateContents(); @@ -297,80 +294,80 @@ LRESULT DesktopNotificationController::Toast::WndProc( case WM_WINDOWPOSCHANGED: { - auto& wp = reinterpret_cast(lParam); + auto& wp = reinterpret_cast(lparam); if (wp->flags & SWP_HIDEWINDOW) { - if (!IsWindowVisible(hWnd)) - Get(hWnd)->is_highlighted_ = false; + if (!IsWindowVisible(hwnd)) + Get(hwnd)->is_highlighted_ = false; } } break; } - return DefWindowProc(hWnd, message, wParam, lParam); + return DefWindowProc(hwnd, message, wparam, lparam); } HWND DesktopNotificationController::Toast::Create( - HINSTANCE hInstance, shared_ptr& data) { + HINSTANCE hinstance, shared_ptr& data) { return CreateWindowEx(WS_EX_LAYERED | WS_EX_NOACTIVATE | WS_EX_TOPMOST, class_name_, nullptr, WS_POPUP, 0, 0, 0, 0, - NULL, NULL, hInstance, &data); + NULL, NULL, hinstance, &data); } void DesktopNotificationController::Toast::Draw() { const COLORREF accent = GetAccentColor(); - COLORREF backColor; + COLORREF back_color; { // base background color is 2/3 of accent // highlighted adds a bit of intensity to every channel int h = is_highlighted_ ? (0xff / 20) : 0; - backColor = RGB(min(0xff, (GetRValue(accent) * 2 / 3) + h), - min(0xff, (GetGValue(accent) * 2 / 3) + h), - min(0xff, (GetBValue(accent) * 2 / 3) + h)); + back_color = RGB(min(0xff, (GetRValue(accent) * 2 / 3) + h), + min(0xff, (GetGValue(accent) * 2 / 3) + h), + min(0xff, (GetBValue(accent) * 2 / 3) + h)); } - const float backLuma = - (GetRValue(backColor) * 0.299f / 255) + - (GetGValue(backColor) * 0.587f / 255) + - (GetBValue(backColor) * 0.114f / 255); + const float back_luma = + (GetRValue(back_color) * 0.299f / 255) + + (GetGValue(back_color) * 0.587f / 255) + + (GetBValue(back_color) * 0.114f / 255); - const struct { float r, g, b; } backF = { - GetRValue(backColor) / 255.0f, - GetGValue(backColor) / 255.0f, - GetBValue(backColor) / 255.0f, + const struct { float r, g, b; } back_f = { + GetRValue(back_color) / 255.0f, + GetGValue(back_color) / 255.0f, + GetBValue(back_color) / 255.0f, }; - COLORREF foreColor, dimmedColor; + COLORREF fore_color, dimmed_color; { // based on the lightness of background, we draw foreground in light // or dark shades of gray blended onto the background with slight // transparency to avoid sharp contrast constexpr float alpha = 0.9f; - constexpr float intensityLight[] = { (1.0f * alpha), (0.8f * alpha) }; - constexpr float intensityDark[] = { (0.1f * alpha), (0.3f * alpha) }; + constexpr float intensity_light[] = { (1.0f * alpha), (0.8f * alpha) }; + constexpr float intensity_dark[] = { (0.1f * alpha), (0.3f * alpha) }; // select foreground intensity values (light or dark) - auto& i = (backLuma < 0.6f) ? intensityLight : intensityDark; + auto& i = (back_luma < 0.6f) ? intensity_light : intensity_dark; float r, g, b; - r = i[0] + backF.r * (1 - alpha); - g = i[0] + backF.g * (1 - alpha); - b = i[0] + backF.b * (1 - alpha); - foreColor = RGB(r * 0xff, g * 0xff, b * 0xff); + r = i[0] + back_f.r * (1 - alpha); + g = i[0] + back_f.g * (1 - alpha); + b = i[0] + back_f.b * (1 - alpha); + fore_color = RGB(r * 0xff, g * 0xff, b * 0xff); - r = i[1] + backF.r * (1 - alpha); - g = i[1] + backF.g * (1 - alpha); - b = i[1] + backF.b * (1 - alpha); - dimmedColor = RGB(r * 0xff, g * 0xff, b * 0xff); + r = i[1] + back_f.r * (1 - alpha); + g = i[1] + back_f.g * (1 - alpha); + b = i[1] + back_f.b * (1 - alpha); + dimmed_color = RGB(r * 0xff, g * 0xff, b * 0xff); } // Draw background { - auto brush = CreateSolidBrush(backColor); + auto brush = CreateSolidBrush(back_color); RECT rc = { 0, 0, toast_size_.cx, toast_size_.cy }; FillRect(hdc_, &rc, brush); @@ -381,24 +378,24 @@ void DesktopNotificationController::Toast::Draw() { SetBkMode(hdc_, TRANSPARENT); const auto close = L'\x2715'; - auto captionFont = data_->controller->GetCaptionFont(); - auto bodyFont = data_->controller->GetBodyFont(); + auto caption_font = data_->controller->GetCaptionFont(); + auto body_font = data_->controller->GetBodyFont(); - TEXTMETRIC tmCap; - SelectFont(hdc_, captionFont); - GetTextMetrics(hdc_, &tmCap); + TEXTMETRIC tm_cap; + SelectFont(hdc_, caption_font); + GetTextMetrics(hdc_, &tm_cap); - auto textOffsetX = margin_.cx; + auto text_offset_x = margin_.cx; - BITMAP imageInfo = {}; + BITMAP image_info = {}; if (scaled_image_) { - GetObject(scaled_image_, sizeof(imageInfo), &imageInfo); + GetObject(scaled_image_, sizeof(image_info), &image_info); - textOffsetX += margin_.cx + imageInfo.bmWidth; + text_offset_x += margin_.cx + image_info.bmWidth; } // calculate close button rect - POINT closePos; + POINT close_pos; { SIZE extent = {}; GetTextExtentPoint32W(hdc_, &close, 1, &extent); @@ -406,37 +403,37 @@ void DesktopNotificationController::Toast::Draw() { close_button_rect_.right = toast_size_.cx; close_button_rect_.top = 0; - closePos.x = close_button_rect_.right - margin_.cy - extent.cx; - closePos.y = close_button_rect_.top + margin_.cy; + close_pos.x = close_button_rect_.right - margin_.cy - extent.cx; + close_pos.y = close_button_rect_.top + margin_.cy; - close_button_rect_.left = closePos.x - margin_.cy; - close_button_rect_.bottom = closePos.y + extent.cy + margin_.cy; + close_button_rect_.left = close_pos.x - margin_.cy; + close_button_rect_.bottom = close_pos.y + extent.cy + margin_.cy; } // image if (scaled_image_) { - HDC hdcImage = CreateCompatibleDC(NULL); - SelectBitmap(hdcImage, scaled_image_); + HDC hdc_image = CreateCompatibleDC(NULL); + SelectBitmap(hdc_image, scaled_image_); BLENDFUNCTION blend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA }; AlphaBlend(hdc_, margin_.cx, margin_.cy, - imageInfo.bmWidth, imageInfo.bmHeight, - hdcImage, 0, 0, - imageInfo.bmWidth, imageInfo.bmHeight, + image_info.bmWidth, image_info.bmHeight, + hdc_image, 0, 0, + image_info.bmWidth, image_info.bmHeight, blend); - DeleteDC(hdcImage); + DeleteDC(hdc_image); } // caption { RECT rc = { - textOffsetX, + text_offset_x, margin_.cy, close_button_rect_.left, toast_size_.cy }; - SelectFont(hdc_, captionFont); - SetTextColor(hdc_, foreColor); + SelectFont(hdc_, caption_font); + SetTextColor(hdc_, fore_color); DrawText(hdc_, data_->caption.data(), (UINT)data_->caption.length(), &rc, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX); } @@ -444,14 +441,14 @@ void DesktopNotificationController::Toast::Draw() { // body text if (!data_->body_text.empty()) { RECT rc = { - textOffsetX, - 2 * margin_.cy + tmCap.tmAscent, + text_offset_x, + 2 * margin_.cy + tm_cap.tmAscent, toast_size_.cx - margin_.cx, toast_size_.cy - margin_.cy }; - SelectFont(hdc_, bodyFont); - SetTextColor(hdc_, dimmedColor); + SelectFont(hdc_, body_font); + SetTextColor(hdc_, dimmed_color); DrawText(hdc_, data_->body_text.data(), (UINT)data_->body_text.length(), &rc, DT_LEFT | DT_WORDBREAK | DT_NOPREFIX | @@ -460,9 +457,9 @@ void DesktopNotificationController::Toast::Draw() { // close button { - SelectFont(hdc_, captionFont); - SetTextColor(hdc_, is_close_hot_ ? foreColor : dimmedColor); - ExtTextOut(hdc_, closePos.x, closePos.y, 0, nullptr, + SelectFont(hdc_, caption_font); + SetTextColor(hdc_, is_close_hot_ ? fore_color : dimmed_color); + ExtTextOut(hdc_, close_pos.x, close_pos.y, 0, nullptr, &close, 1, nullptr); } @@ -479,87 +476,90 @@ bool DesktopNotificationController::Toast::IsRedrawNeeded() const { void DesktopNotificationController::Toast::UpdateBufferSize() { if (hdc_) { - SIZE newSize; + SIZE new_size; { - TEXTMETRIC tmCap = {}; + TEXTMETRIC tm_cap = {}; HFONT font = data_->controller->GetCaptionFont(); if (font) { SelectFont(hdc_, font); - if (!GetTextMetrics(hdc_, &tmCap)) return; + if (!GetTextMetrics(hdc_, &tm_cap)) return; } - TEXTMETRIC tmBody = {}; + TEXTMETRIC tm_body = {}; font = data_->controller->GetBodyFont(); if (font) { SelectFont(hdc_, font); - if (!GetTextMetrics(hdc_, &tmBody)) return; + if (!GetTextMetrics(hdc_, &tm_body)) return; } - this->margin_ = { tmCap.tmAveCharWidth * 2, tmCap.tmAscent / 2 }; + this->margin_ = { tm_cap.tmAveCharWidth * 2, tm_cap.tmAscent / 2 }; - newSize.cx = margin_.cx + (32 * tmCap.tmAveCharWidth) + margin_.cx; - newSize.cy = margin_.cy + (tmCap.tmHeight) + margin_.cy; + new_size.cx = + margin_.cx + (32 * tm_cap.tmAveCharWidth) + margin_.cx; + new_size.cy = + margin_.cy + (tm_cap.tmHeight) + margin_.cy; if (!data_->body_text.empty()) - newSize.cy += margin_.cy + (3 * tmBody.tmHeight); + new_size.cy += margin_.cy + (3 * tm_body.tmHeight); if (data_->image) { BITMAP bm; if (GetObject(data_->image, sizeof(bm), &bm)) { // cap the image size - const int maxDimSize = 80; + const int max_dim_size = 80; auto width = bm.bmWidth; auto height = bm.bmHeight; if (width < height) { - if (height > maxDimSize) { - width = width * maxDimSize / height; - height = maxDimSize; + if (height > max_dim_size) { + width = width * max_dim_size / height; + height = max_dim_size; } } else { - if (width > maxDimSize) { - height = height * maxDimSize / width; - width = maxDimSize; + if (width > max_dim_size) { + height = height * max_dim_size / width; + width = max_dim_size; } } ScreenMetrics scr; - SIZE imageDrawSize = { scr.X(width), scr.Y(height) }; + SIZE image_draw_size = { scr.X(width), scr.Y(height) }; - newSize.cx += imageDrawSize.cx + margin_.cx; + new_size.cx += image_draw_size.cx + margin_.cx; - auto heightWithImage = - margin_.cy + (imageDrawSize.cy) + margin_.cy; - if (newSize.cy < heightWithImage) - newSize.cy = heightWithImage; + auto height_with_image = + margin_.cy + (image_draw_size.cy) + margin_.cy; - UpdateScaledImage(imageDrawSize); + if (new_size.cy < height_with_image) + new_size.cy = height_with_image; + + UpdateScaledImage(image_draw_size); } } } - if (newSize.cx != this->toast_size_.cx || - newSize.cy != this->toast_size_.cy) { - HDC hdcScreen = GetDC(NULL); - auto newBitmap = CreateCompatibleBitmap(hdcScreen, - newSize.cx, newSize.cy); - ReleaseDC(NULL, hdcScreen); + if (new_size.cx != this->toast_size_.cx || + new_size.cy != this->toast_size_.cy) { + HDC hdc_screen = GetDC(NULL); + auto new_bitmap = CreateCompatibleBitmap(hdc_screen, + new_size.cx, new_size.cy); + ReleaseDC(NULL, hdc_screen); - if (newBitmap) { - if (SelectBitmap(hdc_, newBitmap)) { + if (new_bitmap) { + if (SelectBitmap(hdc_, new_bitmap)) { RECT dirty1 = {}, dirty2 = {}; - if (toast_size_.cx < newSize.cx) { + if (toast_size_.cx < new_size.cx) { dirty1 = { toast_size_.cx, 0, - newSize.cx, toast_size_.cy }; + new_size.cx, toast_size_.cy }; } - if (toast_size_.cy < newSize.cy) { + if (toast_size_.cy < new_size.cy) { dirty2 = { 0, toast_size_.cy, - newSize.cx, newSize.cy }; + new_size.cx, new_size.cy }; } if (this->bitmap_) DeleteBitmap(this->bitmap_); - this->bitmap_ = newBitmap; - this->toast_size_ = newSize; + this->bitmap_ = new_bitmap; + this->toast_size_ = new_size; Invalidate(); @@ -589,7 +589,7 @@ void DesktopNotificationController::Toast::UpdateBufferSize() { return; } - DeleteBitmap(newBitmap); + DeleteBitmap(new_bitmap); } } } @@ -598,8 +598,8 @@ void DesktopNotificationController::Toast::UpdateBufferSize() { void DesktopNotificationController::Toast::UpdateScaledImage(const SIZE& size) { BITMAP bm; if (!GetObject(scaled_image_, sizeof(bm), &bm) || - bm.bmWidth != size.cx || - bm.bmHeight != size.cy) { + bm.bmWidth != size.cx || + bm.bmHeight != size.cy) { if (scaled_image_) DeleteBitmap(scaled_image_); scaled_image_ = StretchBitmap(data_->image, size.cx, size.cy); } @@ -680,7 +680,7 @@ HDWP DesktopNotificationController::Toast::Animate( if (IsRedrawNeeded()) Draw(); - POINT srcOrigin = { 0, 0 }; + POINT src_origin = { 0, 0 }; UPDATELAYEREDWINDOWINFO ulw; ulw.cbSize = sizeof(ulw); @@ -688,7 +688,7 @@ HDWP DesktopNotificationController::Toast::Animate( ulw.pptDst = nullptr; ulw.psize = nullptr; ulw.hdcSrc = hdc_; - ulw.pptSrc = &srcOrigin; + ulw.pptSrc = &src_origin; ulw.crKey = 0; ulw.pblend = nullptr; ulw.dwFlags = 0; @@ -700,41 +700,41 @@ HDWP DesktopNotificationController::Toast::Animate( UINT dwpFlags = SWP_NOACTIVATE | SWP_SHOWWINDOW | SWP_NOREDRAW | SWP_NOCOPYBITS; - auto easeInPos = AnimateEaseIn(); - auto easeOutPos = AnimateEaseOut(); - auto stackCollapsePos = AnimateStackCollapse(); + auto ease_in_pos = AnimateEaseIn(); + auto ease_out_pos = AnimateEaseOut(); + auto stack_collapse_pos = AnimateStackCollapse(); - auto yOffset = (vertical_pos_target_ - vertical_pos_) * stackCollapsePos; + auto y_offset = (vertical_pos_target_ - vertical_pos_) * stack_collapse_pos; - size.cx = static_cast(toast_size_.cx * easeInPos); + size.cx = static_cast(toast_size_.cx * ease_in_pos); size.cy = toast_size_.cy; pt.x = origin.x - size.cx; - pt.y = static_cast(origin.y - vertical_pos_ - yOffset - size.cy); + pt.y = static_cast(origin.y - vertical_pos_ - y_offset - size.cy); ulw.pptDst = &pt; ulw.psize = &size; - if (ease_in_active_ && easeInPos == 1.0f) { + if (ease_in_active_ && ease_in_pos == 1.0f) { ease_in_active_ = false; ScheduleDismissal(); } - this->ease_in_pos_ = easeInPos; - this->stack_collapse_pos_ = stackCollapsePos; + this->ease_in_pos_ = ease_in_pos; + this->stack_collapse_pos_ = stack_collapse_pos; - if (easeOutPos != this->ease_out_pos_) { + if (ease_out_pos != this->ease_out_pos_) { blend.BlendOp = AC_SRC_OVER; blend.BlendFlags = 0; - blend.SourceConstantAlpha = (BYTE)(255 * (1.0f - easeOutPos)); + blend.SourceConstantAlpha = (BYTE)(255 * (1.0f - ease_out_pos)); blend.AlphaFormat = 0; ulw.pblend = &blend; ulw.dwFlags = ULW_ALPHA; - this->ease_out_pos_ = easeOutPos; + this->ease_out_pos_ = ease_out_pos; - if (easeOutPos == 1.0f) { + if (ease_out_pos == 1.0f) { ease_out_active_ = false; dwpFlags &= ~SWP_SHOWWINDOW; @@ -742,7 +742,7 @@ HDWP DesktopNotificationController::Toast::Animate( } } - if (stackCollapsePos == 1.0f) { + if (stack_collapse_pos == 1.0f) { vertical_pos_ = vertical_pos_target_; } @@ -751,7 +751,7 @@ HDWP DesktopNotificationController::Toast::Animate( // ULWI fails, which can happen when one of the dimensions is zero (e.g. // at the beginning of ease-in). - auto ulwResult = UpdateLayeredWindowIndirect(hwnd_, &ulw); + auto ulw_result = UpdateLayeredWindowIndirect(hwnd_, &ulw); hdwp = DeferWindowPos(hdwp, hwnd_, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, dwpFlags); return hdwp; diff --git a/brightray/browser/win/win32_desktop_notifications/toast.h b/brightray/browser/win/win32_desktop_notifications/toast.h index 5700341f7e4..bb9bd9fa4ae 100644 --- a/brightray/browser/win/win32_desktop_notifications/toast.h +++ b/brightray/browser/win/win32_desktop_notifications/toast.h @@ -5,15 +5,15 @@ namespace brightray { class DesktopNotificationController::Toast { public: - static void Register(HINSTANCE hInstance); - static HWND Create(HINSTANCE hInstance, + static void Register(HINSTANCE hinstance); + static HWND Create(HINSTANCE hinstance, std::shared_ptr& data); - static Toast* Get(HWND hWnd) { - return reinterpret_cast(GetWindowLongPtr(hWnd, 0)); + static Toast* Get(HWND hwnd) { + return reinterpret_cast(GetWindowLongPtr(hwnd, 0)); } - static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, - WPARAM wParam, LPARAM lParam); + static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, + WPARAM wparam, LPARAM lparam); const std::shared_ptr& GetNotification() const { return data_; @@ -45,7 +45,7 @@ class DesktopNotificationController::Toast { TimerID_AutoDismiss = 1 }; - Toast(HWND hWnd, std::shared_ptr* data); + Toast(HWND hwnd, std::shared_ptr* data); ~Toast(); void UpdateBufferSize(); From fbe3b27409fb855bdd19986c45ebfed7562abc07 Mon Sep 17 00:00:00 2001 From: Ales Pergl Date: Wed, 5 Apr 2017 14:27:52 +0200 Subject: [PATCH 1024/1195] Addressed review feedback --- brightray/browser/notification_presenter.cc | 1 - brightray/browser/win/notification_presenter_win.cc | 2 -- 2 files changed, 3 deletions(-) diff --git a/brightray/browser/notification_presenter.cc b/brightray/browser/notification_presenter.cc index 39c3efd7ddf..30ef3b16b4b 100644 --- a/brightray/browser/notification_presenter.cc +++ b/brightray/browser/notification_presenter.cc @@ -19,7 +19,6 @@ NotificationPresenter::~NotificationPresenter() { base::WeakPtr NotificationPresenter::CreateNotification( NotificationDelegate* delegate) { Notification* notification = CreateNotificationObject(delegate); - if (!notification) return {}; notifications_.insert(notification); return notification->GetWeakPtr(); } diff --git a/brightray/browser/win/notification_presenter_win.cc b/brightray/browser/win/notification_presenter_win.cc index 42819eada71..930775c792b 100644 --- a/brightray/browser/win/notification_presenter_win.cc +++ b/brightray/browser/win/notification_presenter_win.cc @@ -38,8 +38,6 @@ bool SaveIconToPath(const SkBitmap& bitmap, const base::FilePath& path) { // static NotificationPresenter* NotificationPresenter::Create() { auto version = base::win::GetVersion(); - if (version < base::win::VERSION_WIN7) - return nullptr; if (version < base::win::VERSION_WIN8) return new NotificationPresenterWin7; if (!WindowsToastNotification::Initialize()) From 526086d900d8c26e1fc184ea7c348e9ff80139e1 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 6 Apr 2017 11:29:01 +0900 Subject: [PATCH 1025/1195] Improve RootWebContentsTracker --- atom/browser/api/atom_api_window.cc | 2 ++ atom/browser/atom_browser_client.cc | 17 ++------------ atom/browser/atom_browser_client.h | 13 ----------- atom/browser/root_web_contents_tracker.cc | 28 +++++++++++++++++++++++ atom/browser/root_web_contents_tracker.h | 21 +++++++++++++++++ filenames.gypi | 2 ++ 6 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 atom/browser/root_web_contents_tracker.cc create mode 100644 atom/browser/root_web_contents_tracker.h diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 6748c9c0dd1..2a77a46a3ae 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -9,6 +9,7 @@ #include "atom/browser/api/atom_api_web_contents.h" #include "atom/browser/browser.h" #include "atom/browser/native_window.h" +#include "atom/browser/root_web_contents_tracker.h" #include "atom/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/native_mate_converters/gfx_converter.h" @@ -100,6 +101,7 @@ Window::Window(v8::Isolate* isolate, v8::Local wrapper, // Creates the WebContents used by BrowserWindow. web_contents = WebContents::Create(isolate, web_preferences); + new RootWebContentsTracker(web_contents.get()->web_contents()); } Init(isolate, wrapper, options, web_contents); diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 3a9bef9f87d..0a480dcd80a 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -16,6 +16,7 @@ #include "atom/browser/atom_resource_dispatcher_host_delegate.h" #include "atom/browser/atom_speech_recognition_manager_delegate.h" #include "atom/browser/native_window.h" +#include "atom/browser/root_web_contents_tracker.h" #include "atom/browser/web_contents_permission_helper.h" #include "atom/browser/web_contents_preferences.h" #include "atom/browser/window_list.h" @@ -104,7 +105,7 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( } auto web_contents = content::WebContents::FromRenderFrameHost(render_frame_host); - if (root_web_contents_.find(web_contents) != root_web_contents_.end()) { + if (RootWebContentsTracker::IsRootWebContents(web_contents)) { // Root WebContents should always create new process // to make sure native addons are loaded correctly after reload / navigation. // (Non-root WebContents opened by window.open() should try to reuse process @@ -162,8 +163,6 @@ void AtomBrowserClient::RenderProcessWillLaunch( AddProcessPreferences(host->GetID(), process_prefs); // ensure the ProcessPreferences is removed later host->AddObserver(this); - - new RootWebContentsTracker(web_contents, this); } content::SpeechRecognitionManagerDelegate* @@ -407,16 +406,4 @@ void AtomBrowserClient::RenderProcessHostDestroyed( RemoveProcessPreferences(process_id); } -AtomBrowserClient::RootWebContentsTracker::RootWebContentsTracker( - content::WebContents* web_contents, - AtomBrowserClient* client) - : content::WebContentsObserver(web_contents), client_(client) { - client->root_web_contents_.insert(web_contents); -} - -void AtomBrowserClient::RootWebContentsTracker::WebContentsDestroyed() { - client_->root_web_contents_.erase(web_contents()); - delete this; -} - } // namespace atom diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index c1a229edae8..cd73b559e60 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -12,7 +12,6 @@ #include "brightray/browser/browser_client.h" #include "content/public/browser/render_process_host_observer.h" -#include "content/public/browser/web_contents_observer.h" namespace content { class QuotaPermissionContext; @@ -137,18 +136,6 @@ class AtomBrowserClient : public brightray::BrowserClient, Delegate* delegate_; - class RootWebContentsTracker : public content::WebContentsObserver { - public: - RootWebContentsTracker(content::WebContents* web_contents, - AtomBrowserClient* client); - void WebContentsDestroyed() override; - - private: - AtomBrowserClient* client_; - }; - - std::set root_web_contents_; - DISALLOW_COPY_AND_ASSIGN(AtomBrowserClient); }; diff --git a/atom/browser/root_web_contents_tracker.cc b/atom/browser/root_web_contents_tracker.cc new file mode 100644 index 00000000000..dfdc8a1ffbd --- /dev/null +++ b/atom/browser/root_web_contents_tracker.cc @@ -0,0 +1,28 @@ +#include "root_web_contents_tracker.h" +#include + +namespace atom { + +namespace { + +std::unordered_set g_root_web_contents; + +} // namespace + +RootWebContentsTracker::RootWebContentsTracker( + content::WebContents* web_contents) + : content::WebContentsObserver(web_contents) { + g_root_web_contents.insert(web_contents); +} + +bool RootWebContentsTracker::IsRootWebContents( + content::WebContents* web_contents) { + return g_root_web_contents.find(web_contents) != g_root_web_contents.end(); +} + +void RootWebContentsTracker::WebContentsDestroyed() { + g_root_web_contents.erase(web_contents()); + delete this; +} + +} // namespace atom diff --git a/atom/browser/root_web_contents_tracker.h b/atom/browser/root_web_contents_tracker.h new file mode 100644 index 00000000000..4a6ae0776d8 --- /dev/null +++ b/atom/browser/root_web_contents_tracker.h @@ -0,0 +1,21 @@ +#ifndef ATOM_BROWSER_ROOT_WEB_CONTENTS_TRACKER_H_ +#define ATOM_BROWSER_ROOT_WEB_CONTENTS_TRACKER_H_ + +#include "content/public/browser/web_contents_observer.h" + +namespace atom { + +// RootWebContentsTracker tracks root WebContents created by +// `new BrowserWindow`. +class RootWebContentsTracker : public content::WebContentsObserver { + public: + RootWebContentsTracker(content::WebContents* web_contents); + static bool IsRootWebContents(content::WebContents* web_contents); + + protected: + void WebContentsDestroyed() override; +}; + +} // namespace atom + +#endif // ATOM_BROWSER_ROOT_WEB_CONTENTS_TRACKER_H_ diff --git a/filenames.gypi b/filenames.gypi index 935d7033153..a45662beafd 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -273,6 +273,8 @@ 'atom/browser/relauncher.h', 'atom/browser/render_process_preferences.cc', 'atom/browser/render_process_preferences.h', + 'atom/browser/root_web_contents_tracker.cc', + 'atom/browser/root_web_contents_tracker.h', 'atom/browser/ui/accelerator_util.cc', 'atom/browser/ui/accelerator_util.h', 'atom/browser/ui/accelerator_util_mac.mm', From 349ea3a15a7abb46b3d998ebe015e2497ec2b68e Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 6 Apr 2017 11:43:57 +0900 Subject: [PATCH 1026/1195] Add test for native addon after reload --- spec/api-browser-window-spec.js | 15 +++++++++++++-- spec/fixtures/api/native-window-open.html | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 98898c1eed9..7a71bb5f72c 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1095,19 +1095,30 @@ describe('BrowserWindow module', function () { }) }) it('opens window of about:blank with cross-scripting enabled', (done) => { - ipcMain.once('answer', function (event, content) { + ipcMain.once('answer', (event, content) => { assert.equal(content, 'Hello') done() }) w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#blank')) }) it('opens window of same domain with cross-scripting enabled', (done) => { - ipcMain.once('answer', function (event, content) { + ipcMain.once('answer', (event, content) => { assert.equal(content, 'Hello') done() }) w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#file')) }) + it('loads native addons correctly after reload', (done) => { + ipcMain.once('answer', (event, content) => { + assert.equal(content, 'function') + ipcMain.once('answer', (event, content) => { + assert.equal(content, 'function') + done() + }) + w.reload() + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#native-addon')) + }) }) }) diff --git a/spec/fixtures/api/native-window-open.html b/spec/fixtures/api/native-window-open.html index 49c9352265e..0d744fa678f 100644 --- a/spec/fixtures/api/native-window-open.html +++ b/spec/fixtures/api/native-window-open.html @@ -15,6 +15,10 @@ const content = popup.document.querySelector('h1').innerText; ipcRenderer.send('answer', content); }; + }, + 'native-addon': () => { + const runas = require('runas'); + ipcRenderer.send('answer', typeof runas); } } const test = location.hash.slice(1); From 659722924d1116c38895b5f22cd6771bce7f1d30 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 6 Apr 2017 11:44:20 +0900 Subject: [PATCH 1027/1195] Don't show BrowserWindow in test --- spec/api-browser-window-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 7a71bb5f72c..6a1d75bf0ed 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1088,7 +1088,7 @@ describe('BrowserWindow module', function () { beforeEach(() => { w.destroy() w = new BrowserWindow({ - show: true, + show: false, webPreferences: { nativeWindowOpen: true } From 34ed1a9ef88d3f886540f57f827729b9b4be7c92 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Thu, 6 Apr 2017 12:15:27 +0900 Subject: [PATCH 1028/1195] Track child web contents --- atom/browser/api/atom_api_web_contents.cc | 2 ++ atom/browser/api/atom_api_window.cc | 2 -- atom/browser/atom_browser_client.cc | 4 ++-- atom/browser/child_web_contents_tracker.cc | 28 ++++++++++++++++++++++ atom/browser/child_web_contents_tracker.h | 21 ++++++++++++++++ atom/browser/root_web_contents_tracker.cc | 28 ---------------------- atom/browser/root_web_contents_tracker.h | 21 ---------------- filenames.gypi | 4 ++-- 8 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 atom/browser/child_web_contents_tracker.cc create mode 100644 atom/browser/child_web_contents_tracker.h delete mode 100644 atom/browser/root_web_contents_tracker.cc delete mode 100644 atom/browser/root_web_contents_tracker.h diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 9390777f9c5..b9692c228e8 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -13,6 +13,7 @@ #include "atom/browser/atom_browser_client.h" #include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_main_parts.h" +#include "atom/browser/child_web_contents_tracker.h" #include "atom/browser/lib/bluetooth_chooser.h" #include "atom/browser/native_window.h" #include "atom/browser/net/atom_network_delegate.h" @@ -466,6 +467,7 @@ void WebContents::AddNewContents(content::WebContents* source, const gfx::Rect& initial_rect, bool user_gesture, bool* was_blocked) { + new ChildWebContentsTracker(new_contents); v8::Locker locker(isolate()); v8::HandleScope handle_scope(isolate()); auto api_web_contents = CreateFrom(isolate(), new_contents); diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 2a77a46a3ae..6748c9c0dd1 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -9,7 +9,6 @@ #include "atom/browser/api/atom_api_web_contents.h" #include "atom/browser/browser.h" #include "atom/browser/native_window.h" -#include "atom/browser/root_web_contents_tracker.h" #include "atom/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/native_mate_converters/gfx_converter.h" @@ -101,7 +100,6 @@ Window::Window(v8::Isolate* isolate, v8::Local wrapper, // Creates the WebContents used by BrowserWindow. web_contents = WebContents::Create(isolate, web_preferences); - new RootWebContentsTracker(web_contents.get()->web_contents()); } Init(isolate, wrapper, options, web_contents); diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 0a480dcd80a..a2498cb346b 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -15,8 +15,8 @@ #include "atom/browser/atom_quota_permission_context.h" #include "atom/browser/atom_resource_dispatcher_host_delegate.h" #include "atom/browser/atom_speech_recognition_manager_delegate.h" +#include "atom/browser/child_web_contents_tracker.h" #include "atom/browser/native_window.h" -#include "atom/browser/root_web_contents_tracker.h" #include "atom/browser/web_contents_permission_helper.h" #include "atom/browser/web_contents_preferences.h" #include "atom/browser/window_list.h" @@ -105,7 +105,7 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( } auto web_contents = content::WebContents::FromRenderFrameHost(render_frame_host); - if (RootWebContentsTracker::IsRootWebContents(web_contents)) { + if (!ChildWebContentsTracker::IsChildWebContents(web_contents)) { // Root WebContents should always create new process // to make sure native addons are loaded correctly after reload / navigation. // (Non-root WebContents opened by window.open() should try to reuse process diff --git a/atom/browser/child_web_contents_tracker.cc b/atom/browser/child_web_contents_tracker.cc new file mode 100644 index 00000000000..3058fe9906b --- /dev/null +++ b/atom/browser/child_web_contents_tracker.cc @@ -0,0 +1,28 @@ +#include "child_web_contents_tracker.h" +#include + +namespace atom { + +namespace { + +std::unordered_set g_child_web_contents; + +} // namespace + +ChildWebContentsTracker::ChildWebContentsTracker( + content::WebContents* web_contents) + : content::WebContentsObserver(web_contents) { + g_child_web_contents.insert(web_contents); +} + +bool ChildWebContentsTracker::IsChildWebContents( + content::WebContents* web_contents) { + return g_child_web_contents.find(web_contents) != g_child_web_contents.end(); +} + +void ChildWebContentsTracker::WebContentsDestroyed() { + g_child_web_contents.erase(web_contents()); + delete this; +} + +} // namespace atom diff --git a/atom/browser/child_web_contents_tracker.h b/atom/browser/child_web_contents_tracker.h new file mode 100644 index 00000000000..16eaa6424c3 --- /dev/null +++ b/atom/browser/child_web_contents_tracker.h @@ -0,0 +1,21 @@ +#ifndef ATOM_BROWSER_CHILD_WEB_CONTENTS_TRACKER_H_ +#define ATOM_BROWSER_CHILD_WEB_CONTENTS_TRACKER_H_ + +#include "content/public/browser/web_contents_observer.h" + +namespace atom { + +// ChildWebContentsTracker tracks root WebContents created by +// `new BrowserWindow`. +class ChildWebContentsTracker : public content::WebContentsObserver { + public: + ChildWebContentsTracker(content::WebContents* web_contents); + static bool IsChildWebContents(content::WebContents* web_contents); + + protected: + void WebContentsDestroyed() override; +}; + +} // namespace atom + +#endif // ATOM_BROWSER_CHILD_WEB_CONTENTS_TRACKER_H_ diff --git a/atom/browser/root_web_contents_tracker.cc b/atom/browser/root_web_contents_tracker.cc deleted file mode 100644 index dfdc8a1ffbd..00000000000 --- a/atom/browser/root_web_contents_tracker.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include "root_web_contents_tracker.h" -#include - -namespace atom { - -namespace { - -std::unordered_set g_root_web_contents; - -} // namespace - -RootWebContentsTracker::RootWebContentsTracker( - content::WebContents* web_contents) - : content::WebContentsObserver(web_contents) { - g_root_web_contents.insert(web_contents); -} - -bool RootWebContentsTracker::IsRootWebContents( - content::WebContents* web_contents) { - return g_root_web_contents.find(web_contents) != g_root_web_contents.end(); -} - -void RootWebContentsTracker::WebContentsDestroyed() { - g_root_web_contents.erase(web_contents()); - delete this; -} - -} // namespace atom diff --git a/atom/browser/root_web_contents_tracker.h b/atom/browser/root_web_contents_tracker.h deleted file mode 100644 index 4a6ae0776d8..00000000000 --- a/atom/browser/root_web_contents_tracker.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ATOM_BROWSER_ROOT_WEB_CONTENTS_TRACKER_H_ -#define ATOM_BROWSER_ROOT_WEB_CONTENTS_TRACKER_H_ - -#include "content/public/browser/web_contents_observer.h" - -namespace atom { - -// RootWebContentsTracker tracks root WebContents created by -// `new BrowserWindow`. -class RootWebContentsTracker : public content::WebContentsObserver { - public: - RootWebContentsTracker(content::WebContents* web_contents); - static bool IsRootWebContents(content::WebContents* web_contents); - - protected: - void WebContentsDestroyed() override; -}; - -} // namespace atom - -#endif // ATOM_BROWSER_ROOT_WEB_CONTENTS_TRACKER_H_ diff --git a/filenames.gypi b/filenames.gypi index a45662beafd..f872c2830f2 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -198,6 +198,8 @@ 'atom/browser/browser_mac.mm', 'atom/browser/browser_win.cc', 'atom/browser/browser_observer.h', + 'atom/browser/child_web_contents_tracker.cc', + 'atom/browser/child_web_contents_tracker.h', 'atom/browser/common_web_contents_delegate_mac.mm', 'atom/browser/common_web_contents_delegate_views.cc', 'atom/browser/common_web_contents_delegate.cc', @@ -273,8 +275,6 @@ 'atom/browser/relauncher.h', 'atom/browser/render_process_preferences.cc', 'atom/browser/render_process_preferences.h', - 'atom/browser/root_web_contents_tracker.cc', - 'atom/browser/root_web_contents_tracker.h', 'atom/browser/ui/accelerator_util.cc', 'atom/browser/ui/accelerator_util.h', 'atom/browser/ui/accelerator_util_mac.mm', From b07c3adca96e4e43806128aa74092c3ba9afde60 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Wed, 12 Apr 2017 12:20:53 +0900 Subject: [PATCH 1029/1195] Fix comment for ChildWebContentsTracker --- atom/browser/child_web_contents_tracker.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/child_web_contents_tracker.h b/atom/browser/child_web_contents_tracker.h index 16eaa6424c3..ab12f4b374a 100644 --- a/atom/browser/child_web_contents_tracker.h +++ b/atom/browser/child_web_contents_tracker.h @@ -5,8 +5,8 @@ namespace atom { -// ChildWebContentsTracker tracks root WebContents created by -// `new BrowserWindow`. +// ChildWebContentsTracker tracks child WebContents +// created by native `window.open()` class ChildWebContentsTracker : public content::WebContentsObserver { public: ChildWebContentsTracker(content::WebContents* web_contents); From b19c5154ca189f0b1a62ba03e69d764de32518a6 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Wed, 12 Apr 2017 12:25:56 +0900 Subject: [PATCH 1030/1195] Fix cpplint errors --- atom/browser/atom_browser_client.cc | 8 ++++---- atom/browser/child_web_contents_tracker.cc | 7 ++++++- atom/browser/child_web_contents_tracker.h | 6 +++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index a2498cb346b..5620e53c155 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -106,10 +106,10 @@ bool AtomBrowserClient::ShouldCreateNewSiteInstance( auto web_contents = content::WebContents::FromRenderFrameHost(render_frame_host); if (!ChildWebContentsTracker::IsChildWebContents(web_contents)) { - // Root WebContents should always create new process - // to make sure native addons are loaded correctly after reload / navigation. - // (Non-root WebContents opened by window.open() should try to reuse process - // to allow synchronous cross-window scripting.) + // Root WebContents should always create new process to make sure + // native addons are loaded correctly after reload / navigation. + // (Non-root WebContents opened by window.open() should try to + // reuse process to allow synchronous cross-window scripting.) return true; } } diff --git a/atom/browser/child_web_contents_tracker.cc b/atom/browser/child_web_contents_tracker.cc index 3058fe9906b..3c9eb0d3f04 100644 --- a/atom/browser/child_web_contents_tracker.cc +++ b/atom/browser/child_web_contents_tracker.cc @@ -1,4 +1,9 @@ -#include "child_web_contents_tracker.h" +// Copyright (c) 2017 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/child_web_contents_tracker.h" + #include namespace atom { diff --git a/atom/browser/child_web_contents_tracker.h b/atom/browser/child_web_contents_tracker.h index ab12f4b374a..785509e6ea7 100644 --- a/atom/browser/child_web_contents_tracker.h +++ b/atom/browser/child_web_contents_tracker.h @@ -1,3 +1,7 @@ +// Copyright (c) 2017 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + #ifndef ATOM_BROWSER_CHILD_WEB_CONTENTS_TRACKER_H_ #define ATOM_BROWSER_CHILD_WEB_CONTENTS_TRACKER_H_ @@ -9,7 +13,7 @@ namespace atom { // created by native `window.open()` class ChildWebContentsTracker : public content::WebContentsObserver { public: - ChildWebContentsTracker(content::WebContents* web_contents); + explicit ChildWebContentsTracker(content::WebContents* web_contents); static bool IsChildWebContents(content::WebContents* web_contents); protected: From ed9795514efb05ee8ff1d3006b2f8c3d33aefa7f Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 16 Apr 2017 17:27:36 +0300 Subject: [PATCH 1031/1195] Initialize wm::WMState on Windows as well See: https://chromium.googlesource.com/chromium/src/+/cd4f72fdeae5d12e0c7c4efc0a1a0e1d7af1e0ba/ui/views_content_client/views_content_client_main_parts_aura.cc#23 This fixes electron/electron#9197. --- brightray/browser/browser_main_parts.cc | 5 ++++- brightray/browser/browser_main_parts.h | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index 0aae4bcc5bc..1a74d479239 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -25,6 +25,7 @@ #include "ui/display/display.h" #include "ui/display/screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h" +#include "ui/wm/core/wm_state.h" #endif #if defined(TOOLKIT_VIEWS) @@ -41,7 +42,6 @@ #include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util_internal.h" #include "ui/views/linux_ui/linux_ui.h" -#include "ui/wm/core/wm_state.h" #endif #if defined(OS_WIN) @@ -181,6 +181,9 @@ void BrowserMainParts::ToolkitInitialized() { #if defined(USE_AURA) && defined(USE_X11) views::LinuxUI::instance()->Initialize(); +#endif + +#if defined(USE_AURA) wm_state_.reset(new wm::WMState); #endif diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h index a0d58e7609e..91aad276023 100644 --- a/brightray/browser/browser_main_parts.h +++ b/brightray/browser/browser_main_parts.h @@ -19,7 +19,7 @@ class ViewsDelegate; } #endif -#if defined(USE_AURA) && defined(USE_X11) +#if defined(USE_AURA) namespace wm { class WMState; } @@ -54,7 +54,7 @@ class BrowserMainParts : public content::BrowserMainParts { std::unique_ptr views_delegate_; #endif -#if defined(USE_AURA) && defined(USE_X11) +#if defined(USE_AURA) std::unique_ptr wm_state_; #endif From 9ee47385d5f79444c5d28558ae3338e737aec849 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Apr 2017 12:16:42 +0900 Subject: [PATCH 1032/1195] Update libchromiumcontent to Chrome 58 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 44448acf6a2..8c3e5323858 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 44448acf6a21024b9adb7140ffef6402a509f8bf +Subproject commit 8c3e532385811b5cea80e969c1beb1bf3ffb6777 From fdb880eca2cdc1c3391642b1c2486805afff6de3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Apr 2017 12:36:15 +0900 Subject: [PATCH 1033/1195] Remove the ENABLE_WEBRTC define Headers are now defined in gen/media/media_features.h. --- brightray/brightray.gypi | 2 -- 1 file changed, 2 deletions(-) diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index 064ae1a2df0..b7fb38be63a 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -92,8 +92,6 @@ 'Common_Base': { 'abstract': 1, 'defines': [ - # Used by content_browser_client.h: - 'ENABLE_WEBRTC', # We are using Release version libchromiumcontent: 'NDEBUG', # Needed by gin: From 0a110a44f91993c48c15e225d68f4a412777ec60 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Apr 2017 13:26:50 +0900 Subject: [PATCH 1034/1195] ScopedPtrHashMap has been removed --- .../browser/inspectable_web_contents_impl.cc | 2 +- .../browser/inspectable_web_contents_impl.h | 2 +- .../net/devtools_network_controller.cc | 21 +++++++++---------- .../browser/net/devtools_network_controller.h | 11 +++++++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 4c520974273..0bf9b6732a3 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -689,7 +689,7 @@ bool InspectableWebContentsImpl::ShouldCreateWebContents( int32_t route_id, int32_t main_frame_route_id, int32_t main_frame_widget_route_id, - WindowContainerType window_container_type, + content::mojom::WindowContainerType window_container_type, const std::string& frame_name, const GURL& target_url, const std::string& partition_id, diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 2f000c21022..31ebd392b26 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -146,7 +146,7 @@ class InspectableWebContentsImpl : int32_t route_id, int32_t main_frame_route_id, int32_t main_frame_widget_route_id, - WindowContainerType window_container_type, + content::mojom::WindowContainerType window_container_type, const std::string& frame_name, const GURL& target_url, const std::string& partition_id, diff --git a/brightray/browser/net/devtools_network_controller.cc b/brightray/browser/net/devtools_network_controller.cc index 07b469b1f77..8bf411ac1a4 100644 --- a/brightray/browser/net/devtools_network_controller.cc +++ b/brightray/browser/net/devtools_network_controller.cc @@ -27,29 +27,28 @@ void DevToolsNetworkController::SetNetworkState( std::unique_ptr conditions) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - DevToolsNetworkInterceptor* interceptor = interceptors_.get(client_id); - if (!interceptor) { + auto it = interceptors_.find(client_id); + if (it == interceptors_.end()) { if (!conditions) return; std::unique_ptr new_interceptor( new DevToolsNetworkInterceptor); new_interceptor->UpdateConditions(std::move(conditions)); - interceptors_.set(client_id, std::move(new_interceptor)); + interceptors_[client_id] = std::move(new_interceptor); } else { if (!conditions) { std::unique_ptr online_conditions( new DevToolsNetworkConditions(false)); - interceptor->UpdateConditions(std::move(online_conditions)); + it->second->UpdateConditions(std::move(online_conditions)); interceptors_.erase(client_id); } else { - interceptor->UpdateConditions(std::move(conditions)); + it->second->UpdateConditions(std::move(conditions)); } } bool has_offline_interceptors = false; - auto it = interceptors_.begin(); - for (; it != interceptors_.end(); ++it) { - if (it->second->IsOffline()) { + for (const auto& interceptor : interceptors_) { + if (interceptor.second->IsOffline()) { has_offline_interceptors = true; break; } @@ -70,11 +69,11 @@ DevToolsNetworkController::GetInterceptor(const std::string& client_id) { if (interceptors_.empty() || client_id.empty()) return nullptr; - DevToolsNetworkInterceptor* interceptor = interceptors_.get(client_id); - if (!interceptor) + auto it = interceptors_.find(client_id); + if (it == interceptors_.end()) return nullptr; - return interceptor; + return it->second.get(); } } // namespace brightray diff --git a/brightray/browser/net/devtools_network_controller.h b/brightray/browser/net/devtools_network_controller.h index 7e6c948b42b..c36d888df11 100644 --- a/brightray/browser/net/devtools_network_controller.h +++ b/brightray/browser/net/devtools_network_controller.h @@ -5,8 +5,12 @@ #ifndef BROWSER_DEVTOOLS_NETWORK_CONTROLLER_H_ #define BROWSER_DEVTOOLS_NETWORK_CONTROLLER_H_ -#include "base/containers/scoped_ptr_hash_map.h" +#include +#include +#include + #include "base/macros.h" +#include "base/threading/thread_checker.h" namespace brightray { @@ -21,12 +25,13 @@ class DevToolsNetworkController { void SetNetworkState(const std::string& client_id, std::unique_ptr conditions); + DevToolsNetworkInterceptor* GetInterceptor(const std::string& client_id); private: using InterceptorMap = - base::ScopedPtrHashMap>; + std::unordered_map>; std::unique_ptr appcache_interceptor_; InterceptorMap interceptors_; From c41fb922b3ab7b555db53c0315fe14da1dc6f68f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Apr 2017 13:43:49 +0900 Subject: [PATCH 1035/1195] Fix API changes of Chrome 58 --- brightray/browser/browser_main_parts.cc | 2 +- .../devtools_embedder_message_dispatcher.cc | 1 - .../devtools_embedder_message_dispatcher.h | 1 - .../browser/inspectable_web_contents_impl.cc | 21 +++++-------------- .../browser/inspectable_web_contents_impl.h | 3 ++- brightray/browser/network_delegate.cc | 8 ------- brightray/browser/network_delegate.h | 1 - brightray/browser/permission_manager.cc | 6 ------ brightray/browser/permission_manager.h | 3 --- .../browser/platform_notification_service.cc | 2 +- .../browser/platform_notification_service.h | 2 +- brightray/browser/special_storage_policy.cc | 10 +++------ brightray/browser/special_storage_policy.h | 3 +-- 13 files changed, 14 insertions(+), 49 deletions(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index aa2a60eb901..ab2e484f1d3 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -15,7 +15,7 @@ #include "base/strings/utf_string_conversions.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" -#include "media/base/media_resources.h" +#include "media/base/localized_strings.h" #include "net/proxy/proxy_resolver_v8.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/material_design/material_design_controller.h" diff --git a/brightray/browser/devtools_embedder_message_dispatcher.cc b/brightray/browser/devtools_embedder_message_dispatcher.cc index ffba3268aec..13c54c4c7ec 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.cc +++ b/brightray/browser/devtools_embedder_message_dispatcher.cc @@ -194,7 +194,6 @@ DevToolsEmbedderMessageDispatcher::CreateForDevToolsFrontend( d->RegisterHandler("dispatchProtocolMessage", &Delegate::DispatchProtocolMessageFromDevToolsFrontend, delegate); - d->RegisterHandler("recordActionUMA", &Delegate::RecordActionUMA, delegate); d->RegisterHandlerWithCallback("sendJsonRequest", &Delegate::SendJsonRequest, delegate); d->RegisterHandlerWithCallback("getPreferences", diff --git a/brightray/browser/devtools_embedder_message_dispatcher.h b/brightray/browser/devtools_embedder_message_dispatcher.h index 4401bd5ab85..b77a83fc07c 100644 --- a/brightray/browser/devtools_embedder_message_dispatcher.h +++ b/brightray/browser/devtools_embedder_message_dispatcher.h @@ -70,7 +70,6 @@ class DevToolsEmbedderMessageDispatcher { virtual void SetDevicesUpdatesEnabled(bool enabled) = 0; virtual void DispatchProtocolMessageFromDevToolsFrontend( const std::string& message) = 0; - virtual void RecordActionUMA(const std::string& name, int action) = 0; virtual void SendJsonRequest(const DispatchCallback& callback, const std::string& browser_id, const std::string& url) = 0; diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 0bf9b6732a3..f4eb15d3650 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -61,11 +61,6 @@ const char kFrontendHostMethod[] = "method"; const char kFrontendHostParams[] = "params"; const char kTitleFormat[] = "Developer Tools - %s"; -const char kDevToolsActionTakenHistogram[] = "DevTools.ActionTaken"; -const int kDevToolsActionTakenBoundary = 100; -const char kDevToolsPanelShownHistogram[] = "DevTools.PanelShown"; -const int kDevToolsPanelShownBoundary = 20; - const size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; void RectToDictionary(const gfx::Rect& bounds, base::DictionaryValue* dict) { @@ -171,7 +166,7 @@ int ResponseWriter::Initialize(const net::CompletionCallback& callback) { int ResponseWriter::Write(net::IOBuffer* buffer, int num_bytes, const net::CompletionCallback& callback) { - auto* id = new base::FundamentalValue(stream_id_); + auto* id = new base::Value(stream_id_); base::StringValue* chunk = new base::StringValue(std::string(buffer->data(), num_bytes)); @@ -563,14 +558,6 @@ void InspectableWebContentsImpl::DispatchProtocolMessageFromDevToolsFrontend( agent_host_->DispatchProtocolMessage(this, message); } -void InspectableWebContentsImpl::RecordActionUMA(const std::string& name, - int action) { - if (name == kDevToolsActionTakenHistogram) - UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsActionTakenBoundary); - else if (name == kDevToolsPanelShownHistogram) - UMA_HISTOGRAM_ENUMERATION(name, action, kDevToolsPanelShownBoundary); -} - void InspectableWebContentsImpl::SendJsonRequest( const DispatchCallback& callback, const std::string& browser_id, @@ -639,7 +626,7 @@ void InspectableWebContentsImpl::DispatchProtocolMessage( return; } - base::FundamentalValue total_size(static_cast(message.length())); + base::Value total_size(static_cast(message.length())); for (size_t pos = 0; pos < message.length(); pos += kMaxMessageChunkSize) { base::StringValue message_value(message.substr(pos, kMaxMessageChunkSize)); CallClientFunction("DevToolsAPI.dispatchMessageChunk", @@ -686,10 +673,12 @@ bool InspectableWebContentsImpl::DidAddMessageToConsole( bool InspectableWebContentsImpl::ShouldCreateWebContents( content::WebContents* web_contents, + content::SiteInstance* source_site_instance, int32_t route_id, int32_t main_frame_route_id, int32_t main_frame_widget_route_id, content::mojom::WindowContainerType window_container_type, + const GURL& opener_url, const std::string& frame_name, const GURL& target_url, const std::string& partition_id, @@ -777,7 +766,7 @@ void InspectableWebContentsImpl::OnURLFetchComplete( void InspectableWebContentsImpl::SendMessageAck(int request_id, const base::Value* arg) { - base::FundamentalValue id_value(request_id); + base::Value id_value(request_id); CallClientFunction("DevToolsAPI.embedderMessageAck", &id_value, arg, nullptr); } diff --git a/brightray/browser/inspectable_web_contents_impl.h b/brightray/browser/inspectable_web_contents_impl.h index 31ebd392b26..25cffa957af 100644 --- a/brightray/browser/inspectable_web_contents_impl.h +++ b/brightray/browser/inspectable_web_contents_impl.h @@ -107,7 +107,6 @@ class InspectableWebContentsImpl : void SetDevicesUpdatesEnabled(bool enabled) override; void DispatchProtocolMessageFromDevToolsFrontend( const std::string& message) override; - void RecordActionUMA(const std::string& name, int action) override; void SendJsonRequest(const DispatchCallback& callback, const std::string& browser_id, const std::string& url) override; @@ -143,10 +142,12 @@ class InspectableWebContentsImpl : const base::string16& source_id) override; bool ShouldCreateWebContents( content::WebContents* web_contents, + content::SiteInstance* source_site_instance, int32_t route_id, int32_t main_frame_route_id, int32_t main_frame_widget_route_id, content::mojom::WindowContainerType window_container_type, + const GURL& opener_url, const std::string& frame_name, const GURL& target_url, const std::string& partition_id, diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index 2af03e0f959..59b842768bd 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -134,14 +134,6 @@ bool NetworkDelegate::OnCanEnablePrivacyMode( return false; } -bool NetworkDelegate::OnAreStrictSecureCookiesEnabled() const { - return true; -} - -bool NetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const { - return true; -} - bool NetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( const net::URLRequest& request, const GURL& target_url, diff --git a/brightray/browser/network_delegate.h b/brightray/browser/network_delegate.h index 752434222ac..b8a8b522536 100644 --- a/brightray/browser/network_delegate.h +++ b/brightray/browser/network_delegate.h @@ -63,7 +63,6 @@ class NetworkDelegate : public net::NetworkDelegate { bool OnCanEnablePrivacyMode( const GURL& url, const GURL& first_party_for_cookies) const override; - bool OnAreStrictSecureCookiesEnabled() const override; bool OnAreExperimentalCookieFeaturesEnabled() const override; bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( const net::URLRequest& request, diff --git a/brightray/browser/permission_manager.cc b/brightray/browser/permission_manager.cc index f2b0d97d9ba..198e35d8c38 100644 --- a/brightray/browser/permission_manager.cc +++ b/brightray/browser/permission_manager.cc @@ -70,12 +70,6 @@ blink::mojom::PermissionStatus PermissionManager::GetPermissionStatus( return blink::mojom::PermissionStatus::GRANTED; } -void PermissionManager::RegisterPermissionUsage( - content::PermissionType permission, - const GURL& requesting_origin, - const GURL& embedding_origin) { -} - int PermissionManager::SubscribePermissionStatusChange( content::PermissionType permission, const GURL& requesting_origin, diff --git a/brightray/browser/permission_manager.h b/brightray/browser/permission_manager.h index 7e9a283913f..734529f06eb 100644 --- a/brightray/browser/permission_manager.h +++ b/brightray/browser/permission_manager.h @@ -40,9 +40,6 @@ class PermissionManager : public content::PermissionManager { content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) override; - void RegisterPermissionUsage(content::PermissionType permission, - const GURL& requesting_origin, - const GURL& embedding_origin) override; int SubscribePermissionStatusChange( content::PermissionType permission, const GURL& requesting_origin, diff --git a/brightray/browser/platform_notification_service.cc b/brightray/browser/platform_notification_service.cc index 8f9f16a2c17..36c51515353 100644 --- a/brightray/browser/platform_notification_service.cc +++ b/brightray/browser/platform_notification_service.cc @@ -100,7 +100,7 @@ void PlatformNotificationService::ClosePersistentNotification( const std::string& notification_id) { } -bool PlatformNotificationService::GetDisplayedPersistentNotifications( +bool PlatformNotificationService::GetDisplayedNotifications( content::BrowserContext* browser_context, std::set* displayed_notifications) { return false; diff --git a/brightray/browser/platform_notification_service.h b/brightray/browser/platform_notification_service.h index b2b6471d0fd..f9b09c64bdf 100644 --- a/brightray/browser/platform_notification_service.h +++ b/brightray/browser/platform_notification_service.h @@ -45,7 +45,7 @@ class PlatformNotificationService const content::NotificationResources& notification_resources) override; void ClosePersistentNotification(content::BrowserContext* browser_context, const std::string& notification_id) override; - bool GetDisplayedPersistentNotifications( + bool GetDisplayedNotifications( content::BrowserContext* browser_context, std::set* displayed_notifications) override; diff --git a/brightray/browser/special_storage_policy.cc b/brightray/browser/special_storage_policy.cc index 77a302bb1f8..2010dbd1a04 100644 --- a/brightray/browser/special_storage_policy.cc +++ b/brightray/browser/special_storage_policy.cc @@ -24,20 +24,16 @@ bool SpecialStoragePolicy::IsStorageDurable(const GURL& origin) { return true; } -bool SpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { +bool SpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) { return false; } -bool SpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { - return true; +bool SpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { + return false; } bool SpecialStoragePolicy::HasSessionOnlyOrigins() { return false; } -bool SpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) { - return false; -} - } // namespace brightray diff --git a/brightray/browser/special_storage_policy.h b/brightray/browser/special_storage_policy.h index 265df536cf2..0c89db2d4c5 100644 --- a/brightray/browser/special_storage_policy.h +++ b/brightray/browser/special_storage_policy.h @@ -17,9 +17,8 @@ class SpecialStoragePolicy : public storage::SpecialStoragePolicy { bool IsStorageProtected(const GURL& origin) override; bool IsStorageUnlimited(const GURL& origin) override; bool IsStorageDurable(const GURL& origin) override; - bool IsStorageSessionOnly(const GURL& origin) override; - bool CanQueryDiskSize(const GURL& origin) override; bool HasIsolatedStorage(const GURL& origin) override; + bool IsStorageSessionOnly(const GURL& origin) override; bool HasSessionOnlyOrigins() override; protected: From bbd474966884c4eb998e43c8ff8db32d619b99f6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Apr 2017 15:56:35 +0900 Subject: [PATCH 1036/1195] base::WrapUnique has changed its API --- brightray/browser/url_request_context_getter.cc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index a9e0a22756b..2e483d62ae5 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -195,9 +195,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { std::unique_ptr 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(nullptr), - base::WorkerPool::GetTaskRunner(true)))); + storage_->set_channel_id_service(base::MakeUnique( + new net::DefaultChannelIDStore(nullptr))); std::string accept_lang = l10n_util::GetApplicationLocale(""); storage_->set_http_user_agent_settings(base::WrapUnique( @@ -354,9 +353,9 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { it != protocol_interceptors_.rend(); ++it) { top_job_factory.reset(new net::URLRequestInterceptingJobFactory( - std::move(top_job_factory), base::WrapUnique(*it))); + std::move(top_job_factory), std::move(*it))); } - protocol_interceptors_.weak_clear(); + protocol_interceptors_.clear(); storage_->set_job_factory(std::move(top_job_factory)); } From affd80aef0f710828e795378ea00aa42aa888426 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Apr 2017 15:14:36 +0900 Subject: [PATCH 1037/1195] Add gen/third_party/WebKit to include dirs --- brightray/brightray.gyp | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index e60d17a1585..0c96237f4ef 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -35,6 +35,7 @@ '<(libchromiumcontent_src_dir)/third_party/khronos', '<(libchromiumcontent_src_dir)/third_party/WebKit', '<(libchromiumcontent_dir)/gen', + '<(libchromiumcontent_dir)/gen/third_party/WebKit', ], }, 'sources': [ '<@(brightray_sources)' ], From 79a441874ee5acc2135e367ffb588c728b1401b6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 13 Apr 2017 20:04:08 +0900 Subject: [PATCH 1038/1195] Fill missing NetworkDelegate method --- brightray/browser/network_delegate.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/brightray/browser/network_delegate.cc b/brightray/browser/network_delegate.cc index 59b842768bd..f7be1b028b6 100644 --- a/brightray/browser/network_delegate.cc +++ b/brightray/browser/network_delegate.cc @@ -134,6 +134,10 @@ bool NetworkDelegate::OnCanEnablePrivacyMode( return false; } +bool NetworkDelegate::OnAreExperimentalCookieFeaturesEnabled() const { + return true; +} + bool NetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader( const net::URLRequest& request, const GURL& target_url, From 98c039c880068ff2d31ebec99aeaf3b2af6fdc20 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 20 Mar 2017 12:22:46 -0700 Subject: [PATCH 1039/1195] Detach from devtools before destroying Otherwise Electron would crash on exit in Chrome 58. --- brightray/browser/inspectable_web_contents_impl.cc | 13 ++++++++++--- brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index f4eb15d3650..8efb160f63f 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -235,9 +235,14 @@ InspectableWebContentsImpl::InspectableWebContentsImpl( } InspectableWebContentsImpl::~InspectableWebContentsImpl() { - if (devtools_web_contents_) - devtools_web_contents_->Close(); - Observe(nullptr); + // Unsubscribe from devtools and Clean up resources. + if (devtools_web_contents_) { + devtools_web_contents_->SetDelegate(nullptr); + // Calling this also unsubscribes the observer, so WebContentsDestroyed + // won't be called again. + WebContentsDestroyed(); + } + // Let destructor destroy devtools_web_contents_. } InspectableWebContentsView* InspectableWebContentsImpl::GetView() const { @@ -651,6 +656,7 @@ void InspectableWebContentsImpl::RenderFrameHostChanged( void InspectableWebContentsImpl::WebContentsDestroyed() { frontend_loaded_ = false; + Observe(nullptr); Detach(); for (const auto& pair : pending_requests_) @@ -695,6 +701,7 @@ void InspectableWebContentsImpl::HandleKeyboardEvent( } void InspectableWebContentsImpl::CloseContents(content::WebContents* source) { + // This is where the devtools closes itself (by clicking the x button). CloseDevTools(); } diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 8c3e5323858..791141a820e 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 8c3e532385811b5cea80e969c1beb1bf3ffb6777 +Subproject commit 791141a820ecf6166a86249701838b57f43777ea From b82845dc4a6908f4dc2903073a5d25d081eecbf2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Apr 2017 16:10:30 +0900 Subject: [PATCH 1040/1195] A quick fix for crashing when closing devtools --- brightray/browser/inspectable_web_contents_impl.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 8efb160f63f..20ee3081558 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -310,6 +310,7 @@ void InspectableWebContentsImpl::ShowDevTools() { void InspectableWebContentsImpl::CloseDevTools() { if (devtools_web_contents_) { + frontend_loaded_ = false; view_->CloseDevTools(); devtools_web_contents_.reset(); web_contents_->Focus(); From 55e9c3196a59a92cf0b55ea2b1639e7b54b97174 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Apr 2017 16:52:24 +0900 Subject: [PATCH 1041/1195] Fix building on Linux --- brightray/browser/browser_main_parts.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/browser/browser_main_parts.cc b/brightray/browser/browser_main_parts.cc index ab2e484f1d3..8d46b4af4b4 100644 --- a/brightray/browser/browser_main_parts.cc +++ b/brightray/browser/browser_main_parts.cc @@ -163,7 +163,7 @@ void BrowserMainParts::PreEarlyInitialization() { base::FeatureList::SetInstance(std::move(feature_list)); #if defined(USE_X11) - views::LinuxUI::SetInstance(BuildGtk2UI()); + views::LinuxUI::SetInstance(BuildGtkUi()); OverrideLinuxAppDataPath(); // Installs the X11 error handlers for the browser process used during From 70d67f9da4429a0e28730f669e193a4965dca935 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 18 Apr 2017 16:05:57 +0900 Subject: [PATCH 1042/1195] Link with VideoToolbox.framework --- brightray/brightray.gyp | 2 ++ brightray/vendor/libchromiumcontent | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 0c96237f4ef..85b319783a8 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -162,6 +162,8 @@ # Required by webrtc: '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', '$(SDKROOT)/System/Library/Frameworks/IOKit.framework', + # Required by media: + '$(SDKROOT)/System/Library/Frameworks/VideoToolbox.framework', ], }, 'conditions': [ diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 791141a820e..72cfdcb1b91 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 791141a820ecf6166a86249701838b57f43777ea +Subproject commit 72cfdcb1b916546cf198cf39c8fc53c3175c248c From f375e8a7db14e199736b3ef390c107e4b329d593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Lach=C3=A8ze?= Date: Tue, 18 Apr 2017 12:31:20 +0200 Subject: [PATCH 1043/1195] Add OS process id to web-contents --- atom/browser/api/atom_api_web_contents.cc | 8 ++++++++ atom/browser/api/atom_api_web_contents.h | 1 + 2 files changed, 9 insertions(+) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index d3e7bae2e41..9ea413fccce 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -46,6 +46,7 @@ #include "chrome/browser/printing/print_preview_message_handler.h" #include "chrome/browser/printing/print_view_manager_basic.h" #include "chrome/browser/ssl/security_state_tab_helper.h" +#include "base/process/process_handle.h" #include "content/browser/frame_host/navigation_entry_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/web_contents/web_contents_impl.h" @@ -77,6 +78,7 @@ #include "third_party/WebKit/public/web/WebFindOptions.h" #include "ui/display/screen.h" + #if !defined(OS_MACOSX) #include "ui/aura/window.h" #endif @@ -959,6 +961,11 @@ int WebContents::GetProcessID() const { return web_contents()->GetRenderProcessHost()->GetID(); } +int WebContents::GetOSProcessID() const { + auto process_handle = web_contents()->GetRenderProcessHost()->GetHandle(); + return base::GetProcId(process_handle); +} + WebContents::Type WebContents::GetType() const { return type_; } @@ -1708,6 +1715,7 @@ void WebContents::BuildPrototype(v8::Isolate* isolate, .MakeDestroyable() .SetMethod("getId", &WebContents::GetID) .SetMethod("getProcessId", &WebContents::GetProcessID) + .SetMethod("getOSProcessId", &WebContents::GetOSProcessID) .SetMethod("equal", &WebContents::Equal) .SetMethod("_loadURL", &WebContents::LoadURL) .SetMethod("downloadURL", &WebContents::DownloadURL) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 1301ed15f7f..a608c8a401e 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -82,6 +82,7 @@ class WebContents : public mate::TrackableObject, int64_t GetID() const; int GetProcessID() const; + int GetOSProcessID() const; Type GetType() const; bool Equal(const WebContents* web_contents) const; void LoadURL(const GURL& url, const mate::Dictionary& options); From 9aff17afeafb85a94860253f59a16a28d6c483fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Lach=C3=A8ze?= Date: Tue, 18 Apr 2017 13:44:31 +0200 Subject: [PATCH 1044/1195] :shirt: alphabetical order --- atom/browser/api/atom_api_web_contents.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 9ea413fccce..d5395a6872d 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -39,6 +39,7 @@ #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/options_switches.h" +#include "base/process/process_handle.h" #include "base/strings/utf_string_conversions.h" #include "base/threading/thread_task_runner_handle.h" #include "brightray/browser/inspectable_web_contents.h" @@ -46,7 +47,6 @@ #include "chrome/browser/printing/print_preview_message_handler.h" #include "chrome/browser/printing/print_view_manager_basic.h" #include "chrome/browser/ssl/security_state_tab_helper.h" -#include "base/process/process_handle.h" #include "content/browser/frame_host/navigation_entry_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/web_contents/web_contents_impl.h" @@ -78,7 +78,6 @@ #include "third_party/WebKit/public/web/WebFindOptions.h" #include "ui/display/screen.h" - #if !defined(OS_MACOSX) #include "ui/aura/window.h" #endif From 91f31506ef93c7893e478227ad0086dc0b3837d4 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Wed, 19 Apr 2017 00:11:23 +0900 Subject: [PATCH 1045/1195] Skip native addon test in Windows --- spec/api-browser-window-spec.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 6a1d75bf0ed..2b0492eaed3 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1094,6 +1094,7 @@ describe('BrowserWindow module', function () { } }) }) + it('opens window of about:blank with cross-scripting enabled', (done) => { ipcMain.once('answer', (event, content) => { assert.equal(content, 'Hello') @@ -1101,6 +1102,7 @@ describe('BrowserWindow module', function () { }) w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#blank')) }) + it('opens window of same domain with cross-scripting enabled', (done) => { ipcMain.once('answer', (event, content) => { assert.equal(content, 'Hello') @@ -1108,17 +1110,20 @@ describe('BrowserWindow module', function () { }) w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#file')) }) - it('loads native addons correctly after reload', (done) => { - ipcMain.once('answer', (event, content) => { - assert.equal(content, 'function') + + if (process.platform !== 'win32' || process.execPath.toLowerCase().indexOf('\\out\\d\\') === -1) { + it('loads native addons correctly after reload', (done) => { ipcMain.once('answer', (event, content) => { assert.equal(content, 'function') - done() + ipcMain.once('answer', (event, content) => { + assert.equal(content, 'function') + done() + }) + w.reload() }) - w.reload() + w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#native-addon')) }) - w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#native-addon')) - }) + } }) }) From 453cb2c0b40e63196d4eeb4c8ca119c985ee23b7 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Apr 2017 12:16:57 +0900 Subject: [PATCH 1046/1195] Upgrade to Chrome 58.0.3029.40 --- atom/common/chrome_version.h | 2 +- script/lib/config.py | 2 +- vendor/brightray | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/atom/common/chrome_version.h b/atom/common/chrome_version.h index 4838875354a..04d30344ed7 100644 --- a/atom/common/chrome_version.h +++ b/atom/common/chrome_version.h @@ -8,7 +8,7 @@ #ifndef ATOM_COMMON_CHROME_VERSION_H_ #define ATOM_COMMON_CHROME_VERSION_H_ -#define CHROME_VERSION_STRING "56.0.2924.87" +#define CHROME_VERSION_STRING "58.0.3029.40" #define CHROME_VERSION "v" CHROME_VERSION_STRING #endif // ATOM_COMMON_CHROME_VERSION_H_ diff --git a/script/lib/config.py b/script/lib/config.py index 5818571089f..1b8eac01344 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -9,7 +9,7 @@ import sys BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \ 'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent' LIBCHROMIUMCONTENT_COMMIT = os.getenv('LIBCHROMIUMCONTENT_COMMIT') or \ - '4a0e32606e52c12c50c2e3a0973d015d8cdff494' + '8c3e532385811b5cea80e969c1beb1bf3ffb6777' PLATFORM = { 'cygwin': 'win32', diff --git a/vendor/brightray b/vendor/brightray index 909c4926549..5e08ec99231 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 909c49265493bd095c27cefd999567be2107899a +Subproject commit 5e08ec992316520c3c1643b1e3569f297556b8bb From fc2d62d5cb77605d53de2dccaf29dc01b57fbaef Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 4 Apr 2017 13:50:44 +0900 Subject: [PATCH 1047/1195] Fix API changes of Chrome58 --- atom/app/atom_content_client.cc | 43 +++++++------------ atom/app/atom_content_client.h | 10 +---- atom/browser/api/atom_api_cookies.cc | 4 +- atom/browser/api/atom_api_debugger.cc | 2 +- atom/browser/api/atom_api_desktop_capturer.cc | 2 + atom/browser/api/atom_api_session.cc | 3 +- atom/browser/atom_browser_client.cc | 13 +++--- atom/browser/atom_browser_client.h | 9 ++-- .../browser/atom_javascript_dialog_manager.cc | 11 +++-- atom/browser/atom_javascript_dialog_manager.h | 3 +- atom/browser/atom_permission_manager.cc | 8 +--- atom/browser/atom_permission_manager.h | 5 +-- .../common_web_contents_delegate_mac.mm | 2 +- .../net/atom_url_request_job_factory.cc | 9 ++-- .../net/atom_url_request_job_factory.h | 4 +- atom/browser/net/js_asker.cc | 2 +- .../browser/net/url_request_async_asar_job.cc | 2 +- atom/browser/net/url_request_buffer_job.cc | 2 +- atom/browser/net/url_request_fetch_job.cc | 2 +- atom/browser/net/url_request_string_job.cc | 2 +- atom/common/asar/archive.cc | 9 ++-- atom/common/asar/archive.h | 6 +-- .../v8_value_converter.cc | 2 +- .../native_mate_converters/value_converter.cc | 2 +- .../renderer/media/chrome_key_systems.cc | 14 +++--- electron.gyp | 3 -- vendor/crashpad | 2 +- vendor/node | 2 +- 28 files changed, 73 insertions(+), 105 deletions(-) diff --git a/atom/app/atom_content_client.cc b/atom/app/atom_content_client.cc index 8e2a6c57309..09683211c58 100644 --- a/atom/app/atom_content_client.cc +++ b/atom/app/atom_content_client.cc @@ -93,9 +93,9 @@ content::PepperPluginInfo CreateWidevineCdmInfo(const base::FilePath& path, std::vector codecs; codecs.push_back(kCdmSupportedCodecVp8); codecs.push_back(kCdmSupportedCodecVp9); -#if defined(USE_PROPRIETARY_CODECS) +#if BUILDFLAG(USE_PROPRIETARY_CODECS) codecs.push_back(kCdmSupportedCodecAvc1); -#endif // defined(USE_PROPRIETARY_CODECS) +#endif // BUILDFLAG(USE_PROPRIETARY_CODECS) std::string codec_string = base::JoinString( codecs, std::string(1, kCdmSupportedCodecsValueDelimiter)); widevine_cdm_mime_type.additional_param_names.push_back( @@ -198,11 +198,19 @@ base::string16 AtomContentClient::GetLocalizedString(int message_id) const { return l10n_util::GetStringUTF16(message_id); } -void AtomContentClient::AddAdditionalSchemes( - std::vector* standard_schemes, - std::vector* referrer_schemes, - std::vector* savable_schemes) { - standard_schemes->push_back({"chrome-extension", url::SCHEME_WITHOUT_PORT}); +void AtomContentClient::AddAdditionalSchemes(Schemes* schemes) { + schemes->standard_schemes.push_back("chrome-extension"); + + std::vector splited; + ConvertStringWithSeparatorToVector(&splited, ",", + switches::kRegisterServiceWorkerSchemes); + for (const std::string& scheme : splited) + schemes->service_worker_schemes.push_back(scheme); + schemes->service_worker_schemes.push_back(url::kFileScheme); + + ConvertStringWithSeparatorToVector(&splited, ",", switches::kSecureSchemes); + for (const std::string& scheme : splited) + schemes->secure_schemes.push_back(scheme); } void AtomContentClient::AddPepperPlugins( @@ -214,25 +222,4 @@ void AtomContentClient::AddPepperPlugins( ComputeBuiltInPlugins(plugins); } -void AtomContentClient::AddServiceWorkerSchemes( - std::set* service_worker_schemes) { - std::vector schemes; - ConvertStringWithSeparatorToVector(&schemes, ",", - switches::kRegisterServiceWorkerSchemes); - for (const std::string& scheme : schemes) - service_worker_schemes->insert(scheme); - - service_worker_schemes->insert(url::kFileScheme); -} - -void AtomContentClient::AddSecureSchemesAndOrigins( - std::set* secure_schemes, - std::set* secure_origins) { - std::vector schemes; - ConvertStringWithSeparatorToVector(&schemes, ",", switches::kSecureSchemes); - for (const std::string& scheme : schemes) - secure_schemes->insert(scheme); -} - - } // namespace atom diff --git a/atom/app/atom_content_client.h b/atom/app/atom_content_client.h index e396dc23c8e..fcd26f84183 100644 --- a/atom/app/atom_content_client.h +++ b/atom/app/atom_content_client.h @@ -23,17 +23,9 @@ class AtomContentClient : public brightray::ContentClient { std::string GetProduct() const override; std::string GetUserAgent() const override; base::string16 GetLocalizedString(int message_id) const override; - void AddAdditionalSchemes( - std::vector* standard_schemes, - std::vector* referrer_schemes, - std::vector* savable_schemes) override; + void AddAdditionalSchemes(Schemes* schemes) override; void AddPepperPlugins( std::vector* plugins) override; - void AddServiceWorkerSchemes( - std::set* service_worker_schemes) override; - void AddSecureSchemesAndOrigins( - std::set* secure_schemes, - std::set* secure_origins) override; private: DISALLOW_COPY_AND_ASSIGN(AtomContentClient); diff --git a/atom/browser/api/atom_api_cookies.cc b/atom/browser/api/atom_api_cookies.cc index 2ce9e12f6c5..629bb2f1bfc 100644 --- a/atom/browser/api/atom_api_cookies.cc +++ b/atom/browser/api/atom_api_cookies.cc @@ -228,8 +228,8 @@ void SetCookieOnIO(scoped_refptr getter, GetCookieStore(getter)->SetCookieWithDetailsAsync( GURL(url), name, value, domain, path, creation_time, expiration_time, last_access_time, secure, http_only, - net::CookieSameSite::DEFAULT_MODE, false, - net::COOKIE_PRIORITY_DEFAULT, base::Bind(OnSetCookie, callback)); + net::CookieSameSite::DEFAULT_MODE, net::COOKIE_PRIORITY_DEFAULT, + base::Bind(OnSetCookie, callback)); } } // namespace diff --git a/atom/browser/api/atom_api_debugger.cc b/atom/browser/api/atom_api_debugger.cc index 90999a4f602..7883b424d96 100644 --- a/atom/browser/api/atom_api_debugger.cc +++ b/atom/browser/api/atom_api_debugger.cc @@ -46,7 +46,7 @@ void Debugger::DispatchProtocolMessage(DevToolsAgentHost* agent_host, DCHECK(agent_host == agent_host_.get()); std::unique_ptr parsed_message(base::JSONReader::Read(message)); - if (!parsed_message->IsType(base::Value::TYPE_DICTIONARY)) + if (!parsed_message->IsType(base::Value::Type::DICTIONARY)) return; base::DictionaryValue* dict = diff --git a/atom/browser/api/atom_api_desktop_capturer.cc b/atom/browser/api/atom_api_desktop_capturer.cc index 118b3e3bdc6..79feb7520b0 100644 --- a/atom/browser/api/atom_api_desktop_capturer.cc +++ b/atom/browser/api/atom_api_desktop_capturer.cc @@ -4,6 +4,8 @@ #include "atom/browser/api/atom_api_desktop_capturer.h" +using base::PlatformThreadRef; + #include "atom/common/api/atom_api_native_image.h" #include "atom/common/native_mate_converters/gfx_converter.h" #include "base/strings/utf_string_conversions.h" diff --git a/atom/browser/api/atom_api_session.cc b/atom/browser/api/atom_api_session.cc index 83d103a631f..3a2d5f44007 100644 --- a/atom/browser/api/atom_api_session.cc +++ b/atom/browser/api/atom_api_session.cc @@ -432,7 +432,8 @@ void DownloadIdCallback(content::DownloadManager* download_manager, last_modified, offset, length, std::string(), content::DownloadItem::INTERRUPTED, content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, - content::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, false); + content::DOWNLOAD_INTERRUPT_REASON_NETWORK_TIMEOUT, false, + std::vector()); } } // namespace diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 77c3212e2e0..6addfb5c7cb 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -296,27 +296,26 @@ void AtomBrowserClient::ResourceDispatcherHostCreated() { } bool AtomBrowserClient::CanCreateWindow( + int opener_render_process_id, + int opener_render_frame_id, const GURL& opener_url, const GURL& opener_top_level_frame_url, const GURL& source_origin, - WindowContainerType container_type, + content::mojom::WindowContainerType container_type, const GURL& target_url, const content::Referrer& referrer, const std::string& frame_name, WindowOpenDisposition disposition, - const blink::WebWindowFeatures& features, + const blink::mojom::WindowFeatures& features, const std::vector& additional_features, const scoped_refptr& body, bool user_gesture, bool opener_suppressed, content::ResourceContext* context, - int render_process_id, - int opener_render_view_id, - int opener_render_frame_id, bool* no_javascript_access) { DCHECK_CURRENTLY_ON(content::BrowserThread::IO); - if (IsRendererSandboxed(render_process_id)) { + if (IsRendererSandboxed(opener_render_process_id)) { *no_javascript_access = false; return true; } @@ -330,7 +329,7 @@ bool AtomBrowserClient::CanCreateWindow( disposition, additional_features, body, - render_process_id, + opener_render_process_id, opener_render_frame_id)); } diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index 70573d6eee3..ba1bd86fcad 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -80,23 +80,22 @@ class AtomBrowserClient : public brightray::BrowserClient, std::unique_ptr delegate) override; void ResourceDispatcherHostCreated() override; bool CanCreateWindow( + int opener_render_process_id, + int opener_render_frame_id, const GURL& opener_url, const GURL& opener_top_level_frame_url, const GURL& source_origin, - WindowContainerType container_type, + content::mojom::WindowContainerType container_type, const GURL& target_url, const content::Referrer& referrer, const std::string& frame_name, WindowOpenDisposition disposition, - const blink::WebWindowFeatures& features, + const blink::mojom::WindowFeatures& features, const std::vector& additional_features, const scoped_refptr& body, bool user_gesture, bool opener_suppressed, content::ResourceContext* context, - int render_process_id, - int opener_render_view_id, - int opener_render_frame_id, bool* no_javascript_access) override; void GetAdditionalAllowedSchemesForFileSystem( std::vector* schemes) override; diff --git a/atom/browser/atom_javascript_dialog_manager.cc b/atom/browser/atom_javascript_dialog_manager.cc index f874a99db55..79f82d99441 100644 --- a/atom/browser/atom_javascript_dialog_manager.cc +++ b/atom/browser/atom_javascript_dialog_manager.cc @@ -13,27 +13,27 @@ #include "base/strings/utf_string_conversions.h" #include "ui/gfx/image/image_skia.h" -using content::JavaScriptMessageType; +using content::JavaScriptDialogType; namespace atom { void AtomJavaScriptDialogManager::RunJavaScriptDialog( content::WebContents* web_contents, const GURL& origin_url, - JavaScriptMessageType message_type, + JavaScriptDialogType dialog_type, const base::string16& message_text, const base::string16& default_prompt_text, const DialogClosedCallback& callback, bool* did_suppress_message) { - if (message_type != JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_ALERT && - message_type != JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_CONFIRM) { + if (dialog_type != JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_ALERT && + dialog_type != JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_CONFIRM) { callback.Run(false, base::string16()); return; } std::vector buttons = {"OK"}; - if (message_type == JavaScriptMessageType::JAVASCRIPT_MESSAGE_TYPE_CONFIRM) { + if (dialog_type == JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_CONFIRM) { buttons.push_back("Cancel"); } @@ -55,7 +55,6 @@ void AtomJavaScriptDialogManager::RunBeforeUnloadDialog( void AtomJavaScriptDialogManager::CancelDialogs( content::WebContents* web_contents, - bool suppress_callbacks, bool reset_state) { } diff --git a/atom/browser/atom_javascript_dialog_manager.h b/atom/browser/atom_javascript_dialog_manager.h index 01cc76248c8..56b62afe877 100644 --- a/atom/browser/atom_javascript_dialog_manager.h +++ b/atom/browser/atom_javascript_dialog_manager.h @@ -17,7 +17,7 @@ class AtomJavaScriptDialogManager : public content::JavaScriptDialogManager { void RunJavaScriptDialog( content::WebContents* web_contents, const GURL& origin_url, - content::JavaScriptMessageType javascript_message_type, + content::JavaScriptDialogType dialog_type, const base::string16& message_text, const base::string16& default_prompt_text, const DialogClosedCallback& callback, @@ -27,7 +27,6 @@ class AtomJavaScriptDialogManager : public content::JavaScriptDialogManager { bool is_reload, const DialogClosedCallback& callback) override; void CancelDialogs(content::WebContents* web_contents, - bool suppress_callbacks, bool reset_state) override; private: diff --git a/atom/browser/atom_permission_manager.cc b/atom/browser/atom_permission_manager.cc index b22f4253237..e890618be73 100644 --- a/atom/browser/atom_permission_manager.cc +++ b/atom/browser/atom_permission_manager.cc @@ -131,7 +131,7 @@ int AtomPermissionManager::RequestPermissions( auto web_contents = content::WebContents::FromRenderFrameHost(render_frame_host); - int request_id = pending_requests_.Add(new PendingRequest( + int request_id = pending_requests_.Add(base::MakeUnique( render_frame_host, permissions, response_callback)); for (size_t i = 0; i < permissions.size(); ++i) { @@ -187,12 +187,6 @@ blink::mojom::PermissionStatus AtomPermissionManager::GetPermissionStatus( return blink::mojom::PermissionStatus::GRANTED; } -void AtomPermissionManager::RegisterPermissionUsage( - content::PermissionType permission, - const GURL& requesting_origin, - const GURL& embedding_origin) { -} - int AtomPermissionManager::SubscribePermissionStatusChange( content::PermissionType permission, const GURL& requesting_origin, diff --git a/atom/browser/atom_permission_manager.h b/atom/browser/atom_permission_manager.h index 7b74fe3fba4..b8a768a0794 100644 --- a/atom/browser/atom_permission_manager.h +++ b/atom/browser/atom_permission_manager.h @@ -66,9 +66,6 @@ class AtomPermissionManager : public content::PermissionManager { content::PermissionType permission, const GURL& requesting_origin, const GURL& embedding_origin) override; - void RegisterPermissionUsage(content::PermissionType permission, - const GURL& requesting_origin, - const GURL& embedding_origin) override; int SubscribePermissionStatusChange( content::PermissionType permission, const GURL& requesting_origin, @@ -79,7 +76,7 @@ class AtomPermissionManager : public content::PermissionManager { private: class PendingRequest; - using PendingRequestsMap = IDMap; + using PendingRequestsMap = IDMap>; RequestHandler request_handler_; diff --git a/atom/browser/common_web_contents_delegate_mac.mm b/atom/browser/common_web_contents_delegate_mac.mm index c7660613793..079d17624c9 100644 --- a/atom/browser/common_web_contents_delegate_mac.mm +++ b/atom/browser/common_web_contents_delegate_mac.mm @@ -20,7 +20,7 @@ void CommonWebContentsDelegate::HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) { if (event.skip_in_browser || - event.type == content::NativeWebKeyboardEvent::Char) + event.type() == content::NativeWebKeyboardEvent::Char) return; // Escape exits tabbed fullscreen mode. diff --git a/atom/browser/net/atom_url_request_job_factory.cc b/atom/browser/net/atom_url_request_job_factory.cc index 92c4eb40a97..e4ff930aa63 100644 --- a/atom/browser/net/atom_url_request_job_factory.cc +++ b/atom/browser/net/atom_url_request_job_factory.cc @@ -50,15 +50,16 @@ bool AtomURLRequestJobFactory::InterceptProtocol( return false; ProtocolHandler* original_protocol_handler = protocol_handler_map_[scheme]; protocol_handler_map_[scheme] = protocol_handler.release(); - original_protocols_.set(scheme, base::WrapUnique(original_protocol_handler)); + original_protocols_[scheme] = std::move(original_protocol_handler); return true; } bool AtomURLRequestJobFactory::UninterceptProtocol(const std::string& scheme) { - if (!original_protocols_.contains(scheme)) + auto it = original_protocols_.find(scheme); + if (it == original_protocols_.end()) return false; - protocol_handler_map_[scheme] = - original_protocols_.take_and_erase(scheme).release(); + protocol_handler_map_[scheme] = std::move(it->second); + original_protocols_.erase(it); return true; } diff --git a/atom/browser/net/atom_url_request_job_factory.h b/atom/browser/net/atom_url_request_job_factory.h index 5b439c2f9cd..16d1ed3b207 100644 --- a/atom/browser/net/atom_url_request_job_factory.h +++ b/atom/browser/net/atom_url_request_job_factory.h @@ -9,9 +9,9 @@ #include #include #include +#include #include -#include "base/containers/scoped_ptr_hash_map.h" #include "net/url_request/url_request_job_factory.h" namespace atom { @@ -64,7 +64,7 @@ class AtomURLRequestJobFactory : public net::URLRequestJobFactory { ProtocolHandlerMap protocol_handler_map_; // Map that stores the original protocols of schemes. - using OriginalProtocolsMap = base::ScopedPtrHashMap< + using OriginalProtocolsMap = std::unordered_map< std::string, std::unique_ptr>; // Can only be accessed in IO thread. OriginalProtocolsMap original_protocols_; diff --git a/atom/browser/net/js_asker.cc b/atom/browser/net/js_asker.cc index 67fb578650f..a7c2eb50b44 100644 --- a/atom/browser/net/js_asker.cc +++ b/atom/browser/net/js_asker.cc @@ -59,7 +59,7 @@ void AskForOptions(v8::Isolate* isolate, } bool IsErrorOptions(base::Value* value, int* error) { - if (value->IsType(base::Value::TYPE_DICTIONARY)) { + if (value->IsType(base::Value::TYPE::DICTIONARY)) { base::DictionaryValue* dict = static_cast(value); if (dict->GetInteger("error", error)) return true; diff --git a/atom/browser/net/url_request_async_asar_job.cc b/atom/browser/net/url_request_async_asar_job.cc index 942f06233e3..f1b978287f3 100644 --- a/atom/browser/net/url_request_async_asar_job.cc +++ b/atom/browser/net/url_request_async_asar_job.cc @@ -18,7 +18,7 @@ URLRequestAsyncAsarJob::URLRequestAsyncAsarJob( void URLRequestAsyncAsarJob::StartAsync(std::unique_ptr options) { base::FilePath::StringType file_path; - if (options->IsType(base::Value::TYPE_DICTIONARY)) { + if (options->IsType(base::Value::TYPE::DICTIONARY)) { static_cast(options.get())->GetString( "path", &file_path); } else if (options->IsType(base::Value::TYPE_STRING)) { diff --git a/atom/browser/net/url_request_buffer_job.cc b/atom/browser/net/url_request_buffer_job.cc index 70f46030817..670a276dad5 100644 --- a/atom/browser/net/url_request_buffer_job.cc +++ b/atom/browser/net/url_request_buffer_job.cc @@ -34,7 +34,7 @@ URLRequestBufferJob::URLRequestBufferJob( void URLRequestBufferJob::StartAsync(std::unique_ptr options) { const base::BinaryValue* binary = nullptr; - if (options->IsType(base::Value::TYPE_DICTIONARY)) { + if (options->IsType(base::Value::TYPE::DICTIONARY)) { base::DictionaryValue* dict = static_cast(options.get()); dict->GetString("mimeType", &mime_type_); diff --git a/atom/browser/net/url_request_fetch_job.cc b/atom/browser/net/url_request_fetch_job.cc index a8c13483e6a..e69ca56fe3a 100644 --- a/atom/browser/net/url_request_fetch_job.cc +++ b/atom/browser/net/url_request_fetch_job.cc @@ -112,7 +112,7 @@ void URLRequestFetchJob::BeforeStartInUI( } void URLRequestFetchJob::StartAsync(std::unique_ptr options) { - if (!options->IsType(base::Value::TYPE_DICTIONARY)) { + if (!options->IsType(base::Value::TYPE::DICTIONARY)) { NotifyStartError(net::URLRequestStatus( net::URLRequestStatus::FAILED, net::ERR_NOT_IMPLEMENTED)); return; diff --git a/atom/browser/net/url_request_string_job.cc b/atom/browser/net/url_request_string_job.cc index abec345e63d..b212e0d4b3b 100644 --- a/atom/browser/net/url_request_string_job.cc +++ b/atom/browser/net/url_request_string_job.cc @@ -17,7 +17,7 @@ URLRequestStringJob::URLRequestStringJob( } void URLRequestStringJob::StartAsync(std::unique_ptr options) { - if (options->IsType(base::Value::TYPE_DICTIONARY)) { + if (options->IsType(base::Value::TYPE::DICTIONARY)) { base::DictionaryValue* dict = static_cast(options.get()); dict->GetString("mimeType", &mime_type_); diff --git a/atom/common/asar/archive.cc b/atom/common/asar/archive.cc index a3a02996d40..d94c97fe3b4 100644 --- a/atom/common/asar/archive.cc +++ b/atom/common/asar/archive.cc @@ -181,7 +181,7 @@ bool Archive::Init() { std::string error; base::JSONReader reader; std::unique_ptr value(reader.ReadToValue(header)); - if (!value || !value->IsType(base::Value::TYPE_DICTIONARY)) { + if (!value || !value->IsType(base::Value::TYPE::DICTIONARY)) { LOG(ERROR) << "Failed to parse header: " << error; return false; } @@ -269,8 +269,9 @@ bool Archive::Realpath(const base::FilePath& path, base::FilePath* realpath) { } bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) { - if (external_files_.contains(path)) { - *out = external_files_.get(path)->path(); + auto it = external_files_.find(path.value()); + if (it != external_files_.end()) { + *out = it->second->path(); return true; } @@ -296,7 +297,7 @@ bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) { #endif *out = temp_file->path(); - external_files_.set(path, std::move(temp_file)); + external_files_[path.value()] = std::move(temp_file); return true; } diff --git a/atom/common/asar/archive.h b/atom/common/asar/archive.h index 9e3abc3434d..4796d1014b7 100644 --- a/atom/common/asar/archive.h +++ b/atom/common/asar/archive.h @@ -6,9 +6,9 @@ #define ATOM_COMMON_ASAR_ARCHIVE_H_ #include +#include #include -#include "base/containers/scoped_ptr_hash_map.h" #include "base/files/file.h" #include "base/files/file_path.h" @@ -75,8 +75,8 @@ class Archive { std::unique_ptr header_; // Cached external temporary files. - base::ScopedPtrHashMap> - external_files_; + std::unordered_map> external_files_; DISALLOW_COPY_AND_ASSIGN(Archive); }; diff --git a/atom/common/native_mate_converters/v8_value_converter.cc b/atom/common/native_mate_converters/v8_value_converter.cc index 3ba30e14ff4..975527a8380 100644 --- a/atom/common/native_mate_converters/v8_value_converter.cc +++ b/atom/common/native_mate_converters/v8_value_converter.cc @@ -198,7 +198,7 @@ v8::Local V8ValueConverter::ToV8ValueImpl( case base::Value::TYPE_LIST: return ToV8Array(isolate, static_cast(value)); - case base::Value::TYPE_DICTIONARY: + case base::Value::TYPE::DICTIONARY: return ToV8Object(isolate, static_cast(value)); diff --git a/atom/common/native_mate_converters/value_converter.cc b/atom/common/native_mate_converters/value_converter.cc index c3c7ae0383c..c535a06d042 100644 --- a/atom/common/native_mate_converters/value_converter.cc +++ b/atom/common/native_mate_converters/value_converter.cc @@ -15,7 +15,7 @@ bool Converter::FromV8(v8::Isolate* isolate, std::unique_ptr converter(new atom::V8ValueConverter); std::unique_ptr value(converter->FromV8Value( val, isolate->GetCurrentContext())); - if (value && value->IsType(base::Value::TYPE_DICTIONARY)) { + if (value && value->IsType(base::Value::TYPE::DICTIONARY)) { out->Swap(static_cast(value.get())); return true; } else { diff --git a/chromium_src/chrome/renderer/media/chrome_key_systems.cc b/chromium_src/chrome/renderer/media/chrome_key_systems.cc index 206ac400fba..87b5c43e7fb 100644 --- a/chromium_src/chrome/renderer/media/chrome_key_systems.cc +++ b/chromium_src/chrome/renderer/media/chrome_key_systems.cc @@ -66,11 +66,11 @@ class ExternalClearKeyProperties : public KeySystemProperties { return true; case media::EmeInitDataType::CENC: -#if defined(USE_PROPRIETARY_CODECS) +#if BUILDFLAG(USE_PROPRIETARY_CODECS) return true; #else return false; -#endif // defined(USE_PROPRIETARY_CODECS) +#endif // BUILDFLAG(USE_PROPRIETARY_CODECS) case media::EmeInitDataType::UNKNOWN: return false; @@ -80,7 +80,7 @@ class ExternalClearKeyProperties : public KeySystemProperties { } SupportedCodecs GetSupportedCodecs() const override { -#if defined(USE_PROPRIETARY_CODECS) +#if BUILDFLAG(USE_PROPRIETARY_CODECS) return media::EME_CODEC_MP4_ALL | media::EME_CODEC_WEBM_ALL; #else return media::EME_CODEC_WEBM_ALL; @@ -224,21 +224,21 @@ static void AddPepperBasedWidevine( // as those may offer a higher level of protection. supported_codecs |= media::EME_CODEC_WEBM_OPUS; supported_codecs |= media::EME_CODEC_WEBM_VORBIS; -#if defined(USE_PROPRIETARY_CODECS) +#if BUILDFLAG(USE_PROPRIETARY_CODECS) supported_codecs |= media::EME_CODEC_MP4_AAC; -#endif // defined(USE_PROPRIETARY_CODECS) +#endif // BUILDFLAG(USE_PROPRIETARY_CODECS) for (size_t i = 0; i < codecs.size(); ++i) { if (codecs[i] == kCdmSupportedCodecVp8) supported_codecs |= media::EME_CODEC_WEBM_VP8; if (codecs[i] == kCdmSupportedCodecVp9) supported_codecs |= media::EME_CODEC_WEBM_VP9; -#if defined(USE_PROPRIETARY_CODECS) +#if BUILDFLAG(USE_PROPRIETARY_CODECS) if (codecs[i] == kCdmSupportedCodecAvc1) supported_codecs |= media::EME_CODEC_MP4_AVC1; if (codecs[i] == kCdmSupportedCodecVp9) supported_codecs |= media::EME_CODEC_MP4_VP9; -#endif // defined(USE_PROPRIETARY_CODECS) +#endif // BUILDFLAG(USE_PROPRIETARY_CODECS) } using Robustness = cdm::WidevineKeySystemProperties::Robustness; diff --git a/electron.gyp b/electron.gyp index ce3673abf11..9d4d7e6de80 100644 --- a/electron.gyp +++ b/electron.gyp @@ -237,9 +237,6 @@ 'USING_V8_SHARED', 'USING_V8_PLATFORM_SHARED', 'USING_V8_BASE_SHARED', - # Remove this after enable_plugins becomes a feature flag. - 'ENABLE_PLUGINS', - 'USE_PROPRIETARY_CODECS', ], 'sources': [ '<@(lib_sources)', diff --git a/vendor/crashpad b/vendor/crashpad index eeac857dfb5..4054e6cba3b 160000 --- a/vendor/crashpad +++ b/vendor/crashpad @@ -1 +1 @@ -Subproject commit eeac857dfb5b255c899c8763d62654863b4c8890 +Subproject commit 4054e6cba3ba023d9c00260518ec2912607ae17c diff --git a/vendor/node b/vendor/node index 3fe90cfcf54..42eee8a6926 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 3fe90cfcf54dd946980e59daf550a7cdb2317c8f +Subproject commit 42eee8a69267191ac20505bf929bb39a688d7385 From 9d1b88ed593f6568de523b0bca1126f7b4d8a1e9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 5 Apr 2017 17:31:22 +0900 Subject: [PATCH 1048/1195] Fix API changes in OSR code --- atom/browser/api/frame_subscriber.cc | 5 +- atom/browser/api/frame_subscriber.h | 2 +- .../osr/osr_render_widget_host_view.cc | 144 ++++++++++++------ .../browser/osr/osr_render_widget_host_view.h | 39 +++-- .../osr/osr_render_widget_host_view_mac.mm | 6 +- atom/browser/osr/osr_web_contents_view.cc | 5 +- 6 files changed, 132 insertions(+), 69 deletions(-) diff --git a/atom/browser/api/frame_subscriber.cc b/atom/browser/api/frame_subscriber.cc index b5009e15794..652596af15f 100644 --- a/atom/browser/api/frame_subscriber.cc +++ b/atom/browser/api/frame_subscriber.cc @@ -32,8 +32,7 @@ bool FrameSubscriber::ShouldCaptureFrame( base::TimeTicks present_time, scoped_refptr* storage, DeliverFrameCallback* callback) { - const auto host = view_ ? view_->GetRenderWidgetHost() : nullptr; - if (!view_ || !host) + if (!view_) return false; if (dirty_rect.IsEmpty()) @@ -54,7 +53,7 @@ bool FrameSubscriber::ShouldCaptureFrame( rect = gfx::Rect(rect.origin(), bitmap_size); - host->CopyFromBackingStore( + view_->CopyFromSurface( rect, rect.size(), base::Bind(&FrameSubscriber::OnFrameDelivered, diff --git a/atom/browser/api/frame_subscriber.h b/atom/browser/api/frame_subscriber.h index f1c7f0af45e..a32864c1774 100644 --- a/atom/browser/api/frame_subscriber.h +++ b/atom/browser/api/frame_subscriber.h @@ -7,9 +7,9 @@ #include "base/callback.h" #include "base/memory/weak_ptr.h" +#include "content/browser/renderer_host/render_widget_host_view_frame_subscriber.h" #include "content/public/browser/readback_types.h" #include "content/public/browser/render_widget_host_view.h" -#include "content/public/browser/render_widget_host_view_frame_subscriber.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/gfx/geometry/size.h" #include "v8/include/v8.h" diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index 2003118f389..c41a6805c06 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -16,10 +16,11 @@ #include "components/display_compositor/gl_helper.h" #include "content/browser/renderer_host/render_widget_host_delegate.h" #include "content/browser/renderer_host/render_widget_host_impl.h" +#include "content/browser/renderer_host/render_widget_host_view_frame_subscriber.h" #include "content/common/view_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/context_factory.h" -#include "content/public/browser/render_widget_host_view_frame_subscriber.h" +#include "media/base/video_frame.h" #include "ui/compositor/compositor.h" #include "ui/compositor/layer.h" #include "ui/compositor/layer_type.h" @@ -337,6 +338,7 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( bool transparent, const OnPaintCallback& callback, content::RenderWidgetHost* host, + bool is_guest_view_hack, NativeWindow* native_window) : render_widget_host_(content::RenderWidgetHostImpl::From(host)), native_window_(native_window), @@ -355,19 +357,23 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( render_widget_host_->SetView(this); #if !defined(OS_MACOSX) - content::ImageTransportFactory* factory = - content::ImageTransportFactory::GetInstance(); delegated_frame_host_ = base::MakeUnique( - factory->GetContextFactory()->AllocateFrameSinkId(), this); + AllocateFrameSinkId(is_guest_view_hack), this); root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); #endif #if defined(OS_MACOSX) - CreatePlatformWidget(); + CreatePlatformWidget(is_guest_view_hack); #else + // On macOS the ui::Compositor is created/owned by the platform view. + content::ImageTransportFactory* factory = + content::ImageTransportFactory::GetInstance(); + ui::ContextFactoryPrivate* context_factory_private = + factory->GetContextFactoryPrivate(); compositor_.reset( - new ui::Compositor(content::GetContextFactory(), + new ui::Compositor(context_factory_private->AllocateFrameSinkId(), + content::GetContextFactory(), context_factory_private, base::ThreadTaskRunnerHandle::Get())); compositor_->SetAcceleratedWidget(native_window_->GetAcceleratedWidget()); compositor_->SetRootLayer(root_layer_.get()); @@ -399,6 +405,17 @@ OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() { #endif } +void OffScreenRenderWidgetHostView::OnWindowResize() { + // In offscreen mode call RenderWidgetHostView's SetSize explicitly + auto size = native_window_->GetSize(); + SetSize(size); +} + +void OffScreenRenderWidgetHostView::OnWindowClosed() { + native_window_->RemoveObserver(this); + native_window_ = nullptr; +} + void OffScreenRenderWidgetHostView::OnBeginFrameTimerTick() { const base::TimeTicks frame_time = base::TimeTicks::Now(); const base::TimeDelta vsync_period = @@ -416,10 +433,17 @@ void OffScreenRenderWidgetHostView::SendBeginFrame( base::TimeTicks deadline = display_time - estimated_browser_composite_time; + const cc::BeginFrameArgs& begin_frame_args = + cc::BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, + begin_frame_source_.source_id(), + begin_frame_number_, frame_time, deadline, + vsync_period, cc::BeginFrameArgs::NORMAL); + DCHECK(begin_frame_args.IsValid()); + begin_frame_number_++; + render_widget_host_->Send(new ViewMsg_BeginFrame( render_widget_host_->GetRoutingID(), - cc::BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline, - vsync_period, cc::BeginFrameArgs::NORMAL))); + begin_frame_args)); } bool OffScreenRenderWidgetHostView::OnMessageReceived( @@ -481,7 +505,7 @@ bool OffScreenRenderWidgetHostView::HasFocus() const { } bool OffScreenRenderWidgetHostView::IsSurfaceAvailableForCopy() const { - return GetDelegatedFrameHost()->CanCopyToBitmap(); + return GetDelegatedFrameHost()->CanCopyFromCompositingSurface(); } void OffScreenRenderWidgetHostView::Show() { @@ -561,7 +585,7 @@ void OffScreenRenderWidgetHostView::OnSwapCompositorFrame( last_scroll_offset_ = frame.metadata.root_scroll_offset; } - if (frame.delegated_frame_data) { + if (!frame.render_pass_list.empty()) { if (software_output_device_) { if (!begin_frame_timer_.get()) { software_output_device_->SetActive(painting_); @@ -569,13 +593,11 @@ void OffScreenRenderWidgetHostView::OnSwapCompositorFrame( // The compositor will draw directly to the SoftwareOutputDevice which // then calls OnPaint. -#if defined(OS_MACOSX) - browser_compositor_->SwapCompositorFrame(output_surface_id, - std::move(frame)); -#else - delegated_frame_host_->SwapDelegatedFrame(output_surface_id, - std::move(frame)); -#endif + // We would normally call BrowserCompositorMac::SwapCompositorFrame on + // macOS, however it contains compositor resize logic that we don't want. + // Consequently we instead call the SwapDelegatedFrame method directly. + GetDelegatedFrameHost()->SwapDelegatedFrame(output_surface_id, + std::move(frame)); } else { if (!copy_frame_generator_.get()) { copy_frame_generator_.reset( @@ -584,20 +606,17 @@ void OffScreenRenderWidgetHostView::OnSwapCompositorFrame( // Determine the damage rectangle for the current frame. This is the same // calculation that SwapDelegatedFrame uses. - cc::RenderPass* root_pass = - frame.delegated_frame_data->render_pass_list.back().get(); + cc::RenderPass* root_pass = frame.render_pass_list.back().get(); gfx::Size frame_size = root_pass->output_rect.size(); gfx::Rect damage_rect = gfx::ToEnclosingRect(gfx::RectF(root_pass->damage_rect)); damage_rect.Intersect(gfx::Rect(frame_size)); -#if defined(OS_MACOSX) - browser_compositor_->SwapCompositorFrame(output_surface_id, - std::move(frame)); -#else - delegated_frame_host_->SwapDelegatedFrame(output_surface_id, - std::move(frame)); -#endif + // We would normally call BrowserCompositorMac::SwapCompositorFrame on + // macOS, however it contains compositor resize logic that we don't want. + // Consequently we instead call the SwapDelegatedFrame method directly. + GetDelegatedFrameHost()->SwapDelegatedFrame(output_surface_id, + std::move(frame)); // Request a copy of the last compositor frame which will eventually call // OnPaint asynchronously. @@ -647,7 +666,7 @@ void OffScreenRenderWidgetHostView::SelectionBoundsChanged( const ViewHostMsg_SelectionBounds_Params &) { } -void OffScreenRenderWidgetHostView::CopyFromCompositingSurface( +void OffScreenRenderWidgetHostView::CopyFromSurface( const gfx::Rect& src_subrect, const gfx::Size& dst_size, const content::ReadbackRequestCallback& callback, @@ -656,18 +675,14 @@ void OffScreenRenderWidgetHostView::CopyFromCompositingSurface( src_subrect, dst_size, callback, preferred_color_type); } -void OffScreenRenderWidgetHostView::CopyFromCompositingSurfaceToVideoFrame( +void OffScreenRenderWidgetHostView::CopyFromSurfaceToVideoFrame( const gfx::Rect& src_subrect, - const scoped_refptr& target, + scoped_refptr target, const base::Callback& callback) { GetDelegatedFrameHost()->CopyFromCompositingSurfaceToVideoFrame( src_subrect, target, callback); } -bool OffScreenRenderWidgetHostView::CanCopyToVideoFrame() const { - return GetDelegatedFrameHost()->CanCopyToVideoFrame(); -} - void OffScreenRenderWidgetHostView::BeginFrameSubscription( std::unique_ptr subscriber) { GetDelegatedFrameHost()->BeginFrameSubscription(std::move(subscriber)); @@ -685,12 +700,6 @@ gfx::Rect OffScreenRenderWidgetHostView::GetBoundsInRootWindow() { return gfx::Rect(size_); } -void OffScreenRenderWidgetHostView::LockCompositingSurface() { -} - -void OffScreenRenderWidgetHostView::UnlockCompositingSurface() { -} - void OffScreenRenderWidgetHostView::ImeCompositionRangeChanged( const gfx::Range &, const std::vector&) { } @@ -752,6 +761,40 @@ void OffScreenRenderWidgetHostView::SetBeginFrameSource( #endif // !defined(OS_MACOSX) +bool OffScreenRenderWidgetHostView::TransformPointToLocalCoordSpace( + const gfx::Point& point, + const cc::SurfaceId& original_surface, + gfx::Point* transformed_point) { + // Transformations use physical pixels rather than DIP, so conversion + // is necessary. + gfx::Point point_in_pixels = + gfx::ConvertPointToPixel(scale_factor_, point); + if (!GetDelegatedFrameHost()->TransformPointToLocalCoordSpace( + point_in_pixels, original_surface, transformed_point)) { + return false; + } + + *transformed_point = + gfx::ConvertPointToDIP(scale_factor_, *transformed_point); + return true; +} + +bool OffScreenRenderWidgetHostView::TransformPointToCoordSpaceForView( + const gfx::Point& point, + RenderWidgetHostViewBase* target_view, + gfx::Point* transformed_point) { + if (target_view == this) { + *transformed_point = point; + return true; + } + + // In TransformPointToLocalCoordSpace() there is a Point-to-Pixel conversion, + // but it is not necessary here because the final target view is responsible + // for converting before computing the final transform. + return GetDelegatedFrameHost()->TransformPointToCoordSpaceForView( + point, target_view, transformed_point); +} + std::unique_ptr OffScreenRenderWidgetHostView::CreateSoftwareOutputDevice( ui::Compositor* compositor) { @@ -894,15 +937,20 @@ void OffScreenRenderWidgetHostView::ResizeRootLayer() { GetCompositor()->SetScaleAndSize(scale_factor_, size_in_pixels); } -void OffScreenRenderWidgetHostView::OnWindowResize() { - // In offscreen mode call RenderWidgetHostView's SetSize explicitly - auto size = native_window_->GetSize(); - SetSize(size); -} - -void OffScreenRenderWidgetHostView::OnWindowClosed() { - native_window_->RemoveObserver(this); - native_window_ = nullptr; +cc::FrameSinkId OffScreenRenderWidgetHostView::AllocateFrameSinkId( + bool is_guest_view_hack) { + // GuestViews have two RenderWidgetHostViews and so we need to make sure + // we don't have FrameSinkId collisions. + // The FrameSinkId generated here must be unique with FrameSinkId allocated + // in ContextFactoryPrivate. + content::ImageTransportFactory* factory = + content::ImageTransportFactory::GetInstance(); + return is_guest_view_hack + ? factory->GetContextFactoryPrivate()->AllocateFrameSinkId() + : cc::FrameSinkId(base::checked_cast( + render_widget_host_->GetProcess()->GetID()), + base::checked_cast( + render_widget_host_->GetRoutingID())); } } // namespace atom diff --git a/atom/browser/osr/osr_render_widget_host_view.h b/atom/browser/osr/osr_render_widget_host_view.h index 7380476bee6..d215d73ab9c 100644 --- a/atom/browser/osr/osr_render_widget_host_view.h +++ b/atom/browser/osr/osr_render_widget_host_view.h @@ -69,6 +69,7 @@ class OffScreenRenderWidgetHostView OffScreenRenderWidgetHostView(bool transparent, const OnPaintCallback& callback, content::RenderWidgetHost* render_widget_host, + bool is_guest_view_hack, NativeWindow* native_window); ~OffScreenRenderWidgetHostView() override; @@ -126,23 +127,20 @@ class OffScreenRenderWidgetHostView #endif void SelectionBoundsChanged(const ViewHostMsg_SelectionBounds_Params &) override; - void CopyFromCompositingSurface(const gfx::Rect &, - const gfx::Size &, - const content::ReadbackRequestCallback &, - const SkColorType) override; - void CopyFromCompositingSurfaceToVideoFrame( - const gfx::Rect &, - const scoped_refptr &, - const base::Callback &) override; - bool CanCopyToVideoFrame(void) const override; + void CopyFromSurface( + const gfx::Rect& src_subrect, + const gfx::Size& dst_size, + const content::ReadbackRequestCallback& callback, + const SkColorType color_type) override; + void CopyFromSurfaceToVideoFrame( + const gfx::Rect& src_subrect, + scoped_refptr target, + const base::Callback& callback) override; void BeginFrameSubscription( std::unique_ptr) override; void EndFrameSubscription() override; bool HasAcceleratedSurface(const gfx::Size &) override; gfx::Rect GetBoundsInRootWindow(void) override; - void LockCompositingSurface(void) override; - void UnlockCompositingSurface(void) override; void ImeCompositionRangeChanged( const gfx::Range &, const std::vector&) override; gfx::Size GetPhysicalBackingSize() const override; @@ -166,6 +164,15 @@ class OffScreenRenderWidgetHostView void SetBeginFrameSource(cc::BeginFrameSource* source) override; #endif // !defined(OS_MACOSX) + bool TransformPointToLocalCoordSpace( + const gfx::Point& point, + const cc::SurfaceId& original_surface, + gfx::Point* transformed_point) override; + bool TransformPointToCoordSpaceForView( + const gfx::Point& point, + RenderWidgetHostViewBase* target_view, + gfx::Point* transformed_point) override; + // ui::CompositorDelegate: std::unique_ptr CreateSoftwareOutputDevice( ui::Compositor* compositor) override; @@ -182,7 +189,7 @@ class OffScreenRenderWidgetHostView base::TimeDelta vsync_period); #if defined(OS_MACOSX) - void CreatePlatformWidget(); + void CreatePlatformWidget(bool is_guest_view_hack); void DestroyPlatformWidget(); #endif @@ -210,6 +217,8 @@ class OffScreenRenderWidgetHostView void SetupFrameRate(bool force); void ResizeRootLayer(); + cc::FrameSinkId AllocateFrameSinkId(bool is_guest_view_hack); + // Weak ptrs. content::RenderWidgetHostImpl* render_widget_host_; NativeWindow* native_window_; @@ -236,6 +245,10 @@ class OffScreenRenderWidgetHostView std::unique_ptr copy_frame_generator_; std::unique_ptr begin_frame_timer_; + // Provides |source_id| for BeginFrameArgs that we create. + cc::StubBeginFrameSource begin_frame_source_; + uint64_t begin_frame_number_ = cc::BeginFrameArgs::kStartingFrameNumber; + #if defined(OS_MACOSX) CALayer* background_layer_; std::unique_ptr browser_compositor_; diff --git a/atom/browser/osr/osr_render_widget_host_view_mac.mm b/atom/browser/osr/osr_render_widget_host_view_mac.mm index 7cf010ff8e2..8e13c2c577d 100644 --- a/atom/browser/osr/osr_render_widget_host_view_mac.mm +++ b/atom/browser/osr/osr_render_widget_host_view_mac.mm @@ -121,10 +121,12 @@ void OffScreenRenderWidgetHostView::SelectionChanged( RenderWidgetHostViewBase::SelectionChanged(text, offset, range); } -void OffScreenRenderWidgetHostView::CreatePlatformWidget() { +void OffScreenRenderWidgetHostView::CreatePlatformWidget( + bool is_guest_view_hack) { mac_helper_ = new MacHelper(this); browser_compositor_.reset(new content::BrowserCompositorMac( - mac_helper_, mac_helper_, render_widget_host_->is_hidden(), true)); + mac_helper_, mac_helper_, render_widget_host_->is_hidden(), true, + AllocateFrameSinkId(is_guest_view_hack))); } void OffScreenRenderWidgetHostView::DestroyPlatformWidget() { diff --git a/atom/browser/osr/osr_web_contents_view.cc b/atom/browser/osr/osr_web_contents_view.cc index 0d9c52743bc..8d95017b0e6 100644 --- a/atom/browser/osr/osr_web_contents_view.cc +++ b/atom/browser/osr/osr_web_contents_view.cc @@ -79,7 +79,8 @@ content::RenderWidgetHostViewBase* content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { auto relay = NativeWindowRelay::FromWebContents(web_contents_); view_ = new OffScreenRenderWidgetHostView( - transparent_, callback_, render_widget_host, relay->window.get()); + transparent_, callback_, render_widget_host, + is_guest_view_hack, relay->window.get()); return view_; } @@ -88,7 +89,7 @@ content::RenderWidgetHostViewBase* content::RenderWidgetHost* render_widget_host) { auto relay = NativeWindowRelay::FromWebContents(web_contents_); view_ = new OffScreenRenderWidgetHostView( - transparent_, callback_, render_widget_host, relay->window.get()); + transparent_, callback_, render_widget_host, false, relay->window.get()); return view_; } From 50e3bfa764ca3116069cff45ab218e8e38b9e3eb Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 5 Apr 2017 17:34:53 +0900 Subject: [PATCH 1049/1195] Fix API changes of base::Value --- atom/browser/api/atom_api_web_contents.cc | 2 +- atom/browser/common_web_contents_delegate.cc | 12 +++++----- atom/browser/native_window_views.cc | 2 +- atom/browser/net/asar/url_request_asar_job.cc | 2 +- atom/browser/net/js_asker.cc | 4 ++-- .../browser/net/url_request_async_asar_job.cc | 4 ++-- atom/browser/net/url_request_buffer_job.cc | 4 ++-- atom/browser/net/url_request_fetch_job.cc | 2 +- atom/browser/net/url_request_string_job.cc | 4 ++-- atom/browser/node_debugger.cc | 2 +- atom/browser/ui/accelerator_util.cc | 2 +- atom/browser/ui/cocoa/atom_menu_controller.mm | 6 ++--- atom/browser/ui/views/global_menu_bar_x11.cc | 10 ++++---- atom/browser/ui/views/menu_bar.cc | 4 ++-- atom/browser/ui/webui/pdf_viewer_handler.cc | 8 +++---- atom/common/asar/archive.cc | 2 +- .../native_mate_converters/blink_converter.h | 2 +- .../content_converter.cc | 8 +++---- .../v8_value_converter.cc | 24 +++++++++---------- .../v8_value_converter.h | 2 +- .../native_mate_converters/value_converter.cc | 4 ++-- 21 files changed, 55 insertions(+), 55 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index d3e7bae2e41..3152fd33fb4 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -877,7 +877,7 @@ void WebContents::DevToolsOpened() { devtools_web_contents_.Reset(isolate(), handle.ToV8()); // Set inspected tabID. - base::FundamentalValue tab_id(ID()); + base::Value tab_id(ID()); managed_web_contents()->CallClientFunction( "DevToolsAPI.setInspectedTabId", &tab_id, nullptr, nullptr); diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index a10f959dce9..a9312901229 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -489,9 +489,9 @@ void CommonWebContentsDelegate::OnDevToolsIndexingWorkCalculated( int request_id, const std::string& file_system_path, int total_work) { - base::FundamentalValue request_id_value(request_id); + base::Value request_id_value(request_id); base::StringValue file_system_path_value(file_system_path); - base::FundamentalValue total_work_value(total_work); + base::Value total_work_value(total_work); web_contents_->CallClientFunction("DevToolsAPI.indexingTotalWorkCalculated", &request_id_value, &file_system_path_value, @@ -502,9 +502,9 @@ void CommonWebContentsDelegate::OnDevToolsIndexingWorked( int request_id, const std::string& file_system_path, int worked) { - base::FundamentalValue request_id_value(request_id); + base::Value request_id_value(request_id); base::StringValue file_system_path_value(file_system_path); - base::FundamentalValue worked_value(worked); + base::Value worked_value(worked); web_contents_->CallClientFunction("DevToolsAPI.indexingWorked", &request_id_value, &file_system_path_value, @@ -515,7 +515,7 @@ void CommonWebContentsDelegate::OnDevToolsIndexingDone( int request_id, const std::string& file_system_path) { devtools_indexing_jobs_.erase(request_id); - base::FundamentalValue request_id_value(request_id); + base::Value request_id_value(request_id); base::StringValue file_system_path_value(file_system_path); web_contents_->CallClientFunction("DevToolsAPI.indexingDone", &request_id_value, @@ -531,7 +531,7 @@ void CommonWebContentsDelegate::OnDevToolsSearchCompleted( for (const auto& file_path : file_paths) { file_paths_value.AppendString(file_path); } - base::FundamentalValue request_id_value(request_id); + base::Value request_id_value(request_id); base::StringValue file_system_path_value(file_system_path); web_contents_->CallClientFunction("DevToolsAPI.searchCompleted", &request_id_value, diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 7e6f23947c2..1b6c4ff2ad8 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -187,7 +187,7 @@ NativeWindowViews::NativeWindowViews( params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.bounds = bounds; params.delegate = this; - params.type = views::Widget::InitParams::TYPE_WINDOW; + params.type = views::Widget::InitParams::Type::WINDOW; params.remove_standard_frame = !has_frame(); if (transparent()) diff --git a/atom/browser/net/asar/url_request_asar_job.cc b/atom/browser/net/asar/url_request_asar_job.cc index 8bacf1124bf..def6dd71dea 100644 --- a/atom/browser/net/asar/url_request_asar_job.cc +++ b/atom/browser/net/asar/url_request_asar_job.cc @@ -185,7 +185,7 @@ std::unique_ptr URLRequestAsarJob::SetUpSourceStream() { // Bug 9936 - .svgz files needs to be decompressed. return base::LowerCaseEqualsASCII(file_path_.Extension(), ".svgz") ? net::GzipSourceStream::Create(std::move(source), - net::SourceStream::TYPE_GZIP) + net::SourceStream::Type::GZIP) : std::move(source); } diff --git a/atom/browser/net/js_asker.cc b/atom/browser/net/js_asker.cc index a7c2eb50b44..0df6bb5c37d 100644 --- a/atom/browser/net/js_asker.cc +++ b/atom/browser/net/js_asker.cc @@ -59,11 +59,11 @@ void AskForOptions(v8::Isolate* isolate, } bool IsErrorOptions(base::Value* value, int* error) { - if (value->IsType(base::Value::TYPE::DICTIONARY)) { + if (value->IsType(base::Value::Type::DICTIONARY)) { base::DictionaryValue* dict = static_cast(value); if (dict->GetInteger("error", error)) return true; - } else if (value->IsType(base::Value::TYPE_INTEGER)) { + } else if (value->IsType(base::Value::Type::INTEGER)) { if (value->GetAsInteger(error)) return true; } diff --git a/atom/browser/net/url_request_async_asar_job.cc b/atom/browser/net/url_request_async_asar_job.cc index f1b978287f3..bfe862a3738 100644 --- a/atom/browser/net/url_request_async_asar_job.cc +++ b/atom/browser/net/url_request_async_asar_job.cc @@ -18,10 +18,10 @@ URLRequestAsyncAsarJob::URLRequestAsyncAsarJob( void URLRequestAsyncAsarJob::StartAsync(std::unique_ptr options) { base::FilePath::StringType file_path; - if (options->IsType(base::Value::TYPE::DICTIONARY)) { + if (options->IsType(base::Value::Type::DICTIONARY)) { static_cast(options.get())->GetString( "path", &file_path); - } else if (options->IsType(base::Value::TYPE_STRING)) { + } else if (options->IsType(base::Value::Type::STRING)) { options->GetAsString(&file_path); } diff --git a/atom/browser/net/url_request_buffer_job.cc b/atom/browser/net/url_request_buffer_job.cc index 670a276dad5..fa848862bb2 100644 --- a/atom/browser/net/url_request_buffer_job.cc +++ b/atom/browser/net/url_request_buffer_job.cc @@ -34,13 +34,13 @@ URLRequestBufferJob::URLRequestBufferJob( void URLRequestBufferJob::StartAsync(std::unique_ptr options) { const base::BinaryValue* binary = nullptr; - if (options->IsType(base::Value::TYPE::DICTIONARY)) { + if (options->IsType(base::Value::Type::DICTIONARY)) { base::DictionaryValue* dict = static_cast(options.get()); dict->GetString("mimeType", &mime_type_); dict->GetString("charset", &charset_); dict->GetBinary("data", &binary); - } else if (options->IsType(base::Value::TYPE_BINARY)) { + } else if (options->IsType(base::Value::Type::BINARY)) { options->GetAsBinary(&binary); } diff --git a/atom/browser/net/url_request_fetch_job.cc b/atom/browser/net/url_request_fetch_job.cc index e69ca56fe3a..ff426dd08c8 100644 --- a/atom/browser/net/url_request_fetch_job.cc +++ b/atom/browser/net/url_request_fetch_job.cc @@ -112,7 +112,7 @@ void URLRequestFetchJob::BeforeStartInUI( } void URLRequestFetchJob::StartAsync(std::unique_ptr options) { - if (!options->IsType(base::Value::TYPE::DICTIONARY)) { + if (!options->IsType(base::Value::Type::DICTIONARY)) { NotifyStartError(net::URLRequestStatus( net::URLRequestStatus::FAILED, net::ERR_NOT_IMPLEMENTED)); return; diff --git a/atom/browser/net/url_request_string_job.cc b/atom/browser/net/url_request_string_job.cc index b212e0d4b3b..60dc323d8ad 100644 --- a/atom/browser/net/url_request_string_job.cc +++ b/atom/browser/net/url_request_string_job.cc @@ -17,13 +17,13 @@ URLRequestStringJob::URLRequestStringJob( } void URLRequestStringJob::StartAsync(std::unique_ptr options) { - if (options->IsType(base::Value::TYPE::DICTIONARY)) { + if (options->IsType(base::Value::Type::DICTIONARY)) { base::DictionaryValue* dict = static_cast(options.get()); dict->GetString("mimeType", &mime_type_); dict->GetString("charset", &charset_); dict->GetString("data", &data_); - } else if (options->IsType(base::Value::TYPE_STRING)) { + } else if (options->IsType(base::Value::Type::STRING)) { options->GetAsString(&data_); } net::URLRequestSimpleJob::Start(); diff --git a/atom/browser/node_debugger.cc b/atom/browser/node_debugger.cc index 9fdeb6099e6..b16af201243 100644 --- a/atom/browser/node_debugger.cc +++ b/atom/browser/node_debugger.cc @@ -58,7 +58,7 @@ NodeDebugger::NodeDebugger(v8::Isolate* isolate) // Start a new IO thread. base::Thread::Options options; - options.message_loop_type = base::MessageLoop::TYPE_IO; + options.message_loop_type = base::MessageLoop::Type::IO; if (!thread_.StartWithOptions(options)) { LOG(ERROR) << "Unable to start debugger thread"; return; diff --git a/atom/browser/ui/accelerator_util.cc b/atom/browser/ui/accelerator_util.cc index 9ebc4e10849..3efe269ca44 100644 --- a/atom/browser/ui/accelerator_util.cc +++ b/atom/browser/ui/accelerator_util.cc @@ -73,7 +73,7 @@ void GenerateAcceleratorTable(AcceleratorTable* table, int count = model->GetItemCount(); for (int i = 0; i < count; ++i) { atom::AtomMenuModel::ItemType type = model->GetTypeAt(i); - if (type == atom::AtomMenuModel::TYPE_SUBMENU) { + if (type == atom::AtomMenuModel::Type::SUBMENU) { auto submodel = model->GetSubmenuModelAt(i); GenerateAcceleratorTable(table, submodel); } else { diff --git a/atom/browser/ui/cocoa/atom_menu_controller.mm b/atom/browser/ui/cocoa/atom_menu_controller.mm index d0bbf6a153a..7d1612fd01e 100644 --- a/atom/browser/ui/cocoa/atom_menu_controller.mm +++ b/atom/browser/ui/cocoa/atom_menu_controller.mm @@ -87,7 +87,7 @@ Role kRolesMap[] = { const int count = model->GetItemCount(); for (int index = 0; index < count; index++) { - if (model->GetTypeAt(index) == atom::AtomMenuModel::TYPE_SEPARATOR) + if (model->GetTypeAt(index) == atom::AtomMenuModel::Type::SEPARATOR) [self addSeparatorToMenu:menu_ atIndex:index]; else [self addItemToMenu:menu_ atIndex:index fromModel:model]; @@ -109,7 +109,7 @@ Role kRolesMap[] = { const int count = model->GetItemCount(); for (int index = 0; index < count; index++) { - if (model->GetTypeAt(index) == atom::AtomMenuModel::TYPE_SEPARATOR) + if (model->GetTypeAt(index) == atom::AtomMenuModel::Type::SEPARATOR) [self addSeparatorToMenu:menu atIndex:index]; else [self addItemToMenu:menu atIndex:index fromModel:model]; @@ -145,7 +145,7 @@ Role kRolesMap[] = { [item setImage:icon.ToNSImage()]; atom::AtomMenuModel::ItemType type = model->GetTypeAt(index); - if (type == atom::AtomMenuModel::TYPE_SUBMENU) { + if (type == atom::AtomMenuModel::Type::SUBMENU) { // Recursively build a submenu from the sub-model at this index. [item setTarget:nil]; [item setAction:nil]; diff --git a/atom/browser/ui/views/global_menu_bar_x11.cc b/atom/browser/ui/views/global_menu_bar_x11.cc index 266d10b96db..f489fa0d469 100644 --- a/atom/browser/ui/views/global_menu_bar_x11.cc +++ b/atom/browser/ui/views/global_menu_bar_x11.cc @@ -225,7 +225,7 @@ void GlobalMenuBarX11::BuildMenuFromModel(AtomMenuModel* model, menuitem_property_set_bool(item, kPropertyVisible, model->IsVisibleAt(i)); AtomMenuModel::ItemType type = model->GetTypeAt(i); - if (type == AtomMenuModel::TYPE_SEPARATOR) { + if (type == AtomMenuModel::Type::SEPARATOR) { menuitem_property_set(item, kPropertyType, kTypeSeparator); } else { std::string label = ui::ConvertAcceleratorsFromWindowsStyle( @@ -236,7 +236,7 @@ void GlobalMenuBarX11::BuildMenuFromModel(AtomMenuModel* model, g_object_set_data(G_OBJECT(item), "model", model); SetMenuItemID(item, i); - if (type == AtomMenuModel::TYPE_SUBMENU) { + if (type == AtomMenuModel::Type::SUBMENU) { menuitem_property_set(item, kPropertyChildrenDisplay, kDisplaySubmenu); g_signal_connect(item, "about-to-show", G_CALLBACK(OnSubMenuShowThunk), this); @@ -248,10 +248,10 @@ void GlobalMenuBarX11::BuildMenuFromModel(AtomMenuModel* model, g_signal_connect(item, "item-activated", G_CALLBACK(OnItemActivatedThunk), this); - if (type == AtomMenuModel::TYPE_CHECK || - type == AtomMenuModel::TYPE_RADIO) { + if (type == AtomMenuModel::Type::CHECK || + type == AtomMenuModel::Type::RADIO) { menuitem_property_set(item, kPropertyToggleType, - type == AtomMenuModel::TYPE_CHECK ? kToggleCheck : kToggleRadio); + type == AtomMenuModel::Type::CHECK ? kToggleCheck : kToggleRadio); menuitem_property_set_int(item, kPropertyToggleState, model->IsItemCheckedAt(i)); } diff --git a/atom/browser/ui/views/menu_bar.cc b/atom/browser/ui/views/menu_bar.cc index 5d9b7152788..fc65d10099b 100644 --- a/atom/browser/ui/views/menu_bar.cc +++ b/atom/browser/ui/views/menu_bar.cc @@ -120,7 +120,7 @@ bool MenuBar::GetMenuButtonFromScreenPoint(const gfx::Point& point, for (int i = 0; i < child_count(); ++i) { views::View* view = child_at(i); if (view->bounds().Contains(location) && - (menu_model_->GetTypeAt(i) == AtomMenuModel::TYPE_SUBMENU)) { + (menu_model_->GetTypeAt(i) == AtomMenuModel::Type::SUBMENU)) { *menu_model = menu_model_->GetSubmenuModelAt(i); *button = static_cast(view); return true; @@ -148,7 +148,7 @@ void MenuBar::OnMenuButtonClicked(views::MenuButton* source, int id = source->tag(); AtomMenuModel::ItemType type = menu_model_->GetTypeAt(id); - if (type != AtomMenuModel::TYPE_SUBMENU) { + if (type != AtomMenuModel::Type::SUBMENU) { menu_model_->ActivatedAt(id, 0); return; } diff --git a/atom/browser/ui/webui/pdf_viewer_handler.cc b/atom/browser/ui/webui/pdf_viewer_handler.cc index be2f3373055..fd0ef538ba9 100644 --- a/atom/browser/ui/webui/pdf_viewer_handler.cc +++ b/atom/browser/ui/webui/pdf_viewer_handler.cc @@ -131,7 +131,7 @@ void PdfViewerHandler::GetDefaultZoom(const base::ListValue* args) { double zoom_level = host_zoom_map->GetDefaultZoomLevel(); ResolveJavascriptCallback( *callback_id, - base::FundamentalValue(content::ZoomLevelToZoomFactor(zoom_level))); + base::Value(content::ZoomLevelToZoomFactor(zoom_level))); } void PdfViewerHandler::GetInitialZoom(const base::ListValue* args) { @@ -145,7 +145,7 @@ void PdfViewerHandler::GetInitialZoom(const base::ListValue* args) { content::HostZoomMap::GetZoomLevel(web_ui()->GetWebContents()); ResolveJavascriptCallback( *callback_id, - base::FundamentalValue(content::ZoomLevelToZoomFactor(zoom_level))); + base::Value(content::ZoomLevelToZoomFactor(zoom_level))); } void PdfViewerHandler::SetZoom(const base::ListValue* args) { @@ -159,7 +159,7 @@ void PdfViewerHandler::SetZoom(const base::ListValue* args) { content::HostZoomMap::SetZoomLevel(web_ui()->GetWebContents(), zoom_level); - ResolveJavascriptCallback(*callback_id, base::FundamentalValue(zoom_level)); + ResolveJavascriptCallback(*callback_id, base::Value(zoom_level)); } void PdfViewerHandler::GetStrings(const base::ListValue* args) { @@ -204,7 +204,7 @@ void PdfViewerHandler::OnZoomLevelChanged( if (change.host == kPdfViewerUIHost) { CallJavascriptFunction( "cr.webUIListenerCallback", base::StringValue("onZoomLevelChanged"), - base::FundamentalValue( + base::Value( content::ZoomLevelToZoomFactor(change.zoom_level))); } } diff --git a/atom/common/asar/archive.cc b/atom/common/asar/archive.cc index d94c97fe3b4..8f75c8fbb57 100644 --- a/atom/common/asar/archive.cc +++ b/atom/common/asar/archive.cc @@ -181,7 +181,7 @@ bool Archive::Init() { std::string error; base::JSONReader reader; std::unique_ptr value(reader.ReadToValue(header)); - if (!value || !value->IsType(base::Value::TYPE::DICTIONARY)) { + if (!value || !value->IsType(base::Value::Type::DICTIONARY)) { LOG(ERROR) << "Failed to parse header: " << error; return false; } diff --git a/atom/common/native_mate_converters/blink_converter.h b/atom/common/native_mate_converters/blink_converter.h index 34156f313e5..7b3a14e8307 100644 --- a/atom/common/native_mate_converters/blink_converter.h +++ b/atom/common/native_mate_converters/blink_converter.h @@ -6,7 +6,7 @@ #define ATOM_COMMON_NATIVE_MATE_CONVERTERS_BLINK_CONVERTER_H_ #include "native_mate/converter.h" -#include "third_party/WebKit/public/web/WebCache.h" +#include "third_party/WebKit/public/platform/WebCache.h" #include "third_party/WebKit/public/web/WebContextMenuData.h" namespace blink { diff --git a/atom/common/native_mate_converters/content_converter.cc b/atom/common/native_mate_converters/content_converter.cc index 7869e37deee..7ebf4c45d94 100644 --- a/atom/common/native_mate_converters/content_converter.cc +++ b/atom/common/native_mate_converters/content_converter.cc @@ -213,13 +213,13 @@ Converter>::ToV8( std::unique_ptr post_data_dict( new base::DictionaryValue); auto type = element.type(); - if (type == ResourceRequestBodyImpl::Element::TYPE_BYTES) { + if (type == ResourceRequestBodyImpl::Element::Type::BYTES) { std::unique_ptr bytes( base::BinaryValue::CreateWithCopiedBuffer( element.bytes(), static_cast(element.length()))); post_data_dict->SetString("type", "rawData"); post_data_dict->Set("bytes", std::move(bytes)); - } else if (type == ResourceRequestBodyImpl::Element::TYPE_FILE) { + } else if (type == ResourceRequestBodyImpl::Element::Type::FILE) { post_data_dict->SetString("type", "file"); post_data_dict->SetStringWithoutPathExpansion( "filePath", element.path().AsUTF8Unsafe()); @@ -227,7 +227,7 @@ Converter>::ToV8( post_data_dict->SetInteger("length", static_cast(element.length())); post_data_dict->SetDouble( "modificationTime", element.expected_modification_time().ToDoubleT()); - } else if (type == ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM) { + } else if (type == ResourceRequestBodyImpl::Element::Type::FILE_FILESYSTEM) { post_data_dict->SetString("type", "fileSystem"); post_data_dict->SetStringWithoutPathExpansion( "fileSystemURL", element.filesystem_url().spec()); @@ -235,7 +235,7 @@ Converter>::ToV8( post_data_dict->SetInteger("length", static_cast(element.length())); post_data_dict->SetDouble( "modificationTime", element.expected_modification_time().ToDoubleT()); - } else if (type == ResourceRequestBodyImpl::Element::TYPE_BLOB) { + } else if (type == ResourceRequestBodyImpl::Element::Type::BLOB) { post_data_dict->SetString("type", "blob"); post_data_dict->SetString("blobUUID", element.blob_uuid()); } diff --git a/atom/common/native_mate_converters/v8_value_converter.cc b/atom/common/native_mate_converters/v8_value_converter.cc index 975527a8380..0286723a9df 100644 --- a/atom/common/native_mate_converters/v8_value_converter.cc +++ b/atom/common/native_mate_converters/v8_value_converter.cc @@ -167,42 +167,42 @@ base::Value* V8ValueConverter::FromV8Value( v8::Local V8ValueConverter::ToV8ValueImpl( v8::Isolate* isolate, const base::Value* value) const { switch (value->GetType()) { - case base::Value::TYPE_NULL: + case base::Value::Type::NULL: return v8::Null(isolate); - case base::Value::TYPE_BOOLEAN: { + case base::Value::Type::BOOLEAN: { bool val = false; value->GetAsBoolean(&val); return v8::Boolean::New(isolate, val); } - case base::Value::TYPE_INTEGER: { + case base::Value::Type::INTEGER: { int val = 0; value->GetAsInteger(&val); return v8::Integer::New(isolate, val); } - case base::Value::TYPE_DOUBLE: { + case base::Value::Type::DOUBLE: { double val = 0.0; value->GetAsDouble(&val); return v8::Number::New(isolate, val); } - case base::Value::TYPE_STRING: { + case base::Value::Type::STRING: { std::string val; value->GetAsString(&val); return v8::String::NewFromUtf8( isolate, val.c_str(), v8::String::kNormalString, val.length()); } - case base::Value::TYPE_LIST: + case base::Value::Type::LIST: return ToV8Array(isolate, static_cast(value)); - case base::Value::TYPE::DICTIONARY: + case base::Value::Type::DICTIONARY: return ToV8Object(isolate, static_cast(value)); - case base::Value::TYPE_BINARY: + case base::Value::Type::BINARY: return ToArrayBuffer(isolate, static_cast(value)); @@ -314,13 +314,13 @@ base::Value* V8ValueConverter::FromV8ValueImpl( return base::Value::CreateNullValue().release(); if (val->IsBoolean()) - return new base::FundamentalValue(val->ToBoolean()->Value()); + return new base::Value(val->ToBoolean()->Value()); if (val->IsInt32()) - return new base::FundamentalValue(val->ToInt32()->Value()); + return new base::Value(val->ToInt32()->Value()); if (val->IsNumber()) - return new base::FundamentalValue(val->ToNumber()->Value()); + return new base::Value(val->ToNumber()->Value()); if (val->IsString()) { v8::String::Utf8Value utf8(val->ToString()); @@ -490,7 +490,7 @@ base::Value* V8ValueConverter::FromV8Object( // there *is* a "windowId" property, but since it should be an int, code // on the browser which doesn't additionally check for null will fail. // We can avoid all bugs related to this by stripping null. - if (strip_null_from_objects_ && child->IsType(base::Value::TYPE_NULL)) + if (strip_null_from_objects_ && child->IsType(base::Value::Type::NULL)) continue; result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), diff --git a/atom/common/native_mate_converters/v8_value_converter.h b/atom/common/native_mate_converters/v8_value_converter.h index 2b8dcf85964..ae6113cfeb0 100644 --- a/atom/common/native_mate_converters/v8_value_converter.h +++ b/atom/common/native_mate_converters/v8_value_converter.h @@ -10,10 +10,10 @@ #include "v8/include/v8.h" namespace base { -class BinaryValue; class DictionaryValue; class ListValue; class Value; +using BinaryValue = Value; } namespace atom { diff --git a/atom/common/native_mate_converters/value_converter.cc b/atom/common/native_mate_converters/value_converter.cc index c535a06d042..3ed68136709 100644 --- a/atom/common/native_mate_converters/value_converter.cc +++ b/atom/common/native_mate_converters/value_converter.cc @@ -15,7 +15,7 @@ bool Converter::FromV8(v8::Isolate* isolate, std::unique_ptr converter(new atom::V8ValueConverter); std::unique_ptr value(converter->FromV8Value( val, isolate->GetCurrentContext())); - if (value && value->IsType(base::Value::TYPE::DICTIONARY)) { + if (value && value->IsType(base::Value::Type::DICTIONARY)) { out->Swap(static_cast(value.get())); return true; } else { @@ -36,7 +36,7 @@ bool Converter::FromV8(v8::Isolate* isolate, std::unique_ptr converter(new atom::V8ValueConverter); std::unique_ptr value(converter->FromV8Value( val, isolate->GetCurrentContext())); - if (value->IsType(base::Value::TYPE_LIST)) { + if (value->IsType(base::Value::Type::LIST)) { out->Swap(static_cast(value.get())); return true; } else { From 6be10ffef290d13c195f0e3f65ab869fbe6eb74e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 5 Apr 2017 18:02:06 +0900 Subject: [PATCH 1050/1195] Fix more API changes due to name changes --- atom/browser/native_window_mac.mm | 2 +- atom/browser/native_window_views.cc | 2 +- atom/browser/net/asar/url_request_asar_job.cc | 2 +- atom/browser/net/atom_url_request_job_factory.cc | 7 ++++--- atom/browser/net/url_request_async_asar_job.cc | 1 + atom/browser/node_debugger.cc | 2 +- atom/browser/osr/osr_output_device.cc | 2 +- atom/browser/ui/accelerator_util.cc | 2 +- atom/browser/ui/cocoa/atom_menu_controller.mm | 6 +++--- atom/browser/ui/views/global_menu_bar_x11.cc | 10 +++++----- atom/browser/ui/views/menu_bar.cc | 4 ++-- atom/browser/ui/webui/pdf_viewer_handler.cc | 5 ++--- atom/common/native_mate_converters/blink_converter.cc | 1 - .../common/native_mate_converters/content_converter.cc | 8 ++++---- .../native_mate_converters/v8_value_converter.cc | 4 ++-- atom/renderer/api/atom_api_web_frame.h | 2 +- 16 files changed, 30 insertions(+), 30 deletions(-) diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 9dc119e239d..330d48226dc 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1458,7 +1458,7 @@ void NativeWindowMac::SetEscapeTouchBarItem(const mate::PersistentDictionary& it } void NativeWindowMac::OnInputEvent(const blink::WebInputEvent& event) { - switch (event.type) { + switch (event.type()) { case blink::WebInputEvent::GestureScrollBegin: case blink::WebInputEvent::GestureScrollUpdate: case blink::WebInputEvent::GestureScrollEnd: diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 1b6c4ff2ad8..7e6f23947c2 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -187,7 +187,7 @@ NativeWindowViews::NativeWindowViews( params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.bounds = bounds; params.delegate = this; - params.type = views::Widget::InitParams::Type::WINDOW; + params.type = views::Widget::InitParams::TYPE_WINDOW; params.remove_standard_frame = !has_frame(); if (transparent()) diff --git a/atom/browser/net/asar/url_request_asar_job.cc b/atom/browser/net/asar/url_request_asar_job.cc index def6dd71dea..8bacf1124bf 100644 --- a/atom/browser/net/asar/url_request_asar_job.cc +++ b/atom/browser/net/asar/url_request_asar_job.cc @@ -185,7 +185,7 @@ std::unique_ptr URLRequestAsarJob::SetUpSourceStream() { // Bug 9936 - .svgz files needs to be decompressed. return base::LowerCaseEqualsASCII(file_path_.Extension(), ".svgz") ? net::GzipSourceStream::Create(std::move(source), - net::SourceStream::Type::GZIP) + net::SourceStream::TYPE_GZIP) : std::move(source); } diff --git a/atom/browser/net/atom_url_request_job_factory.cc b/atom/browser/net/atom_url_request_job_factory.cc index e4ff930aa63..2348e1a6b44 100644 --- a/atom/browser/net/atom_url_request_job_factory.cc +++ b/atom/browser/net/atom_url_request_job_factory.cc @@ -50,7 +50,7 @@ bool AtomURLRequestJobFactory::InterceptProtocol( return false; ProtocolHandler* original_protocol_handler = protocol_handler_map_[scheme]; protocol_handler_map_[scheme] = protocol_handler.release(); - original_protocols_[scheme] = std::move(original_protocol_handler); + original_protocols_[scheme].reset(original_protocol_handler); return true; } @@ -58,7 +58,7 @@ bool AtomURLRequestJobFactory::UninterceptProtocol(const std::string& scheme) { auto it = original_protocols_.find(scheme); if (it == original_protocols_.end()) return false; - protocol_handler_map_[scheme] = std::move(it->second); + protocol_handler_map_[scheme] = it->second.release(); original_protocols_.erase(it); return true; } @@ -79,7 +79,8 @@ bool AtomURLRequestJobFactory::HasProtocolHandler( } void AtomURLRequestJobFactory::Clear() { - base::STLDeleteValues(&protocol_handler_map_); + for (auto& it : protocol_handler_map_) + delete it.second; } net::URLRequestJob* AtomURLRequestJobFactory::MaybeCreateJobWithProtocolHandler( diff --git a/atom/browser/net/url_request_async_asar_job.cc b/atom/browser/net/url_request_async_asar_job.cc index bfe862a3738..86aa7c55067 100644 --- a/atom/browser/net/url_request_async_asar_job.cc +++ b/atom/browser/net/url_request_async_asar_job.cc @@ -7,6 +7,7 @@ #include #include "atom/common/atom_constants.h" +#include "base/threading/sequenced_worker_pool.h" namespace atom { diff --git a/atom/browser/node_debugger.cc b/atom/browser/node_debugger.cc index b16af201243..9fdeb6099e6 100644 --- a/atom/browser/node_debugger.cc +++ b/atom/browser/node_debugger.cc @@ -58,7 +58,7 @@ NodeDebugger::NodeDebugger(v8::Isolate* isolate) // Start a new IO thread. base::Thread::Options options; - options.message_loop_type = base::MessageLoop::Type::IO; + options.message_loop_type = base::MessageLoop::TYPE_IO; if (!thread_.StartWithOptions(options)) { LOG(ERROR) << "Unable to start debugger thread"; return; diff --git a/atom/browser/osr/osr_output_device.cc b/atom/browser/osr/osr_output_device.cc index 5f605f668c9..49c4191e21e 100644 --- a/atom/browser/osr/osr_output_device.cc +++ b/atom/browser/osr/osr_output_device.cc @@ -4,7 +4,7 @@ #include "atom/browser/osr/osr_output_device.h" -#include "third_party/skia/include/core/SkDevice.h" +#include "third_party/skia/src/core/SkDevice.h" #include "ui/gfx/skia_util.h" namespace atom { diff --git a/atom/browser/ui/accelerator_util.cc b/atom/browser/ui/accelerator_util.cc index 3efe269ca44..9ebc4e10849 100644 --- a/atom/browser/ui/accelerator_util.cc +++ b/atom/browser/ui/accelerator_util.cc @@ -73,7 +73,7 @@ void GenerateAcceleratorTable(AcceleratorTable* table, int count = model->GetItemCount(); for (int i = 0; i < count; ++i) { atom::AtomMenuModel::ItemType type = model->GetTypeAt(i); - if (type == atom::AtomMenuModel::Type::SUBMENU) { + if (type == atom::AtomMenuModel::TYPE_SUBMENU) { auto submodel = model->GetSubmenuModelAt(i); GenerateAcceleratorTable(table, submodel); } else { diff --git a/atom/browser/ui/cocoa/atom_menu_controller.mm b/atom/browser/ui/cocoa/atom_menu_controller.mm index 7d1612fd01e..d0bbf6a153a 100644 --- a/atom/browser/ui/cocoa/atom_menu_controller.mm +++ b/atom/browser/ui/cocoa/atom_menu_controller.mm @@ -87,7 +87,7 @@ Role kRolesMap[] = { const int count = model->GetItemCount(); for (int index = 0; index < count; index++) { - if (model->GetTypeAt(index) == atom::AtomMenuModel::Type::SEPARATOR) + if (model->GetTypeAt(index) == atom::AtomMenuModel::TYPE_SEPARATOR) [self addSeparatorToMenu:menu_ atIndex:index]; else [self addItemToMenu:menu_ atIndex:index fromModel:model]; @@ -109,7 +109,7 @@ Role kRolesMap[] = { const int count = model->GetItemCount(); for (int index = 0; index < count; index++) { - if (model->GetTypeAt(index) == atom::AtomMenuModel::Type::SEPARATOR) + if (model->GetTypeAt(index) == atom::AtomMenuModel::TYPE_SEPARATOR) [self addSeparatorToMenu:menu atIndex:index]; else [self addItemToMenu:menu atIndex:index fromModel:model]; @@ -145,7 +145,7 @@ Role kRolesMap[] = { [item setImage:icon.ToNSImage()]; atom::AtomMenuModel::ItemType type = model->GetTypeAt(index); - if (type == atom::AtomMenuModel::Type::SUBMENU) { + if (type == atom::AtomMenuModel::TYPE_SUBMENU) { // Recursively build a submenu from the sub-model at this index. [item setTarget:nil]; [item setAction:nil]; diff --git a/atom/browser/ui/views/global_menu_bar_x11.cc b/atom/browser/ui/views/global_menu_bar_x11.cc index f489fa0d469..266d10b96db 100644 --- a/atom/browser/ui/views/global_menu_bar_x11.cc +++ b/atom/browser/ui/views/global_menu_bar_x11.cc @@ -225,7 +225,7 @@ void GlobalMenuBarX11::BuildMenuFromModel(AtomMenuModel* model, menuitem_property_set_bool(item, kPropertyVisible, model->IsVisibleAt(i)); AtomMenuModel::ItemType type = model->GetTypeAt(i); - if (type == AtomMenuModel::Type::SEPARATOR) { + if (type == AtomMenuModel::TYPE_SEPARATOR) { menuitem_property_set(item, kPropertyType, kTypeSeparator); } else { std::string label = ui::ConvertAcceleratorsFromWindowsStyle( @@ -236,7 +236,7 @@ void GlobalMenuBarX11::BuildMenuFromModel(AtomMenuModel* model, g_object_set_data(G_OBJECT(item), "model", model); SetMenuItemID(item, i); - if (type == AtomMenuModel::Type::SUBMENU) { + if (type == AtomMenuModel::TYPE_SUBMENU) { menuitem_property_set(item, kPropertyChildrenDisplay, kDisplaySubmenu); g_signal_connect(item, "about-to-show", G_CALLBACK(OnSubMenuShowThunk), this); @@ -248,10 +248,10 @@ void GlobalMenuBarX11::BuildMenuFromModel(AtomMenuModel* model, g_signal_connect(item, "item-activated", G_CALLBACK(OnItemActivatedThunk), this); - if (type == AtomMenuModel::Type::CHECK || - type == AtomMenuModel::Type::RADIO) { + if (type == AtomMenuModel::TYPE_CHECK || + type == AtomMenuModel::TYPE_RADIO) { menuitem_property_set(item, kPropertyToggleType, - type == AtomMenuModel::Type::CHECK ? kToggleCheck : kToggleRadio); + type == AtomMenuModel::TYPE_CHECK ? kToggleCheck : kToggleRadio); menuitem_property_set_int(item, kPropertyToggleState, model->IsItemCheckedAt(i)); } diff --git a/atom/browser/ui/views/menu_bar.cc b/atom/browser/ui/views/menu_bar.cc index fc65d10099b..5d9b7152788 100644 --- a/atom/browser/ui/views/menu_bar.cc +++ b/atom/browser/ui/views/menu_bar.cc @@ -120,7 +120,7 @@ bool MenuBar::GetMenuButtonFromScreenPoint(const gfx::Point& point, for (int i = 0; i < child_count(); ++i) { views::View* view = child_at(i); if (view->bounds().Contains(location) && - (menu_model_->GetTypeAt(i) == AtomMenuModel::Type::SUBMENU)) { + (menu_model_->GetTypeAt(i) == AtomMenuModel::TYPE_SUBMENU)) { *menu_model = menu_model_->GetSubmenuModelAt(i); *button = static_cast(view); return true; @@ -148,7 +148,7 @@ void MenuBar::OnMenuButtonClicked(views::MenuButton* source, int id = source->tag(); AtomMenuModel::ItemType type = menu_model_->GetTypeAt(id); - if (type != AtomMenuModel::Type::SUBMENU) { + if (type != AtomMenuModel::TYPE_SUBMENU) { menu_model_->ActivatedAt(id, 0); return; } diff --git a/atom/browser/ui/webui/pdf_viewer_handler.cc b/atom/browser/ui/webui/pdf_viewer_handler.cc index fd0ef538ba9..5829b59f6d3 100644 --- a/atom/browser/ui/webui/pdf_viewer_handler.cc +++ b/atom/browser/ui/webui/pdf_viewer_handler.cc @@ -33,9 +33,8 @@ void CreateResponseHeadersDictionary(const net::HttpResponseHeaders* headers, while (headers->EnumerateHeaderLines(&iter, &header_name, &header_value)) { base::Value* existing_value = nullptr; if (result->Get(header_name, &existing_value)) { - base::StringValue* existing_string_value = - static_cast(existing_value); - existing_string_value->GetString()->append(", ").append(header_value); + std::string src = existing_value->GetString(); + result->SetString(header_name, src + ", " + header_value); } else { result->SetString(header_name, header_value); } diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index d4ee1e44891..5935c26899c 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -14,7 +14,6 @@ #include "content/public/browser/native_web_keyboard_event.h" #include "native_mate/dictionary.h" #include "third_party/WebKit/public/platform/WebInputEvent.h" -#include "third_party/WebKit/public/web/WebCache.h" #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" #include "third_party/WebKit/public/web/WebFindOptions.h" #include "ui/base/clipboard/clipboard.h" diff --git a/atom/common/native_mate_converters/content_converter.cc b/atom/common/native_mate_converters/content_converter.cc index 7ebf4c45d94..7869e37deee 100644 --- a/atom/common/native_mate_converters/content_converter.cc +++ b/atom/common/native_mate_converters/content_converter.cc @@ -213,13 +213,13 @@ Converter>::ToV8( std::unique_ptr post_data_dict( new base::DictionaryValue); auto type = element.type(); - if (type == ResourceRequestBodyImpl::Element::Type::BYTES) { + if (type == ResourceRequestBodyImpl::Element::TYPE_BYTES) { std::unique_ptr bytes( base::BinaryValue::CreateWithCopiedBuffer( element.bytes(), static_cast(element.length()))); post_data_dict->SetString("type", "rawData"); post_data_dict->Set("bytes", std::move(bytes)); - } else if (type == ResourceRequestBodyImpl::Element::Type::FILE) { + } else if (type == ResourceRequestBodyImpl::Element::TYPE_FILE) { post_data_dict->SetString("type", "file"); post_data_dict->SetStringWithoutPathExpansion( "filePath", element.path().AsUTF8Unsafe()); @@ -227,7 +227,7 @@ Converter>::ToV8( post_data_dict->SetInteger("length", static_cast(element.length())); post_data_dict->SetDouble( "modificationTime", element.expected_modification_time().ToDoubleT()); - } else if (type == ResourceRequestBodyImpl::Element::Type::FILE_FILESYSTEM) { + } else if (type == ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM) { post_data_dict->SetString("type", "fileSystem"); post_data_dict->SetStringWithoutPathExpansion( "fileSystemURL", element.filesystem_url().spec()); @@ -235,7 +235,7 @@ Converter>::ToV8( post_data_dict->SetInteger("length", static_cast(element.length())); post_data_dict->SetDouble( "modificationTime", element.expected_modification_time().ToDoubleT()); - } else if (type == ResourceRequestBodyImpl::Element::Type::BLOB) { + } else if (type == ResourceRequestBodyImpl::Element::TYPE_BLOB) { post_data_dict->SetString("type", "blob"); post_data_dict->SetString("blobUUID", element.blob_uuid()); } diff --git a/atom/common/native_mate_converters/v8_value_converter.cc b/atom/common/native_mate_converters/v8_value_converter.cc index 0286723a9df..65620bdb8ba 100644 --- a/atom/common/native_mate_converters/v8_value_converter.cc +++ b/atom/common/native_mate_converters/v8_value_converter.cc @@ -167,7 +167,7 @@ base::Value* V8ValueConverter::FromV8Value( v8::Local V8ValueConverter::ToV8ValueImpl( v8::Isolate* isolate, const base::Value* value) const { switch (value->GetType()) { - case base::Value::Type::NULL: + case base::Value::Type::NONE: return v8::Null(isolate); case base::Value::Type::BOOLEAN: { @@ -490,7 +490,7 @@ base::Value* V8ValueConverter::FromV8Object( // there *is* a "windowId" property, but since it should be an int, code // on the browser which doesn't additionally check for null will fail. // We can avoid all bugs related to this by stripping null. - if (strip_null_from_objects_ && child->IsType(base::Value::Type::NULL)) + if (strip_null_from_objects_ && child->IsType(base::Value::Type::NONE)) continue; result->SetWithoutPathExpansion(std::string(*name_utf8, name_utf8.length()), diff --git a/atom/renderer/api/atom_api_web_frame.h b/atom/renderer/api/atom_api_web_frame.h index a35b86cacfa..6c6d0b19f98 100644 --- a/atom/renderer/api/atom_api_web_frame.h +++ b/atom/renderer/api/atom_api_web_frame.h @@ -11,7 +11,7 @@ #include "atom/renderer/guest_view_container.h" #include "native_mate/handle.h" #include "native_mate/wrappable.h" -#include "third_party/WebKit/public/web/WebCache.h" +#include "third_party/WebKit/public/platform/WebCache.h" namespace blink { class WebLocalFrame; From 803120dae6690fe31b9a56e24d8a28b15b50c221 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 5 Apr 2017 18:03:07 +0900 Subject: [PATCH 1051/1195] Update libcc to fix missing gen/cc headers --- script/lib/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/lib/config.py b/script/lib/config.py index 1b8eac01344..747fbb31148 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -9,7 +9,7 @@ import sys BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \ 'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent' LIBCHROMIUMCONTENT_COMMIT = os.getenv('LIBCHROMIUMCONTENT_COMMIT') or \ - '8c3e532385811b5cea80e969c1beb1bf3ffb6777' + '1433d43a013f6029aec7c1263e1576ad9ab8a7a0' PLATFORM = { 'cygwin': 'win32', From 5fb87f0c1ed57d1b8ff66500bd1c9157d38dd9df Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Apr 2017 14:58:42 +0900 Subject: [PATCH 1052/1195] ResourceHandler API has been changed --- atom/browser/loader/layered_resource_handler.cc | 6 +++--- atom/browser/loader/layered_resource_handler.h | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/atom/browser/loader/layered_resource_handler.cc b/atom/browser/loader/layered_resource_handler.cc index 8b41b1ad638..c22ddd355de 100644 --- a/atom/browser/loader/layered_resource_handler.cc +++ b/atom/browser/loader/layered_resource_handler.cc @@ -15,12 +15,12 @@ LayeredResourceHandler::LayeredResourceHandler( LayeredResourceHandler::~LayeredResourceHandler() {} -bool LayeredResourceHandler::OnResponseStarted( +void LayeredResourceHandler::OnResponseStarted( content::ResourceResponse* response, - bool* defer) { + std::unique_ptr controller) { if (delegate_) delegate_->OnResponseStarted(response); - return next_handler_->OnResponseStarted(response, defer); + next_handler_->OnResponseStarted(response, std::move(controller)); } } // namespace atom diff --git a/atom/browser/loader/layered_resource_handler.h b/atom/browser/loader/layered_resource_handler.h index db3a974eea3..9aad269c7e6 100644 --- a/atom/browser/loader/layered_resource_handler.h +++ b/atom/browser/loader/layered_resource_handler.h @@ -26,8 +26,9 @@ class LayeredResourceHandler : public content::LayeredResourceHandler { ~LayeredResourceHandler() override; // content::LayeredResourceHandler: - bool OnResponseStarted(content::ResourceResponse* response, - bool* defer) override; + void OnResponseStarted( + content::ResourceResponse* response, + std::unique_ptr controller) override; private: Delegate* delegate_; From dd3d791cb99dba27b925aba108cc1e399be1a4a1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Apr 2017 15:01:57 +0900 Subject: [PATCH 1053/1195] IsolateHolder API has been changed --- atom/browser/javascript_environment.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/atom/browser/javascript_environment.cc b/atom/browser/javascript_environment.cc index b3e01c1c300..b7e3aae20aa 100644 --- a/atom/browser/javascript_environment.cc +++ b/atom/browser/javascript_environment.cc @@ -8,6 +8,7 @@ #include "base/command_line.h" #include "base/message_loop/message_loop.h" +#include "base/threading/thread_task_runner_handle.h" #include "content/public/common/content_switches.h" #include "gin/array_buffer.h" #include "gin/v8_initializer.h" @@ -18,6 +19,7 @@ namespace atom { JavascriptEnvironment::JavascriptEnvironment() : initialized_(Initialize()), + isolate_holder_(base::ThreadTaskRunnerHandle::Get()), isolate_(isolate_holder_.isolate()), isolate_scope_(isolate_), locker_(isolate_), From 8634f37dfce9a565a5063ae31d4e22361d366d46 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Apr 2017 15:15:19 +0900 Subject: [PATCH 1054/1195] Add gen/third_party/WebKit to include dirs --- atom/browser/api/atom_api_web_contents.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 3152fd33fb4..38bda34e5d9 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -554,8 +554,8 @@ bool WebContents::PreHandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { - if (event.type == blink::WebInputEvent::Type::RawKeyDown - || event.type == blink::WebInputEvent::Type::KeyUp) + if (event.type() == blink::WebInputEvent::Type::RawKeyDown || + event.type() == blink::WebInputEvent::Type::KeyUp) return Emit("before-input-event", event); else return false; From 481b04358e6f45cb4297ab965a6d7d1013827fae Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Apr 2017 16:18:40 +0900 Subject: [PATCH 1055/1195] Fix blink API changes --- atom/browser/api/atom_api_web_contents.cc | 2 +- atom/browser/ui/webui/pdf_viewer_ui.cc | 3 +- .../native_mate_converters/blink_converter.cc | 34 +++++++++++-------- .../api/atom_api_spell_check_client.cc | 8 ++--- .../api/atom_api_spell_check_client.h | 8 +++-- atom/renderer/api/atom_api_web_frame.cc | 15 ++++---- atom/renderer/atom_render_frame_observer.cc | 4 +-- atom/renderer/atom_render_frame_observer.h | 5 --- atom/renderer/atom_renderer_client.cc | 3 +- atom/renderer/renderer_client_base.cc | 7 ---- .../media/native_desktop_media_list.cc | 2 ++ 11 files changed, 42 insertions(+), 49 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 38bda34e5d9..8b46484b36e 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -950,7 +950,7 @@ void WebContents::NavigationEntryCommitted( int64_t WebContents::GetID() const { int64_t process_id = web_contents()->GetRenderProcessHost()->GetID(); - int64_t routing_id = web_contents()->GetRoutingID(); + int64_t routing_id = web_contents()->GetRenderViewHost()->GetRoutingID(); int64_t rv = (process_id << 32) + routing_id; return rv; } diff --git a/atom/browser/ui/webui/pdf_viewer_ui.cc b/atom/browser/ui/webui/pdf_viewer_ui.cc index 580d1831e58..c1b6dbfccfa 100644 --- a/atom/browser/ui/webui/pdf_viewer_ui.cc +++ b/atom/browser/ui/webui/pdf_viewer_ui.cc @@ -134,7 +134,8 @@ class PdfViewerUI::ResourceRequester content::ResourceDispatcherHostImpl::Get()->InitializeURLRequest( request.get(), content::Referrer(url, blink::WebReferrerPolicyDefault), false, // download. - render_process_id, render_view_id, render_frame_id, resource_context); + render_process_id, render_view_id, render_frame_id, + content::PREVIEWS_OFF, resource_context); content::ResourceRequestInfoImpl* info = content::ResourceRequestInfoImpl::ForRequest(request.get()); diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index 5935c26899c..6633ef887dc 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -14,6 +14,8 @@ #include "content/public/browser/native_web_keyboard_event.h" #include "native_mate/dictionary.h" #include "third_party/WebKit/public/platform/WebInputEvent.h" +#include "third_party/WebKit/public/platform/WebMouseEvent.h" +#include "third_party/WebKit/public/platform/WebMouseWheelEvent.h" #include "third_party/WebKit/public/web/WebDeviceEmulationParams.h" #include "third_party/WebKit/public/web/WebFindOptions.h" #include "ui/base/clipboard/clipboard.h" @@ -148,12 +150,14 @@ bool Converter::FromV8( mate::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; - if (!dict.Get("type", &out->type)) + blink::WebInputEvent::Type type; + if (!dict.Get("type", &type)) return false; + out->setType(type); std::vector modifiers; if (dict.Get("modifiers", &modifiers)) - out->modifiers = VectorToBitArray(modifiers); - out->timeStampSeconds = base::Time::Now().ToDoubleT(); + out->setModifiers(VectorToBitArray(modifiers)); + out->setTimeStampSeconds(base::Time::Now().ToDoubleT()); return true; } @@ -174,19 +178,19 @@ bool Converter::FromV8( ui::KeyboardCode keyCode = atom::KeyboardCodeFromStr(str, &shifted); out->windowsKeyCode = keyCode; if (shifted) - out->modifiers |= blink::WebInputEvent::ShiftKey; + out->setModifiers(out->modifiers() | blink::WebInputEvent::ShiftKey); ui::DomCode domCode = ui::UsLayoutKeyboardCodeToDomCode(keyCode); out->domCode = static_cast(domCode); ui::DomKey domKey; ui::KeyboardCode dummy_code; - int flags = atom::WebEventModifiersToEventFlags(out->modifiers); + int flags = atom::WebEventModifiersToEventFlags(out->modifiers()); if (ui::DomCodeToUsLayoutDomKey(domCode, flags, &domKey, &dummy_code)) out->domKey = static_cast(domKey); - if ((out->type == blink::WebInputEvent::Char || - out->type == blink::WebInputEvent::RawKeyDown)) { + if ((out->type() == blink::WebInputEvent::Char || + out->type() == blink::WebInputEvent::RawKeyDown)) { // Make sure to not read beyond the buffer in case some bad code doesn't // NULL-terminate it (this is called from plugins). size_t text_length_cap = blink::WebKeyboardEvent::textLengthCap; @@ -218,20 +222,20 @@ v8::Local Converter::ToV8( v8::Isolate* isolate, const content::NativeWebKeyboardEvent& in) { mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); - if (in.type == blink::WebInputEvent::Type::RawKeyDown) + if (in.type() == blink::WebInputEvent::Type::RawKeyDown) dict.Set("type", "keyDown"); - else if (in.type == blink::WebInputEvent::Type::KeyUp) + else if (in.type() == blink::WebInputEvent::Type::KeyUp) dict.Set("type", "keyUp"); dict.Set("key", ui::KeycodeConverter::DomKeyToKeyString(in.domKey)); dict.Set("code", ui::KeycodeConverter::DomCodeToCodeString( static_cast(in.domCode))); using Modifiers = blink::WebInputEvent::Modifiers; - dict.Set("isAutoRepeat", (in.modifiers & Modifiers::IsAutoRepeat) != 0); - dict.Set("shift", (in.modifiers & Modifiers::ShiftKey) != 0); - dict.Set("control", (in.modifiers & Modifiers::ControlKey) != 0); - dict.Set("alt", (in.modifiers & Modifiers::AltKey) != 0); - dict.Set("meta", (in.modifiers & Modifiers::MetaKey) != 0); + dict.Set("isAutoRepeat", (in.modifiers() & Modifiers::IsAutoRepeat) != 0); + dict.Set("shift", (in.modifiers() & Modifiers::ShiftKey) != 0); + dict.Set("control", (in.modifiers() & Modifiers::ControlKey) != 0); + dict.Set("alt", (in.modifiers() & Modifiers::AltKey) != 0); + dict.Set("meta", (in.modifiers() & Modifiers::MetaKey) != 0); return dict.GetHandle(); } @@ -443,7 +447,7 @@ v8::Local Converter::ToV8( mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate); dict.Set("count", static_cast(stat.count)); dict.Set("size", static_cast(stat.size)); - dict.Set("liveSize", static_cast(stat.liveSize)); + dict.Set("liveSize", static_cast(stat.decodedSize)); return dict.GetHandle(); } diff --git a/atom/renderer/api/atom_api_spell_check_client.cc b/atom/renderer/api/atom_api_spell_check_client.cc index 9a07cbf6eaa..8d434f1aa0c 100644 --- a/atom/renderer/api/atom_api_spell_check_client.cc +++ b/atom/renderer/api/atom_api_spell_check_client.cc @@ -51,13 +51,13 @@ SpellCheckClient::SpellCheckClient(const std::string& language, SpellCheckClient::~SpellCheckClient() {} -void SpellCheckClient::spellCheck( +void SpellCheckClient::checkSpelling( const blink::WebString& text, int& misspelling_start, int& misspelling_len, blink::WebVector* optional_suggestions) { std::vector results; - SpellCheckText(base::string16(text), true, &results); + SpellCheckText(text.utf16(), true, &results); if (results.size() == 1) { misspelling_start = results[0].location; misspelling_len = results[0].length; @@ -66,10 +66,8 @@ void SpellCheckClient::spellCheck( void SpellCheckClient::requestCheckingOfText( const blink::WebString& textToCheck, - const blink::WebVector& markersInText, - const blink::WebVector& markerOffsets, blink::WebTextCheckingCompletion* completionCallback) { - base::string16 text(textToCheck); + base::string16 text(textToCheck.utf16()); if (text.empty() || !HasWordCharacters(text, 0)) { completionCallback->didCancelCheckingText(); return; diff --git a/atom/renderer/api/atom_api_spell_check_client.h b/atom/renderer/api/atom_api_spell_check_client.h index aa6abb0f56b..cb4a36aadf0 100644 --- a/atom/renderer/api/atom_api_spell_check_client.h +++ b/atom/renderer/api/atom_api_spell_check_client.h @@ -13,6 +13,10 @@ #include "native_mate/scoped_persistent.h" #include "third_party/WebKit/public/web/WebSpellCheckClient.h" +namespace blink { +struct WebTextCheckingResult; +} + namespace atom { namespace api { @@ -27,15 +31,13 @@ class SpellCheckClient : public blink::WebSpellCheckClient { private: // blink::WebSpellCheckClient: - void spellCheck( + void checkSpelling( const blink::WebString& text, int& misspelledOffset, int& misspelledLength, blink::WebVector* optionalSuggestions) override; void requestCheckingOfText( const blink::WebString& textToCheck, - const blink::WebVector& markersInText, - const blink::WebVector& markerOffsets, blink::WebTextCheckingCompletion* completionCallback) override; void showSpellingUI(bool show) override; bool isShowingSpellingUI() override; diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index f103b89391d..77928724c05 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -16,7 +16,7 @@ #include "content/public/renderer/render_view.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" -#include "third_party/WebKit/public/web/WebCache.h" +#include "third_party/WebKit/public/platform/WebCache.h" #include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebFrameWidget.h" #include "third_party/WebKit/public/web/WebInputMethodController.h" @@ -110,7 +110,8 @@ void WebFrame::SetLayoutZoomLevelLimits(double min_level, double max_level) { v8::Local WebFrame::RegisterEmbedderCustomElement( const base::string16& name, v8::Local options) { blink::WebExceptionCode c = 0; - return web_frame_->document().registerEmbedderCustomElement(name, options, c); + return web_frame_->document().registerEmbedderCustomElement( + blink::WebString::fromUTF16(name), options, c); } void WebFrame::RegisterElementResizeCallback( @@ -145,9 +146,6 @@ void WebFrame::SetSpellCheckProvider(mate::Arguments* args, void WebFrame::RegisterURLSchemeAsSecure(const std::string& scheme) { // TODO(pfrazee): Remove 2.0 - // Register scheme to secure list (https, wss, data). - blink::WebSecurityPolicy::registerURLSchemeAsSecure( - blink::WebString::fromUTF8(scheme)); } void WebFrame::RegisterURLSchemeAsBypassingCSP(const std::string& scheme) { @@ -200,7 +198,10 @@ void WebFrame::RegisterURLSchemeAsPrivileged(const std::string& scheme, void WebFrame::InsertText(const std::string& text) { web_frame_->frameWidget() ->getActiveWebInputMethodController() - ->commitText(blink::WebString::fromUTF8(text), 0); + ->commitText(blink::WebString::fromUTF8(text), + blink::WebVector(), + blink::WebRange(), + 0); } void WebFrame::InsertCSS(const std::string& css) { @@ -216,7 +217,7 @@ void WebFrame::ExecuteJavaScript(const base::string16& code, std::unique_ptr callback( new ScriptExecutionCallback(completion_callback)); web_frame_->requestExecuteScriptAndReturnValue( - blink::WebScriptSource(code), + blink::WebScriptSource(blink::WebString::fromUTF16(code)), has_user_gesture, callback.release()); } diff --git a/atom/renderer/atom_render_frame_observer.cc b/atom/renderer/atom_render_frame_observer.cc index d9a41a48d4a..3912a7bcc6d 100644 --- a/atom/renderer/atom_render_frame_observer.cc +++ b/atom/renderer/atom_render_frame_observer.cc @@ -24,7 +24,6 @@ void AtomRenderFrameObserver::DidClearWindowObject() { void AtomRenderFrameObserver::DidCreateScriptContext( v8::Handle context, - int extension_group, int world_id) { if (ShouldNotifyClient(world_id)) renderer_client_->DidCreateScriptContext(context, render_frame_); @@ -62,8 +61,7 @@ void AtomRenderFrameObserver::CreateIsolatedWorldContext() { // Create initial script context in isolated world blink::WebScriptSource source("void 0"); - frame->executeScriptInIsolatedWorld( - World::ISOLATED_WORLD, &source, 1, ExtensionGroup::MAIN_GROUP); + frame->executeScriptInIsolatedWorld(World::ISOLATED_WORLD, &source, 1); } bool AtomRenderFrameObserver::IsMainWorld(int world_id) { diff --git a/atom/renderer/atom_render_frame_observer.h b/atom/renderer/atom_render_frame_observer.h index 51cb21b3b0e..6eeb32aac03 100644 --- a/atom/renderer/atom_render_frame_observer.h +++ b/atom/renderer/atom_render_frame_observer.h @@ -17,10 +17,6 @@ enum World { ISOLATED_WORLD = 999 }; -enum ExtensionGroup { - MAIN_GROUP = 1 -}; - // Helper class to forward the messages to the client. class AtomRenderFrameObserver : public content::RenderFrameObserver { public: @@ -30,7 +26,6 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver { // content::RenderFrameObserver: void DidClearWindowObject() override; void DidCreateScriptContext(v8::Handle context, - int extension_group, int world_id) override; void WillReleaseScriptContext(v8::Local context, int world_id) override; diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 5dafe084ce2..1ce17193dff 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -172,8 +172,7 @@ void AtomRendererClient::WillDestroyWorkerContextOnWorkerThread( v8::Local AtomRendererClient::GetContext( blink::WebFrame* frame, v8::Isolate* isolate) { if (isolated_world()) - return frame->worldScriptContext( - isolate, World::ISOLATED_WORLD, ExtensionGroup::MAIN_GROUP); + return frame->worldScriptContext(isolate, World::ISOLATED_WORLD); else return frame->mainWorldScriptContext(); } diff --git a/atom/renderer/renderer_client_base.cc b/atom/renderer/renderer_client_base.cc index 4d3675e2f6f..8a4ed82f07c 100644 --- a/atom/renderer/renderer_client_base.cc +++ b/atom/renderer/renderer_client_base.cc @@ -126,13 +126,6 @@ void RendererClientBase::RenderFrameCreated( // Allow access to file scheme from pdf viewer. blink::WebSecurityPolicy::addOriginAccessWhitelistEntry( GURL(kPdfViewerUIOrigin), "file", "", true); - - // Parse --secure-schemes=scheme1,scheme2 - std::vector secure_schemes_list = - ParseSchemesCLISwitch(switches::kSecureSchemes); - for (const std::string& secure_scheme : secure_schemes_list) - blink::WebSecurityPolicy::registerURLSchemeAsSecure( - blink::WebString::fromUTF8(secure_scheme)); } void RendererClientBase::RenderViewCreated(content::RenderView* render_view) { diff --git a/chromium_src/chrome/browser/media/native_desktop_media_list.cc b/chromium_src/chrome/browser/media/native_desktop_media_list.cc index 391bdd50a31..4a9c0e03c8b 100644 --- a/chromium_src/chrome/browser/media/native_desktop_media_list.cc +++ b/chromium_src/chrome/browser/media/native_desktop_media_list.cc @@ -8,6 +8,8 @@ #include #include +using base::PlatformThreadRef; + #include "base/hash.h" #include "base/logging.h" #include "base/strings/string_number_conversions.h" From e43b34b8f839367e5a420b3cd859a6bac208bc68 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 11 Apr 2017 17:22:12 +0900 Subject: [PATCH 1056/1195] Use blink::SchemeRegistry over WebSecurityPolicy The latter is removing some APIs we use. --- atom/renderer/api/atom_api_web_frame.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc index 77928724c05..ac12f974791 100644 --- a/atom/renderer/api/atom_api_web_frame.cc +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -23,8 +23,8 @@ #include "third_party/WebKit/public/web/WebLocalFrame.h" #include "third_party/WebKit/public/web/WebScriptExecutionCallback.h" #include "third_party/WebKit/public/web/WebScriptSource.h" -#include "third_party/WebKit/public/web/WebSecurityPolicy.h" #include "third_party/WebKit/public/web/WebView.h" +#include "third_party/WebKit/Source/platform/weborigin/SchemeRegistry.h" #include "atom/common/node_includes.h" @@ -146,12 +146,14 @@ void WebFrame::SetSpellCheckProvider(mate::Arguments* args, void WebFrame::RegisterURLSchemeAsSecure(const std::string& scheme) { // TODO(pfrazee): Remove 2.0 + blink::SchemeRegistry::registerURLSchemeAsSecure( + WTF::String::fromUTF8(scheme.data(), scheme.length())); } void WebFrame::RegisterURLSchemeAsBypassingCSP(const std::string& scheme) { // Register scheme to bypass pages's Content Security Policy. - blink::WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy( - blink::WebString::fromUTF8(scheme)); + blink::SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy( + WTF::String::fromUTF8(scheme.data(), scheme.length())); } void WebFrame::RegisterURLSchemeAsPrivileged(const std::string& scheme, @@ -173,25 +175,26 @@ void WebFrame::RegisterURLSchemeAsPrivileged(const std::string& scheme, } } // Register scheme to privileged list (https, wss, data, chrome-extension) - blink::WebString privileged_scheme(blink::WebString::fromUTF8(scheme)); + WTF::String privileged_scheme( + WTF::String::fromUTF8(scheme.data(), scheme.length())); if (secure) { // TODO(pfrazee): Remove 2.0 - blink::WebSecurityPolicy::registerURLSchemeAsSecure(privileged_scheme); + blink::SchemeRegistry::registerURLSchemeAsSecure(privileged_scheme); } if (bypassCSP) { - blink::WebSecurityPolicy::registerURLSchemeAsBypassingContentSecurityPolicy( + blink::SchemeRegistry::registerURLSchemeAsBypassingContentSecurityPolicy( privileged_scheme); } if (allowServiceWorkers) { - blink::WebSecurityPolicy::registerURLSchemeAsAllowingServiceWorkers( + blink::SchemeRegistry::registerURLSchemeAsAllowingServiceWorkers( privileged_scheme); } if (supportFetchAPI) { - blink::WebSecurityPolicy::registerURLSchemeAsSupportingFetchAPI( + blink::SchemeRegistry::registerURLSchemeAsSupportingFetchAPI( privileged_scheme); } if (corsEnabled) { - blink::WebSecurityPolicy::registerURLSchemeAsCORSEnabled(privileged_scheme); + blink::SchemeRegistry::registerURLSchemeAsCORSEnabled(privileged_scheme); } } From 9f94a0b2463f049d456336dfff29556cf0c7b8d9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 13 Apr 2017 18:03:57 +0900 Subject: [PATCH 1057/1195] Update Singleton code --- .../chrome/browser/process_singleton_posix.cc | 185 +++++++++--------- 1 file changed, 92 insertions(+), 93 deletions(-) diff --git a/chromium_src/chrome/browser/process_singleton_posix.cc b/chromium_src/chrome/browser/process_singleton_posix.cc index 7d5677031f4..e1e25cf91de 100644 --- a/chromium_src/chrome/browser/process_singleton_posix.cc +++ b/chromium_src/chrome/browser/process_singleton_posix.cc @@ -49,25 +49,34 @@ #include #include +#include #include #include +#include + #include "atom/common/atom_command_line.h" + #include "base/base_paths.h" #include "base/bind.h" #include "base/command_line.h" +#include "base/files/file_descriptor_watcher_posix.h" #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/location.h" #include "base/logging.h" +#include "base/macros.h" +#include "base/memory/ptr_util.h" +#include "base/memory/ref_counted.h" #include "base/message_loop/message_loop.h" +#include "base/metrics/histogram_macros.h" #include "base/path_service.h" #include "base/posix/eintr_wrapper.h" #include "base/posix/safe_strerror.h" #include "base/rand_util.h" #include "base/sequenced_task_runner_helpers.h" #include "base/single_thread_task_runner.h" -#include "base/stl_util.h" +#include "base/single_thread_task_runner.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "base/strings/string_util.h" @@ -78,6 +87,7 @@ #include "base/threading/thread_task_runner_handle.h" #include "base/time/time.h" #include "base/timer/timer.h" +#include "build/build_config.h" #include "content/public/browser/browser_thread.h" #include "net/base/network_interfaces.h" #include "ui/base/l10n/l10n_util.h" @@ -222,9 +232,8 @@ int SetupSocketOnly() { int sock = socket(PF_UNIX, SOCK_STREAM, 0); PCHECK(sock >= 0) << "socket() failed"; - int rv = base::SetNonBlocking(sock); - DCHECK_EQ(0, rv) << "Failed to make non-blocking socket."; - rv = SetCloseOnExec(sock); + DCHECK(base::SetNonBlocking(sock)) << "Failed to make non-blocking socket."; + int rv = SetCloseOnExec(sock); DCHECK_EQ(0, rv) << "Failed to set CLOEXEC on socket."; return sock; @@ -305,7 +314,6 @@ bool ParseLockPath(const base::FilePath& path, bool DisplayProfileInUseError(const base::FilePath& lock_path, const std::string& hostname, int pid) { - // TODO: yolo return true; } @@ -455,44 +463,38 @@ bool ReplaceOldSingletonLock(const base::FilePath& symlink_content, // This class sets up a listener on the singleton socket and handles parsing // messages that come in on the singleton socket. class ProcessSingleton::LinuxWatcher - : public base::MessageLoopForIO::Watcher, - public base::MessageLoop::DestructionObserver, - public base::RefCountedThreadSafe { public: // A helper class to read message from an established socket. - class SocketReader : public base::MessageLoopForIO::Watcher { + class SocketReader { public: SocketReader(ProcessSingleton::LinuxWatcher* parent, - base::MessageLoop* ui_message_loop, + scoped_refptr ui_task_runner, int fd) : parent_(parent), - ui_message_loop_(ui_message_loop), + ui_task_runner_(ui_task_runner), fd_(fd), bytes_read_(0) { DCHECK_CURRENTLY_ON(BrowserThread::IO); // Wait for reads. - base::MessageLoopForIO::current()->WatchFileDescriptor( - fd, true, base::MessageLoopForIO::WATCH_READ, &fd_reader_, this); + fd_watch_controller_ = base::FileDescriptorWatcher::WatchReadable( + fd, base::Bind(&SocketReader::OnSocketCanReadWithoutBlocking, + base::Unretained(this))); // If we haven't completed in a reasonable amount of time, give up. timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kTimeoutInSeconds), this, &SocketReader::CleanupAndDeleteSelf); } - ~SocketReader() override { CloseSocket(fd_); } - - // MessageLoopForIO::Watcher impl. - void OnFileCanReadWithoutBlocking(int fd) override; - void OnFileCanWriteWithoutBlocking(int fd) override { - // SocketReader only watches for accept (read) events. - NOTREACHED(); - } + ~SocketReader() { CloseSocket(fd_); } // Finish handling the incoming message by optionally sending back an ACK // message and removing this SocketReader. void FinishWithACK(const char *message, size_t length); private: + void OnSocketCanReadWithoutBlocking(); + void CleanupAndDeleteSelf() { DCHECK_CURRENTLY_ON(BrowserThread::IO); @@ -500,13 +502,15 @@ class ProcessSingleton::LinuxWatcher // We're deleted beyond this point. } - base::MessageLoopForIO::FileDescriptorWatcher fd_reader_; + // Controls watching |fd_|. + std::unique_ptr + fd_watch_controller_; // The ProcessSingleton::LinuxWatcher that owns us. ProcessSingleton::LinuxWatcher* const parent_; - // A reference to the UI message loop. - base::MessageLoop* const ui_message_loop_; + // A reference to the UI task runner. + scoped_refptr ui_task_runner_; // The file descriptor we're reading. const int fd_; @@ -525,9 +529,7 @@ class ProcessSingleton::LinuxWatcher // We expect to only be constructed on the UI thread. explicit LinuxWatcher(ProcessSingleton* parent) - : ui_message_loop_(base::MessageLoop::current()), - parent_(parent) { - } + : ui_task_runner_(base::ThreadTaskRunnerHandle::Get()), parent_(parent) {} // Start listening for connections on the socket. This method should be // called from the IO thread. @@ -540,79 +542,63 @@ class ProcessSingleton::LinuxWatcher const std::vector& argv, SocketReader* reader); - // MessageLoopForIO::Watcher impl. These run on the IO thread. - void OnFileCanReadWithoutBlocking(int fd) override; - void OnFileCanWriteWithoutBlocking(int fd) override { - // ProcessSingleton only watches for accept (read) events. - NOTREACHED(); - } - - // MessageLoop::DestructionObserver - void WillDestroyCurrentMessageLoop() override { - fd_watcher_.StopWatchingFileDescriptor(); - } - private: friend struct BrowserThread::DeleteOnThread; friend class base::DeleteHelper; - ~LinuxWatcher() override { + ~LinuxWatcher() { DCHECK_CURRENTLY_ON(BrowserThread::IO); - STLDeleteElements(&readers_); - - base::MessageLoopForIO* ml = base::MessageLoopForIO::current(); - ml->RemoveDestructionObserver(this); } + void OnSocketCanReadWithoutBlocking(int socket); + // Removes and deletes the SocketReader. void RemoveSocketReader(SocketReader* reader); - base::MessageLoopForIO::FileDescriptorWatcher fd_watcher_; + std::unique_ptr socket_watcher_; // A reference to the UI message loop (i.e., the message loop we were // constructed on). - base::MessageLoop* ui_message_loop_; + scoped_refptr ui_task_runner_; // The ProcessSingleton that owns us. ProcessSingleton* const parent_; - std::set readers_; + std::set> readers_; DISALLOW_COPY_AND_ASSIGN(LinuxWatcher); }; -void ProcessSingleton::LinuxWatcher::OnFileCanReadWithoutBlocking(int fd) { +void ProcessSingleton::LinuxWatcher::OnSocketCanReadWithoutBlocking( + int socket) { DCHECK_CURRENTLY_ON(BrowserThread::IO); // Accepting incoming client. sockaddr_un from; socklen_t from_len = sizeof(from); - int connection_socket = HANDLE_EINTR(accept( - fd, reinterpret_cast(&from), &from_len)); + int connection_socket = HANDLE_EINTR( + accept(socket, reinterpret_cast(&from), &from_len)); if (-1 == connection_socket) { PLOG(ERROR) << "accept() failed"; return; } - int rv = base::SetNonBlocking(connection_socket); - DCHECK_EQ(0, rv) << "Failed to make non-blocking socket."; - SocketReader* reader = new SocketReader(this, - ui_message_loop_, - connection_socket); - readers_.insert(reader); + DCHECK(base::SetNonBlocking(connection_socket)) + << "Failed to make non-blocking socket."; + readers_.insert( + base::MakeUnique(this, ui_task_runner_, connection_socket)); } void ProcessSingleton::LinuxWatcher::StartListening(int socket) { DCHECK_CURRENTLY_ON(BrowserThread::IO); // Watch for client connections on this socket. - base::MessageLoopForIO* ml = base::MessageLoopForIO::current(); - ml->AddDestructionObserver(this); - ml->WatchFileDescriptor(socket, true, base::MessageLoopForIO::WATCH_READ, - &fd_watcher_, this); + socket_watcher_ = base::FileDescriptorWatcher::WatchReadable( + socket, base::Bind(&LinuxWatcher::OnSocketCanReadWithoutBlocking, + base::Unretained(this), socket)); } void ProcessSingleton::LinuxWatcher::HandleMessage( const std::string& current_dir, const std::vector& argv, SocketReader* reader) { - DCHECK(ui_message_loop_ == base::MessageLoop::current()); + DCHECK(ui_task_runner_->BelongsToCurrentThread()); DCHECK(reader); if (parent_->notification_callback_.Run(argv, @@ -632,25 +618,27 @@ void ProcessSingleton::LinuxWatcher::HandleMessage( void ProcessSingleton::LinuxWatcher::RemoveSocketReader(SocketReader* reader) { DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(reader); - readers_.erase(reader); - delete reader; + auto it = std::find_if(readers_.begin(), readers_.end(), + [reader](const std::unique_ptr& ptr) { + return ptr.get() == reader; + }); + readers_.erase(it); } /////////////////////////////////////////////////////////////////////////////// // ProcessSingleton::LinuxWatcher::SocketReader // -void ProcessSingleton::LinuxWatcher::SocketReader::OnFileCanReadWithoutBlocking( - int fd) { +void ProcessSingleton::LinuxWatcher::SocketReader:: + OnSocketCanReadWithoutBlocking() { DCHECK_CURRENTLY_ON(BrowserThread::IO); - DCHECK_EQ(fd, fd_); while (bytes_read_ < sizeof(buf_)) { - ssize_t rv = HANDLE_EINTR( - read(fd, buf_ + bytes_read_, sizeof(buf_) - bytes_read_)); + ssize_t rv = + HANDLE_EINTR(read(fd_, buf_ + bytes_read_, sizeof(buf_) - bytes_read_)); if (rv < 0) { if (errno != EAGAIN && errno != EWOULDBLOCK) { PLOG(ERROR) << "read() failed"; - CloseSocket(fd); + CloseSocket(fd_); return; } else { // It would block, so we just return and continue to watch for the next @@ -696,10 +684,10 @@ void ProcessSingleton::LinuxWatcher::SocketReader::OnFileCanReadWithoutBlocking( tokens.erase(tokens.begin()); // Return to the UI thread to handle opening a new browser tab. - ui_message_loop_->task_runner()->PostTask( + ui_task_runner_->PostTask( FROM_HERE, base::Bind(&ProcessSingleton::LinuxWatcher::HandleMessage, parent_, current_dir, tokens, this)); - fd_reader_.StopWatchingFileDescriptor(); + fd_watch_controller_.reset(); // LinuxWatcher::HandleMessage() is in charge of destroying this SocketReader // object by invoking SocketReader::FinishWithACK(). @@ -731,7 +719,8 @@ ProcessSingleton::ProcessSingleton( const base::FilePath& user_data_dir, const NotificationCallback& notification_callback) : notification_callback_(notification_callback), - current_pid_(base::GetCurrentProcId()) { + current_pid_(base::GetCurrentProcId()), + watcher_(new LinuxWatcher(this)) { // The user_data_dir may have not been created yet. base::CreateDirectoryAndGetError(user_data_dir, nullptr); @@ -897,12 +886,26 @@ ProcessSingleton::NotifyOtherProcessWithTimeoutOrCreate( const base::CommandLine& command_line, int retry_attempts, const base::TimeDelta& timeout) { + const base::TimeTicks begin_ticks = base::TimeTicks::Now(); NotifyResult result = NotifyOtherProcessWithTimeout( command_line, retry_attempts, timeout, true); - if (result != PROCESS_NONE) + if (result != PROCESS_NONE) { + if (result == PROCESS_NOTIFIED) { + UMA_HISTOGRAM_MEDIUM_TIMES("Chrome.ProcessSingleton.TimeToNotify", + base::TimeTicks::Now() - begin_ticks); + } else { + UMA_HISTOGRAM_MEDIUM_TIMES("Chrome.ProcessSingleton.TimeToFailure", + base::TimeTicks::Now() - begin_ticks); + } return result; - if (Create()) + } + + if (Create()) { + UMA_HISTOGRAM_MEDIUM_TIMES("Chrome.ProcessSingleton.TimeToCreate", + base::TimeTicks::Now() - begin_ticks); return PROCESS_NONE; + } + // If the Create() failed, try again to notify. (It could be that another // instance was starting at the same time and managed to grab the lock before // we did.) @@ -910,6 +913,15 @@ ProcessSingleton::NotifyOtherProcessWithTimeoutOrCreate( // aren't going to try to take over the lock ourselves. result = NotifyOtherProcessWithTimeout( command_line, retry_attempts, timeout, false); + + if (result == PROCESS_NOTIFIED) { + UMA_HISTOGRAM_MEDIUM_TIMES("Chrome.ProcessSingleton.TimeToNotify", + base::TimeTicks::Now() - begin_ticks); + } else { + UMA_HISTOGRAM_MEDIUM_TIMES("Chrome.ProcessSingleton.TimeToFailure", + base::TimeTicks::Now() - begin_ticks); + } + if (result != PROCESS_NONE) return result; @@ -1019,15 +1031,13 @@ bool ProcessSingleton::Create() { if (listen(sock, 5) < 0) NOTREACHED() << "listen failed: " << base::safe_strerror(errno); - // In Electron the ProcessSingleton is created earlier than the IO - // thread gets created, so we have to postpone the call until message - // loop is up an running. - scoped_refptr task_runner = - base::ThreadTaskRunnerHandle::Get(); - task_runner->PostTask( + DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, - base::Bind(&ProcessSingleton::StartListening, - base::Unretained(this), sock)); + base::Bind(&ProcessSingleton::LinuxWatcher::StartListening, + watcher_, + sock)); return true; } @@ -1038,17 +1048,6 @@ void ProcessSingleton::Cleanup() { UnlinkPath(lock_path_); } -void ProcessSingleton::StartListening(int sock) { - watcher_ = new LinuxWatcher(this); - DCHECK(BrowserThread::IsMessageLoopValid(BrowserThread::IO)); - BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - base::Bind(&ProcessSingleton::LinuxWatcher::StartListening, - watcher_.get(), - sock)); -} - bool ProcessSingleton::IsSameChromeInstance(pid_t pid) { pid_t cur_pid = current_pid_; while (pid != cur_pid) { From 326908cebb16bdca9de6022929db621457d139ce Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 13 Apr 2017 18:11:25 +0900 Subject: [PATCH 1058/1195] Fix change of FileDescriptorWatcher API --- .../net/test/embedded_test_server/stream_listen_socket.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/chromium_src/net/test/embedded_test_server/stream_listen_socket.cc b/chromium_src/net/test/embedded_test_server/stream_listen_socket.cc index 0b16c1395eb..6cdc1e6ea93 100644 --- a/chromium_src/net/test/embedded_test_server/stream_listen_socket.cc +++ b/chromium_src/net/test/embedded_test_server/stream_listen_socket.cc @@ -57,6 +57,9 @@ const int StreamListenSocket::kSocketError = -1; StreamListenSocket::StreamListenSocket(SocketDescriptor s, StreamListenSocket::Delegate* del) : socket_delegate_(del), +#if defined(OS_POSIX) + watcher_(FROM_HERE), +#endif socket_(s), reads_paused_(false), has_pending_reads_(false) { From 6da696b6f28d771a5dbe04ebef24b258f8a0c8d9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 13 Apr 2017 19:11:16 +0900 Subject: [PATCH 1059/1195] Update printing code --- .../chrome/browser/printing/print_job.cc | 1 + .../pepper/pepper_flash_renderer_host.cc | 3 ++- .../renderer/printing/print_web_view_helper.cc | 17 +++++++++-------- .../printing/print_web_view_helper_linux.cc | 6 +++--- .../printing/print_web_view_helper_mac.mm | 7 +++---- .../printing/print_web_view_helper_pdf_win.cc | 6 +++--- .../components/pdf/renderer/pepper_pdf_host.cc | 4 ++-- 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/chromium_src/chrome/browser/printing/print_job.cc b/chromium_src/chrome/browser/printing/print_job.cc index 70bdb900458..8a969618bdb 100644 --- a/chromium_src/chrome/browser/printing/print_job.cc +++ b/chromium_src/chrome/browser/printing/print_job.cc @@ -14,6 +14,7 @@ #include "base/message_loop/message_loop.h" #include "base/run_loop.h" #include "base/single_thread_task_runner.h" +#include "base/threading/sequenced_worker_pool.h" #include "base/threading/thread_restrictions.h" #include "base/threading/thread_task_runner_handle.h" #include "base/threading/worker_pool.h" diff --git a/chromium_src/chrome/renderer/pepper/pepper_flash_renderer_host.cc b/chromium_src/chrome/renderer/pepper/pepper_flash_renderer_host.cc index 5e41c5b8a65..09e5b46df6f 100644 --- a/chromium_src/chrome/renderer/pepper/pepper_flash_renderer_host.cc +++ b/chromium_src/chrome/renderer/pepper/pepper_flash_renderer_host.cc @@ -8,7 +8,8 @@ #include #include "base/lazy_instance.h" -#include "base/metrics/histogram.h" +#include "base/macros.h" +#include "base/metrics/histogram_macros.h" #include "base/strings/string_util.h" #include "content/public/renderer/pepper_plugin_instance.h" #include "content/public/renderer/render_thread.h" diff --git a/chromium_src/chrome/renderer/printing/print_web_view_helper.cc b/chromium_src/chrome/renderer/printing/print_web_view_helper.cc index d93cdea8312..adac07cb7ce 100644 --- a/chromium_src/chrome/renderer/printing/print_web_view_helper.cc +++ b/chromium_src/chrome/renderer/printing/print_web_view_helper.cc @@ -12,7 +12,7 @@ #include "base/json/json_writer.h" #include "base/logging.h" #include "base/message_loop/message_loop.h" -#include "base/metrics/histogram.h" +#include "base/metrics/histogram_macros.h" #include "base/process/process_handle.h" #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" @@ -32,6 +32,7 @@ #include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebElement.h" #include "third_party/WebKit/public/web/WebFrameClient.h" +#include "third_party/WebKit/public/web/WebFrameWidget.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" #include "third_party/WebKit/public/web/WebPlugin.h" #include "third_party/WebKit/public/web/WebPluginDocument.h" @@ -484,12 +485,9 @@ void PrepareFrameAndViewForPrint::ResizeForPrinting() { // Backup size and offset if it's a local frame. blink::WebView* web_view = frame_.view(); - // Backup size and offset. - if (blink::WebFrame* web_frame = web_view->mainFrame()) - prev_scroll_offset_ = web_frame->scrollOffset(); if (blink::WebFrame* web_frame = web_view->mainFrame()) { if (web_frame->isWebLocalFrame()) - prev_scroll_offset_ = web_frame->scrollOffset(); + prev_scroll_offset_ = web_frame->getScrollOffset(); } prev_view_size_ = web_view->size(); @@ -535,8 +533,10 @@ void PrepareFrameAndViewForPrint::CopySelection( blink::WebView::create(this, blink::WebPageVisibilityStateVisible); owns_web_view_ = true; content::RenderView::ApplyWebPreferences(prefs, web_view); - web_view->setMainFrame( - blink::WebLocalFrame::create(blink::WebTreeScopeType::Document, this)); + blink::WebLocalFrame* main_frame = blink::WebLocalFrame::create( + blink::WebTreeScopeType::Document, this, nullptr, nullptr); + web_view->setMainFrame(main_frame); + blink::WebFrameWidget::create(this, web_view, main_frame); frame_.Reset(web_view->mainFrame()->toWebLocalFrame()); node_to_print_.reset(); @@ -565,7 +565,8 @@ blink::WebLocalFrame* PrepareFrameAndViewForPrint::createChildFrame( const blink::WebString& unique_name, blink::WebSandboxFlags sandbox_flags, const blink::WebFrameOwnerProperties& frame_owner_properties) { - blink::WebLocalFrame* frame = blink::WebLocalFrame::create(scope, this); + blink::WebLocalFrame* frame = blink::WebLocalFrame::create( + scope, this, nullptr, nullptr); parent->appendChild(frame); return frame; } diff --git a/chromium_src/chrome/renderer/printing/print_web_view_helper_linux.cc b/chromium_src/chrome/renderer/printing/print_web_view_helper_linux.cc index 197baedc2f1..4bc37f4da97 100644 --- a/chromium_src/chrome/renderer/printing/print_web_view_helper_linux.cc +++ b/chromium_src/chrome/renderer/printing/print_web_view_helper_linux.cc @@ -126,12 +126,12 @@ void PrintWebViewHelper::PrintPageInternal( &content_area); gfx::Rect canvas_area = content_area; - SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( - page_size, canvas_area, scale_factor); + cc::PaintCanvas* canvas = + metafile->GetVectorCanvasForNewPage(page_size, canvas_area, scale_factor); if (!canvas) return; - MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); + MetafileSkiaWrapper::SetMetafileOnCanvas(canvas, metafile); RenderPageContent(frame, params.page_number, canvas_area, content_area, scale_factor, canvas); diff --git a/chromium_src/chrome/renderer/printing/print_web_view_helper_mac.mm b/chromium_src/chrome/renderer/printing/print_web_view_helper_mac.mm index 341b89717be..6332df49af5 100644 --- a/chromium_src/chrome/renderer/printing/print_web_view_helper_mac.mm +++ b/chromium_src/chrome/renderer/printing/print_web_view_helper_mac.mm @@ -14,7 +14,6 @@ #include "printing/page_size_margins.h" #include "third_party/WebKit/public/platform/WebCanvas.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" -#include "third_party/skia/include/core/SkCanvas.h" namespace printing { @@ -112,13 +111,13 @@ void PrintWebViewHelper::RenderPage(const PrintMsg_Print_Params& params, gfx::Rect canvas_area = content_area; { - SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( + cc::PaintCanvas* canvas = metafile->GetVectorCanvasForNewPage( *page_size, canvas_area, scale_factor); if (!canvas) return; - MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); - skia::SetIsPreviewMetafile(*canvas, is_preview); + MetafileSkiaWrapper::SetMetafileOnCanvas(canvas, metafile); + cc::SetIsPreviewMetafile(canvas, is_preview); RenderPageContent(frame, page_number, canvas_area, content_area, scale_factor, static_cast(canvas)); } diff --git a/chromium_src/chrome/renderer/printing/print_web_view_helper_pdf_win.cc b/chromium_src/chrome/renderer/printing/print_web_view_helper_pdf_win.cc index e96a2b8339a..6449f09feec 100644 --- a/chromium_src/chrome/renderer/printing/print_web_view_helper_pdf_win.cc +++ b/chromium_src/chrome/renderer/printing/print_web_view_helper_pdf_win.cc @@ -161,12 +161,12 @@ void PrintWebViewHelper::PrintPageInternal( frame->getPrintPageShrink(params.page_number); float scale_factor = css_scale_factor * webkit_page_shrink_factor; - SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( - page_size, canvas_area, scale_factor); + cc::PaintCanvas* canvas = + metafile->GetVectorCanvasForNewPage(page_size, canvas_area, scale_factor); if (!canvas) return; - MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); + MetafileSkiaWrapper::SetMetafileOnCanvas(canvas, metafile); #if 0 if (params.params.display_header_footer) { diff --git a/chromium_src/components/pdf/renderer/pepper_pdf_host.cc b/chromium_src/components/pdf/renderer/pepper_pdf_host.cc index 5f0e9afe548..28f046c13ce 100644 --- a/chromium_src/components/pdf/renderer/pepper_pdf_host.cc +++ b/chromium_src/components/pdf/renderer/pepper_pdf_host.cc @@ -47,7 +47,7 @@ int32_t PepperPDFHost::OnHostMsgDidStartLoading( if (!render_frame) return PP_ERROR_FAILED; - render_frame->DidStartLoading(); + render_frame->PluginDidStartLoading(); return PP_OK; } @@ -57,7 +57,7 @@ int32_t PepperPDFHost::OnHostMsgDidStopLoading( if (!render_frame) return PP_ERROR_FAILED; - render_frame->DidStopLoading(); + render_frame->PluginDidStopLoading(); return PP_OK; } From d85b58fdb59082abf336b1eed54afbcc3766b872 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 13 Apr 2017 19:21:30 +0900 Subject: [PATCH 1060/1195] Fix API changes of FrameSubscriber --- atom/browser/api/atom_api_web_contents.cc | 19 +++++++++++-------- atom/browser/api/frame_subscriber.cc | 5 +++++ atom/browser/api/frame_subscriber.h | 3 +++ atom/browser/ui/webui/pdf_viewer_ui.cc | 3 ++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 8b46484b36e..a189cc211b4 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -76,6 +76,7 @@ #include "third_party/WebKit/public/platform/WebInputEvent.h" #include "third_party/WebKit/public/web/WebFindOptions.h" #include "ui/display/screen.h" +#include "ui/events/base_event_utils.h" #if !defined(OS_MACOSX) #include "ui/aura/window.h" @@ -1306,7 +1307,7 @@ void WebContents::SelectAll() { } void WebContents::Unselect() { - web_contents()->Unselect(); + web_contents()->CollapseSelection(); } void WebContents::Replace(const base::string16& word) { @@ -1396,7 +1397,10 @@ void WebContents::SendInputEvent(v8::Isolate* isolate, return; } } else if (blink::WebInputEvent::isKeyboardEventType(type)) { - content::NativeWebKeyboardEvent keyboard_event; + content::NativeWebKeyboardEvent keyboard_event( + blink::WebKeyboardEvent::RawKeyDown, + blink::WebInputEvent::NoModifiers, + ui::EventTimeForNow()); if (mate::ConvertFromV8(isolate, input_event, &keyboard_event)) { host->ForwardKeyboardEvent(keyboard_event); return; @@ -1486,8 +1490,7 @@ void WebContents::CapturePage(mate::Arguments* args) { } const auto view = web_contents()->GetRenderWidgetHostView(); - const auto host = view ? view->GetRenderWidgetHost() : nullptr; - if (!view || !host) { + if (!view) { callback.Run(gfx::Image()); return; } @@ -1507,10 +1510,10 @@ void WebContents::CapturePage(mate::Arguments* args) { if (scale > 1.0f) bitmap_size = gfx::ScaleToCeiledSize(view_size, scale); - host->CopyFromBackingStore(gfx::Rect(rect.origin(), view_size), - bitmap_size, - base::Bind(&OnCapturePageDone, callback), - kBGRA_8888_SkColorType); + view->CopyFromSurface(gfx::Rect(rect.origin(), view_size), + bitmap_size, + base::Bind(&OnCapturePageDone, callback), + kBGRA_8888_SkColorType); } void WebContents::OnCursorChange(const content::WebCursor& cursor) { diff --git a/atom/browser/api/frame_subscriber.cc b/atom/browser/api/frame_subscriber.cc index 652596af15f..076ebde9826 100644 --- a/atom/browser/api/frame_subscriber.cc +++ b/atom/browser/api/frame_subscriber.cc @@ -24,6 +24,7 @@ FrameSubscriber::FrameSubscriber(v8::Isolate* isolate, view_(view), callback_(callback), only_dirty_(only_dirty), + source_id_for_copy_request_(base::UnguessableToken::Create()), weak_factory_(this) { } @@ -63,6 +64,10 @@ bool FrameSubscriber::ShouldCaptureFrame( return false; } +const base::UnguessableToken& FrameSubscriber::GetSourceIdForCopyRequest() { + return source_id_for_copy_request_; +} + void FrameSubscriber::OnFrameDelivered(const FrameCaptureCallback& callback, const gfx::Rect& damage_rect, const SkBitmap& bitmap, diff --git a/atom/browser/api/frame_subscriber.h b/atom/browser/api/frame_subscriber.h index a32864c1774..3761f144d04 100644 --- a/atom/browser/api/frame_subscriber.h +++ b/atom/browser/api/frame_subscriber.h @@ -32,6 +32,7 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber { base::TimeTicks present_time, scoped_refptr* storage, DeliverFrameCallback* callback) override; + const base::UnguessableToken& GetSourceIdForCopyRequest() override; private: void OnFrameDelivered(const FrameCaptureCallback& callback, @@ -44,6 +45,8 @@ class FrameSubscriber : public content::RenderWidgetHostViewFrameSubscriber { FrameCaptureCallback callback_; bool only_dirty_; + base::UnguessableToken source_id_for_copy_request_; + base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(FrameSubscriber); diff --git a/atom/browser/ui/webui/pdf_viewer_ui.cc b/atom/browser/ui/webui/pdf_viewer_ui.cc index c1b6dbfccfa..b6073f8409a 100644 --- a/atom/browser/ui/webui/pdf_viewer_ui.cc +++ b/atom/browser/ui/webui/pdf_viewer_ui.cc @@ -203,7 +203,8 @@ PdfViewerUI::PdfViewerUI(content::BrowserContext* browser_context, content::WebContentsObserver(web_ui->GetWebContents()), src_(src) { pdf_handler_ = new PdfViewerHandler(src); - web_ui->AddMessageHandler(pdf_handler_); + web_ui->AddMessageHandler( + std::unique_ptr(pdf_handler_)); content::URLDataSource::Add(browser_context, new BundledDataSource); } From b2b2d8d9a4d55a5c3903e7e44a9a9c04affaa874 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 13 Apr 2017 20:34:47 +0900 Subject: [PATCH 1061/1195] Fix crash on exit --- atom/browser/net/atom_url_request_job_factory.cc | 1 + atom/browser/ui/certificate_trust_mac.mm | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/atom/browser/net/atom_url_request_job_factory.cc b/atom/browser/net/atom_url_request_job_factory.cc index 2348e1a6b44..d0488085f5f 100644 --- a/atom/browser/net/atom_url_request_job_factory.cc +++ b/atom/browser/net/atom_url_request_job_factory.cc @@ -81,6 +81,7 @@ bool AtomURLRequestJobFactory::HasProtocolHandler( void AtomURLRequestJobFactory::Clear() { for (auto& it : protocol_handler_map_) delete it.second; + protocol_handler_map_.clear(); } net::URLRequestJob* AtomURLRequestJobFactory::MaybeCreateJobWithProtocolHandler( diff --git a/atom/browser/ui/certificate_trust_mac.mm b/atom/browser/ui/certificate_trust_mac.mm index e0888dd3ea2..be6e6963f46 100644 --- a/atom/browser/ui/certificate_trust_mac.mm +++ b/atom/browser/ui/certificate_trust_mac.mm @@ -69,7 +69,7 @@ auto cert_db = net::CertDatabase::GetInstance(); // This forces Chromium to reload the certificate since it might be trusted // now. - cert_db->NotifyObserversCertDBChanged(cert_.get()); + cert_db->NotifyObserversCertDBChanged(); callback_.Run(); From 08069e18db85e9c79736a0441c010d4d879d6b4d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Apr 2017 16:03:57 +0900 Subject: [PATCH 1062/1195] Don't use gzip when uploading crash reports --- atom/common/crash_reporter/crash_reporter_mac.mm | 7 ++++++- vendor/crashpad | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/atom/common/crash_reporter/crash_reporter_mac.mm b/atom/common/crash_reporter/crash_reporter_mac.mm index 4b59be5dfca..970cca1acdb 100644 --- a/atom/common/crash_reporter/crash_reporter_mac.mm +++ b/atom/common/crash_reporter/crash_reporter_mac.mm @@ -43,11 +43,16 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name, base::FilePath handler_path = framework_bundle_path.Append("Resources").Append("crashpad_handler"); + std::vector args = { + "--no-rate-limit", + "--no-upload-gzip", // no all servers accept gzip + }; + crashpad::CrashpadClient crashpad_client; crashpad_client.StartHandler(handler_path, crashes_dir, crashes_dir, submit_url, StringMap(), - std::vector(), + args, true, false); } // @autoreleasepool diff --git a/vendor/crashpad b/vendor/crashpad index 4054e6cba3b..2871326543e 160000 --- a/vendor/crashpad +++ b/vendor/crashpad @@ -1 +1 @@ -Subproject commit 4054e6cba3ba023d9c00260518ec2912607ae17c +Subproject commit 2871326543ea0e01488f034bb660bf5a39f55c0c From 7d9d82b522316d991ace6611872370c9407abc0b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Apr 2017 16:14:05 +0900 Subject: [PATCH 1063/1195] Fix lack of some Chromium headers --- script/lib/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/lib/config.py b/script/lib/config.py index 747fbb31148..fbcf9e6ca7b 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -9,7 +9,7 @@ import sys BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \ 'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent' LIBCHROMIUMCONTENT_COMMIT = os.getenv('LIBCHROMIUMCONTENT_COMMIT') or \ - '1433d43a013f6029aec7c1263e1576ad9ab8a7a0' + '791141a820ecf6166a86249701838b57f43777ea' PLATFORM = { 'cygwin': 'win32', From 97fd383c5322e707d5a664c623c8f725f1a3be59 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Apr 2017 16:39:02 +0900 Subject: [PATCH 1064/1195] There are a few more new values for ChangeCause --- atom/browser/api/atom_api_cookies.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/atom/browser/api/atom_api_cookies.cc b/atom/browser/api/atom_api_cookies.cc index 629bb2f1bfc..9f58922fd0a 100644 --- a/atom/browser/api/atom_api_cookies.cc +++ b/atom/browser/api/atom_api_cookies.cc @@ -62,6 +62,10 @@ struct Converter { switch (val) { case net::CookieStore::ChangeCause::INSERTED: case net::CookieStore::ChangeCause::EXPLICIT: + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_BETWEEN: + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_PREDICATE: + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_SINGLE: + case net::CookieStore::ChangeCause::EXPLICIT_DELETE_CANONICAL: return mate::StringToV8(isolate, "explicit"); case net::CookieStore::ChangeCause::OVERWRITE: return mate::StringToV8(isolate, "overwrite"); From b3d60bfb3a74d1378728ec6a9801ff7d91815f1d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Apr 2017 17:17:02 +0900 Subject: [PATCH 1065/1195] Fix building on Linux --- atom/browser/api/atom_api_app.cc | 4 ++-- atom/browser/native_window_views.cc | 17 +++++++++-------- atom/browser/ui/message_box_gtk.cc | 8 ++++---- atom/browser/ui/views/global_menu_bar_x11.cc | 4 +++- atom/browser/ui/views/submenu_button.cc | 6 +++--- .../native_mate_converters/blink_converter.cc | 2 +- .../chrome/browser/certificate_manager_model.cc | 4 ++-- .../chrome/browser/certificate_manager_model.h | 2 +- .../pepper/pepper_flash_font_file_host.cc | 3 ++- vendor/brightray | 2 +- 10 files changed, 28 insertions(+), 24 deletions(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 115041d0082..168628b16a6 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -453,8 +453,8 @@ int ImportIntoCertStore( if (!cert_path.empty()) { if (base::ReadFileToString(base::FilePath(cert_path), &file_data)) { - auto module = model->cert_db()->GetPublicModule(); - rv = model->ImportFromPKCS12(module, + auto module = model->cert_db()->GetPrivateSlot(); + rv = model->ImportFromPKCS12(module.get(), file_data, password, true, diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 7e6f23947c2..ed524cbdcbc 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -86,7 +86,7 @@ bool IsAltKey(const content::NativeWebKeyboardEvent& event) { bool IsAltModifier(const content::NativeWebKeyboardEvent& event) { typedef content::NativeWebKeyboardEvent::Modifiers Modifiers; - int modifiers = event.modifiers; + int modifiers = event.modifiers(); modifiers &= ~Modifiers::NumLockOn; modifiers &= ~Modifiers::CapsLockOn; return (modifiers == Modifiers::AltKey) || @@ -767,13 +767,14 @@ void NativeWindowViews::SetBackgroundColor(const std::string& color_name) { } void NativeWindowViews::SetHasShadow(bool has_shadow) { - wm::SetShadowType( + wm::SetShadowElevation( GetNativeWindow(), - has_shadow ? wm::SHADOW_TYPE_RECTANGULAR : wm::SHADOW_TYPE_NONE); + has_shadow ? wm::ShadowElevation::MEDIUM : wm::ShadowElevation::NONE); } bool NativeWindowViews::HasShadow() { - return wm::GetShadowType(GetNativeWindow()) != wm::SHADOW_TYPE_NONE; + return GetNativeWindow()->GetProperty(wm::kShadowElevationKey) + != wm::ShadowElevation::NONE; } void NativeWindowViews::SetIgnoreMouseEvents(bool ignore) { @@ -1234,10 +1235,10 @@ void NativeWindowViews::HandleKeyboardEvent( // Show accelerator when "Alt" is pressed. if (menu_bar_visible_ && IsAltKey(event)) menu_bar_->SetAcceleratorVisibility( - event.type == blink::WebInputEvent::RawKeyDown); + event.type() == blink::WebInputEvent::RawKeyDown); // Show the submenu when "Alt+Key" is pressed. - if (event.type == blink::WebInputEvent::RawKeyDown && !IsAltKey(event) && + if (event.type() == blink::WebInputEvent::RawKeyDown && !IsAltKey(event) && IsAltModifier(event)) { if (!menu_bar_visible_ && (menu_bar_->GetAcceleratorIndex(event.windowsKeyCode) != -1)) @@ -1250,10 +1251,10 @@ void NativeWindowViews::HandleKeyboardEvent( return; // Toggle the menu bar only when a single Alt is released. - if (event.type == blink::WebInputEvent::RawKeyDown && IsAltKey(event)) { + if (event.type() == blink::WebInputEvent::RawKeyDown && IsAltKey(event)) { // When a single Alt is pressed: menu_bar_alt_pressed_ = true; - } else if (event.type == blink::WebInputEvent::KeyUp && IsAltKey(event) && + } else if (event.type() == blink::WebInputEvent::KeyUp && IsAltKey(event) && menu_bar_alt_pressed_) { // When a single Alt is released right after a Alt is pressed: menu_bar_alt_pressed_ = false; diff --git a/atom/browser/ui/message_box_gtk.cc b/atom/browser/ui/message_box_gtk.cc index a7bbe51ecf1..ffaa0a76cd7 100644 --- a/atom/browser/ui/message_box_gtk.cc +++ b/atom/browser/ui/message_box_gtk.cc @@ -41,7 +41,7 @@ class GtkMessageBox : public NativeWindowObserver { const gfx::ImageSkia& icon) : cancel_id_(cancel_id), checkbox_checked_(false), - parent_(static_cast(parent_window)) { + parent_(static_cast(parent_window)) { // Create dialog. dialog_ = gtk_message_dialog_new( nullptr, // parent @@ -94,7 +94,7 @@ class GtkMessageBox : public NativeWindowObserver { // Parent window. if (parent_) { parent_->AddObserver(this); - parent_->SetEnabled(false); + static_cast(parent_)->SetEnabled(false); libgtkui::SetGtkTransientForAura(dialog_, parent_->GetNativeWindow()); gtk_window_set_modal(GTK_WINDOW(dialog_), TRUE); } @@ -104,7 +104,7 @@ class GtkMessageBox : public NativeWindowObserver { gtk_widget_destroy(dialog_); if (parent_) { parent_->RemoveObserver(this); - parent_->SetEnabled(true); + static_cast(parent_)->SetEnabled(true); } } @@ -179,7 +179,7 @@ class GtkMessageBox : public NativeWindowObserver { bool checkbox_checked_; - NativeWindowViews* parent_; + NativeWindow* parent_; GtkWidget* dialog_; MessageBoxCallback callback_; diff --git a/atom/browser/ui/views/global_menu_bar_x11.cc b/atom/browser/ui/views/global_menu_bar_x11.cc index 266d10b96db..eb5a8d81d23 100644 --- a/atom/browser/ui/views/global_menu_bar_x11.cc +++ b/atom/browser/ui/views/global_menu_bar_x11.cc @@ -4,6 +4,9 @@ #include "atom/browser/ui/views/global_menu_bar_x11.h" +// There are conflicts between Xlib.h and this header. +#include "atom/browser/native_window_views.h" // NOLINT + #include // This conflicts with mate::Converter, @@ -15,7 +18,6 @@ #include #include -#include "atom/browser/native_window_views.h" #include "atom/browser/ui/atom_menu_model.h" #include "base/logging.h" #include "base/strings/stringprintf.h" diff --git a/atom/browser/ui/views/submenu_button.cc b/atom/browser/ui/views/submenu_button.cc index 617dd3346da..aabed323d2b 100644 --- a/atom/browser/ui/views/submenu_button.cc +++ b/atom/browser/ui/views/submenu_button.cc @@ -36,7 +36,7 @@ SubmenuButton::SubmenuButton(const base::string16& title, if (GetUnderlinePosition(title, &accelerator_, &underline_start_, &underline_end_)) - gfx::Canvas::SizeStringInt(GetText(), GetFontList(), &text_width_, + gfx::Canvas::SizeStringInt(GetText(), gfx::FontList(), &text_width_, &text_height_, 0, 0); SetInkDropMode(InkDropMode::ON); @@ -107,8 +107,8 @@ bool SubmenuButton::GetUnderlinePosition(const base::string16& text, void SubmenuButton::GetCharacterPosition( const base::string16& text, int index, int* pos) { int height = 0; - gfx::Canvas::SizeStringInt(text.substr(0, index), GetFontList(), pos, &height, - 0, 0); + gfx::Canvas::SizeStringInt(text.substr(0, index), gfx::FontList(), pos, + &height, 0, 0); } } // namespace atom diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index 6633ef887dc..c70ffe21391 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -280,7 +280,7 @@ bool Converter::FromV8( bool can_scroll = true; if (dict.Get("canScroll", &can_scroll) && !can_scroll) { out->hasPreciseScrollingDeltas = false; - out->modifiers &= ~blink::WebInputEvent::ControlKey; + out->setModifiers(out->modifiers() | blink::WebInputEvent::ControlKey); } #endif return true; diff --git a/chromium_src/chrome/browser/certificate_manager_model.cc b/chromium_src/chrome/browser/certificate_manager_model.cc index 2274c09e341..5f073478cdc 100644 --- a/chromium_src/chrome/browser/certificate_manager_model.cc +++ b/chromium_src/chrome/browser/certificate_manager_model.cc @@ -92,12 +92,12 @@ CertificateManagerModel::CertificateManagerModel( CertificateManagerModel::~CertificateManagerModel() { } -int CertificateManagerModel::ImportFromPKCS12(net::CryptoModule* module, +int CertificateManagerModel::ImportFromPKCS12(PK11SlotInfo* slot_info, const std::string& data, const base::string16& password, bool is_extractable, net::CertificateList* imported_certs) { - return cert_db_->ImportFromPKCS12(module, data, password, + return cert_db_->ImportFromPKCS12(slot_info, data, password, is_extractable, imported_certs); } diff --git a/chromium_src/chrome/browser/certificate_manager_model.h b/chromium_src/chrome/browser/certificate_manager_model.h index 7646da5b9b4..eb84b69f733 100644 --- a/chromium_src/chrome/browser/certificate_manager_model.h +++ b/chromium_src/chrome/browser/certificate_manager_model.h @@ -44,7 +44,7 @@ class CertificateManagerModel { // |data|, using the given |password|. If |is_extractable| is false, // mark the private key as unextractable from the module. // Returns a net error code on failure. - int ImportFromPKCS12(net::CryptoModule* module, + int ImportFromPKCS12(PK11SlotInfo* slot_info, const std::string& data, const base::string16& password, bool is_extractable, diff --git a/chromium_src/chrome/renderer/pepper/pepper_flash_font_file_host.cc b/chromium_src/chrome/renderer/pepper/pepper_flash_font_file_host.cc index c1097093335..450f9f89398 100644 --- a/chromium_src/chrome/renderer/pepper/pepper_flash_font_file_host.cc +++ b/chromium_src/chrome/renderer/pepper/pepper_flash_font_file_host.cc @@ -15,7 +15,8 @@ #include "ppapi/proxy/serialized_structs.h" #if defined(OS_LINUX) || defined(OS_OPENBSD) -#include "content/public/common/child_process_sandbox_support_linux.h" +#include "content/public/child/child_process_sandbox_support_linux.h" +#include "content/public/common/common_sandbox_support_linux.h" #elif defined(OS_WIN) #include "third_party/skia/include/ports/SkFontMgr.h" #endif diff --git a/vendor/brightray b/vendor/brightray index 5e08ec99231..3e77e9faa16 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 5e08ec992316520c3c1643b1e3569f297556b8bb +Subproject commit 3e77e9faa16fcbda5fe740e1f2332201cf423c56 From 8c5fd76286bd62c452170cda062eff3decd59ec5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Apr 2017 17:21:13 +0900 Subject: [PATCH 1066/1195] Fix symbol conflicts in Xlib.h --- atom/browser/ui/views/global_menu_bar_x11.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/atom/browser/ui/views/global_menu_bar_x11.cc b/atom/browser/ui/views/global_menu_bar_x11.cc index eb5a8d81d23..d48d86961ba 100644 --- a/atom/browser/ui/views/global_menu_bar_x11.cc +++ b/atom/browser/ui/views/global_menu_bar_x11.cc @@ -4,20 +4,20 @@ #include "atom/browser/ui/views/global_menu_bar_x11.h" -// There are conflicts between Xlib.h and this header. -#include "atom/browser/native_window_views.h" // NOLINT - #include // This conflicts with mate::Converter, #undef True #undef False -// and V8. +// and V8, #undef None +// and url_request_status.h, +#undef Status #include #include +#include "atom/browser/native_window_views.h" #include "atom/browser/ui/atom_menu_model.h" #include "base/logging.h" #include "base/strings/stringprintf.h" From fb42a72ad82f1343718c381de4a96174626b4f98 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 17 Apr 2017 19:42:12 +0900 Subject: [PATCH 1067/1195] Fix building on Windows --- atom/common/common_message_generator.cc | 1 - atom/common/common_message_generator.h | 1 + .../browser/printing/pdf_to_emf_converter.cc | 432 +++++++++++------- .../browser/printing/pdf_to_emf_converter.h | 26 +- .../chrome/browser/printing/print_job.cc | 94 ++-- .../chrome/browser/printing/print_job.h | 18 +- .../common/chrome_utility_printing_messages.h | 111 +++++ chromium_src/chrome/common/print_messages.h | 39 +- .../printing/print_web_view_helper_pdf_win.cc | 1 - .../chrome/utility/printing_handler_win.cc | 58 ++- .../chrome/utility/printing_handler_win.h | 6 +- common.gypi | 1 + 12 files changed, 505 insertions(+), 283 deletions(-) create mode 100644 chromium_src/chrome/common/chrome_utility_printing_messages.h diff --git a/atom/common/common_message_generator.cc b/atom/common/common_message_generator.cc index 854fc8778e9..6b14637cf3c 100644 --- a/atom/common/common_message_generator.cc +++ b/atom/common/common_message_generator.cc @@ -31,4 +31,3 @@ namespace IPC { namespace IPC { #include "atom/common/common_message_generator.h" } // namespace IPC - diff --git a/atom/common/common_message_generator.h b/atom/common/common_message_generator.h index a63c40b9623..8b41a17f29b 100644 --- a/atom/common/common_message_generator.h +++ b/atom/common/common_message_generator.h @@ -9,4 +9,5 @@ #include "chrome/common/tts_messages.h" #include "chrome/common/widevine_cdm_messages.h" #include "chrome/common/chrome_utility_messages.h" +#include "chrome/common/chrome_utility_printing_messages.h" #include "components/pdf/common/pdf_messages.h" diff --git a/chromium_src/chrome/browser/printing/pdf_to_emf_converter.cc b/chromium_src/chrome/browser/printing/pdf_to_emf_converter.cc index b06c3a06409..a35e80cea23 100644 --- a/chromium_src/chrome/browser/printing/pdf_to_emf_converter.cc +++ b/chromium_src/chrome/browser/printing/pdf_to_emf_converter.cc @@ -18,10 +18,9 @@ #include "base/logging.h" #include "base/macros.h" #include "base/memory/ptr_util.h" -#include "base/strings/utf_string_conversions.h" #include "base/threading/thread_task_runner_handle.h" #include "chrome/common/chrome_utility_messages.h" -#include "chrome/common/print_messages.h" +#include "chrome/common/chrome_utility_printing_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_data.h" #include "content/public/browser/utility_process_host.h" @@ -30,13 +29,13 @@ #include "printing/pdf_render_settings.h" #include "ui/base/l10n/l10n_util.h" +using content::BrowserThread; + namespace printing { namespace { -using content::BrowserThread; - -class PdfToEmfConverterImpl; +class PdfConverterImpl; // Allows to delete temporary directory after all temporary files created inside // are closed. Windows cannot delete directory with opened files. Directory is @@ -59,8 +58,8 @@ class RefCountedTempDir DISALLOW_COPY_AND_ASSIGN(RefCountedTempDir); }; -typedef std::unique_ptr - ScopedTempFile; +using ScopedTempFile = + std::unique_ptr; // Wrapper for Emf to keep only file handle in memory, and load actual data only // on playback. Emf::InitFromFile() can play metafile directly from disk, but it @@ -74,21 +73,39 @@ class LazyEmf : public MetafilePlayer { } ~LazyEmf() override { Close(); } + protected: + // MetafilePlayer: bool SafePlayback(HDC hdc) const override; - bool GetDataAsVector(std::vector* buffer) const override; - bool SaveTo(base::File* file) const override; - private: void Close() const; bool LoadEmf(Emf* emf) const; + private: mutable scoped_refptr temp_dir_; mutable ScopedTempFile file_; // Mutable because of consts in base class. + bool GetDataAsVector(std::vector* buffer) const override; + bool SaveTo(base::File* file) const override; + DISALLOW_COPY_AND_ASSIGN(LazyEmf); }; -// Converts PDF into EMF. +// Postscript metafile subclass to override SafePlayback. +class PostScriptMetaFile : public LazyEmf { + public: + PostScriptMetaFile(const scoped_refptr& temp_dir, + ScopedTempFile file) + : LazyEmf(temp_dir, std::move(file)) {} + ~PostScriptMetaFile() override; + + protected: + // MetafilePlayer: + bool SafePlayback(HDC hdc) const override; + + DISALLOW_COPY_AND_ASSIGN(PostScriptMetaFile); +}; + +// Class for converting PDF to another format for printing (Emf, Postscript). // Class uses 3 threads: UI, IO and FILE. // Internal workflow is following: // 1. Create instance on the UI thread. (files_, settings_,) @@ -101,36 +118,33 @@ class LazyEmf : public MetafilePlayer { // // All these steps work sequentially, so no data should be accessed // simultaneously by several threads. -class PdfToEmfUtilityProcessHostClient +class PdfConverterUtilityProcessHostClient : public content::UtilityProcessHostClient { public: - PdfToEmfUtilityProcessHostClient( - base::WeakPtr converter, + PdfConverterUtilityProcessHostClient( + base::WeakPtr converter, const PdfRenderSettings& settings); void Start(const scoped_refptr& data, - bool print_text_with_gdi, - const PdfToEmfConverter::StartCallback& start_callback); + const PdfConverter::StartCallback& start_callback); void GetPage(int page_number, - const PdfToEmfConverter::GetPageCallback& get_page_callback); + const PdfConverter::GetPageCallback& get_page_callback); void Stop(); + // UtilityProcessHostClient implementation. + void OnProcessCrashed(int exit_code) override; + void OnProcessLaunchFailed(int exit_code) override; + // Needs to be public to handle ChromeUtilityHostMsg_PreCacheFontCharacters // sync message replies. bool Send(IPC::Message* msg); - // UtilityProcessHostClient implementation. - void OnProcessCrashed(int exit_code) override; - void OnProcessLaunchFailed(int exit_code) override; - bool OnMessageReceived(const IPC::Message& message) override; - - private: + protected: class GetPageCallbackData { public: - GetPageCallbackData(int page_number, - PdfToEmfConverter::GetPageCallback callback) + GetPageCallbackData(int page_number, PdfConverter::GetPageCallback callback) : page_number_(page_number), callback_(callback) {} GetPageCallbackData(GetPageCallbackData&& other) { @@ -140,45 +154,62 @@ class PdfToEmfUtilityProcessHostClient GetPageCallbackData& operator=(GetPageCallbackData&& rhs) { page_number_ = rhs.page_number_; callback_ = rhs.callback_; - emf_ = std::move(rhs.emf_); + file_ = std::move(rhs.file_); return *this; } int page_number() const { return page_number_; } - const PdfToEmfConverter::GetPageCallback& callback() const { - return callback_; - } - ScopedTempFile TakeEmf() { return std::move(emf_); } - void set_emf(ScopedTempFile emf) { emf_ = std::move(emf); } + const PdfConverter::GetPageCallback& callback() const { return callback_; } + ScopedTempFile TakeFile() { return std::move(file_); } + void set_file(ScopedTempFile file) { file_ = std::move(file); } private: int page_number_; - PdfToEmfConverter::GetPageCallback callback_; - ScopedTempFile emf_; + + PdfConverter::GetPageCallback callback_; + ScopedTempFile file_; DISALLOW_COPY_AND_ASSIGN(GetPageCallbackData); }; - ~PdfToEmfUtilityProcessHostClient() override; + ~PdfConverterUtilityProcessHostClient() override; - // Message handlers. + bool OnMessageReceived(const IPC::Message& message) override; + + // Helper functions: must be overridden by subclasses + // Set the process name + virtual base::string16 GetName() const; + // Create a metafileplayer subclass file from a temporary file. + virtual std::unique_ptr GetFileFromTemp( + std::unique_ptr + temp_file); + // Send the messages to Start, GetPage, and Stop. + virtual void SendStartMessage(IPC::PlatformFileForTransit transit); + virtual void SendGetPageMessage(int page_number, + IPC::PlatformFileForTransit transit); + virtual void SendStopMessage(); + + // Message handlers: void OnPageCount(int page_count); void OnPageDone(bool success, float scale_factor); + + void OnFailed(); + void OnTempPdfReady(ScopedTempFile pdf); + void OnTempFileReady(GetPageCallbackData* callback_data, + ScopedTempFile temp_file); + + // Additional message handler needed for Pdf to Emf void OnPreCacheFontCharacters(const LOGFONT& log_font, const base::string16& characters); - void OnFailed(); - void OnTempPdfReady(bool print_text_with_gdi, ScopedTempFile pdf); - void OnTempEmfReady(GetPageCallbackData* callback_data, ScopedTempFile emf); - scoped_refptr temp_dir_; - // Used to suppress callbacks after PdfToEmfConverterImpl is deleted. - base::WeakPtr converter_; + // Used to suppress callbacks after PdfConverter is deleted. + base::WeakPtr converter_; PdfRenderSettings settings_; // Document loaded callback. - PdfToEmfConverter::StartCallback start_callback_; + PdfConverter::StartCallback start_callback_; // Process host for IPC. base::WeakPtr utility_process_host_; @@ -186,22 +217,37 @@ class PdfToEmfUtilityProcessHostClient // Queue of callbacks for GetPage() requests. Utility process should reply // with PageDone in the same order as requests were received. // Use containers that keeps element pointers valid after push() and pop(). - typedef std::queue GetPageCallbacks; + using GetPageCallbacks = std::queue; GetPageCallbacks get_page_callbacks_; - DISALLOW_COPY_AND_ASSIGN(PdfToEmfUtilityProcessHostClient); + DISALLOW_COPY_AND_ASSIGN(PdfConverterUtilityProcessHostClient); }; -class PdfToEmfConverterImpl : public PdfToEmfConverter { - public: - PdfToEmfConverterImpl(); +std::unique_ptr +PdfConverterUtilityProcessHostClient::GetFileFromTemp( + std::unique_ptr + temp_file) { + if (settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 || + settings_.mode == PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3) { + return base::MakeUnique(temp_dir_, + std::move(temp_file)); + } + return base::MakeUnique(temp_dir_, std::move(temp_file)); +} - ~PdfToEmfConverterImpl() override; +class PdfConverterImpl : public PdfConverter { + public: + PdfConverterImpl(); + + ~PdfConverterImpl() override; + + base::WeakPtr GetWeakPtr() { + return weak_ptr_factory_.GetWeakPtr(); + } void Start(const scoped_refptr& data, const PdfRenderSettings& conversion_settings, - bool print_text_with_gdi, - const StartCallback& start_callback) override; + const StartCallback& start_callback); void GetPage(int page_number, const GetPageCallback& get_page_callback) override; @@ -209,11 +255,17 @@ class PdfToEmfConverterImpl : public PdfToEmfConverter { // Helps to cancel callbacks if this object is destroyed. void RunCallback(const base::Closure& callback); - private: - scoped_refptr utility_client_; - base::WeakPtrFactory weak_ptr_factory_; + void Start( + const scoped_refptr& utility_client, + const scoped_refptr& data, + const StartCallback& start_callback); - DISALLOW_COPY_AND_ASSIGN(PdfToEmfConverterImpl); + private: + scoped_refptr utility_client_; + + base::WeakPtrFactory weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(PdfConverterImpl); }; ScopedTempFile CreateTempFile(scoped_refptr* temp_dir) { @@ -260,10 +312,10 @@ ScopedTempFile CreateTempPdfFile( bool LazyEmf::SafePlayback(HDC hdc) const { Emf emf; bool result = LoadEmf(&emf) && emf.SafePlayback(hdc); - // TODO(vitalybuka): Fix destruction of metafiles. For some reasons - // instances of Emf are not deleted. crbug.com/411683 + // TODO(thestig): Fix destruction of metafiles. For some reasons + // instances of Emf are not deleted. https://crbug.com/260806 // It's known that the Emf going to be played just once to a printer. So just - // release file here. + // release |file_| here. Close(); return result; } @@ -280,7 +332,7 @@ bool LazyEmf::SaveTo(base::File* file) const { void LazyEmf::Close() const { file_.reset(); - temp_dir_ = NULL; + temp_dir_ = nullptr; } bool LazyEmf::LoadEmf(Emf* emf) const { @@ -294,24 +346,55 @@ bool LazyEmf::LoadEmf(Emf* emf) const { return emf->InitFromData(data.data(), data.size()); } -PdfToEmfUtilityProcessHostClient::PdfToEmfUtilityProcessHostClient( - base::WeakPtr converter, +PostScriptMetaFile::~PostScriptMetaFile() { +} + +bool PostScriptMetaFile::SafePlayback(HDC hdc) const { + // TODO(thestig): Fix destruction of metafiles. For some reasons + // instances of Emf are not deleted. https://crbug.com/260806 + // It's known that the Emf going to be played just once to a printer. So just + // release |file_| before returning. + Emf emf; + if (!LoadEmf(&emf)) { + Close(); + return false; + } + + { + // Ensure enumerator destruction before calling Close() below. + Emf::Enumerator emf_enum(emf, nullptr, nullptr); + for (const Emf::Record& record : emf_enum) { + auto* emf_record = record.record(); + if (emf_record->iType != EMR_GDICOMMENT) + continue; + + const EMRGDICOMMENT* comment = + reinterpret_cast(emf_record); + const char* data = reinterpret_cast(comment->Data); + const uint16_t* ptr = reinterpret_cast(data); + int ret = ExtEscape(hdc, PASSTHROUGH, 2 + *ptr, data, 0, nullptr); + DCHECK_EQ(*ptr, ret); + } + } + Close(); + return true; +} + +PdfConverterUtilityProcessHostClient::PdfConverterUtilityProcessHostClient( + base::WeakPtr converter, const PdfRenderSettings& settings) - : converter_(converter), settings_(settings) { -} + : converter_(converter), settings_(settings) {} -PdfToEmfUtilityProcessHostClient::~PdfToEmfUtilityProcessHostClient() { -} +PdfConverterUtilityProcessHostClient::~PdfConverterUtilityProcessHostClient() {} -void PdfToEmfUtilityProcessHostClient::Start( +void PdfConverterUtilityProcessHostClient::Start( const scoped_refptr& data, - bool print_text_with_gdi, - const PdfToEmfConverter::StartCallback& start_callback) { + const PdfConverter::StartCallback& start_callback) { if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - base::Bind(&PdfToEmfUtilityProcessHostClient::Start, this, data, - print_text_with_gdi, start_callback)); + base::Bind(&PdfConverterUtilityProcessHostClient::Start, this, data, + start_callback)); return; } @@ -324,50 +407,41 @@ void PdfToEmfUtilityProcessHostClient::Start( utility_process_host_ = content::UtilityProcessHost::Create( this, base::ThreadTaskRunnerHandle::Get()) ->AsWeakPtr(); - utility_process_host_->SetName(base::ASCIIToUTF16( - "IDS_UTILITY_PROCESS_EMF_CONVERTOR_NAME")); + utility_process_host_->SetName(GetName()); BrowserThread::PostTaskAndReplyWithResult( BrowserThread::FILE, FROM_HERE, base::Bind(&CreateTempPdfFile, data, &temp_dir_), - base::Bind(&PdfToEmfUtilityProcessHostClient::OnTempPdfReady, this, - print_text_with_gdi)); + base::Bind(&PdfConverterUtilityProcessHostClient::OnTempPdfReady, this)); } -void PdfToEmfUtilityProcessHostClient::OnTempPdfReady(bool print_text_with_gdi, - ScopedTempFile pdf) { +void PdfConverterUtilityProcessHostClient::OnTempPdfReady(ScopedTempFile pdf) { DCHECK_CURRENTLY_ON(BrowserThread::IO); if (!utility_process_host_ || !pdf) return OnFailed(); // Should reply with OnPageCount(). - Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles( - IPC::GetPlatformFileForTransit(pdf->GetPlatformFile(), false), settings_, - print_text_with_gdi)); + SendStartMessage( + IPC::GetPlatformFileForTransit(pdf->GetPlatformFile(), false)); } -void PdfToEmfUtilityProcessHostClient::OnPageCount(int page_count) { +void PdfConverterUtilityProcessHostClient::OnPageCount(int page_count) { DCHECK_CURRENTLY_ON(BrowserThread::IO); if (start_callback_.is_null()) return OnFailed(); - BrowserThread::PostTask(BrowserThread::UI, - FROM_HERE, - base::Bind(&PdfToEmfConverterImpl::RunCallback, - converter_, + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + base::Bind(&PdfConverterImpl::RunCallback, converter_, base::Bind(start_callback_, page_count))); start_callback_.Reset(); } -void PdfToEmfUtilityProcessHostClient::GetPage( +void PdfConverterUtilityProcessHostClient::GetPage( int page_number, - const PdfToEmfConverter::GetPageCallback& get_page_callback) { + const PdfConverter::GetPageCallback& get_page_callback) { if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - base::Bind(&PdfToEmfUtilityProcessHostClient::GetPage, - this, - page_number, - get_page_callback)); + BrowserThread::IO, FROM_HERE, + base::Bind(&PdfConverterUtilityProcessHostClient::GetPage, this, + page_number, get_page_callback)); return; } @@ -378,55 +452,84 @@ void PdfToEmfUtilityProcessHostClient::GetPage( return OnFailed(); BrowserThread::PostTaskAndReplyWithResult( - BrowserThread::FILE, - FROM_HERE, - base::Bind(&CreateTempFile, &temp_dir_), - base::Bind(&PdfToEmfUtilityProcessHostClient::OnTempEmfReady, - this, + BrowserThread::FILE, FROM_HERE, base::Bind(&CreateTempFile, &temp_dir_), + base::Bind(&PdfConverterUtilityProcessHostClient::OnTempFileReady, this, &get_page_callbacks_.back())); } -void PdfToEmfUtilityProcessHostClient::OnTempEmfReady( +void PdfConverterUtilityProcessHostClient::OnTempFileReady( GetPageCallbackData* callback_data, - ScopedTempFile emf) { + ScopedTempFile temp_file) { DCHECK_CURRENTLY_ON(BrowserThread::IO); - if (!utility_process_host_ || !emf) + if (!utility_process_host_ || !temp_file) return OnFailed(); IPC::PlatformFileForTransit transit = - IPC::GetPlatformFileForTransit(emf->GetPlatformFile(), false); - callback_data->set_emf(std::move(emf)); + IPC::GetPlatformFileForTransit(temp_file->GetPlatformFile(), false); + callback_data->set_file(std::move(temp_file)); // Should reply with OnPageDone(). - Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage( - callback_data->page_number(), transit)); + SendGetPageMessage(callback_data->page_number(), transit); } -void PdfToEmfUtilityProcessHostClient::OnPageDone(bool success, - float scale_factor) { +void PdfConverterUtilityProcessHostClient::OnPageDone(bool success, + float scale_factor) { DCHECK_CURRENTLY_ON(BrowserThread::IO); if (get_page_callbacks_.empty()) return OnFailed(); GetPageCallbackData& data = get_page_callbacks_.front(); - std::unique_ptr emf; + std::unique_ptr file; if (success) { - ScopedTempFile temp_emf = data.TakeEmf(); - if (!temp_emf) // Unexpected message from utility process. + ScopedTempFile temp_file = data.TakeFile(); + if (!temp_file) // Unexpected message from utility process. return OnFailed(); - emf = base::MakeUnique(temp_dir_, std::move(temp_emf)); + file = GetFileFromTemp(std::move(temp_file)); } - BrowserThread::PostTask(BrowserThread::UI, - FROM_HERE, - base::Bind(&PdfToEmfConverterImpl::RunCallback, - converter_, - base::Bind(data.callback(), - data.page_number(), - scale_factor, - base::Passed(&emf)))); + BrowserThread::PostTask( + BrowserThread::UI, FROM_HERE, + base::Bind(&PdfConverterImpl::RunCallback, converter_, + base::Bind(data.callback(), data.page_number(), scale_factor, + base::Passed(&file)))); get_page_callbacks_.pop(); } -void PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters( +void PdfConverterUtilityProcessHostClient::Stop() { + if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&PdfConverterUtilityProcessHostClient::Stop, this)); + return; + } + SendStopMessage(); +} + +void PdfConverterUtilityProcessHostClient::OnProcessCrashed(int exit_code) { + OnFailed(); +} + +void PdfConverterUtilityProcessHostClient::OnProcessLaunchFailed( + int exit_code) { + OnFailed(); +} + +bool PdfConverterUtilityProcessHostClient::Send(IPC::Message* msg) { + if (utility_process_host_) + return utility_process_host_->Send(msg); + delete msg; + return false; +} + +void PdfConverterUtilityProcessHostClient::OnFailed() { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + if (!start_callback_.is_null()) + OnPageCount(0); + while (!get_page_callbacks_.empty()) + OnPageDone(false, 0.0f); + utility_process_host_.reset(); +} + + +void PdfConverterUtilityProcessHostClient::OnPreCacheFontCharacters( const LOGFONT& font, const base::string16& str) { // TODO(scottmg): pdf/ppapi still require the renderer to be able to precache @@ -458,29 +561,10 @@ void PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters( DeleteEnhMetaFile(metafile); } -void PdfToEmfUtilityProcessHostClient::Stop() { - if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { - BrowserThread::PostTask( - BrowserThread::IO, - FROM_HERE, - base::Bind(&PdfToEmfUtilityProcessHostClient::Stop, this)); - return; - } - Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop()); -} - -void PdfToEmfUtilityProcessHostClient::OnProcessCrashed(int exit_code) { - OnFailed(); -} - -void PdfToEmfUtilityProcessHostClient::OnProcessLaunchFailed(int exit_code) { - OnFailed(); -} - -bool PdfToEmfUtilityProcessHostClient::OnMessageReceived( +bool PdfConverterUtilityProcessHostClient::OnMessageReceived( const IPC::Message& message) { bool handled = true; - IPC_BEGIN_MESSAGE_MAP(PdfToEmfUtilityProcessHostClient, message) + IPC_BEGIN_MESSAGE_MAP(PdfConverterUtilityProcessHostClient, message) IPC_MESSAGE_HANDLER( ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, OnPageCount) IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone, @@ -492,59 +576,69 @@ bool PdfToEmfUtilityProcessHostClient::OnMessageReceived( return handled; } -bool PdfToEmfUtilityProcessHostClient::Send(IPC::Message* msg) { - if (utility_process_host_) - return utility_process_host_->Send(msg); - delete msg; - return false; +base::string16 PdfConverterUtilityProcessHostClient::GetName() const { + return L"ChromeUtilityProcessPDFConvertor"; } -void PdfToEmfUtilityProcessHostClient::OnFailed() { - DCHECK_CURRENTLY_ON(BrowserThread::IO); - if (!start_callback_.is_null()) - OnPageCount(0); - while (!get_page_callbacks_.empty()) - OnPageDone(false, 0.0f); - utility_process_host_.reset(); +void PdfConverterUtilityProcessHostClient::SendGetPageMessage( + int page_number, + IPC::PlatformFileForTransit transit) { + Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage(page_number, + transit)); } -PdfToEmfConverterImpl::PdfToEmfConverterImpl() : weak_ptr_factory_(this) { +void PdfConverterUtilityProcessHostClient::SendStartMessage( + IPC::PlatformFileForTransit transit) { + Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles(transit, settings_)); } -PdfToEmfConverterImpl::~PdfToEmfConverterImpl() { +void PdfConverterUtilityProcessHostClient::SendStopMessage() { + Send(new ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop()); +} + +// Pdf Converter Impl and subclasses +PdfConverterImpl::PdfConverterImpl() : weak_ptr_factory_(this) {} + +PdfConverterImpl::~PdfConverterImpl() { if (utility_client_.get()) utility_client_->Stop(); } -void PdfToEmfConverterImpl::Start( - const scoped_refptr& data, - const PdfRenderSettings& conversion_settings, - bool print_text_with_gdi, - const StartCallback& start_callback) { - DCHECK(!utility_client_.get()); - utility_client_ = new PdfToEmfUtilityProcessHostClient( - weak_ptr_factory_.GetWeakPtr(), conversion_settings); - utility_client_->Start(data, print_text_with_gdi, start_callback); +void PdfConverterImpl::Start( + const scoped_refptr& utility_client, + const scoped_refptr& data, + const StartCallback& start_callback) { + DCHECK(!utility_client_); + utility_client_ = utility_client; + utility_client_->Start(data, start_callback); } -void PdfToEmfConverterImpl::GetPage(int page_number, - const GetPageCallback& get_page_callback) { +void PdfConverterImpl::GetPage(int page_number, + const GetPageCallback& get_page_callback) { utility_client_->GetPage(page_number, get_page_callback); } -void PdfToEmfConverterImpl::RunCallback(const base::Closure& callback) { +void PdfConverterImpl::RunCallback(const base::Closure& callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); callback.Run(); } } // namespace -PdfToEmfConverter::~PdfToEmfConverter() { -} +PdfConverter::~PdfConverter() {} // static -std::unique_ptr PdfToEmfConverter::CreateDefault() { - return std::unique_ptr(new PdfToEmfConverterImpl()); +std::unique_ptr PdfConverter::StartPdfConverter( + const scoped_refptr& data, + const PdfRenderSettings& conversion_settings, + const StartCallback& start_callback) { + std::unique_ptr converter = + base::MakeUnique(); + converter->Start( + new PdfConverterUtilityProcessHostClient(converter->GetWeakPtr(), + conversion_settings), + data, start_callback); + return std::move(converter); } } // namespace printing diff --git a/chromium_src/chrome/browser/printing/pdf_to_emf_converter.h b/chromium_src/chrome/browser/printing/pdf_to_emf_converter.h index 1f527152740..9990400a7bc 100644 --- a/chromium_src/chrome/browser/printing/pdf_to_emf_converter.h +++ b/chromium_src/chrome/browser/printing/pdf_to_emf_converter.h @@ -15,24 +15,21 @@ namespace printing { class MetafilePlayer; struct PdfRenderSettings; -class PdfToEmfConverter { +class PdfConverter { public: - typedef base::Callback StartCallback; - typedef base::Callback emf)> - GetPageCallback; - - virtual ~PdfToEmfConverter(); - - static std::unique_ptr CreateDefault(); + using StartCallback = base::Callback; + using GetPageCallback = + base::Callback file)>; + virtual ~PdfConverter(); // Starts conversion of PDF provided as |data|. Calls |start_callback| // with positive |page_count|. |page_count| is 0 if initialization failed. - virtual void Start(const scoped_refptr& data, - const PdfRenderSettings& conversion_settings, - bool print_text_with_gdi, - const StartCallback& start_callback) = 0; + static std::unique_ptr StartPdfConverter( + const scoped_refptr& data, + const PdfRenderSettings& conversion_settings, + const StartCallback& start_callback); // Requests conversion of the page. |page_number| is 0-base page number in // PDF provided in Start() call. @@ -41,7 +38,6 @@ class PdfToEmfConverter { virtual void GetPage(int page_number, const GetPageCallback& get_page_callback) = 0; }; - } // namespace printing #endif // CHROME_BROWSER_PRINTING_PDF_TO_EMF_CONVERTER_H_ diff --git a/chromium_src/chrome/browser/printing/print_job.cc b/chromium_src/chrome/browser/printing/print_job.cc index 8a969618bdb..c5038f370de 100644 --- a/chromium_src/chrome/browser/printing/print_job.cc +++ b/chromium_src/chrome/browser/printing/print_job.cc @@ -223,27 +223,23 @@ PrintedDocument* PrintJob::document() const { } #if defined(OS_WIN) - -class PrintJob::PdfToEmfState { +class PrintJob::PdfConversionState { public: - PdfToEmfState(const gfx::Size& page_size, const gfx::Rect& content_area) + PdfConversionState(gfx::Size page_size, gfx::Rect content_area) : page_count_(0), current_page_(0), pages_in_progress_(0), page_size_(page_size), - content_area_(content_area), - converter_(PdfToEmfConverter::CreateDefault()) {} + content_area_(content_area) {} void Start(const scoped_refptr& data, const PdfRenderSettings& conversion_settings, - bool print_text_with_gdi, - const PdfToEmfConverter::StartCallback& start_callback) { - converter_->Start(data, conversion_settings, print_text_with_gdi, - start_callback); + const PdfConverter::StartCallback& start_callback) { + converter_ = PdfConverter::StartPdfConverter( + data, conversion_settings, start_callback); } - void GetMorePages( - const PdfToEmfConverter::GetPageCallback& get_page_callback) { + void GetMorePages(const PdfConverter::GetPageCallback& get_page_callback) { const int kMaxNumberOfTempFilesPerDocument = 3; while (pages_in_progress_ < kMaxNumberOfTempFilesPerDocument && current_page_ < page_count_) { @@ -252,8 +248,7 @@ class PrintJob::PdfToEmfState { } } - void OnPageProcessed( - const PdfToEmfConverter::GetPageCallback& get_page_callback) { + void OnPageProcessed(const PdfConverter::GetPageCallback& get_page_callback) { --pages_in_progress_; GetMorePages(get_page_callback); // Release converter if we don't need this any more. @@ -271,7 +266,7 @@ class PrintJob::PdfToEmfState { int pages_in_progress_; gfx::Size page_size_; gfx::Rect content_area_; - std::unique_ptr converter_; + std::unique_ptr converter_; }; void PrintJob::AppendPrintedPage(int page_number) { @@ -283,46 +278,67 @@ void PrintJob::StartPdfToEmfConversion( const gfx::Size& page_size, const gfx::Rect& content_area, bool print_text_with_gdi) { - DCHECK(!pdf_to_emf_state_); - pdf_to_emf_state_ = base::MakeUnique(page_size, content_area); + DCHECK(!pdf_conversion_state_); + pdf_conversion_state_ = + base::MakeUnique(page_size, content_area); const int kPrinterDpi = settings().dpi(); - pdf_to_emf_state_->Start( - bytes, PdfRenderSettings(content_area, kPrinterDpi, true), - print_text_with_gdi, base::Bind(&PrintJob::OnPdfToEmfStarted, this)); + PdfRenderSettings settings( + content_area, gfx::Point(0, 0), kPrinterDpi, /*autorotate=*/true, + print_text_with_gdi ? PdfRenderSettings::Mode::GDI_TEXT + : PdfRenderSettings::Mode::NORMAL); + pdf_conversion_state_->Start( + bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); } -void PrintJob::OnPdfToEmfStarted(int page_count) { +void PrintJob::OnPdfConversionStarted(int page_count) { if (page_count <= 0) { - pdf_to_emf_state_.reset(); + pdf_conversion_state_.reset(); Cancel(); return; } - pdf_to_emf_state_->set_page_count(page_count); - pdf_to_emf_state_->GetMorePages( - base::Bind(&PrintJob::OnPdfToEmfPageConverted, this)); + pdf_conversion_state_->set_page_count(page_count); + pdf_conversion_state_->GetMorePages( + base::Bind(&PrintJob::OnPdfPageConverted, this)); } -void PrintJob::OnPdfToEmfPageConverted(int page_number, - float scale_factor, - std::unique_ptr emf) { - DCHECK(pdf_to_emf_state_); - if (!document_.get() || !emf || page_number < 0 || +void PrintJob::OnPdfPageConverted(int page_number, + float scale_factor, + std::unique_ptr metafile) { + DCHECK(pdf_conversion_state_); + if (!document_.get() || !metafile || page_number < 0 || static_cast(page_number) >= pdf_page_mapping_.size()) { - pdf_to_emf_state_.reset(); + pdf_conversion_state_.reset(); Cancel(); return; } // Update the rendered document. It will send notifications to the listener. - document_->SetPage(pdf_page_mapping_[page_number], std::move(emf), - scale_factor, pdf_to_emf_state_->page_size(), - pdf_to_emf_state_->content_area()); + document_->SetPage(pdf_page_mapping_[page_number], std::move(metafile), + scale_factor, pdf_conversion_state_->page_size(), + pdf_conversion_state_->content_area()); - pdf_to_emf_state_->GetMorePages( - base::Bind(&PrintJob::OnPdfToEmfPageConverted, this)); + pdf_conversion_state_->GetMorePages( + base::Bind(&PrintJob::OnPdfPageConverted, this)); } -#endif // OS_WIN +void PrintJob::StartPdfToPostScriptConversion( + const scoped_refptr& bytes, + const gfx::Rect& content_area, + const gfx::Point& physical_offsets, + bool ps_level2) { + DCHECK(!pdf_conversion_state_); + pdf_conversion_state_ = base::MakeUnique( + gfx::Size(), gfx::Rect()); + const int kPrinterDpi = settings().dpi(); + PdfRenderSettings settings( + content_area, physical_offsets, kPrinterDpi, true /* autorotate? */, + ps_level2 ? PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 + : PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3); + pdf_conversion_state_->Start( + bytes, settings, base::Bind(&PrintJob::OnPdfConversionStarted, this)); +} + +#endif // defined(OS_WIN) void PrintJob::UpdatePrintedDocument(PrintedDocument* new_document) { if (document_.get() == new_document) @@ -373,8 +389,10 @@ void PrintJob::OnNotifyPrintJobEvent(const JobEventDetails& event_details) { } case JobEventDetails::PAGE_DONE: #if defined(OS_WIN) - pdf_to_emf_state_->OnPageProcessed( - base::Bind(&PrintJob::OnPdfToEmfPageConverted, this)); + if (pdf_conversion_state_) { + pdf_conversion_state_->OnPageProcessed( + base::Bind(&PrintJob::OnPdfPageConverted, this)); + } #endif // defined(OS_WIN) break; default: { diff --git a/chromium_src/chrome/browser/printing/print_job.h b/chromium_src/chrome/browser/printing/print_job.h index e5c77aeb234..bca518f6fcd 100644 --- a/chromium_src/chrome/browser/printing/print_job.h +++ b/chromium_src/chrome/browser/printing/print_job.h @@ -100,6 +100,12 @@ class PrintJob : public PrintJobWorkerOwner, const gfx::Size& page_size, const gfx::Rect& content_area, bool print_text_with_gdi); + + void StartPdfToPostScriptConversion( + const scoped_refptr& bytes, + const gfx::Rect& content_area, + const gfx::Point& physical_offset, + bool ps_level2); #endif // defined(OS_WIN) protected: @@ -126,10 +132,10 @@ class PrintJob : public PrintJobWorkerOwner, void HoldUntilStopIsCalled(); #if defined(OS_WIN) - void OnPdfToEmfStarted(int page_count); - void OnPdfToEmfPageConverted(int page_number, - float scale_factor, - std::unique_ptr emf); + void OnPdfConversionStarted(int page_count); + void OnPdfPageConverted(int page_number, + float scale_factor, + std::unique_ptr emf); #endif // defined(OS_WIN) content::NotificationRegistrar registrar_; @@ -157,8 +163,8 @@ class PrintJob : public PrintJobWorkerOwner, bool is_canceling_; #if defined(OS_WIN) - class PdfToEmfState; - std::unique_ptr pdf_to_emf_state_; + class PdfConversionState; + std::unique_ptr pdf_conversion_state_; std::vector pdf_page_mapping_; #endif // defined(OS_WIN) diff --git a/chromium_src/chrome/common/chrome_utility_printing_messages.h b/chromium_src/chrome/common/chrome_utility_printing_messages.h new file mode 100644 index 00000000000..fc71f0bd05f --- /dev/null +++ b/chromium_src/chrome/common/chrome_utility_printing_messages.h @@ -0,0 +1,111 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Multiply-included message file, so no include guard. + +#include +#include + +#include "base/strings/string16.h" +#include "build/build_config.h" +#include "ipc/ipc_message_macros.h" +#include "ipc/ipc_param_traits.h" +#include "ipc/ipc_platform_file.h" +#include "printing/backend/print_backend.h" +#include "printing/features/features.h" +#include "printing/page_range.h" +#include "printing/pdf_render_settings.h" +#include "printing/pwg_raster_settings.h" + +#if defined(OS_WIN) +#include +#endif + +#define IPC_MESSAGE_START ChromeUtilityPrintingMsgStart + +IPC_ENUM_TRAITS_MAX_VALUE(printing::PdfRenderSettings::Mode, + printing::PdfRenderSettings::Mode::LAST) + +IPC_STRUCT_TRAITS_BEGIN(printing::PdfRenderSettings) + IPC_STRUCT_TRAITS_MEMBER(area) + IPC_STRUCT_TRAITS_MEMBER(offsets) + IPC_STRUCT_TRAITS_MEMBER(dpi) + IPC_STRUCT_TRAITS_MEMBER(autorotate) + IPC_STRUCT_TRAITS_MEMBER(mode) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(printing::PrinterCapsAndDefaults) + IPC_STRUCT_TRAITS_MEMBER(printer_capabilities) + IPC_STRUCT_TRAITS_MEMBER(caps_mime_type) + IPC_STRUCT_TRAITS_MEMBER(printer_defaults) + IPC_STRUCT_TRAITS_MEMBER(defaults_mime_type) +IPC_STRUCT_TRAITS_END() + +IPC_ENUM_TRAITS_MAX_VALUE(printing::ColorModel, printing::PROCESSCOLORMODEL_RGB) + +IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults::Paper) + IPC_STRUCT_TRAITS_MEMBER(display_name) + IPC_STRUCT_TRAITS_MEMBER(vendor_id) + IPC_STRUCT_TRAITS_MEMBER(size_um) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults) + IPC_STRUCT_TRAITS_MEMBER(collate_capable) + IPC_STRUCT_TRAITS_MEMBER(collate_default) + IPC_STRUCT_TRAITS_MEMBER(copies_capable) + IPC_STRUCT_TRAITS_MEMBER(duplex_capable) + IPC_STRUCT_TRAITS_MEMBER(duplex_default) + IPC_STRUCT_TRAITS_MEMBER(color_changeable) + IPC_STRUCT_TRAITS_MEMBER(color_default) + IPC_STRUCT_TRAITS_MEMBER(color_model) + IPC_STRUCT_TRAITS_MEMBER(bw_model) + IPC_STRUCT_TRAITS_MEMBER(papers) + IPC_STRUCT_TRAITS_MEMBER(default_paper) + IPC_STRUCT_TRAITS_MEMBER(dpis) + IPC_STRUCT_TRAITS_MEMBER(default_dpi) +IPC_STRUCT_TRAITS_END() + +IPC_ENUM_TRAITS_MAX_VALUE(printing::PwgRasterTransformType, + printing::TRANSFORM_TYPE_LAST) + +IPC_STRUCT_TRAITS_BEGIN(printing::PwgRasterSettings) + IPC_STRUCT_TRAITS_MEMBER(odd_page_transform) + IPC_STRUCT_TRAITS_MEMBER(rotate_all_pages) + IPC_STRUCT_TRAITS_MEMBER(reverse_page_order) +IPC_STRUCT_TRAITS_END() + +#if defined(OS_WIN) +// Reply when the utility process loaded PDF. |page_count| is 0, if loading +// failed. +IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, + int /* page_count */) + +// Reply when the utility process rendered the PDF page. +IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone, + bool /* success */, + float /* scale_factor */) + +// Request that the given font characters be loaded by the browser so it's +// cached by the OS. Please see +// PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters for details. +IPC_SYNC_MESSAGE_CONTROL2_0(ChromeUtilityHostMsg_PreCacheFontCharacters, + LOGFONT /* font_data */, + base::string16 /* characters */) + +// Tell the utility process to start rendering the given PDF into a metafile. +// Utility process would be alive until +// ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop message. +IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_RenderPDFPagesToMetafiles, + IPC::PlatformFileForTransit /* input_file */, + printing::PdfRenderSettings /* settings */) + +// Requests conversion of the next page. +IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage, + int /* page_number */, + IPC::PlatformFileForTransit /* output_file */) + +// Requests utility process to stop conversion and exit. +IPC_MESSAGE_CONTROL0(ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop) + +#endif // OS_WIN diff --git a/chromium_src/chrome/common/print_messages.h b/chromium_src/chrome/common/print_messages.h index e74dfafa71a..196d8be508c 100644 --- a/chromium_src/chrome/common/print_messages.h +++ b/chromium_src/chrome/common/print_messages.h @@ -74,6 +74,9 @@ struct PrintMsg_PrintPages_Params { IPC_ENUM_TRAITS_MAX_VALUE(printing::MarginType, printing::MARGIN_TYPE_LAST) +IPC_ENUM_TRAITS_MIN_MAX_VALUE(printing::DuplexMode, + printing::UNKNOWN_DUPLEX_MODE, + printing::SHORT_EDGE) IPC_ENUM_TRAITS_MAX_VALUE(blink::WebPrintScalingOption, blink::WebPrintScalingOptionLast) @@ -310,39 +313,3 @@ IPC_MESSAGE_ROUTED1(PrintHostMsg_MetafileReadyForPrinting, IPC_MESSAGE_ROUTED2(PrintHostMsg_PrintPreviewFailed, int /* document cookie */, int /* request_id */); - -#if defined(OS_WIN) -// Tell the utility process to start rendering the given PDF into a metafile. -// Utility process would be alive until -// ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop message. -IPC_MESSAGE_CONTROL3(ChromeUtilityMsg_RenderPDFPagesToMetafiles, - IPC::PlatformFileForTransit /* input_file */, - printing::PdfRenderSettings /* settings */, - bool /* print_text_with_gdi */) - -// Requests conversion of the next page. -IPC_MESSAGE_CONTROL2(ChromeUtilityMsg_RenderPDFPagesToMetafiles_GetPage, - int /* page_number */, - IPC::PlatformFileForTransit /* output_file */) - -// Requests utility process to stop conversion and exit. -IPC_MESSAGE_CONTROL0(ChromeUtilityMsg_RenderPDFPagesToMetafiles_Stop) - -// Reply when the utility process loaded PDF. |page_count| is 0, if loading -// failed. -IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount, - int /* page_count */) - -// Reply when the utility process rendered the PDF page. -IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone, - bool /* success */, - float /* scale_factor */) - -// Request that the given font characters be loaded by the browser so it's -// cached by the OS. Please see -// PdfToEmfUtilityProcessHostClient::OnPreCacheFontCharacters for details. -IPC_SYNC_MESSAGE_CONTROL2_0(ChromeUtilityHostMsg_PreCacheFontCharacters, - LOGFONT /* font_data */, - base::string16 /* characters */) - -#endif diff --git a/chromium_src/chrome/renderer/printing/print_web_view_helper_pdf_win.cc b/chromium_src/chrome/renderer/printing/print_web_view_helper_pdf_win.cc index 6449f09feec..abac5543003 100644 --- a/chromium_src/chrome/renderer/printing/print_web_view_helper_pdf_win.cc +++ b/chromium_src/chrome/renderer/printing/print_web_view_helper_pdf_win.cc @@ -14,7 +14,6 @@ #include "printing/page_size_margins.h" #include "printing/pdf_metafile_skia.h" #include "printing/units.h" -#include "skia/ext/platform_device.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" diff --git a/chromium_src/chrome/utility/printing_handler_win.cc b/chromium_src/chrome/utility/printing_handler_win.cc index 4265991272a..cd01a09601a 100644 --- a/chromium_src/chrome/utility/printing_handler_win.cc +++ b/chromium_src/chrome/utility/printing_handler_win.cc @@ -8,6 +8,7 @@ #include "base/lazy_instance.h" #include "base/path_service.h" #include "base/scoped_native_library.h" +#include "chrome/common/chrome_utility_printing_messages.h" #include "chrome/common/print_messages.h" #include "content/public/utility/utility_thread.h" #include "pdf/pdf.h" @@ -59,13 +60,25 @@ bool PrintingHandlerWin::OnMessageReceived(const IPC::Message& message) { void PrintingHandlerWin::OnRenderPDFPagesToMetafile( IPC::PlatformFileForTransit pdf_transit, - const PdfRenderSettings& settings, - bool print_text_with_gdi) { + const PdfRenderSettings& settings) { pdf_rendering_settings_ = settings; - chrome_pdf::SetPDFUseGDIPrinting(print_text_with_gdi); + chrome_pdf::SetPDFUseGDIPrinting(pdf_rendering_settings_.mode == + PdfRenderSettings::Mode::GDI_TEXT); + int postscript_level; + switch (pdf_rendering_settings_.mode) { + case PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2: + postscript_level = 2; + break; + case PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3: + postscript_level = 3; + break; + default: + postscript_level = 0; // Not using postscript. + } + chrome_pdf::SetPDFPostscriptPrintingLevel(postscript_level); + base::File pdf_file = IPC::PlatformFileForTransitToFile(pdf_transit); int page_count = LoadPDF(std::move(pdf_file)); - //int page_count = 1; Send( new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageCount(page_count)); } @@ -75,8 +88,12 @@ void PrintingHandlerWin::OnRenderPDFPagesToMetafileGetPage( IPC::PlatformFileForTransit output_file) { base::File emf_file = IPC::PlatformFileForTransitToFile(output_file); float scale_factor = 1.0f; - bool success = - RenderPdfPageToMetafile(page_number, std::move(emf_file), &scale_factor); + bool postscript = pdf_rendering_settings_.mode == + PdfRenderSettings::Mode::POSTSCRIPT_LEVEL2 || + pdf_rendering_settings_.mode == + PdfRenderSettings::Mode::POSTSCRIPT_LEVEL3; + bool success = RenderPdfPageToMetafile(page_number, std::move(emf_file), + &scale_factor, postscript); Send(new ChromeUtilityHostMsg_RenderPDFPagesToMetafiles_PageDone( success, scale_factor)); } @@ -105,7 +122,8 @@ int PrintingHandlerWin::LoadPDF(base::File pdf_file) { bool PrintingHandlerWin::RenderPdfPageToMetafile(int page_number, base::File output_file, - float* scale_factor) { + float* scale_factor, + bool postscript) { Emf metafile; metafile.Init(); @@ -116,18 +134,30 @@ bool PrintingHandlerWin::RenderPdfPageToMetafile(int page_number, // original coordinates and we'll be able to print in full resolution. // Before playback we'll need to counter the scaling up that will happen // in the service (print_system_win.cc). - *scale_factor = gfx::CalculatePageScale( - metafile.context(), pdf_rendering_settings_.area.right(), - pdf_rendering_settings_.area.bottom()); - gfx::ScaleDC(metafile.context(), *scale_factor); + // + // The postscript driver does not use the metafile size since it outputs + // postscript rather than a metafile. Instead it uses the printable area + // sent to RenderPDFPageToDC to determine the area to render. Therefore, + // don't scale the DC to match the metafile, and send the printer physical + // offsets to the driver. + if (!postscript) { + *scale_factor = gfx::CalculatePageScale( + metafile.context(), pdf_rendering_settings_.area.right(), + pdf_rendering_settings_.area.bottom()); + gfx::ScaleDC(metafile.context(), *scale_factor); + } // The underlying metafile is of type Emf and ignores the arguments passed // to StartPage. metafile.StartPage(gfx::Size(), gfx::Rect(), 1); + int offset_x = postscript ? pdf_rendering_settings_.offsets.x() : 0; + int offset_y = postscript ? pdf_rendering_settings_.offsets.y() : 0; + if (!chrome_pdf::RenderPDFPageToDC( &pdf_data_.front(), pdf_data_.size(), page_number, metafile.context(), - pdf_rendering_settings_.dpi, pdf_rendering_settings_.area.x(), - pdf_rendering_settings_.area.y(), + pdf_rendering_settings_.dpi, + pdf_rendering_settings_.area.x() - offset_x, + pdf_rendering_settings_.area.y() - offset_y, pdf_rendering_settings_.area.width(), pdf_rendering_settings_.area.height(), true, false, true, true, pdf_rendering_settings_.autorotate)) { @@ -138,4 +168,4 @@ bool PrintingHandlerWin::RenderPdfPageToMetafile(int page_number, return metafile.SaveTo(&output_file); } -} // printing +} // namespace printing diff --git a/chromium_src/chrome/utility/printing_handler_win.h b/chromium_src/chrome/utility/printing_handler_win.h index b4a1902dc71..d058e7e5055 100644 --- a/chromium_src/chrome/utility/printing_handler_win.h +++ b/chromium_src/chrome/utility/printing_handler_win.h @@ -29,8 +29,7 @@ class PrintingHandlerWin : public UtilityMessageHandler { private: // IPC message handlers. void OnRenderPDFPagesToMetafile(IPC::PlatformFileForTransit pdf_transit, - const PdfRenderSettings& settings, - bool print_text_with_gdi); + const PdfRenderSettings& settings); void OnRenderPDFPagesToMetafileGetPage( int page_number, IPC::PlatformFileForTransit output_file); @@ -39,7 +38,8 @@ class PrintingHandlerWin : public UtilityMessageHandler { int LoadPDF(base::File pdf_file); bool RenderPdfPageToMetafile(int page_number, base::File output_file, - float* scale_factor); + float* scale_factor, + bool postscript); std::vector pdf_data_; PdfRenderSettings pdf_rendering_settings_; diff --git a/common.gypi b/common.gypi index 7c1bf366aa6..d4b7646c28e 100644 --- a/common.gypi +++ b/common.gypi @@ -240,6 +240,7 @@ 4302, # (atldlgs.h) 'type cast': truncation from 'LPCTSTR' to 'WORD' 4458, # (atldlgs.h) declaration of 'dwCommonButtons' hides class member 4503, # decorated name length exceeded, name was truncated + 4714, # (atomicstring.h) function marked as __forceinline not inlined 4800, # (v8.h) forcing value to bool 'true' or 'false' 4819, # The file contains a character that cannot be represented in the current code page 4838, # (atlgdi.h) conversion from 'int' to 'UINT' requires a narrowing conversion From 0fb746b350327f7e530c8a801e67d4f79c7e2589 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 18 Apr 2017 16:20:08 +0900 Subject: [PATCH 1068/1195] Fix crash when using secure schemes --- atom/browser/api/atom_api_protocol.cc | 17 +++++++++++------ vendor/brightray | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/atom/browser/api/atom_api_protocol.cc b/atom/browser/api/atom_api_protocol.cc index e3b15ed4329..4ff8c5c6bab 100644 --- a/atom/browser/api/atom_api_protocol.cc +++ b/atom/browser/api/atom_api_protocol.cc @@ -50,20 +50,25 @@ void RegisterStandardSchemes(const std::vector& schemes, mate::Arguments* args) { g_standard_schemes = schemes; + mate::Dictionary opts; + bool secure = false; + args->GetNext(&opts) && opts.Get("secure", &secure); + + // Dynamically register the schemes. auto* policy = content::ChildProcessSecurityPolicy::GetInstance(); for (const std::string& scheme : schemes) { url::AddStandardScheme(scheme.c_str(), url::SCHEME_WITHOUT_PORT); + if (secure) { + url::AddSecureScheme(scheme.c_str()); + } policy->RegisterWebSafeScheme(scheme); } - // add switches to register as standard + // Add the schemes to command line switches, so child processes can also + // register them. base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( atom::switches::kStandardSchemes, base::JoinString(schemes, ",")); - - mate::Dictionary opts; - bool secure = false; - if (args->GetNext(&opts) && opts.Get("secure", &secure) && secure) { - // add switches to register as secure + if (secure) { base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( atom::switches::kSecureSchemes, base::JoinString(schemes, ",")); } diff --git a/vendor/brightray b/vendor/brightray index 3e77e9faa16..541da8135eb 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 3e77e9faa16fcbda5fe740e1f2332201cf423c56 +Subproject commit 541da8135eb72ca6f59da0e59ded4245fb12278e From 5563cf0dc5cf89a85a38f294f8a8861a36a9e140 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 20 Apr 2017 17:44:25 +0900 Subject: [PATCH 1069/1195] Automatically register secure schemes in renderer Otherwise the behavior of secure schemes would be different with before. --- atom/renderer/renderer_client_base.cc | 8 ++++++++ script/lib/config.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/atom/renderer/renderer_client_base.cc b/atom/renderer/renderer_client_base.cc index 8a4ed82f07c..1219dfb5dcf 100644 --- a/atom/renderer/renderer_client_base.cc +++ b/atom/renderer/renderer_client_base.cc @@ -30,6 +30,7 @@ #include "third_party/WebKit/public/web/WebPluginParams.h" #include "third_party/WebKit/public/web/WebScriptSource.h" #include "third_party/WebKit/public/web/WebSecurityPolicy.h" +#include "third_party/WebKit/Source/platform/weborigin/SchemeRegistry.h" #if defined(OS_MACOSX) #include "base/mac/mac_util.h" @@ -85,6 +86,13 @@ void RendererClientBase::RenderThreadStarted() { blink::WebCustomElement::addEmbedderCustomElementName("webview"); blink::WebCustomElement::addEmbedderCustomElementName("browserplugin"); + // Parse --secure-schemes=scheme1,scheme2 + std::vector secure_schemes_list = + ParseSchemesCLISwitch(switches::kSecureSchemes); + for (const std::string& scheme : secure_schemes_list) + blink::SchemeRegistry::registerURLSchemeAsSecure( + WTF::String::fromUTF8(scheme.data(), scheme.length())); + preferences_manager_.reset(new PreferencesManager); #if defined(OS_WIN) diff --git a/script/lib/config.py b/script/lib/config.py index fbcf9e6ca7b..602b07e10d1 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -9,7 +9,7 @@ import sys BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \ 'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent' LIBCHROMIUMCONTENT_COMMIT = os.getenv('LIBCHROMIUMCONTENT_COMMIT') or \ - '791141a820ecf6166a86249701838b57f43777ea' + '72cfdcb1b916546cf198cf39c8fc53c3175c248c' PLATFORM = { 'cygwin': 'win32', From e6e985c6770b1a82209454b878d0b41b1f4495ff Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 20 Apr 2017 19:58:37 +0900 Subject: [PATCH 1070/1195] Fix linking error with icu symbols --- atom/node/osfhandle.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/atom/node/osfhandle.cc b/atom/node/osfhandle.cc index b0ac8c1ce3b..c6cc991ec61 100644 --- a/atom/node/osfhandle.cc +++ b/atom/node/osfhandle.cc @@ -15,6 +15,7 @@ #include "third_party/icu/source/common/unicode/unorm.h" #include "third_party/icu/source/common/unicode/urename.h" #include "third_party/icu/source/common/unicode/ustring.h" +#include "third_party/icu/source/i18n/unicode/dtitvfmt.h" #include "third_party/icu/source/i18n/unicode/measfmt.h" #include "third_party/icu/source/i18n/unicode/translit.h" #include "third_party/icu/source/i18n/unicode/ucsdet.h" @@ -60,6 +61,8 @@ void ReferenceSymbols() { UMeasureFormatWidth width = UMEASFMT_WIDTH_WIDE; UErrorCode status = U_ZERO_ERROR; icu::MeasureFormat format(icu::Locale::getRoot(), width, status); + icu::DateIntervalFormat::createInstance(UnicodeString(), + icu::Locale::getRoot(), status); reinterpret_cast(nullptr)->clone(); } From 620a1ca1679c71bb3388f354c0e59fd001639608 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 21 Apr 2017 09:57:30 +0900 Subject: [PATCH 1071/1195] Fix unresolved symbol to icu::DateInterval --- atom/node/osfhandle.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/atom/node/osfhandle.cc b/atom/node/osfhandle.cc index c6cc991ec61..ae5ee725d78 100644 --- a/atom/node/osfhandle.cc +++ b/atom/node/osfhandle.cc @@ -7,6 +7,8 @@ #include #define U_I18N_IMPLEMENTATION +#define U_COMMON_IMPLEMENTATION +#define U_COMBINED_IMPLEMENTATION #include "third_party/icu/source/common/unicode/ubidi.h" #include "third_party/icu/source/common/unicode/uchar.h" @@ -61,6 +63,7 @@ void ReferenceSymbols() { UMeasureFormatWidth width = UMEASFMT_WIDTH_WIDE; UErrorCode status = U_ZERO_ERROR; icu::MeasureFormat format(icu::Locale::getRoot(), width, status); + icu::DateInterval internal(0, 0); icu::DateIntervalFormat::createInstance(UnicodeString(), icu::Locale::getRoot(), status); reinterpret_cast(nullptr)->clone(); From cbd3b054cb83f7dce16410c24d50bf471cdfb777 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 21 Apr 2017 19:00:11 +0900 Subject: [PATCH 1072/1195] Fix release build --- script/lib/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/lib/config.py b/script/lib/config.py index 602b07e10d1..d5b148ff58d 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -9,7 +9,7 @@ import sys BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \ 'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent' LIBCHROMIUMCONTENT_COMMIT = os.getenv('LIBCHROMIUMCONTENT_COMMIT') or \ - '72cfdcb1b916546cf198cf39c8fc53c3175c248c' + '3ca4584486acbfb4b344c7ce956fdcd40a4ed63e' PLATFORM = { 'cygwin': 'win32', From 301ed2d66cd4db04838292554b5b40a671e0906f Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 25 Apr 2017 08:51:47 +0900 Subject: [PATCH 1073/1195] Fix typo when updating code --- atom/common/native_mate_converters/blink_converter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/common/native_mate_converters/blink_converter.cc b/atom/common/native_mate_converters/blink_converter.cc index c70ffe21391..5acfe545e49 100644 --- a/atom/common/native_mate_converters/blink_converter.cc +++ b/atom/common/native_mate_converters/blink_converter.cc @@ -280,7 +280,7 @@ bool Converter::FromV8( bool can_scroll = true; if (dict.Get("canScroll", &can_scroll) && !can_scroll) { out->hasPreciseScrollingDeltas = false; - out->setModifiers(out->modifiers() | blink::WebInputEvent::ControlKey); + out->setModifiers(out->modifiers() & ~blink::WebInputEvent::ControlKey); } #endif return true; From 4c47f2d15edc885fb59062a00ab84f7c750eb756 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 27 Apr 2017 16:56:47 +0900 Subject: [PATCH 1074/1195] Update to Node v7.9.0 --- atom/common/api/atom_api_asar.cc | 6 +++--- atom/renderer/atom_renderer_client.cc | 3 +-- atom/renderer/atom_sandboxed_renderer_client.cc | 6 +++--- vendor/node | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/atom/common/api/atom_api_asar.cc b/atom/common/api/atom_api_asar.cc index 3151da6f171..5b0c9cc6cb9 100644 --- a/atom/common/api/atom_api_asar.cc +++ b/atom/common/api/atom_api_asar.cc @@ -6,17 +6,17 @@ #include -#include "atom_natives.h" // NOLINT: This file is generated with coffee2c. - #include "atom/common/asar/archive.h" #include "atom/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/file_path_converter.h" -#include "atom/common/node_includes.h" #include "native_mate/arguments.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" #include "native_mate/wrappable.h" +#include "atom/common/node_includes.h" +#include "atom_natives.h" // NOLINT: This file is generated with coffee2c. + namespace { class Archive : public mate::Wrappable { diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 1ce17193dff..ce36f9520e5 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -7,8 +7,6 @@ #include #include -#include "atom_natives.h" // NOLINT: This file is generated with js2c - #include "atom/common/api/atom_bindings.h" #include "atom/common/api/event_emitter_caller.h" #include "atom/common/asar/asar_util.h" @@ -27,6 +25,7 @@ #include "third_party/WebKit/public/web/WebLocalFrame.h" #include "atom/common/node_includes.h" +#include "atom_natives.h" // NOLINT: This file is generated with js2c namespace atom { diff --git a/atom/renderer/atom_sandboxed_renderer_client.cc b/atom/renderer/atom_sandboxed_renderer_client.cc index 4fe9bd449dd..c0d7d4a6af5 100644 --- a/atom/renderer/atom_sandboxed_renderer_client.cc +++ b/atom/renderer/atom_sandboxed_renderer_client.cc @@ -6,14 +6,11 @@ #include -#include "atom_natives.h" // NOLINT: This file is generated with js2c - #include "atom/common/api/api_messages.h" #include "atom/common/api/atom_bindings.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/v8_value_converter.h" #include "atom/common/native_mate_converters/value_converter.h" -#include "atom/common/node_includes.h" #include "atom/common/options_switches.h" #include "atom/renderer/api/atom_api_renderer_ipc.h" #include "atom/renderer/atom_render_view_observer.h" @@ -31,6 +28,9 @@ #include "third_party/WebKit/public/web/WebScriptSource.h" #include "third_party/WebKit/public/web/WebView.h" +#include "atom/common/node_includes.h" +#include "atom_natives.h" // NOLINT: This file is generated with js2c + namespace atom { namespace { diff --git a/vendor/node b/vendor/node index 42eee8a6926..df227c3a5db 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 42eee8a69267191ac20505bf929bb39a688d7385 +Subproject commit df227c3a5db7aa8eab64c86f54588c6cd2d6c623 From 3601ae3549d3ed00dfa927cb8546be4bf198656e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 27 Apr 2017 17:50:02 +0900 Subject: [PATCH 1075/1195] Update to Chrome 58.0.3029.81 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 72cfdcb1b91..3ca4584486a 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 72cfdcb1b916546cf198cf39c8fc53c3175c248c +Subproject commit 3ca4584486acbfb4b344c7ce956fdcd40a4ed63e From dd2d0b3f4f7016dbd910d6fdcf6c9f844c14f95c Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 27 Apr 2017 17:50:41 +0900 Subject: [PATCH 1076/1195] Update to Chrome 58.0.3029.81 --- atom/common/chrome_version.h | 2 +- vendor/brightray | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/common/chrome_version.h b/atom/common/chrome_version.h index 04d30344ed7..092b654a441 100644 --- a/atom/common/chrome_version.h +++ b/atom/common/chrome_version.h @@ -8,7 +8,7 @@ #ifndef ATOM_COMMON_CHROME_VERSION_H_ #define ATOM_COMMON_CHROME_VERSION_H_ -#define CHROME_VERSION_STRING "58.0.3029.40" +#define CHROME_VERSION_STRING "58.0.3029.81" #define CHROME_VERSION "v" CHROME_VERSION_STRING #endif // ATOM_COMMON_CHROME_VERSION_H_ diff --git a/vendor/brightray b/vendor/brightray index 541da8135eb..e8b5d5b4134 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit 541da8135eb72ca6f59da0e59ded4245fb12278e +Subproject commit e8b5d5b41342b63ae4f93f024f31707ab189cc8d From edeac2f59e20af140cf5c15d55f8aeecacedc558 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 30 Apr 2017 18:53:31 +0900 Subject: [PATCH 1077/1195] Split test HTML file into separate ones --- spec/api-browser-window-spec.js | 6 ++-- .../api/native-window-open-blank.html | 11 +++++++ .../fixtures/api/native-window-open-file.html | 12 ++++++++ .../api/native-window-open-native-addon.html | 9 ++++++ spec/fixtures/api/native-window-open.html | 30 ------------------- 5 files changed, 35 insertions(+), 33 deletions(-) create mode 100644 spec/fixtures/api/native-window-open-blank.html create mode 100644 spec/fixtures/api/native-window-open-file.html create mode 100644 spec/fixtures/api/native-window-open-native-addon.html delete mode 100644 spec/fixtures/api/native-window-open.html diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 703f5a6d3ec..8df5e675ec6 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1099,14 +1099,14 @@ describe('BrowserWindow module', function () { assert.equal(content, 'Hello') done() }) - w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#blank')) + w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-blank.html')) }) it('opens window of same domain with cross-scripting enabled', (done) => { ipcMain.once('answer', (event, content) => { assert.equal(content, 'Hello') done() }) - w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#file')) + w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-file.html')) }) it('loads native addons correctly after reload', (done) => { ipcMain.once('answer', (event, content) => { @@ -1117,7 +1117,7 @@ describe('BrowserWindow module', function () { }) w.reload() }) - w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open.html#native-addon')) + w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-native-addon.html')) }) }) }) diff --git a/spec/fixtures/api/native-window-open-blank.html b/spec/fixtures/api/native-window-open-blank.html new file mode 100644 index 00000000000..f87495e2a3c --- /dev/null +++ b/spec/fixtures/api/native-window-open-blank.html @@ -0,0 +1,11 @@ + + + + + diff --git a/spec/fixtures/api/native-window-open-file.html b/spec/fixtures/api/native-window-open-file.html new file mode 100644 index 00000000000..fa64f56a68c --- /dev/null +++ b/spec/fixtures/api/native-window-open-file.html @@ -0,0 +1,12 @@ + + + + + diff --git a/spec/fixtures/api/native-window-open-native-addon.html b/spec/fixtures/api/native-window-open-native-addon.html new file mode 100644 index 00000000000..00192ef9ab6 --- /dev/null +++ b/spec/fixtures/api/native-window-open-native-addon.html @@ -0,0 +1,9 @@ + + + + + diff --git a/spec/fixtures/api/native-window-open.html b/spec/fixtures/api/native-window-open.html deleted file mode 100644 index 0d744fa678f..00000000000 --- a/spec/fixtures/api/native-window-open.html +++ /dev/null @@ -1,30 +0,0 @@ - - - - - From 0034b306f557ed8fd4b8fa3ca05521458613c9c7 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 30 Apr 2017 19:09:52 +0900 Subject: [PATCH 1078/1195] Add test for nativeWindowOpen + contextIsolation --- spec/api-browser-window-spec.js | 22 +++++++++++++++++++ .../native-window-open-isolated-preload.js | 5 +++++ .../api/native-window-open-isolated.html | 10 +++++++++ 3 files changed, 37 insertions(+) create mode 100644 spec/fixtures/api/native-window-open-isolated-preload.js create mode 100644 spec/fixtures/api/native-window-open-isolated.html diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 8df5e675ec6..475d2ea4c50 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1122,6 +1122,28 @@ describe('BrowserWindow module', function () { }) }) + describe('nativeWindowOpen + contextIsolation options', () => { + beforeEach(() => { + w.destroy() + w = new BrowserWindow({ + show: false, + webPreferences: { + nativeWindowOpen: true, + contextIsolation: true, + preload: path.join(fixtures, 'api', 'native-window-open-isolated-preload.js') + } + }) + }) + + it('opens window with cross-scripting enabled from isolated context', (done) => { + ipcMain.once('answer', (event, content) => { + assert.equal(content, 'Hello') + done() + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'native-window-open-isolated.html')) + }) + }) + describe('beforeunload handler', function () { it('returning undefined would not prevent close', function (done) { w.once('closed', function () { diff --git a/spec/fixtures/api/native-window-open-isolated-preload.js b/spec/fixtures/api/native-window-open-isolated-preload.js new file mode 100644 index 00000000000..aa214166021 --- /dev/null +++ b/spec/fixtures/api/native-window-open-isolated-preload.js @@ -0,0 +1,5 @@ +const {ipcRenderer} = require('electron') + +window.addEventListener('message', (event) => { + ipcRenderer.send('answer', event.data) +}) diff --git a/spec/fixtures/api/native-window-open-isolated.html b/spec/fixtures/api/native-window-open-isolated.html new file mode 100644 index 00000000000..41cce8e82ef --- /dev/null +++ b/spec/fixtures/api/native-window-open-isolated.html @@ -0,0 +1,10 @@ + + + + + From 8b6b512485a2928f6e93630889b530986f6bf428 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 30 Apr 2017 19:35:41 +0900 Subject: [PATCH 1079/1195] Pass nativeWindowOpen flag to isolated init.js --- atom/renderer/atom_renderer_client.cc | 2 ++ lib/isolated_renderer/init.js | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index 5dafe084ce2..1471fcac6a0 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -206,6 +206,8 @@ void AtomRendererClient::SetupMainWorldOverrides( dict.Set(options::kOpenerID, command_line->GetSwitchValueASCII(switches::kOpenerID)); dict.Set("hiddenPage", command_line->HasSwitch(switches::kHiddenPage)); + dict.Set("nativeWindowOpen", + command_line->HasSwitch(switches::kNativeWindowOpen)); v8::Local args[] = { binding }; ignore_result(func->Call(context, v8::Null(isolate), 1, args)); diff --git a/lib/isolated_renderer/init.js b/lib/isolated_renderer/init.js index 943713d985b..1536ab10638 100644 --- a/lib/isolated_renderer/init.js +++ b/lib/isolated_renderer/init.js @@ -19,8 +19,8 @@ const ipcRenderer = { once () {} } -let {guestInstanceId, hiddenPage, openerId} = binding +let {guestInstanceId, hiddenPage, openerId, nativeWindowOpen} = binding if (guestInstanceId != null) guestInstanceId = parseInt(guestInstanceId) if (openerId != null) openerId = parseInt(openerId) -require('../renderer/window-setup')(ipcRenderer, guestInstanceId, openerId, hiddenPage) +require('../renderer/window-setup')(ipcRenderer, guestInstanceId, openerId, hiddenPage, nativeWindowOpen) From da97150fc979a5c2066e9ee68bd143aedc452432 Mon Sep 17 00:00:00 2001 From: Ryohei Ikegami Date: Sun, 30 Apr 2017 19:43:21 +0900 Subject: [PATCH 1080/1195] Fix JS style in test HTMLs --- spec/fixtures/api/native-window-open-blank.html | 10 +++++----- spec/fixtures/api/native-window-open-file.html | 10 +++++----- spec/fixtures/api/native-window-open-isolated.html | 8 ++++---- spec/fixtures/api/native-window-open-native-addon.html | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/fixtures/api/native-window-open-blank.html b/spec/fixtures/api/native-window-open-blank.html index f87495e2a3c..7174594e244 100644 --- a/spec/fixtures/api/native-window-open-blank.html +++ b/spec/fixtures/api/native-window-open-blank.html @@ -1,11 +1,11 @@ diff --git a/spec/fixtures/api/native-window-open-file.html b/spec/fixtures/api/native-window-open-file.html index fa64f56a68c..30f2c61c9e0 100644 --- a/spec/fixtures/api/native-window-open-file.html +++ b/spec/fixtures/api/native-window-open-file.html @@ -1,12 +1,12 @@ diff --git a/spec/fixtures/api/native-window-open-isolated.html b/spec/fixtures/api/native-window-open-isolated.html index 41cce8e82ef..706209f1908 100644 --- a/spec/fixtures/api/native-window-open-isolated.html +++ b/spec/fixtures/api/native-window-open-isolated.html @@ -1,10 +1,10 @@ diff --git a/spec/fixtures/api/native-window-open-native-addon.html b/spec/fixtures/api/native-window-open-native-addon.html index 00192ef9ab6..c1f75872ef9 100644 --- a/spec/fixtures/api/native-window-open-native-addon.html +++ b/spec/fixtures/api/native-window-open-native-addon.html @@ -1,9 +1,9 @@ From c19c14d0b3ba7967242002c2cd1b42e9cde6457e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 2 May 2017 10:14:49 -0700 Subject: [PATCH 1081/1195] Build spec modules against locally generated node headers tarball --- script/bootstrap.py | 13 ++++- script/create-node-headers.py | 104 ++++++++++++++++++++++++++++++++++ script/upload-node-headers.py | 79 +------------------------- script/upload.py | 1 + 4 files changed, 117 insertions(+), 80 deletions(-) create mode 100755 script/create-node-headers.py diff --git a/script/bootstrap.py b/script/bootstrap.py index 1fd3fd83906..ac5f51f6e8d 100755 --- a/script/bootstrap.py +++ b/script/bootstrap.py @@ -63,6 +63,7 @@ def main(): create_chrome_version_h() touch_config_gypi() run_update(defines, args.msvs) + create_node_headers() update_electron_modules('spec', args.target_arch) @@ -184,9 +185,11 @@ def update_node_modules(dirname, env=None): def update_electron_modules(dirname, target_arch): env = os.environ.copy() + version = get_electron_version() env['npm_config_arch'] = target_arch - env['npm_config_target'] = get_electron_version() - env['npm_config_disturl'] = 'https://atom.io/download/electron' + env['npm_config_target'] = version + env['npm_config_tarball'] = os.path.join(SOURCE_ROOT, 'dist', + 'node-{0}.tar.gz'.format(version)) update_node_modules(dirname, env) @@ -260,5 +263,11 @@ def run_update(defines, msvs): execute_stdout(args) +def create_node_headers(): + execute_stdout([sys.executable, + os.path.join(SOURCE_ROOT, 'script', 'create-node-headers.py'), + '--version', get_electron_version()]) + + if __name__ == '__main__': sys.exit(main()) diff --git a/script/create-node-headers.py b/script/create-node-headers.py new file mode 100755 index 00000000000..baf9c86aba3 --- /dev/null +++ b/script/create-node-headers.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python + +import argparse +import os +import shutil +import sys +import tarfile + +from lib.util import safe_mkdir, scoped_cwd + + +SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) +DIST_DIR = os.path.join(SOURCE_ROOT, 'dist') +NODE_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'node') +OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'R') + +HEADERS_SUFFIX = [ + '.h', + '.gypi', +] +HEADERS_DIRS = [ + 'src', + 'deps/http_parser', + 'deps/zlib', + 'deps/uv', + 'deps/npm', + 'deps/mdb_v8', +] +HEADERS_FILES = [ + 'common.gypi', + 'config.gypi', +] + + +def main(): + safe_mkdir(DIST_DIR) + + args = parse_args() + node_headers_dir = os.path.join(DIST_DIR, 'node-{0}'.format(args.version)) + iojs_headers_dir = os.path.join(DIST_DIR, 'iojs-{0}'.format(args.version)) + iojs2_headers_dir = os.path.join(DIST_DIR, + 'iojs-{0}-headers'.format(args.version)) + + copy_headers(node_headers_dir) + create_header_tarball(node_headers_dir) + copy_headers(iojs_headers_dir) + create_header_tarball(iojs_headers_dir) + copy_headers(iojs2_headers_dir) + create_header_tarball(iojs2_headers_dir) + + +def parse_args(): + parser = argparse.ArgumentParser(description='create node header tarballs') + parser.add_argument('-v', '--version', help='Specify the version', + required=True) + return parser.parse_args() + + +def copy_headers(dist_headers_dir): + safe_mkdir(dist_headers_dir) + + # Copy standard node headers from node. repository. + for include_path in HEADERS_DIRS: + abs_path = os.path.join(NODE_DIR, include_path) + for dirpath, _, filenames in os.walk(abs_path): + for filename in filenames: + extension = os.path.splitext(filename)[1] + if extension not in HEADERS_SUFFIX: + continue + copy_source_file(os.path.join(dirpath, filename), NODE_DIR, + dist_headers_dir) + for other_file in HEADERS_FILES: + copy_source_file(os.path.join(NODE_DIR, other_file), NODE_DIR, + dist_headers_dir) + + # Copy V8 headers from chromium's repository. + src = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', 'download', + 'libchromiumcontent', 'src') + for dirpath, _, filenames in os.walk(os.path.join(src, 'v8')): + for filename in filenames: + extension = os.path.splitext(filename)[1] + if extension not in HEADERS_SUFFIX: + continue + copy_source_file(os.path.join(dirpath, filename), src, + os.path.join(dist_headers_dir, 'deps')) + + +def create_header_tarball(dist_headers_dir): + target = dist_headers_dir + '.tar.gz' + with scoped_cwd(DIST_DIR): + tarball = tarfile.open(name=target, mode='w:gz') + tarball.add(os.path.relpath(dist_headers_dir)) + tarball.close() + + +def copy_source_file(source, start, destination): + relative = os.path.relpath(source, start=start) + final_destination = os.path.join(destination, relative) + safe_mkdir(os.path.dirname(final_destination)) + shutil.copy2(source, final_destination) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/script/upload-node-headers.py b/script/upload-node-headers.py index 230b08ed5ac..6c5163f7629 100755 --- a/script/upload-node-headers.py +++ b/script/upload-node-headers.py @@ -5,50 +5,17 @@ import glob import os import shutil import sys -import tarfile from lib.config import PLATFORM, get_target_arch, s3_config -from lib.util import execute, safe_mkdir, scoped_cwd, s3put +from lib.util import safe_mkdir, scoped_cwd, s3put SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) DIST_DIR = os.path.join(SOURCE_ROOT, 'dist') -NODE_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'node') OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'R') -HEADERS_SUFFIX = [ - '.h', - '.gypi', -] -HEADERS_DIRS = [ - 'src', - 'deps/http_parser', - 'deps/zlib', - 'deps/uv', - 'deps/npm', - 'deps/mdb_v8', -] -HEADERS_FILES = [ - 'common.gypi', - 'config.gypi', -] - - def main(): - safe_mkdir(DIST_DIR) - args = parse_args() - node_headers_dir = os.path.join(DIST_DIR, 'node-{0}'.format(args.version)) - iojs_headers_dir = os.path.join(DIST_DIR, 'iojs-{0}'.format(args.version)) - iojs2_headers_dir = os.path.join(DIST_DIR, - 'iojs-{0}-headers'.format(args.version)) - - copy_headers(node_headers_dir) - create_header_tarball(node_headers_dir) - copy_headers(iojs_headers_dir) - create_header_tarball(iojs_headers_dir) - copy_headers(iojs2_headers_dir) - create_header_tarball(iojs2_headers_dir) # Upload node's headers to S3. bucket, access_key, secret_key = s3_config() @@ -62,50 +29,6 @@ def parse_args(): return parser.parse_args() -def copy_headers(dist_headers_dir): - safe_mkdir(dist_headers_dir) - - # Copy standard node headers from node. repository. - for include_path in HEADERS_DIRS: - abs_path = os.path.join(NODE_DIR, include_path) - for dirpath, _, filenames in os.walk(abs_path): - for filename in filenames: - extension = os.path.splitext(filename)[1] - if extension not in HEADERS_SUFFIX: - continue - copy_source_file(os.path.join(dirpath, filename), NODE_DIR, - dist_headers_dir) - for other_file in HEADERS_FILES: - copy_source_file(os.path.join(NODE_DIR, other_file), NODE_DIR, - dist_headers_dir) - - # Copy V8 headers from chromium's repository. - src = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', 'download', - 'libchromiumcontent', 'src') - for dirpath, _, filenames in os.walk(os.path.join(src, 'v8')): - for filename in filenames: - extension = os.path.splitext(filename)[1] - if extension not in HEADERS_SUFFIX: - continue - copy_source_file(os.path.join(dirpath, filename), src, - os.path.join(dist_headers_dir, 'deps')) - - -def create_header_tarball(dist_headers_dir): - target = dist_headers_dir + '.tar.gz' - with scoped_cwd(DIST_DIR): - tarball = tarfile.open(name=target, mode='w:gz') - tarball.add(os.path.relpath(dist_headers_dir)) - tarball.close() - - -def copy_source_file(source, start, destination): - relative = os.path.relpath(source, start=start) - final_destination = os.path.join(destination, relative) - safe_mkdir(os.path.dirname(final_destination)) - shutil.copy2(source, final_destination) - - def upload_node(bucket, access_key, secret_key, version): with scoped_cwd(DIST_DIR): s3put(bucket, access_key, secret_key, DIST_DIR, diff --git a/script/upload.py b/script/upload.py index 8b4cdfcbdf0..3a9d1a0a8f7 100755 --- a/script/upload.py +++ b/script/upload.py @@ -101,6 +101,7 @@ def main(): run_python_script('upload-windows-pdb.py') # Upload node headers. + run_python_script('create-node-headers.py', '-v', args.version) run_python_script('upload-node-headers.py', '-v', args.version) From 20fa2ce1470d055b9ecb470dcfbb7fa88c477f8a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 2 May 2017 13:24:29 -0700 Subject: [PATCH 1082/1195] Rebuild native modules during bootstrap --- script/bootstrap.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script/bootstrap.py b/script/bootstrap.py index ac5f51f6e8d..29fd1e27ce2 100755 --- a/script/bootstrap.py +++ b/script/bootstrap.py @@ -177,10 +177,12 @@ def update_node_modules(dirname, env=None): if os.environ.has_key('CI'): try: execute_stdout(args, env) + execute_stdout([NPM, 'rebuild'], env) except subprocess.CalledProcessError: pass else: execute_stdout(args, env) + execute_stdout([NPM, 'rebuild'], env) def update_electron_modules(dirname, target_arch): From 164b97af4c575eff6d3b0deebaf8c76af6804a60 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 2 May 2017 13:47:34 -0700 Subject: [PATCH 1083/1195] Use nodedir option to specify local headers --- script/bootstrap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/bootstrap.py b/script/bootstrap.py index 29fd1e27ce2..08d84cff28e 100755 --- a/script/bootstrap.py +++ b/script/bootstrap.py @@ -190,8 +190,8 @@ def update_electron_modules(dirname, target_arch): version = get_electron_version() env['npm_config_arch'] = target_arch env['npm_config_target'] = version - env['npm_config_tarball'] = os.path.join(SOURCE_ROOT, 'dist', - 'node-{0}.tar.gz'.format(version)) + env['npm_config_nodedir'] = os.path.join(SOURCE_ROOT, 'dist', + 'node-{0}'.format(version)) update_node_modules(dirname, env) From dec7a3c12ae75a2175eea3e4afba8a09827aa818 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 May 2017 08:48:58 -0700 Subject: [PATCH 1084/1195] Upgrade to 58.0.3029.96 --- brightray/vendor/libchromiumcontent | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brightray/vendor/libchromiumcontent b/brightray/vendor/libchromiumcontent index 3ca4584486a..8b373ae3b7a 160000 --- a/brightray/vendor/libchromiumcontent +++ b/brightray/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 3ca4584486acbfb4b344c7ce956fdcd40a4ed63e +Subproject commit 8b373ae3b7a22c0e7a2506107904f93a8d1c425a From e1d564da6eb1835db8f4520120df5cfcf2149f7f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 May 2017 08:49:09 -0700 Subject: [PATCH 1085/1195] Upgrade to Chrome 58.0.3029.96 --- atom/common/chrome_version.h | 2 +- script/lib/config.py | 2 +- vendor/brightray | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/atom/common/chrome_version.h b/atom/common/chrome_version.h index 092b654a441..3e2ed42e709 100644 --- a/atom/common/chrome_version.h +++ b/atom/common/chrome_version.h @@ -8,7 +8,7 @@ #ifndef ATOM_COMMON_CHROME_VERSION_H_ #define ATOM_COMMON_CHROME_VERSION_H_ -#define CHROME_VERSION_STRING "58.0.3029.81" +#define CHROME_VERSION_STRING "58.0.3029.96" #define CHROME_VERSION "v" CHROME_VERSION_STRING #endif // ATOM_COMMON_CHROME_VERSION_H_ diff --git a/script/lib/config.py b/script/lib/config.py index d5b148ff58d..2a79c9148f4 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -9,7 +9,7 @@ import sys BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \ 'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent' LIBCHROMIUMCONTENT_COMMIT = os.getenv('LIBCHROMIUMCONTENT_COMMIT') or \ - '3ca4584486acbfb4b344c7ce956fdcd40a4ed63e' + '8b373ae3b7a22c0e7a2506107904f93a8d1c425a' PLATFORM = { 'cygwin': 'win32', diff --git a/vendor/brightray b/vendor/brightray index e8b5d5b4134..c84b587acf1 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit e8b5d5b41342b63ae4f93f024f31707ab189cc8d +Subproject commit c84b587acf181c4fec60459900b4e993f0fd95d9 From 042b511a274331e0b39c1467b34672038c26d720 Mon Sep 17 00:00:00 2001 From: 22222 <22222@users.noreply.github.com> Date: Tue, 25 Apr 2017 18:14:34 -0500 Subject: [PATCH 1086/1195] Fix #8911 --- atom/browser/api/atom_api_web_contents.cc | 9 ++++ atom/browser/api/atom_api_web_contents.h | 1 + spec/api-browser-window-spec.js | 54 +++++++++++++++++++ .../api/beforeunload-false-prevent3.html | 17 ++++++ 4 files changed, 81 insertions(+) create mode 100644 spec/fixtures/api/beforeunload-false-prevent3.html diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index a06ec2244dd..94fb80ca85b 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -872,6 +872,15 @@ void WebContents::Observe(int type, } } +void WebContents::BeforeUnloadDialogCancelled() { + if (deferred_load_url_.id) { + auto& controller = web_contents()->GetController(); + if (!controller.GetPendingEntry()) { + deferred_load_url_.id = 0; + } + } +} + void WebContents::DevToolsReloadPage() { Emit("devtools-reload-page"); } diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 2289cdb4a45..1f926dbd7a5 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -340,6 +340,7 @@ class WebContents : public mate::TrackableObject, void Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) override; + void BeforeUnloadDialogCancelled() override; // brightray::InspectableWebContentsDelegate: void DevToolsReloadPage() override; diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 34db4a6ae79..f9396e19d00 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1174,6 +1174,60 @@ describe('BrowserWindow module', function () { }) w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-empty-string.html')) }) + + it('emits for each close attempt', function (done) { + var beforeUnloadCount = 0 + w.on('onbeforeunload', function () { + beforeUnloadCount++ + if (beforeUnloadCount < 3) { + w.close() + } else if (beforeUnloadCount === 3) { + done() + } + }) + w.webContents.once('did-finish-load', function () { + w.close() + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false-prevent3.html')) + }) + + it('emits for each reload attempt', function (done) { + var beforeUnloadCount = 0 + w.on('onbeforeunload', function () { + beforeUnloadCount++ + if (beforeUnloadCount < 3) { + w.reload() + } else if (beforeUnloadCount === 3) { + done() + } + }) + w.webContents.once('did-finish-load', function () { + w.webContents.once('did-finish-load', function () { + assert.fail('Reload was not prevented') + }) + w.reload() + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false-prevent3.html')) + }) + + it('emits for each navigation attempt', function (done) { + var beforeUnloadCount = 0 + w.on('onbeforeunload', function () { + beforeUnloadCount++ + if (beforeUnloadCount < 3) { + w.loadURL('about:blank') + } else if (beforeUnloadCount === 3) { + done() + } + }) + w.webContents.once('did-finish-load', function () { + w.webContents.once('did-finish-load', function () { + assert.fail('Navigation was not prevented') + }) + w.loadURL('about:blank') + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'beforeunload-false-prevent3.html')) + }) }) describe('new-window event', function () { diff --git a/spec/fixtures/api/beforeunload-false-prevent3.html b/spec/fixtures/api/beforeunload-false-prevent3.html new file mode 100644 index 00000000000..6ed2a7d1aa4 --- /dev/null +++ b/spec/fixtures/api/beforeunload-false-prevent3.html @@ -0,0 +1,17 @@ + + + + + From 50057163c6d4a14034b945897fece05affa47835 Mon Sep 17 00:00:00 2001 From: Tom Watson Date: Mon, 8 May 2017 10:41:16 +0200 Subject: [PATCH 1087/1195] :memo: clarify dialog buttons blocking side effect --- docs/api/dialog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/dialog.md b/docs/api/dialog.md index 68cfa7fcea9..79a4ea781ac 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -161,8 +161,8 @@ It returns the index of the clicked button. The `browserWindow` argument allows the dialog to attach itself to a parent window, making it modal. -If a `callback` is passed, the API call will be asynchronous and the result -will be passed via `callback(response)`. +If a `callback` is passed, the dialog will not block the process. The API call +will be asynchronous and the result will be passed via `callback(response)`. ### `dialog.showErrorBox(title, content)` From a694110d48b0f6a5988339974c2f51ab7071a3c7 Mon Sep 17 00:00:00 2001 From: Hum4n01d Date: Mon, 8 May 2017 13:36:28 -0700 Subject: [PATCH 1088/1195] Fix order of OSs It was previously inconsistent --- docs/tutorial/quick-start.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/tutorial/quick-start.md b/docs/tutorial/quick-start.md index f490b738891..9a13715fad6 100644 --- a/docs/tutorial/quick-start.md +++ b/docs/tutorial/quick-start.md @@ -192,10 +192,10 @@ $ .\node_modules\.bin\electron . If you downloaded Electron manually, you can also use the included binary to execute your app directly. -#### Windows +#### macOS ```bash -$ .\electron\electron.exe your-app\ +$ ./Electron.app/Contents/MacOS/Electron your-app/ ``` #### Linux @@ -204,10 +204,10 @@ $ .\electron\electron.exe your-app\ $ ./electron/electron your-app/ ``` -#### macOS +#### Windows ```bash -$ ./Electron.app/Contents/MacOS/Electron your-app/ +$ .\electron\electron.exe your-app\ ``` `Electron.app` here is part of the Electron's release package, you can download From 3dee76a6c1f557a20b5882955a4172f2ab8862c4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 8 May 2017 13:43:13 -0700 Subject: [PATCH 1089/1195] :art: --- atom/common/api/atom_api_asar.cc | 2 +- atom/common/crash_reporter/crash_reporter_mac.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/common/api/atom_api_asar.cc b/atom/common/api/atom_api_asar.cc index 5b0c9cc6cb9..83d5efb09b9 100644 --- a/atom/common/api/atom_api_asar.cc +++ b/atom/common/api/atom_api_asar.cc @@ -15,7 +15,7 @@ #include "native_mate/wrappable.h" #include "atom/common/node_includes.h" -#include "atom_natives.h" // NOLINT: This file is generated with coffee2c. +#include "atom_natives.h" // NOLINT: This file is generated with js2c. namespace { diff --git a/atom/common/crash_reporter/crash_reporter_mac.mm b/atom/common/crash_reporter/crash_reporter_mac.mm index 970cca1acdb..990e1b3b195 100644 --- a/atom/common/crash_reporter/crash_reporter_mac.mm +++ b/atom/common/crash_reporter/crash_reporter_mac.mm @@ -45,7 +45,7 @@ void CrashReporterMac::InitBreakpad(const std::string& product_name, std::vector args = { "--no-rate-limit", - "--no-upload-gzip", // no all servers accept gzip + "--no-upload-gzip", // not all servers accept gzip }; crashpad::CrashpadClient crashpad_client; From 8be4332765cc29a0b64a44f1c60e0622ed71d582 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 8 May 2017 14:06:58 -0700 Subject: [PATCH 1090/1195] coffee -> js --- atom/common/api/atom_api_asar.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/common/api/atom_api_asar.cc b/atom/common/api/atom_api_asar.cc index 83d5efb09b9..ef27850370f 100644 --- a/atom/common/api/atom_api_asar.cc +++ b/atom/common/api/atom_api_asar.cc @@ -130,7 +130,7 @@ class Archive : public mate::Wrappable { void InitAsarSupport(v8::Isolate* isolate, v8::Local process, v8::Local require) { - // Evaluate asar_init.coffee. + // Evaluate asar_init.js. const char* asar_init_native = reinterpret_cast( static_cast(node::asar_init_data)); v8::Local asar_init = v8::Script::Compile(v8::String::NewFromUtf8( From efe23b7595744eb1f068bbd2816ba973ad4fcee2 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 9 May 2017 14:12:39 +0900 Subject: [PATCH 1091/1195] Use Node's memory allocator for ArrayBuffer For Buffers created in Node, they are usually allocated in Node and freed by Chromium's allocator, which will cause crashes when Node and Chromium are using different allocators. This commit makes Chromium use Node' allocator for ArrayBuffers. --- atom/browser/javascript_environment.cc | 31 ++++++++++++++++++++++++-- atom/browser/javascript_environment.h | 9 ++++++++ atom/node/osfhandle.cc | 13 +++++++++++ atom/node/osfhandle.h | 6 +++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/atom/browser/javascript_environment.cc b/atom/browser/javascript_environment.cc index b7e3aae20aa..d13b955972f 100644 --- a/atom/browser/javascript_environment.cc +++ b/atom/browser/javascript_environment.cc @@ -10,13 +10,40 @@ #include "base/message_loop/message_loop.h" #include "base/threading/thread_task_runner_handle.h" #include "content/public/common/content_switches.h" -#include "gin/array_buffer.h" #include "gin/v8_initializer.h" +#if defined(OS_WIN) +#include "atom/node/osfhandle.h" +#endif + #include "atom/common/node_includes.h" namespace atom { +void* ArrayBufferAllocator::Allocate(size_t length) { +#if defined(OS_WIN) + return node::ArrayBufferCalloc(length); +#else + return calloc(1, length); +#endif +} + +void* ArrayBufferAllocator::AllocateUninitialized(size_t length) { +#if defined(OS_WIN) + return node::ArrayBufferMalloc(length); +#else + return malloc(length); +#endif +} + +void ArrayBufferAllocator::Free(void* data, size_t length) { +#if defined(OS_WIN) + node::ArrayBufferFree(data, length); +#else + free(data); +#endif +} + JavascriptEnvironment::JavascriptEnvironment() : initialized_(Initialize()), isolate_holder_(base::ThreadTaskRunnerHandle::Get()), @@ -46,7 +73,7 @@ bool JavascriptEnvironment::Initialize() { gin::IsolateHolder::Initialize(gin::IsolateHolder::kNonStrictMode, gin::IsolateHolder::kStableV8Extras, - gin::ArrayBufferAllocator::SharedInstance()); + &allocator_); return true; } diff --git a/atom/browser/javascript_environment.h b/atom/browser/javascript_environment.h index 43a7295f902..75d1629f661 100644 --- a/atom/browser/javascript_environment.h +++ b/atom/browser/javascript_environment.h @@ -14,6 +14,14 @@ class Environment; namespace atom { +// ArrayBuffer's allocator, used on Chromium's side. +class ArrayBufferAllocator : public v8::ArrayBuffer::Allocator { + public: + void* Allocate(size_t length) override; + void* AllocateUninitialized(size_t length) override; + void Free(void* data, size_t length) override; +}; + // Manage the V8 isolate and context automatically. class JavascriptEnvironment { public: @@ -31,6 +39,7 @@ class JavascriptEnvironment { bool Initialize(); bool initialized_; + ArrayBufferAllocator allocator_; gin::IsolateHolder isolate_holder_; v8::Isolate* isolate_; v8::Isolate::Scope isolate_scope_; diff --git a/atom/node/osfhandle.cc b/atom/node/osfhandle.cc index ae5ee725d78..e9ec03a5c81 100644 --- a/atom/node/osfhandle.cc +++ b/atom/node/osfhandle.cc @@ -25,6 +25,7 @@ #include "third_party/icu/source/i18n/unicode/uregex.h" #include "third_party/icu/source/i18n/unicode/uspoof.h" #include "third_party/icu/source/i18n/unicode/usearch.h" +#include "util-inl.h" #include "v8-profiler.h" #include "v8-inspector.h" @@ -38,6 +39,18 @@ int close(int fd) { return _close(fd); } +void* ArrayBufferCalloc(size_t length) { + return UncheckedCalloc(length); +} + +void* ArrayBufferMalloc(size_t length) { + return UncheckedMalloc(length); +} + +void ArrayBufferFree(void* data, size_t length) { + return ::free(data); +} + void ReferenceSymbols() { // Following symbols are used by electron.exe but got stripped by compiler, // by using the symbols we can force compiler to keep the objects in node.dll, diff --git a/atom/node/osfhandle.h b/atom/node/osfhandle.h index 1427bb89511..58f87198ae2 100644 --- a/atom/node/osfhandle.h +++ b/atom/node/osfhandle.h @@ -21,6 +21,12 @@ namespace node { __declspec(dllexport) int open_osfhandle(intptr_t osfhandle, int flags); __declspec(dllexport) int close(int fd); +// Memory allocation functions from Node's module, used by ArrayBuffer allocator +// to make sure memories are allocated and freed with the same allocator. +__declspec(dllexport) void* ArrayBufferCalloc(size_t length); +__declspec(dllexport) void* ArrayBufferMalloc(size_t length); +__declspec(dllexport) void ArrayBufferFree(void* data, size_t length); + // A trick to force referencing symbols. __declspec(dllexport) void ReferenceSymbols(); From 9b82d1a996e41389f8d2fb4c49340a8870b4315f Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Tue, 9 May 2017 15:44:25 -0700 Subject: [PATCH 1092/1195] let the typescript module do its own linting --- package.json | 2 +- script/create-dist.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index af80571da52..5a4d24f46e6 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "browserify": "^13.1.0", "electabul": "~0.0.4", "electron-docs-linter": "^2.1.0", - "electron-typescript-definitions": "^1.0.1", + "electron-typescript-definitions": "^1.2.0", "request": "*", "standard": "^8.4.0", "standard-markdown": "^2.1.1" diff --git a/script/create-dist.py b/script/create-dist.py index 9188ad8dca5..2602a9f943d 100755 --- a/script/create-dist.py +++ b/script/create-dist.py @@ -150,11 +150,8 @@ def create_typescript_definitions(): env['PATH'] = os.path.pathsep.join([node_bin_dir, env['PATH']]) infile = os.path.relpath(os.path.join(DIST_DIR, 'electron-api.json')) outfile = os.path.relpath(os.path.join(DIST_DIR, 'electron.d.ts')) - tslintconfig = os.path.relpath(os.path.join(DIST_DIR, - '../node_modules/electron-typescript-definitions/tslint.json')) execute(['electron-typescript-definitions', '--in={0}'.format(infile), '--out={0}'.format(outfile)], env=env) - execute(['tslint', '--config', tslintconfig, outfile], env=env) def strip_binaries(): for binary in TARGET_BINARIES[PLATFORM]: From 65bd0ecaa96be30a8fee770f94225e82702be532 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 9 May 2017 21:11:46 -0700 Subject: [PATCH 1093/1195] Upgrade to Chrome 58.0.3029.110 --- atom/common/chrome_version.h | 2 +- script/lib/config.py | 2 +- vendor/brightray | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/atom/common/chrome_version.h b/atom/common/chrome_version.h index 3e2ed42e709..e25591c3bf8 100644 --- a/atom/common/chrome_version.h +++ b/atom/common/chrome_version.h @@ -8,7 +8,7 @@ #ifndef ATOM_COMMON_CHROME_VERSION_H_ #define ATOM_COMMON_CHROME_VERSION_H_ -#define CHROME_VERSION_STRING "58.0.3029.96" +#define CHROME_VERSION_STRING "58.0.3029.110" #define CHROME_VERSION "v" CHROME_VERSION_STRING #endif // ATOM_COMMON_CHROME_VERSION_H_ diff --git a/script/lib/config.py b/script/lib/config.py index 2a79c9148f4..c920f2acc22 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -9,7 +9,7 @@ import sys BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \ 'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent' LIBCHROMIUMCONTENT_COMMIT = os.getenv('LIBCHROMIUMCONTENT_COMMIT') or \ - '8b373ae3b7a22c0e7a2506107904f93a8d1c425a' + '44a803957cb27610c38f7e859016ac257959aeb5' PLATFORM = { 'cygwin': 'win32', diff --git a/vendor/brightray b/vendor/brightray index c84b587acf1..3d9ebb54999 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit c84b587acf181c4fec60459900b4e993f0fd95d9 +Subproject commit 3d9ebb549990d50ab67b705b8ff16433a3dbc546 From 379499e71ed12c248e56777773de886a03ae3858 Mon Sep 17 00:00:00 2001 From: Surya Setiyaputra Date: Thu, 11 May 2017 00:55:38 +1000 Subject: [PATCH 1094/1195] create folders for translation work --- README.md | 1 + docs-translations/id/README.md | 0 docs-translations/id/faq.md | 162 ++++++++++++ docs-translations/id/glossary.md | 0 .../id/project/CODE_OF_CONDUCT.md | 46 ++++ docs-translations/id/project/CONTRIBUTING.md | 79 ++++++ docs-translations/id/project/README.md | 90 +++++++ docs-translations/id/styleguide.md | 246 ++++++++++++++++++ 8 files changed, 624 insertions(+) create mode 100644 docs-translations/id/README.md create mode 100644 docs-translations/id/faq.md create mode 100644 docs-translations/id/glossary.md create mode 100644 docs-translations/id/project/CODE_OF_CONDUCT.md create mode 100644 docs-translations/id/project/CONTRIBUTING.md create mode 100644 docs-translations/id/project/README.md create mode 100644 docs-translations/id/styleguide.md diff --git a/README.md b/README.md index f32fbfab929..70107cb2317 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ contains documents describing how to build and contribute to Electron. - [Ukrainian](https://github.com/electron/electron/tree/master/docs-translations/uk-UA) - [Russian](https://github.com/electron/electron/tree/master/docs-translations/ru-RU) - [French](https://github.com/electron/electron/tree/master/docs-translations/fr-FR) +- [Indonesian](https://github.com/electron/electron/tree/master/docs-translations/id) ## Quick Start diff --git a/docs-translations/id/README.md b/docs-translations/id/README.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/docs-translations/id/faq.md b/docs-translations/id/faq.md new file mode 100644 index 00000000000..abeac23f76e --- /dev/null +++ b/docs-translations/id/faq.md @@ -0,0 +1,162 @@ +# Electron FAQ + +## When will Electron upgrade to latest Chrome? + +The Chrome version of Electron is usually bumped within one or two weeks after +a new stable Chrome version gets released. This estimate is not guaranteed and +depends on the amount of work involved with upgrading. + +Only the stable channel of Chrome is used. If an important fix is in beta or dev +channel, we will back-port it. + +For more information, please see the [security introduction](tutorial/security.md). + +## When will Electron upgrade to latest Node.js? + +When a new version of Node.js gets released, we usually wait for about a month +before upgrading the one in Electron. So we can avoid getting affected by bugs +introduced in new Node.js versions, which happens very often. + +New features of Node.js are usually brought by V8 upgrades, since Electron is +using the V8 shipped by Chrome browser, the shiny new JavaScript feature of a +new Node.js version is usually already in Electron. + +## How to share data between web pages? + +To share data between web pages (the renderer processes) the simplest way is to +use HTML5 APIs which are already available in browsers. Good candidates are +[Storage API][storage], [`localStorage`][local-storage], +[`sessionStorage`][session-storage], and [IndexedDB][indexed-db]. + +Or you can use the IPC system, which is specific to Electron, to store objects +in the main process as a global variable, and then to access them from the +renderers through the `remote` property of `electron` module: + +```javascript +// In the main process. +global.sharedObject = { + someProperty: 'default value' +} +``` + +```javascript +// In page 1. +require('electron').remote.getGlobal('sharedObject').someProperty = 'new value' +``` + +```javascript +// In page 2. +console.log(require('electron').remote.getGlobal('sharedObject').someProperty) +``` + +## My app's window/tray disappeared after a few minutes. + +This happens when the variable which is used to store the window/tray gets +garbage collected. + +If you encounter this problem, the following articles may prove helpful: + +* [Memory Management][memory-management] +* [Variable Scope][variable-scope] + +If you want a quick fix, you can make the variables global by changing your +code from this: + +```javascript +const {app, Tray} = require('electron') +app.on('ready', () => { + const tray = new Tray('/path/to/icon.png') + tray.setTitle('hello world') +}) +``` + +to this: + +```javascript +const {app, Tray} = require('electron') +let tray = null +app.on('ready', () => { + tray = new Tray('/path/to/icon.png') + tray.setTitle('hello world') +}) +``` + +## I can not use jQuery/RequireJS/Meteor/AngularJS in Electron. + +Due to the Node.js integration of Electron, there are some extra symbols +inserted into the DOM like `module`, `exports`, `require`. This causes problems +for some libraries since they want to insert the symbols with the same names. + +To solve this, you can turn off node integration in Electron: + +```javascript +// In the main process. +const {BrowserWindow} = require('electron') +let win = new BrowserWindow({ + webPreferences: { + nodeIntegration: false + } +}) +win.show() +``` + +But if you want to keep the abilities of using Node.js and Electron APIs, you +have to rename the symbols in the page before including other libraries: + +```html + + + + +``` + +## `require('electron').xxx` is undefined. + +When using Electron's built-in module you might encounter an error like this: + +``` +> require('electron').webFrame.setZoomFactor(1.0) +Uncaught TypeError: Cannot read property 'setZoomLevel' of undefined +``` + +This is because you have the [npm `electron` module][electron-module] installed +either locally or globally, which overrides Electron's built-in module. + +To verify whether you are using the correct built-in module, you can print the +path of the `electron` module: + +```javascript +console.log(require.resolve('electron')) +``` + +and then check if it is in the following form: + +``` +"/path/to/Electron.app/Contents/Resources/atom.asar/renderer/api/lib/exports/electron.js" +``` + +If it is something like `node_modules/electron/index.js`, then you have to +either remove the npm `electron` module, or rename it. + +```bash +npm uninstall electron +npm uninstall -g electron +``` + +However if you are using the built-in module but still getting this error, it +is very likely you are using the module in the wrong process. For example +`electron.app` can only be used in the main process, while `electron.webFrame` +is only available in renderer processes. + +[memory-management]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management +[variable-scope]: https://msdn.microsoft.com/library/bzt2dkta(v=vs.94).aspx +[electron-module]: https://www.npmjs.com/package/electron +[storage]: https://developer.mozilla.org/en-US/docs/Web/API/Storage +[local-storage]: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage +[session-storage]: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage +[indexed-db]: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API diff --git a/docs-translations/id/glossary.md b/docs-translations/id/glossary.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/docs-translations/id/project/CODE_OF_CONDUCT.md b/docs-translations/id/project/CODE_OF_CONDUCT.md new file mode 100644 index 00000000000..e4d4c531e5a --- /dev/null +++ b/docs-translations/id/project/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [electron@github.com](mailto:electron@github.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/docs-translations/id/project/CONTRIBUTING.md b/docs-translations/id/project/CONTRIBUTING.md new file mode 100644 index 00000000000..1deb2e49264 --- /dev/null +++ b/docs-translations/id/project/CONTRIBUTING.md @@ -0,0 +1,79 @@ +# Contributing to Electron + +:memo: Available Translations: [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR/project/CONTRIBUTING.md) | [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN/project/CONTRIBUTING.md) | [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR/project/CONTRIBUTING.md) | [Dutch](https://github.com/electron/electron/tree/master/docs-translations/nl/project/CONTRIBUTING.md) + +:+1::tada: First off, thanks for taking the time to contribute! :tada::+1: + +This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md). +By participating, you are expected to uphold this code. Please report unacceptable +behavior to atom@github.com. + +The following is a set of guidelines for contributing to Electron. +These are just guidelines, not rules, use your best judgment and feel free to +propose changes to this document in a pull request. + +## Submitting Issues + +* You can create an issue [here](https://github.com/electron/electron/issues/new), +but before doing that please read the notes below and include as many details as +possible with your report. If you can, please include: + * The version of Electron you are using + * The operating system you are using + * If applicable, what you were doing when the issue arose and what you + expected to happen +* Other things that will help resolve your issue: + * Screenshots and animated GIFs + * Error output that appears in your terminal, dev tools or as an alert + * Perform a [cursory search](https://github.com/electron/electron/issues?utf8=✓&q=is%3Aissue+) + to see if a similar issue has already been submitted + +## Submitting Pull Requests + +* Include screenshots and animated GIFs in your pull request whenever possible. +* Follow the JavaScript, C++, and Python [coding style defined in docs](/docs/development/coding-style.md). +* Write documentation in [Markdown](https://daringfireball.net/projects/markdown). + See the [Documentation Styleguide](/docs/styleguide.md). +* Use short, present tense commit messages. See [Commit Message Styleguide](#git-commit-messages). + +## Styleguides + +### General Code + +* End files with a newline. +* Place requires in the following order: + * Built in Node Modules (such as `path`) + * Built in Electron Modules (such as `ipc`, `app`) + * Local Modules (using relative paths) +* Place class properties in the following order: + * Class methods and properties (methods starting with a `@`) + * Instance methods and properties +* Avoid platform-dependent code: + * Use `path.join()` to concatenate filenames. + * Use `os.tmpdir()` rather than `/tmp` when you need to reference the + temporary directory. +* Using a plain `return` when returning explicitly at the end of a function. + * Not `return null`, `return undefined`, `null`, or `undefined` + +### Git Commit Messages + +* Use the present tense ("Add feature" not "Added feature") +* Use the imperative mood ("Move cursor to..." not "Moves cursor to...") +* Limit the first line to 72 characters or less +* Reference issues and pull requests liberally +* When only changing documentation, include `[ci skip]` in the commit description +* Consider starting the commit message with an applicable emoji: + * :art: `:art:` when improving the format/structure of the code + * :racehorse: `:racehorse:` when improving performance + * :non-potable_water: `:non-potable_water:` when plugging memory leaks + * :memo: `:memo:` when writing docs + * :penguin: `:penguin:` when fixing something on Linux + * :apple: `:apple:` when fixing something on macOS + * :checkered_flag: `:checkered_flag:` when fixing something on Windows + * :bug: `:bug:` when fixing a bug + * :fire: `:fire:` when removing code or files + * :green_heart: `:green_heart:` when fixing the CI build + * :white_check_mark: `:white_check_mark:` when adding tests + * :lock: `:lock:` when dealing with security + * :arrow_up: `:arrow_up:` when upgrading dependencies + * :arrow_down: `:arrow_down:` when downgrading dependencies + * :shirt: `:shirt:` when removing linter warnings diff --git a/docs-translations/id/project/README.md b/docs-translations/id/project/README.md new file mode 100644 index 00000000000..70107cb2317 --- /dev/null +++ b/docs-translations/id/project/README.md @@ -0,0 +1,90 @@ +[![Electron Logo](https://electron.atom.io/images/electron-logo.svg)](https://electron.atom.io/) + +[![Travis Build Status](https://travis-ci.org/electron/electron.svg?branch=master)](https://travis-ci.org/electron/electron) +[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/bc56v83355fi3369/branch/master?svg=true)](https://ci.appveyor.com/project/electron-bot/electron/branch/master) +[![devDependency Status](https://david-dm.org/electron/electron/dev-status.svg)](https://david-dm.org/electron/electron?type=dev) +[![Join the Electron Community on Slack](http://atom-slack.herokuapp.com/badge.svg)](http://atom-slack.herokuapp.com/) + +:memo: Available Translations: [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR/project/README.md) | [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN/project/README.md) | [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR/project/README.md) | [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW/project/README.md) | [Spanish](https://github.com/electron/electron/tree/master/docs-translations/es/project/README.md) | [Turkish](https://github.com/electron/electron/tree/master/docs-translations/tr-TR/project/README.md) + +The Electron framework lets you write cross-platform desktop applications +using JavaScript, HTML and CSS. It is based on [Node.js](https://nodejs.org/) and +[Chromium](http://www.chromium.org) and is used by the [Atom +editor](https://github.com/atom/atom) and many other [apps](https://electron.atom.io/apps). + +Follow [@ElectronJS](https://twitter.com/electronjs) on Twitter for important +announcements. + +This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md). +By participating, you are expected to uphold this code. Please report unacceptable +behavior to electron@github.com. + +## Downloads + +To install prebuilt Electron binaries, use +[`npm`](https://docs.npmjs.com/): + +```sh +# Install as a development dependency +npm install electron --save-dev + +# Install the `electron` command globally in your $PATH +npm install electron -g +``` + +See the [releases page](https://github.com/electron/electron/releases) for +prebuilt binaries, debug symbols, and more. + +### Mirrors + +- [China](https://npm.taobao.org/mirrors/electron) + +## Documentation + +Guides and the API reference are located in the +[docs](https://github.com/electron/electron/tree/master/docs) directory. It also +contains documents describing how to build and contribute to Electron. + +## Documentation Translations + +- [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR) +- [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR) +- [Japanese](https://github.com/electron/electron/tree/master/docs-translations/jp) +- [Spanish](https://github.com/electron/electron/tree/master/docs-translations/es) +- [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN) +- [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW) +- [Turkish](https://github.com/electron/electron/tree/master/docs-translations/tr-TR) +- [Thai](https://github.com/electron/electron/tree/master/docs-Translations/th-TH) +- [Ukrainian](https://github.com/electron/electron/tree/master/docs-translations/uk-UA) +- [Russian](https://github.com/electron/electron/tree/master/docs-translations/ru-RU) +- [French](https://github.com/electron/electron/tree/master/docs-translations/fr-FR) +- [Indonesian](https://github.com/electron/electron/tree/master/docs-translations/id) + +## Quick Start + +Clone and run the [`electron/electron-quick-start`](https://github.com/electron/electron-quick-start) +repository to see a minimal Electron app in action. + +## Community + +You can ask questions and interact with the community in the following +locations: +- [`electron`](http://discuss.atom.io/c/electron) category on the Atom +forums +- `#atom-shell` channel on Freenode +- [`Atom`](http://atom-slack.herokuapp.com/) channel on Slack +- [`electron-ru`](https://telegram.me/electron_ru) *(Russian)* +- [`electron-br`](https://electron-br.slack.com) *(Brazilian Portuguese)* +- [`electron-kr`](http://www.meetup.com/electron-kr/) *(Korean)* +- [`electron-jp`](https://electron-jp.slack.com) *(Japanese)* +- [`electron-tr`](http://electron-tr.herokuapp.com) *(Turkish)* +- [`electron-id`](https://electron-id.slack.com) *(Indonesia)* + +Check out [awesome-electron](https://github.com/sindresorhus/awesome-electron) +for a community maintained list of useful example apps, tools and resources. + +## License + +[MIT](https://github.com/electron/electron/blob/master/LICENSE) + +When using the Electron or other GitHub logos, be sure to follow the [GitHub logo guidelines](https://github.com/logos). diff --git a/docs-translations/id/styleguide.md b/docs-translations/id/styleguide.md new file mode 100644 index 00000000000..8f59c8a3419 --- /dev/null +++ b/docs-translations/id/styleguide.md @@ -0,0 +1,246 @@ +# Electron Documentation Styleguide + +These are the guidelines for writing Electron documentation. + +## Titles + +* Each page must have a single `#`-level title at the top. +* Chapters in the same page must have `##`-level titles. +* Sub-chapters need to increase the number of `#` in the title according to + their nesting depth. +* All words in the page's title must be capitalized, except for conjunctions + like "of" and "and" . +* Only the first word of a chapter title must be capitalized. + +Using `Quick Start` as example: + +```markdown +# Quick Start + +... + +## Main process + +... + +## Renderer process + +... + +## Run your app + +... + +### Run as a distribution + +... + +### Manually downloaded Electron binary + +... +``` + +For API references, there are exceptions to this rule. + +## Markdown rules + +* Use `bash` instead of `cmd` in code blocks (due to the syntax highlighter). +* Lines should be wrapped at 80 columns. +* No nesting lists more than 2 levels (due to the markdown renderer). +* All `js` and `javascript` code blocks are linted with +[standard-markdown](http://npm.im/standard-markdown). + +## Picking words + +* Use "will" over "would" when describing outcomes. +* Prefer "in the ___ process" over "on". + +## API references + +The following rules only apply to the documentation of APIs. + +### Page title + +Each page must use the actual object name returned by `require('electron')` +as the title, such as `BrowserWindow`, `autoUpdater`, and `session`. + +Under the page tile must be a one-line description starting with `>`. + +Using `session` as example: + +```markdown +# session + +> Manage browser sessions, cookies, cache, proxy settings, etc. +``` + +### Module methods and events + +For modules that are not classes, their methods and events must be listed under +the `## Methods` and `## Events` chapters. + +Using `autoUpdater` as an example: + +```markdown +# autoUpdater + +## Events + +### Event: 'error' + +## Methods + +### `autoUpdater.setFeedURL(url[, requestHeaders])` +``` + +### Classes + +* API classes or classes that are part of modules must be listed under a + `## Class: TheClassName` chapter. +* One page can have multiple classes. +* Constructors must be listed with `###`-level titles. +* [Static Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static) must be listed under a `### Static Methods` chapter. +* [Instance Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Prototype_methods) must be listed under an `### Instance Methods` chapter. +* All methods that have a return value must start their description with "Returns `[TYPE]` - Return description" + * If the method returns an `Object`, its structure can be specified using a colon followed by a newline then an unordered list of properties in the same style as function parameters. +* Instance Events must be listed under an `### Instance Events` chapter. +* Instance Properties must be listed under an `### Instance Properties` chapter. + * Instance properties must start with "A [Property Type] ..." + +Using the `Session` and `Cookies` classes as an example: + +```markdown +# session + +## Methods + +### session.fromPartition(partition) + +## Properties + +### session.defaultSession + +## Class: Session + +### Instance Events + +#### Event: 'will-download' + +### Instance Methods + +#### `ses.getCacheSize(callback)` + +### Instance Properties + +#### `ses.cookies` + +## Class: Cookies + +### Instance Methods + +#### `cookies.get(filter, callback)` +``` + +### Methods + +The methods chapter must be in the following form: + +```markdown +### `objectName.methodName(required[, optional]))` + +* `required` String - A parameter description. +* `optional` Integer (optional) - Another parameter description. + +... +``` + +The title can be `###` or `####`-levels depending on whether it is a method of +a module or a class. + +For modules, the `objectName` is the module's name. For classes, it must be the +name of the instance of the class, and must not be the same as the module's +name. + +For example, the methods of the `Session` class under the `session` module must +use `ses` as the `objectName`. + +The optional arguments are notated by square brackets `[]` surrounding the optional argument +as well as the comma required if this optional argument follows another +argument: + +``` +required[, optional] +``` + +Below the method is more detailed information on each of the arguments. The type +of argument is notated by either the common types: + +* [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) +* [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) +* [`Object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) +* [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) +* [`Boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) +* Or a custom type like Electron's [`WebContent`](api/web-contents.md) + +If an argument or a method is unique to certain platforms, those platforms are +denoted using a space-delimited italicized list following the datatype. Values +can be `macOS`, `Windows`, or `Linux`. + +```markdown +* `animate` Boolean (optional) _macOS_ _Windows_ - Animate the thing. +``` + +`Array` type arguments must specify what elements the array may include in +the description below. + +The description for `Function` type arguments should make it clear how it may be +called and list the types of the parameters that will be passed to it. + +### Events + +The events chapter must be in following form: + +```markdown +### Event: 'wake-up' + +Returns: + +* `time` String + +... +``` + +The title can be `###` or `####`-levels depending on whether it is an event of +a module or a class. + +The arguments of an event follow the same rules as methods. + +### Properties + +The properties chapter must be in following form: + +```markdown +### session.defaultSession + +... +``` + +The title can be `###` or `####`-levels depending on whether it is a property of +a module or a class. + +## Documentation Translations + +Translations of the Electron docs are located within the `docs-translations` +directory. + +To add another set (or partial set): + +* Create a subdirectory named by language abbreviation. +* Translate the files. +* Update the `README.md` within your language directory to link to the files + you have translated. +* Add a link to your translation directory on the main Electron + [README](https://github.com/electron/electron#documentation-translations). + +Note that the files under `docs-translations` must only include the translated +ones, the original English files should not be copied there. From f0c38b7354fa0890950dd92550e8a8ff858a6dbb Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 08:35:30 -0700 Subject: [PATCH 1095/1195] Bump v1.6.9 --- atom/browser/resources/mac/Info.plist | 4 ++-- atom/browser/resources/win/atom.rc | 8 ++++---- atom/common/atom_version.h | 2 +- electron.gyp | 2 +- package.json | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/atom/browser/resources/mac/Info.plist b/atom/browser/resources/mac/Info.plist index 673bceb38f0..d260d2e71f3 100644 --- a/atom/browser/resources/mac/Info.plist +++ b/atom/browser/resources/mac/Info.plist @@ -17,9 +17,9 @@ CFBundleIconFile electron.icns CFBundleVersion - 1.6.8 + 1.6.9 CFBundleShortVersionString - 1.6.8 + 1.6.9 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/atom/browser/resources/win/atom.rc b/atom/browser/resources/win/atom.rc index bc9d66a5800..de126c8f957 100644 --- a/atom/browser/resources/win/atom.rc +++ b/atom/browser/resources/win/atom.rc @@ -56,8 +56,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,6,8,0 - PRODUCTVERSION 1,6,8,0 + FILEVERSION 1,6,9,0 + PRODUCTVERSION 1,6,9,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -74,12 +74,12 @@ BEGIN BEGIN VALUE "CompanyName", "GitHub, Inc." VALUE "FileDescription", "Electron" - VALUE "FileVersion", "1.6.8" + VALUE "FileVersion", "1.6.9" VALUE "InternalName", "electron.exe" VALUE "LegalCopyright", "Copyright (C) 2015 GitHub, Inc. All rights reserved." VALUE "OriginalFilename", "electron.exe" VALUE "ProductName", "Electron" - VALUE "ProductVersion", "1.6.8" + VALUE "ProductVersion", "1.6.9" VALUE "SquirrelAwareVersion", "1" END END diff --git a/atom/common/atom_version.h b/atom/common/atom_version.h index 5474abbc93b..5e7df1040f8 100644 --- a/atom/common/atom_version.h +++ b/atom/common/atom_version.h @@ -7,7 +7,7 @@ #define ATOM_MAJOR_VERSION 1 #define ATOM_MINOR_VERSION 6 -#define ATOM_PATCH_VERSION 8 +#define ATOM_PATCH_VERSION 9 #define ATOM_VERSION_IS_RELEASE 1 diff --git a/electron.gyp b/electron.gyp index f960fd99f1a..5987a5b541a 100644 --- a/electron.gyp +++ b/electron.gyp @@ -4,7 +4,7 @@ 'product_name%': 'Electron', 'company_name%': 'GitHub, Inc', 'company_abbr%': 'github', - 'version%': '1.6.8', + 'version%': '1.6.9', 'js2c_input_dir': '<(SHARED_INTERMEDIATE_DIR)/js2c', }, 'includes': [ diff --git a/package.json b/package.json index 5a4d24f46e6..a6ab2737818 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "electron", - "version": "1.6.8", + "version": "1.6.9", "devDependencies": { "asar": "^0.11.0", "browserify": "^13.1.0", From de38461a3f83bb055948d16dad4ae93f323df781 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 10:05:48 -0700 Subject: [PATCH 1096/1195] Update NotifyObserversCertDBChanged call to take no arguments --- atom/browser/ui/certificate_trust_win.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/ui/certificate_trust_win.cc b/atom/browser/ui/certificate_trust_win.cc index 06c0ffd7f14..dd26291a2e4 100644 --- a/atom/browser/ui/certificate_trust_win.cc +++ b/atom/browser/ui/certificate_trust_win.cc @@ -38,7 +38,7 @@ BOOL AddToTrustedRootStore(const PCCERT_CONTEXT cert_context, if (result) { // force Chromium to reload it's database for this certificate auto cert_db = net::CertDatabase::GetInstance(); - cert_db->NotifyObserversCertDBChanged(cert.get()); + cert_db->NotifyObserversCertDBChanged(); } CertCloseStore(root_cert_store, CERT_CLOSE_STORE_FORCE_FLAG); From b6319698f12f6f0d8095da7a0528b4a3b9949834 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 10:42:05 -0700 Subject: [PATCH 1097/1195] Bump v1.7.0 --- atom/browser/resources/mac/Info.plist | 4 ++-- atom/browser/resources/win/atom.rc | 8 ++++---- atom/common/atom_version.h | 4 ++-- electron.gyp | 2 +- package.json | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/atom/browser/resources/mac/Info.plist b/atom/browser/resources/mac/Info.plist index d260d2e71f3..989d0410476 100644 --- a/atom/browser/resources/mac/Info.plist +++ b/atom/browser/resources/mac/Info.plist @@ -17,9 +17,9 @@ CFBundleIconFile electron.icns CFBundleVersion - 1.6.9 + 1.7.0 CFBundleShortVersionString - 1.6.9 + 1.7.0 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/atom/browser/resources/win/atom.rc b/atom/browser/resources/win/atom.rc index de126c8f957..af65704a2ea 100644 --- a/atom/browser/resources/win/atom.rc +++ b/atom/browser/resources/win/atom.rc @@ -56,8 +56,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,6,9,0 - PRODUCTVERSION 1,6,9,0 + FILEVERSION 1,7,0,0 + PRODUCTVERSION 1,7,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -74,12 +74,12 @@ BEGIN BEGIN VALUE "CompanyName", "GitHub, Inc." VALUE "FileDescription", "Electron" - VALUE "FileVersion", "1.6.9" + VALUE "FileVersion", "1.7.0" VALUE "InternalName", "electron.exe" VALUE "LegalCopyright", "Copyright (C) 2015 GitHub, Inc. All rights reserved." VALUE "OriginalFilename", "electron.exe" VALUE "ProductName", "Electron" - VALUE "ProductVersion", "1.6.9" + VALUE "ProductVersion", "1.7.0" VALUE "SquirrelAwareVersion", "1" END END diff --git a/atom/common/atom_version.h b/atom/common/atom_version.h index 5e7df1040f8..92b79c0c14d 100644 --- a/atom/common/atom_version.h +++ b/atom/common/atom_version.h @@ -6,8 +6,8 @@ #define ATOM_COMMON_ATOM_VERSION_H_ #define ATOM_MAJOR_VERSION 1 -#define ATOM_MINOR_VERSION 6 -#define ATOM_PATCH_VERSION 9 +#define ATOM_MINOR_VERSION 7 +#define ATOM_PATCH_VERSION 0 #define ATOM_VERSION_IS_RELEASE 1 diff --git a/electron.gyp b/electron.gyp index be5a2787783..dd40842bb86 100644 --- a/electron.gyp +++ b/electron.gyp @@ -4,7 +4,7 @@ 'product_name%': 'Electron', 'company_name%': 'GitHub, Inc', 'company_abbr%': 'github', - 'version%': '1.6.9', + 'version%': '1.7.0', 'js2c_input_dir': '<(SHARED_INTERMEDIATE_DIR)/js2c', }, 'includes': [ diff --git a/package.json b/package.json index a6ab2737818..d6215fd2f43 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "electron", - "version": "1.6.9", + "version": "1.7.0", "devDependencies": { "asar": "^0.11.0", "browserify": "^13.1.0", From 20d2ab29ab51cafc1c8b391c19134fbb7f711779 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sat, 4 Mar 2017 03:09:16 +0100 Subject: [PATCH 1098/1195] Add support for child and popup windows in OSR --- atom/browser/api/atom_api_web_contents.cc | 41 +- atom/browser/api/atom_api_web_contents.h | 1 + atom/browser/native_window.h | 1 + atom/browser/native_window_views.cc | 4 + atom/browser/native_window_views.h | 1 + .../osr/osr_render_widget_host_view.cc | 386 ++++++++++++++++-- .../browser/osr/osr_render_widget_host_view.h | 57 ++- atom/browser/osr/osr_web_contents_view.cc | 99 ++++- atom/browser/osr/osr_web_contents_view.h | 6 +- 9 files changed, 541 insertions(+), 55 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index bedc0976969..e5f8bfe9d29 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -48,6 +48,7 @@ #include "chrome/browser/ssl/security_state_tab_helper.h" #include "content/browser/frame_host/navigation_entry_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h" +#include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/common/view_messages.h" #include "content/public/browser/favicon_status.h" @@ -315,6 +316,9 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) else if (options.Get("offscreen", &b) && b) type_ = OFF_SCREEN; + // Init embedder earlier + options.Get("embedder", &embedder_); + // Whether to enable DevTools. options.Get("devTools", &enable_devtools_); @@ -339,7 +343,18 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) session->browser_context(), site_instance); guest_delegate_.reset(new WebViewGuestDelegate); params.guest_delegate = guest_delegate_.get(); - web_contents = content::WebContents::Create(params); + + if (embedder_ && embedder_->IsOffScreen()) { + auto* view = new OffScreenWebContentsView(false, + base::Bind(&WebContents::OnPaint, base::Unretained(this))); + params.view = view; + params.delegate_view = view; + + web_contents = content::WebContents::Create(params); + view->SetWebContents(web_contents); + } else { + web_contents = content::WebContents::Create(params); + } } else if (IsOffScreen()) { bool transparent = false; options.Get("transparent", &transparent); @@ -389,7 +404,7 @@ void WebContents::InitWithSessionAndOptions(v8::Isolate* isolate, guest_delegate_->Initialize(this); NativeWindow* owner_window = nullptr; - if (options.Get("embedder", &embedder_) && embedder_) { + if (embedder_) { // New WebContents's owner_window is the embedder's owner_window. auto relay = NativeWindowRelay::FromWebContents(embedder_->web_contents()); @@ -1402,18 +1417,16 @@ bool WebContents::SendIPCMessage(bool all_frames, void WebContents::SendInputEvent(v8::Isolate* isolate, v8::Local input_event) { - const auto view = web_contents()->GetRenderWidgetHostView(); + const auto view = static_cast( + web_contents()->GetRenderWidgetHostView()); if (!view) return; - const auto host = view->GetRenderWidgetHost(); - if (!host) - return; int type = mate::GetWebInputEventType(isolate, input_event); if (blink::WebInputEvent::isMouseEventType(type)) { blink::WebMouseEvent mouse_event; if (mate::ConvertFromV8(isolate, input_event, &mouse_event)) { - host->ForwardMouseEvent(mouse_event); + view->ProcessMouseEvent(mouse_event, ui::LatencyInfo()); return; } } else if (blink::WebInputEvent::isKeyboardEventType(type)) { @@ -1422,13 +1435,13 @@ void WebContents::SendInputEvent(v8::Isolate* isolate, blink::WebInputEvent::NoModifiers, ui::EventTimeForNow()); if (mate::ConvertFromV8(isolate, input_event, &keyboard_event)) { - host->ForwardKeyboardEvent(keyboard_event); + view->ProcessKeyboardEvent(keyboard_event); return; } } else if (type == blink::WebInputEvent::MouseWheel) { blink::WebMouseWheelEvent mouse_wheel_event; if (mate::ConvertFromV8(isolate, input_event, &mouse_wheel_event)) { - host->ForwardWheelEvent(mouse_wheel_event); + view->ProcessMouseEvent(mouse_wheel_event, ui::LatencyInfo()); return; } } @@ -1631,6 +1644,16 @@ void WebContents::Invalidate() { } } +gfx::Size WebContents::GetSizeForNewRenderView( + content::WebContents* web_contents) const { + auto relay = NativeWindowRelay::FromWebContents(web_contents); + if (relay) { + return relay->window->GetSize(); + } + + return gfx::Size(); +} + void WebContents::SetZoomLevel(double level) { zoom_controller_->SetZoomLevel(level); } diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 1f926dbd7a5..1916964fa25 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -183,6 +183,7 @@ class WebContents : public mate::TrackableObject, void SetFrameRate(int frame_rate); int GetFrameRate() const; void Invalidate(); + gfx::Size GetSizeForNewRenderView(content::WebContents*) const override; // Methods for zoom handling. void SetZoomLevel(double level); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index d3f18d8fb95..b0d25e03f23 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -147,6 +147,7 @@ class NativeWindow : public base::SupportsUserData, virtual void SetMenu(AtomMenuModel* menu); virtual void SetParentWindow(NativeWindow* parent); virtual void SetBrowserView(NativeBrowserView* browser_view) = 0; + virtual gfx::NativeView GetNativeView() = 0; virtual gfx::NativeWindow GetNativeWindow() = 0; virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0; diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index ed524cbdcbc..00f0befd50f 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -924,6 +924,10 @@ void NativeWindowViews::SetParentWindow(NativeWindow* parent) { #endif } +gfx::NativeView NativeWindowViews::GetNativeView() { + return window_->GetNativeView(); +} + gfx::NativeWindow NativeWindowViews::GetNativeWindow() { return window_->GetNativeWindow(); } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 276cd4adde2..15bdbad1880 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -106,6 +106,7 @@ class NativeWindowViews : public NativeWindow, void SetMenu(AtomMenuModel* menu_model) override; void SetBrowserView(NativeBrowserView* browser_view) override; void SetParentWindow(NativeWindow* parent) override; + gfx::NativeView GetNativeView() override; gfx::NativeWindow GetNativeWindow() override; void SetOverlayIcon(const gfx::Image& overlay, const std::string& description) override; diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index c41a6805c06..6719b7b4545 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -17,6 +17,7 @@ #include "content/browser/renderer_host/render_widget_host_delegate.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber.h" +#include "content/browser/renderer_host/resize_lock.h" #include "content/common/view_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/context_factory.h" @@ -25,6 +26,7 @@ #include "ui/compositor/layer.h" #include "ui/compositor/layer_type.h" #include "ui/events/latency_info.h" +#include "ui/gfx/skbitmap_operations.h" #include "ui/gfx/geometry/dip_util.h" #include "ui/gfx/native_widget_types.h" @@ -35,6 +37,66 @@ namespace { const float kDefaultScaleFactor = 1.0; const int kFrameRetryLimit = 2; +#if !defined(OS_MACOSX) + +const int kResizeLockTimeoutMs = 67; + +class AtomResizeLock : public content::ResizeLock { + public: + AtomResizeLock(OffScreenRenderWidgetHostView* host, + const gfx::Size new_size, + bool defer_compositor_lock) + : ResizeLock(new_size, defer_compositor_lock), + host_(host), + cancelled_(false), + weak_ptr_factory_(this) { + DCHECK(host_); + host_->HoldResize(); + + content::BrowserThread::PostDelayedTask(content::BrowserThread::UI, + FROM_HERE, base::Bind(&AtomResizeLock::CancelLock, + weak_ptr_factory_.GetWeakPtr()), + base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs)); + } + + ~AtomResizeLock() override { + CancelLock(); + } + + bool GrabDeferredLock() override { + return ResizeLock::GrabDeferredLock(); + } + + void UnlockCompositor() override { + ResizeLock::UnlockCompositor(); + compositor_lock_ = NULL; + } + + protected: + void LockCompositor() override { + ResizeLock::LockCompositor(); + compositor_lock_ = host_->GetCompositor()->GetCompositorLock(); + } + + void CancelLock() { + if (cancelled_) + return; + cancelled_ = true; + UnlockCompositor(); + host_->ReleaseResize(); + } + + private: + OffScreenRenderWidgetHostView* host_; + scoped_refptr compositor_lock_; + bool cancelled_; + base::WeakPtrFactory weak_ptr_factory_; + + DISALLOW_COPY_AND_ASSIGN(AtomResizeLock); +}; + +#endif // !defined(OS_MACOSX) + } // namespace class AtomCopyFrameGenerator { @@ -338,24 +400,30 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( bool transparent, const OnPaintCallback& callback, content::RenderWidgetHost* host, - bool is_guest_view_hack, + OffScreenRenderWidgetHostView* parent_host_view, NativeWindow* native_window) : render_widget_host_(content::RenderWidgetHostImpl::From(host)), + parent_host_view_(parent_host_view), + popup_host_view_(nullptr), + child_host_view_(nullptr), native_window_(native_window), software_output_device_(nullptr), transparent_(transparent), callback_(callback), + parent_callback_(nullptr), frame_rate_(60), frame_rate_threshold_ms_(0), last_time_(base::Time::Now()), scale_factor_(kDefaultScaleFactor), - is_showing_(!render_widget_host_->is_hidden()), - size_(native_window->GetSize()), painting_(true), + is_showing_(!render_widget_host_->is_hidden()), + is_destroyed_(false), + popup_position_(gfx::Rect()), + hold_resize_(false), + pending_resize_(false), + size_(native_window->GetSize()), weak_ptr_factory_(this) { DCHECK(render_widget_host_); - render_widget_host_->SetView(this); - #if !defined(OS_MACOSX) delegated_frame_host_ = base::MakeUnique( AllocateFrameSinkId(is_guest_view_hack), this); @@ -383,6 +451,8 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( native_window_->AddObserver(this); ResizeRootLayer(); + render_widget_host_->SetView(this); + InstallTransparency(); } OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() { @@ -400,8 +470,15 @@ OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() { delegated_frame_host_->ResetCompositor(); #endif + if (copy_frame_generator_.get()) + copy_frame_generator_.reset(NULL); + #if defined(OS_MACOSX) DestroyPlatformWidget(); +#else + delegated_frame_host_.reset(NULL); + compositor_.reset(NULL); + root_layer_.reset(NULL); #endif } @@ -461,6 +538,17 @@ bool OffScreenRenderWidgetHostView::OnMessageReceived( } void OffScreenRenderWidgetHostView::InitAsChild(gfx::NativeView) { + DCHECK(parent_host_view_); + + if (parent_host_view_->child_host_view_) { + parent_host_view_->child_host_view_->CancelWidget(); + } + + parent_host_view_->set_child_host_view(this); + parent_host_view_->Hide(); + + ResizeRootLayer(); + Show(); } content::RenderWidgetHost* OffScreenRenderWidgetHostView::GetRenderWidgetHost() @@ -470,14 +558,11 @@ content::RenderWidgetHost* OffScreenRenderWidgetHostView::GetRenderWidgetHost() void OffScreenRenderWidgetHostView::SetSize(const gfx::Size& size) { size_ = size; - - ResizeRootLayer(); - if (render_widget_host_) - render_widget_host_->WasResized(); - GetDelegatedFrameHost()->WasResized(); + WasResized(); } void OffScreenRenderWidgetHostView::SetBounds(const gfx::Rect& new_bounds) { + SetSize(new_bounds.size()); } gfx::Vector2dF OffScreenRenderWidgetHostView::GetLastScrollOffset() const { @@ -547,6 +632,9 @@ bool OffScreenRenderWidgetHostView::IsShowing() { } gfx::Rect OffScreenRenderWidgetHostView::GetViewBounds() const { + if (IsPopupWidget()) + return popup_position_; + return gfx::Rect(size_); } @@ -587,7 +675,7 @@ void OffScreenRenderWidgetHostView::OnSwapCompositorFrame( if (!frame.render_pass_list.empty()) { if (software_output_device_) { - if (!begin_frame_timer_.get()) { + if (!begin_frame_timer_.get() || IsPopupWidget()) { software_output_device_->SetActive(painting_); } @@ -631,10 +719,25 @@ void OffScreenRenderWidgetHostView::ClearCompositorFrame() { void OffScreenRenderWidgetHostView::InitAsPopup( content::RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { + DCHECK_EQ(parent_host_view_, parent_host_view); + + if (parent_host_view_->popup_host_view_) { + parent_host_view_->popup_host_view_->CancelWidget(); + } + + parent_host_view_->set_popup_host_view(this); + parent_host_view_->popup_bitmap_.reset(new SkBitmap); + parent_callback_ = base::Bind(&OffScreenRenderWidgetHostView::OnPopupPaint, + parent_host_view_->weak_ptr_factory_.GetWeakPtr()); + + popup_position_ = pos; + + ResizeRootLayer(); + Show(); } void OffScreenRenderWidgetHostView::InitAsFullscreen( - content::RenderWidgetHostView *) { + content::RenderWidgetHostView *) { } void OffScreenRenderWidgetHostView::UpdateCursor(const content::WebCursor &) { @@ -656,6 +759,23 @@ void OffScreenRenderWidgetHostView::RenderProcessGone(base::TerminationStatus, } void OffScreenRenderWidgetHostView::Destroy() { + if (!is_destroyed_) { + is_destroyed_ = true; + + if (parent_host_view_ != NULL) { + CancelWidget(); + } else { + if (popup_host_view_) + popup_host_view_->CancelWidget(); + popup_bitmap_.reset(); + if (child_host_view_) + child_host_view_->CancelWidget(); + for (auto guest_host_view : guest_host_views_) + guest_host_view->CancelWidget(); + Hide(); + } + } + delete this; } @@ -692,6 +812,13 @@ void OffScreenRenderWidgetHostView::EndFrameSubscription() { GetDelegatedFrameHost()->EndFrameSubscription(); } +void OffScreenRenderWidgetHostView::InitAsGuest( + content::RenderWidgetHostView* parent_host_view, + content::RenderWidgetHostViewGuest* guest_view) { + parent_host_view_->AddGuestHostView(this); + parent_host_view_->RegisterGuestViewFrameSwappedCallback(guest_view); +} + bool OffScreenRenderWidgetHostView::HasAcceleratedSurface(const gfx::Size &) { return false; } @@ -705,11 +832,11 @@ void OffScreenRenderWidgetHostView::ImeCompositionRangeChanged( } gfx::Size OffScreenRenderWidgetHostView::GetPhysicalBackingSize() const { - return size_; + return gfx::ConvertSizeToPixel(scale_factor_, GetRequestedRendererSize()); } gfx::Size OffScreenRenderWidgetHostView::GetRequestedRendererSize() const { - return size_; + return GetDelegatedFrameHost()->GetRequestedRendererSize(); } #if !defined(OS_MACOSX) @@ -723,22 +850,29 @@ bool OffScreenRenderWidgetHostView::DelegatedFrameHostIsVisible() const { SkColor OffScreenRenderWidgetHostView::DelegatedFrameHostGetGutterColor( SkColor color) const { + if (render_widget_host_->delegate() && + render_widget_host_->delegate()->IsFullscreenForCurrentTab()) { + return SK_ColorBLACK; + } return color; } gfx::Size OffScreenRenderWidgetHostView::DelegatedFrameHostDesiredSizeInDIP() const { - return size_; + return GetRootLayer()->bounds().size(); } bool OffScreenRenderWidgetHostView::DelegatedFrameCanCreateResizeLock() const { - return false; + return !render_widget_host_->auto_resize_enabled(); } std::unique_ptr OffScreenRenderWidgetHostView::DelegatedFrameHostCreateResizeLock( bool defer_compositor_lock) { - return nullptr; + return std::unique_ptr(new AtomResizeLock( + this, + DelegatedFrameHostDesiredSizeInDIP(), + defer_compositor_lock)); } void OffScreenRenderWidgetHostView::DelegatedFrameHostResizeLockWasReleased() { @@ -795,6 +929,57 @@ bool OffScreenRenderWidgetHostView::TransformPointToCoordSpaceForView( point, target_view, transformed_point); } +void OffScreenRenderWidgetHostView::CancelWidget() { + if (render_widget_host_) + render_widget_host_->LostCapture(); + Hide(); + + if (parent_host_view_) { + if (parent_host_view_->popup_host_view_ == this) { + parent_host_view_->set_popup_host_view(NULL); + parent_host_view_->popup_bitmap_.reset(); + } else if (parent_host_view_->child_host_view_ == this) { + parent_host_view_->set_child_host_view(NULL); + parent_host_view_->Show(); + } else { + parent_host_view_->RemoveGuestHostView(this); + } + parent_host_view_ = NULL; + } + + if (render_widget_host_ && !is_destroyed_) { + is_destroyed_ = true; + // Results in a call to Destroy(). + render_widget_host_->ShutdownAndDestroyWidget(true); + } +} + +void OffScreenRenderWidgetHostView::AddGuestHostView( + OffScreenRenderWidgetHostView* guest_host) { + guest_host_views_.insert(guest_host); +} + +void OffScreenRenderWidgetHostView::RemoveGuestHostView( + OffScreenRenderWidgetHostView* guest_host) { + guest_host_views_.erase(guest_host); +} + +void OffScreenRenderWidgetHostView::RegisterGuestViewFrameSwappedCallback( + content::RenderWidgetHostViewGuest* guest_host_view) { + guest_host_view->RegisterFrameSwappedCallback(base::MakeUnique( + base::Bind(&OffScreenRenderWidgetHostView::OnGuestViewFrameSwapped, + weak_ptr_factory_.GetWeakPtr(), + base::Unretained(guest_host_view)))); +} + +void OffScreenRenderWidgetHostView::OnGuestViewFrameSwapped( + content::RenderWidgetHostViewGuest* guest_host_view) { + InvalidateBounds( + gfx::ConvertRectToPixel(scale_factor_, guest_host_view->GetViewBounds())); + + RegisterGuestViewFrameSwappedCallback(guest_host_view); +} + std::unique_ptr OffScreenRenderWidgetHostView::CreateSoftwareOutputDevice( ui::Compositor* compositor) { @@ -823,7 +1008,7 @@ bool OffScreenRenderWidgetHostView::InstallTransparency() { } bool OffScreenRenderWidgetHostView::IsAutoResizeEnabled() const { - return false; + return render_widget_host_->auto_resize_enabled(); } void OffScreenRenderWidgetHostView::SetNeedsBeginFrames( @@ -837,10 +1022,143 @@ void OffScreenRenderWidgetHostView::SetNeedsBeginFrames( } } +void CopyBitmapTo( + const SkBitmap& destination, + const SkBitmap& source, + const gfx::Rect& pos) { + SkAutoLockPixels source_pixels_lock(source); + SkAutoLockPixels destination_pixels_lock(destination); + + char* src = static_cast(source.getPixels()); + char* dest = static_cast(destination.getPixels()); + int pixelsize = source.bytesPerPixel(); + + if (pos.x() + pos.width() <= destination.width() && + pos.y() + pos.height() <= destination.height()) { + for (int i = 0; i < pos.height(); i++) { + memcpy(dest + ((pos.y() + i) * destination.width() + pos.x()) * pixelsize, + src + (i * source.width()) * pixelsize, + source.width() * pixelsize); + } + } + + destination.notifyPixelsChanged(); +} + void OffScreenRenderWidgetHostView::OnPaint( const gfx::Rect& damage_rect, const SkBitmap& bitmap) { TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint"); - callback_.Run(damage_rect, bitmap); + + HoldResize(); + + if (parent_callback_) + parent_callback_.Run(damage_rect, bitmap); + else if (popup_host_view_ && popup_bitmap_.get()) { + gfx::Rect pos = popup_host_view_->popup_position_; + SkBitmap copy = SkBitmapOperations::CreateTiledBitmap(bitmap, + pos.x(), pos.y(), pos.width(), pos.height()); + + CopyBitmapTo(bitmap, *popup_bitmap_, pos); + callback_.Run(damage_rect, bitmap); + CopyBitmapTo(bitmap, copy, pos); + } else { + callback_.Run(damage_rect, bitmap); + } + + ReleaseResize(); +} + +void OffScreenRenderWidgetHostView::OnPopupPaint( + const gfx::Rect& damage_rect, const SkBitmap& bitmap) { + if (popup_host_view_ && popup_bitmap_.get()) + bitmap.deepCopyTo(popup_bitmap_.get()); +} + +void OffScreenRenderWidgetHostView::HoldResize() { + if (!hold_resize_) + hold_resize_ = true; +} + +void OffScreenRenderWidgetHostView::ReleaseResize() { + if (!hold_resize_) + return; + + hold_resize_ = false; + if (pending_resize_) { + pending_resize_ = false; + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, + base::Bind(&OffScreenRenderWidgetHostView::WasResized, + weak_ptr_factory_.GetWeakPtr())); + } +} + +void OffScreenRenderWidgetHostView::WasResized() { + if (hold_resize_) { + if (!pending_resize_) + pending_resize_ = true; + return; + } + + ResizeRootLayer(); + if (render_widget_host_) + render_widget_host_->WasResized(); + GetDelegatedFrameHost()->WasResized(); +} + +void OffScreenRenderWidgetHostView::ProcessKeyboardEvent( + const content::NativeWebKeyboardEvent& event) { + if (!render_widget_host_) + return; + render_widget_host_->ForwardKeyboardEvent(event); +} + +void OffScreenRenderWidgetHostView::ProcessMouseEvent( + const blink::WebMouseEvent& event, + const ui::LatencyInfo& latency) { + if (!IsPopupWidget()) { + if (popup_host_view_ && + popup_host_view_->popup_position_.Contains(event.x, event.y)) { + blink::WebMouseEvent popup_event(event); + popup_event.x -= popup_host_view_->popup_position_.x(); + popup_event.y -= popup_host_view_->popup_position_.y(); + popup_event.windowX = popup_event.x; + popup_event.windowY = popup_event.y; + + popup_host_view_->ProcessMouseEvent(popup_event, latency); + return; + } + } + if (!render_widget_host_) + return; + render_widget_host_->ForwardMouseEvent(event); +} + +void OffScreenRenderWidgetHostView::ProcessMouseWheelEvent( + const blink::WebMouseWheelEvent& event, + const ui::LatencyInfo& latency) { + if (!IsPopupWidget()) { + if (popup_host_view_) { + if (popup_host_view_->popup_position_.Contains(event.x, event.y)) { + blink::WebMouseWheelEvent popup_event(event); + popup_event.x -= popup_host_view_->popup_position_.x(); + popup_event.y -= popup_host_view_->popup_position_.y(); + popup_event.windowX = popup_event.x; + popup_event.windowY = popup_event.y; + popup_host_view_->ProcessMouseWheelEvent(popup_event, latency); + return; + } else { + // Scrolling outside of the popup widget so destroy it. + // Execute asynchronously to avoid deleting the widget from inside some + // other callback. + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, + base::Bind(&OffScreenRenderWidgetHostView::CancelWidget, + popup_host_view_->weak_ptr_factory_.GetWeakPtr())); + } + } + } + if (!render_widget_host_) + return; + render_widget_host_->ForwardWheelEvent(event); } void OffScreenRenderWidgetHostView::SetPainting(bool painting) { @@ -856,12 +1174,22 @@ bool OffScreenRenderWidgetHostView::IsPainting() const { } void OffScreenRenderWidgetHostView::SetFrameRate(int frame_rate) { - if (frame_rate <= 0) - frame_rate = 1; - if (frame_rate > 60) - frame_rate = 60; + if (parent_host_view_) { + if (parent_host_view_->GetFrameRate() == GetFrameRate()) + return; - frame_rate_ = frame_rate; + frame_rate_ = parent_host_view_->GetFrameRate(); + } else { + if (frame_rate <= 0) + frame_rate = 1; + if (frame_rate > 60) + frame_rate = 60; + + frame_rate_ = frame_rate; + } + + for (auto guest_host_view : guest_host_views_) + guest_host_view->SetFrameRate(frame_rate); SetupFrameRate(true); } @@ -910,8 +1238,10 @@ void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) { } void OffScreenRenderWidgetHostView::Invalidate() { - const gfx::Rect& bounds_in_pixels = GetViewBounds(); + InvalidateBounds(GetViewBounds()); +} +void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) { if (software_output_device_) { software_output_device_->OnPaint(bounds_in_pixels); } else if (copy_frame_generator_) { @@ -925,7 +1255,11 @@ void OffScreenRenderWidgetHostView::ResizeRootLayer() { const float orgScaleFactor = scale_factor_; const bool scaleFactorDidChange = (orgScaleFactor != scale_factor_); - gfx::Size size = GetViewBounds().size(); + gfx::Size size; + if (!IsPopupWidget()) + size = GetViewBounds().size(); + else + size = popup_position_.size(); if (!scaleFactorDidChange && size == GetRootLayer()->bounds().size()) return; diff --git a/atom/browser/osr/osr_render_widget_host_view.h b/atom/browser/osr/osr_render_widget_host_view.h index d215d73ab9c..aa7a0577778 100644 --- a/atom/browser/osr/osr_render_widget_host_view.h +++ b/atom/browser/osr/osr_render_widget_host_view.h @@ -20,10 +20,12 @@ #include "base/time/time.h" #include "cc/output/compositor_frame.h" #include "cc/scheduler/begin_frame_source.h" +#include "content/browser/frame_host/render_widget_host_view_guest.h" #include "content/browser/renderer_host/delegated_frame_host.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/browser/renderer_host/resize_lock.h" +#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/WebKit/public/platform/WebVector.h" #include "ui/base/ime/text_input_client.h" #include "ui/compositor/compositor.h" @@ -69,7 +71,7 @@ class OffScreenRenderWidgetHostView OffScreenRenderWidgetHostView(bool transparent, const OnPaintCallback& callback, content::RenderWidgetHost* render_widget_host, - bool is_guest_view_hack, + OffScreenRenderWidgetHostView* parent_host_view, NativeWindow* native_window); ~OffScreenRenderWidgetHostView() override; @@ -139,6 +141,9 @@ class OffScreenRenderWidgetHostView void BeginFrameSubscription( std::unique_ptr) override; void EndFrameSubscription() override; + void InitAsGuest( + content::RenderWidgetHostView*, + content::RenderWidgetHostViewGuest*) override; bool HasAcceleratedSurface(const gfx::Size &) override; gfx::Rect GetBoundsInRootWindow(void) override; void ImeCompositionRangeChanged( @@ -193,7 +198,32 @@ class OffScreenRenderWidgetHostView void DestroyPlatformWidget(); #endif + void CancelWidget(); + void AddGuestHostView(OffScreenRenderWidgetHostView* guest_host); + void RemoveGuestHostView(OffScreenRenderWidgetHostView* guest_host); + + void RegisterGuestViewFrameSwappedCallback( + content::RenderWidgetHostViewGuest* guest_host_view); + void OnGuestViewFrameSwapped( + content::RenderWidgetHostViewGuest* guest_host_view); + void OnPaint(const gfx::Rect& damage_rect, const SkBitmap& bitmap); + void OnPopupPaint(const gfx::Rect& damage_rect, const SkBitmap& bitmap); + + bool IsPopupWidget() const { + return popup_type_ != blink::WebPopupTypeNone; + } + + void HoldResize(); + void ReleaseResize(); + void WasResized(); + + void ProcessKeyboardEvent( + const content::NativeWebKeyboardEvent& event) override; + void ProcessMouseEvent(const blink::WebMouseEvent& event, + const ui::LatencyInfo& latency) override; + void ProcessMouseWheelEvent(const blink::WebMouseWheelEvent& event, + const ui::LatencyInfo& latency) override; void SetPainting(bool painting); bool IsPainting() const; @@ -206,6 +236,7 @@ class OffScreenRenderWidgetHostView content::DelegatedFrameHost* GetDelegatedFrameHost() const; void Invalidate(); + void InvalidateBounds(const gfx::Rect&); content::RenderWidgetHostImpl* render_widget_host() const { return render_widget_host_; } @@ -213,6 +244,14 @@ class OffScreenRenderWidgetHostView gfx::Size size() const { return size_; } float scale_factor() const { return scale_factor_; } + void set_popup_host_view(OffScreenRenderWidgetHostView* popup_view) { + popup_host_view_ = popup_view; + } + + void set_child_host_view(OffScreenRenderWidgetHostView* child_view) { + child_host_view_ = child_view; + } + private: void SetupFrameRate(bool force); void ResizeRootLayer(); @@ -221,11 +260,19 @@ class OffScreenRenderWidgetHostView // Weak ptrs. content::RenderWidgetHostImpl* render_widget_host_; + + OffScreenRenderWidgetHostView* parent_host_view_; + OffScreenRenderWidgetHostView* popup_host_view_; + std::unique_ptr popup_bitmap_; + OffScreenRenderWidgetHostView* child_host_view_; + std::set guest_host_views_; + NativeWindow* native_window_; OffScreenOutputDevice* software_output_device_; const bool transparent_; OnPaintCallback callback_; + OnPaintCallback parent_callback_; int frame_rate_; int frame_rate_threshold_ms_; @@ -233,10 +280,16 @@ class OffScreenRenderWidgetHostView base::Time last_time_; float scale_factor_; - bool is_showing_; gfx::Vector2dF last_scroll_offset_; gfx::Size size_; bool painting_; + + bool is_showing_; + bool is_destroyed_; + gfx::Rect popup_position_; + + bool hold_resize_; + bool pending_resize_; std::unique_ptr root_layer_; std::unique_ptr compositor_; diff --git a/atom/browser/osr/osr_web_contents_view.cc b/atom/browser/osr/osr_web_contents_view.cc index 8d95017b0e6..18b24c1c1ce 100644 --- a/atom/browser/osr/osr_web_contents_view.cc +++ b/atom/browser/osr/osr_web_contents_view.cc @@ -4,7 +4,9 @@ #include "atom/browser/osr/osr_web_contents_view.h" +#include "content/public/browser/render_view_host.h" #include "third_party/WebKit/public/platform/WebScreenInfo.h" +#include "ui/display/screen.h" namespace atom { @@ -31,15 +33,27 @@ void OffScreenWebContentsView::SetWebContents( #if !defined(OS_MACOSX) gfx::NativeView OffScreenWebContentsView::GetNativeView() const { - return gfx::NativeView(); + if (!web_contents_) return gfx::NativeView(); + + auto relay = NativeWindowRelay::FromWebContents(web_contents_); + if (!relay) return gfx::NativeView(); + return relay->window->GetNativeView(); } gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const { - return gfx::NativeView(); + if (!web_contents_) return gfx::NativeView(); + + auto relay = NativeWindowRelay::FromWebContents(web_contents_); + if (!relay) return gfx::NativeView(); + return relay->window->GetNativeView(); } gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const { - return gfx::NativeWindow(); + if (!web_contents_) return gfx::NativeWindow(); + + auto relay = NativeWindowRelay::FromWebContents(web_contents_); + if (!relay) return gfx::NativeWindow(); + return relay->window->GetNativeWindow(); } #endif @@ -67,7 +81,7 @@ content::DropData* OffScreenWebContentsView::GetDropData() const { } gfx::Rect OffScreenWebContentsView::GetViewBounds() const { - return view_ ? view_->GetViewBounds() : gfx::Rect(); + return GetView() ? GetView()->GetViewBounds() : gfx::Rect(); } void OffScreenWebContentsView::CreateView(const gfx::Size& initial_size, @@ -76,21 +90,55 @@ void OffScreenWebContentsView::CreateView(const gfx::Size& initial_size, content::RenderWidgetHostViewBase* OffScreenWebContentsView::CreateViewForWidget( - content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { + content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { + if (render_widget_host->GetView()) { + return static_cast( + render_widget_host->GetView()); + } + auto relay = NativeWindowRelay::FromWebContents(web_contents_); - view_ = new OffScreenRenderWidgetHostView( - transparent_, callback_, render_widget_host, - is_guest_view_hack, relay->window.get()); - return view_; + return new OffScreenRenderWidgetHostView( + transparent_, + callback_, + render_widget_host, + nullptr, + relay->window.get()); +} + +content::RenderWidgetHostViewBase* + OffScreenWebContentsView::CreateViewForWidget( + content::RenderWidgetHost* render_widget_host, + content::RenderWidgetHost* embedder_render_widget_host) { + if (render_widget_host->GetView()) { + return static_cast( + render_widget_host->GetView()); + } + + OffScreenRenderWidgetHostView* embedder_host_view = nullptr; + if (embedder_render_widget_host) { + embedder_host_view = static_cast( + embedder_render_widget_host->GetView()); + } + + auto relay = NativeWindowRelay::FromWebContents(web_contents_); + return new OffScreenRenderWidgetHostView( + transparent_, + callback_, + render_widget_host, + embedder_host_view, + relay->window.get()); } content::RenderWidgetHostViewBase* OffScreenWebContentsView::CreateViewForPopupWidget( content::RenderWidgetHost* render_widget_host) { auto relay = NativeWindowRelay::FromWebContents(web_contents_); - view_ = new OffScreenRenderWidgetHostView( - transparent_, callback_, render_widget_host, false, relay->window.get()); - return view_; + return new OffScreenRenderWidgetHostView( + transparent_, + callback_, + render_widget_host, + GetView(), + relay->window.get()); } void OffScreenWebContentsView::SetPageTitle(const base::string16& title) { @@ -98,8 +146,8 @@ void OffScreenWebContentsView::SetPageTitle(const base::string16& title) { void OffScreenWebContentsView::RenderViewCreated( content::RenderViewHost* host) { - if (view_) - view_->InstallTransparency(); + if (GetView()) + GetView()->InstallTransparency(); } void OffScreenWebContentsView::RenderViewSwappedIn( @@ -111,14 +159,23 @@ void OffScreenWebContentsView::SetOverscrollControllerEnabled(bool enabled) { void OffScreenWebContentsView::GetScreenInfo( content::ScreenInfo* screen_info) const { - screen_info->rect = gfx::Rect(view_->size()); - screen_info->available_rect = gfx::Rect(view_->size()); screen_info->depth = 24; screen_info->depth_per_component = 8; - screen_info->device_scale_factor = view_->scale_factor(); screen_info->orientation_angle = 0; screen_info->orientation_type = content::SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY; + + if (GetView()) { + screen_info->rect = gfx::Rect(GetView()->size()); + screen_info->available_rect = gfx::Rect(GetView()->size()); + screen_info->device_scale_factor = GetView()->scale_factor(); + } else { + const display::Display display = + display::Screen::GetScreen()->GetPrimaryDisplay(); + screen_info->rect = display.bounds(); + screen_info->available_rect = display.work_area(); + screen_info->device_scale_factor = display.device_scale_factor(); + } } #if defined(OS_MACOSX) @@ -152,4 +209,12 @@ void OffScreenWebContentsView::UpdateDragCursor( blink::WebDragOperation operation) { } +OffScreenRenderWidgetHostView* OffScreenWebContentsView::GetView() const { + if (web_contents_) { + return static_cast( + web_contents_->GetRenderViewHost()->GetWidget()->GetView()); + } + return nullptr; +} + } // namespace atom diff --git a/atom/browser/osr/osr_web_contents_view.h b/atom/browser/osr/osr_web_contents_view.h index 8e4e2429947..57aee80d91f 100644 --- a/atom/browser/osr/osr_web_contents_view.h +++ b/atom/browser/osr/osr_web_contents_view.h @@ -45,6 +45,9 @@ class OffScreenWebContentsView : public content::WebContentsView, content::RenderWidgetHostViewBase* CreateViewForWidget( content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) override; + content::RenderWidgetHostViewBase* CreateViewForWidget( + content::RenderWidgetHost* render_widget_host, + content::RenderWidgetHost* embedder_render_widget_host) override; content::RenderWidgetHostViewBase* CreateViewForPopupWidget( content::RenderWidgetHost* render_widget_host) override; void SetPageTitle(const base::string16& title) override; @@ -75,11 +78,12 @@ class OffScreenWebContentsView : public content::WebContentsView, void PlatformDestroy(); #endif + OffScreenRenderWidgetHostView* GetView() const; + const bool transparent_; OnPaintCallback callback_; // Weak refs. - OffScreenRenderWidgetHostView* view_; content::WebContents* web_contents_; #if defined(OS_MACOSX) From c9fa71bdb31874196f671d039310a61b5f41de90 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sun, 5 Mar 2017 16:18:57 +0100 Subject: [PATCH 1099/1195] lint fix --- atom/browser/api/atom_api_web_contents.cc | 8 +-- .../osr/osr_render_widget_host_view.cc | 54 +++++++++---------- .../browser/osr/osr_render_widget_host_view.h | 17 +++--- atom/browser/osr/osr_web_contents_view.cc | 42 +++++++-------- 4 files changed, 61 insertions(+), 60 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index e5f8bfe9d29..b6fb523c161 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -343,13 +343,13 @@ WebContents::WebContents(v8::Isolate* isolate, const mate::Dictionary& options) session->browser_context(), site_instance); guest_delegate_.reset(new WebViewGuestDelegate); params.guest_delegate = guest_delegate_.get(); - + if (embedder_ && embedder_->IsOffScreen()) { - auto* view = new OffScreenWebContentsView(false, + auto* view = new OffScreenWebContentsView(false, base::Bind(&WebContents::OnPaint, base::Unretained(this))); params.view = view; params.delegate_view = view; - + web_contents = content::WebContents::Create(params); view->SetWebContents(web_contents); } else { @@ -1650,7 +1650,7 @@ gfx::Size WebContents::GetSizeForNewRenderView( if (relay) { return relay->window->GetSize(); } - + return gfx::Size(); } diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index 6719b7b4545..f20e96f89d6 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -26,9 +26,9 @@ #include "ui/compositor/layer.h" #include "ui/compositor/layer_type.h" #include "ui/events/latency_info.h" -#include "ui/gfx/skbitmap_operations.h" #include "ui/gfx/geometry/dip_util.h" #include "ui/gfx/native_widget_types.h" +#include "ui/gfx/skbitmap_operations.h" namespace atom { @@ -53,9 +53,9 @@ class AtomResizeLock : public content::ResizeLock { DCHECK(host_); host_->HoldResize(); - content::BrowserThread::PostDelayedTask(content::BrowserThread::UI, + content::BrowserThread::PostDelayedTask(content::BrowserThread::UI, FROM_HERE, base::Bind(&AtomResizeLock::CancelLock, - weak_ptr_factory_.GetWeakPtr()), + weak_ptr_factory_.GetWeakPtr()), base::TimeDelta::FromMilliseconds(kResizeLockTimeoutMs)); } @@ -472,7 +472,7 @@ OffScreenRenderWidgetHostView::~OffScreenRenderWidgetHostView() { if (copy_frame_generator_.get()) copy_frame_generator_.reset(NULL); - + #if defined(OS_MACOSX) DestroyPlatformWidget(); #else @@ -543,7 +543,7 @@ void OffScreenRenderWidgetHostView::InitAsChild(gfx::NativeView) { if (parent_host_view_->child_host_view_) { parent_host_view_->child_host_view_->CancelWidget(); } - + parent_host_view_->set_child_host_view(this); parent_host_view_->Hide(); @@ -720,18 +720,18 @@ void OffScreenRenderWidgetHostView::ClearCompositorFrame() { void OffScreenRenderWidgetHostView::InitAsPopup( content::RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { DCHECK_EQ(parent_host_view_, parent_host_view); - + if (parent_host_view_->popup_host_view_) { parent_host_view_->popup_host_view_->CancelWidget(); } - + parent_host_view_->set_popup_host_view(this); parent_host_view_->popup_bitmap_.reset(new SkBitmap); parent_callback_ = base::Bind(&OffScreenRenderWidgetHostView::OnPopupPaint, parent_host_view_->weak_ptr_factory_.GetWeakPtr()); - + popup_position_ = pos; - + ResizeRootLayer(); Show(); } @@ -775,7 +775,7 @@ void OffScreenRenderWidgetHostView::Destroy() { Hide(); } } - + delete this; } @@ -813,8 +813,8 @@ void OffScreenRenderWidgetHostView::EndFrameSubscription() { } void OffScreenRenderWidgetHostView::InitAsGuest( - content::RenderWidgetHostView* parent_host_view, - content::RenderWidgetHostViewGuest* guest_view) { + content::RenderWidgetHostView* parent_host_view, + content::RenderWidgetHostViewGuest* guest_view) { parent_host_view_->AddGuestHostView(this); parent_host_view_->RegisterGuestViewFrameSwappedCallback(guest_view); } @@ -931,9 +931,9 @@ bool OffScreenRenderWidgetHostView::TransformPointToCoordSpaceForView( void OffScreenRenderWidgetHostView::CancelWidget() { if (render_widget_host_) - render_widget_host_->LostCapture(); + render_widget_host_->LostCapture(); Hide(); - + if (parent_host_view_) { if (parent_host_view_->popup_host_view_ == this) { parent_host_view_->set_popup_host_view(NULL); @@ -946,7 +946,7 @@ void OffScreenRenderWidgetHostView::CancelWidget() { } parent_host_view_ = NULL; } - + if (render_widget_host_ && !is_destroyed_) { is_destroyed_ = true; // Results in a call to Destroy(). @@ -976,7 +976,7 @@ void OffScreenRenderWidgetHostView::OnGuestViewFrameSwapped( content::RenderWidgetHostViewGuest* guest_host_view) { InvalidateBounds( gfx::ConvertRectToPixel(scale_factor_, guest_host_view->GetViewBounds())); - + RegisterGuestViewFrameSwappedCallback(guest_host_view); } @@ -1023,16 +1023,16 @@ void OffScreenRenderWidgetHostView::SetNeedsBeginFrames( } void CopyBitmapTo( - const SkBitmap& destination, - const SkBitmap& source, + const SkBitmap& destination, + const SkBitmap& source, const gfx::Rect& pos) { SkAutoLockPixels source_pixels_lock(source); SkAutoLockPixels destination_pixels_lock(destination); - + char* src = static_cast(source.getPixels()); char* dest = static_cast(destination.getPixels()); int pixelsize = source.bytesPerPixel(); - + if (pos.x() + pos.width() <= destination.width() && pos.y() + pos.height() <= destination.height()) { for (int i = 0; i < pos.height(); i++) { @@ -1041,14 +1041,14 @@ void CopyBitmapTo( source.width() * pixelsize); } } - + destination.notifyPixelsChanged(); } void OffScreenRenderWidgetHostView::OnPaint( const gfx::Rect& damage_rect, const SkBitmap& bitmap) { TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint"); - + HoldResize(); if (parent_callback_) @@ -1057,14 +1057,14 @@ void OffScreenRenderWidgetHostView::OnPaint( gfx::Rect pos = popup_host_view_->popup_position_; SkBitmap copy = SkBitmapOperations::CreateTiledBitmap(bitmap, pos.x(), pos.y(), pos.width(), pos.height()); - + CopyBitmapTo(bitmap, *popup_bitmap_, pos); callback_.Run(damage_rect, bitmap); CopyBitmapTo(bitmap, copy, pos); } else { callback_.Run(damage_rect, bitmap); } - + ReleaseResize(); } @@ -1098,7 +1098,7 @@ void OffScreenRenderWidgetHostView::WasResized() { pending_resize_ = true; return; } - + ResizeRootLayer(); if (render_widget_host_) render_widget_host_->WasResized(); @@ -1184,10 +1184,10 @@ void OffScreenRenderWidgetHostView::SetFrameRate(int frame_rate) { frame_rate = 1; if (frame_rate > 60) frame_rate = 60; - + frame_rate_ = frame_rate; } - + for (auto guest_host_view : guest_host_views_) guest_host_view->SetFrameRate(frame_rate); diff --git a/atom/browser/osr/osr_render_widget_host_view.h b/atom/browser/osr/osr_render_widget_host_view.h index aa7a0577778..f1d6a0066dc 100644 --- a/atom/browser/osr/osr_render_widget_host_view.h +++ b/atom/browser/osr/osr_render_widget_host_view.h @@ -5,6 +5,7 @@ #ifndef ATOM_BROWSER_OSR_OSR_RENDER_WIDGET_HOST_VIEW_H_ #define ATOM_BROWSER_OSR_OSR_RENDER_WIDGET_HOST_VIEW_H_ +#include #include #include @@ -142,7 +143,7 @@ class OffScreenRenderWidgetHostView std::unique_ptr) override; void EndFrameSubscription() override; void InitAsGuest( - content::RenderWidgetHostView*, + content::RenderWidgetHostView*, content::RenderWidgetHostViewGuest*) override; bool HasAcceleratedSurface(const gfx::Size &) override; gfx::Rect GetBoundsInRootWindow(void) override; @@ -209,15 +210,15 @@ class OffScreenRenderWidgetHostView void OnPaint(const gfx::Rect& damage_rect, const SkBitmap& bitmap); void OnPopupPaint(const gfx::Rect& damage_rect, const SkBitmap& bitmap); - + bool IsPopupWidget() const { return popup_type_ != blink::WebPopupTypeNone; } - + void HoldResize(); void ReleaseResize(); void WasResized(); - + void ProcessKeyboardEvent( const content::NativeWebKeyboardEvent& event) override; void ProcessMouseEvent(const blink::WebMouseEvent& event, @@ -247,7 +248,7 @@ class OffScreenRenderWidgetHostView void set_popup_host_view(OffScreenRenderWidgetHostView* popup_view) { popup_host_view_ = popup_view; } - + void set_child_host_view(OffScreenRenderWidgetHostView* child_view) { child_host_view_ = child_view; } @@ -260,13 +261,13 @@ class OffScreenRenderWidgetHostView // Weak ptrs. content::RenderWidgetHostImpl* render_widget_host_; - + OffScreenRenderWidgetHostView* parent_host_view_; OffScreenRenderWidgetHostView* popup_host_view_; std::unique_ptr popup_bitmap_; OffScreenRenderWidgetHostView* child_host_view_; std::set guest_host_views_; - + NativeWindow* native_window_; OffScreenOutputDevice* software_output_device_; @@ -283,7 +284,7 @@ class OffScreenRenderWidgetHostView gfx::Vector2dF last_scroll_offset_; gfx::Size size_; bool painting_; - + bool is_showing_; bool is_destroyed_; gfx::Rect popup_position_; diff --git a/atom/browser/osr/osr_web_contents_view.cc b/atom/browser/osr/osr_web_contents_view.cc index 18b24c1c1ce..38dbbe00440 100644 --- a/atom/browser/osr/osr_web_contents_view.cc +++ b/atom/browser/osr/osr_web_contents_view.cc @@ -34,7 +34,7 @@ void OffScreenWebContentsView::SetWebContents( #if !defined(OS_MACOSX) gfx::NativeView OffScreenWebContentsView::GetNativeView() const { if (!web_contents_) return gfx::NativeView(); - + auto relay = NativeWindowRelay::FromWebContents(web_contents_); if (!relay) return gfx::NativeView(); return relay->window->GetNativeView(); @@ -42,7 +42,7 @@ gfx::NativeView OffScreenWebContentsView::GetNativeView() const { gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const { if (!web_contents_) return gfx::NativeView(); - + auto relay = NativeWindowRelay::FromWebContents(web_contents_); if (!relay) return gfx::NativeView(); return relay->window->GetNativeView(); @@ -50,7 +50,7 @@ gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const { gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const { if (!web_contents_) return gfx::NativeWindow(); - + auto relay = NativeWindowRelay::FromWebContents(web_contents_); if (!relay) return gfx::NativeWindow(); return relay->window->GetNativeWindow(); @@ -90,18 +90,18 @@ void OffScreenWebContentsView::CreateView(const gfx::Size& initial_size, content::RenderWidgetHostViewBase* OffScreenWebContentsView::CreateViewForWidget( - content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { + content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) { if (render_widget_host->GetView()) { return static_cast( render_widget_host->GetView()); } - + auto relay = NativeWindowRelay::FromWebContents(web_contents_); return new OffScreenRenderWidgetHostView( - transparent_, - callback_, - render_widget_host, - nullptr, + transparent_, + callback_, + render_widget_host, + nullptr, relay->window.get()); } @@ -113,19 +113,19 @@ content::RenderWidgetHostViewBase* return static_cast( render_widget_host->GetView()); } - + OffScreenRenderWidgetHostView* embedder_host_view = nullptr; if (embedder_render_widget_host) { embedder_host_view = static_cast( embedder_render_widget_host->GetView()); } - + auto relay = NativeWindowRelay::FromWebContents(web_contents_); return new OffScreenRenderWidgetHostView( - transparent_, - callback_, - render_widget_host, - embedder_host_view, + transparent_, + callback_, + render_widget_host, + embedder_host_view, relay->window.get()); } @@ -134,10 +134,10 @@ content::RenderWidgetHostViewBase* content::RenderWidgetHost* render_widget_host) { auto relay = NativeWindowRelay::FromWebContents(web_contents_); return new OffScreenRenderWidgetHostView( - transparent_, - callback_, - render_widget_host, - GetView(), + transparent_, + callback_, + render_widget_host, + GetView(), relay->window.get()); } @@ -164,13 +164,13 @@ void OffScreenWebContentsView::GetScreenInfo( screen_info->orientation_angle = 0; screen_info->orientation_type = content::SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY; - + if (GetView()) { screen_info->rect = gfx::Rect(GetView()->size()); screen_info->available_rect = gfx::Rect(GetView()->size()); screen_info->device_scale_factor = GetView()->scale_factor(); } else { - const display::Display display = + const display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); screen_info->rect = display.bounds(); screen_info->available_rect = display.work_area(); From 8f546313b66cad4ee3d38ff01bff0e956cac18ae Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sun, 5 Mar 2017 16:19:51 +0100 Subject: [PATCH 1100/1195] add popup window bounds to damage_rect --- atom/browser/osr/osr_render_widget_host_view.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index f20e96f89d6..7d370fbed65 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -1050,16 +1050,19 @@ void OffScreenRenderWidgetHostView::OnPaint( TRACE_EVENT0("electron", "OffScreenRenderWidgetHostView::OnPaint"); HoldResize(); - - if (parent_callback_) + + if (parent_callback_) { parent_callback_.Run(damage_rect, bitmap); - else if (popup_host_view_ && popup_bitmap_.get()) { + } else if (popup_host_view_ && popup_bitmap_.get()) { gfx::Rect pos = popup_host_view_->popup_position_; + gfx::Rect damage(damage_rect); + damage.Union(pos); + SkBitmap copy = SkBitmapOperations::CreateTiledBitmap(bitmap, pos.x(), pos.y(), pos.width(), pos.height()); CopyBitmapTo(bitmap, *popup_bitmap_, pos); - callback_.Run(damage_rect, bitmap); + callback_.Run(damage, bitmap); CopyBitmapTo(bitmap, copy, pos); } else { callback_.Run(damage_rect, bitmap); From bccc25165d1d7d9745eb29643ab99e850a34eb25 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sun, 5 Mar 2017 16:20:32 +0100 Subject: [PATCH 1101/1195] fix mouse wheel event sending typo --- atom/browser/api/atom_api_web_contents.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index b6fb523c161..880cdddedf3 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1441,7 +1441,7 @@ void WebContents::SendInputEvent(v8::Isolate* isolate, } else if (type == blink::WebInputEvent::MouseWheel) { blink::WebMouseWheelEvent mouse_wheel_event; if (mate::ConvertFromV8(isolate, input_event, &mouse_wheel_event)) { - view->ProcessMouseEvent(mouse_wheel_event, ui::LatencyInfo()); + view->ProcessMouseWheelEvent(mouse_wheel_event, ui::LatencyInfo()); return; } } From 062b1ed43e1ef952234d017ac476e06dc85486ea Mon Sep 17 00:00:00 2001 From: gellert Date: Tue, 14 Mar 2017 12:56:24 +0100 Subject: [PATCH 1102/1195] moves createviewfordwidget method to osrrwhv --- atom/browser/native_window_mac.h | 1 + atom/browser/native_window_mac.mm | 4 +++ .../osr/osr_render_widget_host_view.cc | 26 ++++++++++++++++++- .../browser/osr/osr_render_widget_host_view.h | 6 +++++ atom/browser/osr/osr_web_contents_view.cc | 24 ----------------- atom/browser/osr/osr_web_contents_view.h | 3 --- 6 files changed, 36 insertions(+), 28 deletions(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index af0f157ecae..69bf3afef65 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -89,6 +89,7 @@ class NativeWindowMac : public NativeWindow, void SetContentProtection(bool enable) override; void SetBrowserView(NativeBrowserView* browser_view) override; void SetParentWindow(NativeWindow* parent) override; + gfx::NativeView GetNativeView() override; gfx::NativeWindow GetNativeWindow() override; gfx::AcceleratedWidget GetAcceleratedWidget() override; void SetProgressBar(double progress, const ProgressState state) override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 330d48226dc..755e46c4f32 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1314,6 +1314,10 @@ void NativeWindowMac::SetParentWindow(NativeWindow* parent) { [parent->GetNativeWindow() addChildWindow:window_ ordered:NSWindowAbove]; } +gfx::NativeView NativeWindowMac::GetNativeView() { + return inspectable_web_contents()->GetView()->GetNativeView(); +} + gfx::NativeWindow NativeWindowMac::GetNativeWindow() { return window_; } diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index 7d370fbed65..22cbd7a15c5 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -415,13 +415,13 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( frame_rate_threshold_ms_(0), last_time_(base::Time::Now()), scale_factor_(kDefaultScaleFactor), + size_(native_window->GetSize()), painting_(true), is_showing_(!render_widget_host_->is_hidden()), is_destroyed_(false), popup_position_(gfx::Rect()), hold_resize_(false), pending_resize_(false), - size_(native_window->GetSize()), weak_ptr_factory_(this) { DCHECK(render_widget_host_); #if !defined(OS_MACOSX) @@ -839,6 +839,30 @@ gfx::Size OffScreenRenderWidgetHostView::GetRequestedRendererSize() const { return GetDelegatedFrameHost()->GetRequestedRendererSize(); } +content::RenderWidgetHostViewBase* + OffScreenRenderWidgetHostView::CreateViewForWidget( + content::RenderWidgetHost* render_widget_host, + content::RenderWidgetHost* embedder_render_widget_host, + content::WebContentsView* web_contents_view) { + if (render_widget_host->GetView()) { + return static_cast( + render_widget_host->GetView()); + } + + OffScreenRenderWidgetHostView* embedder_host_view = nullptr; + if (embedder_render_widget_host) { + embedder_host_view = static_cast( + embedder_render_widget_host->GetView()); + } + + return new OffScreenRenderWidgetHostView( + transparent_, + callback_, + render_widget_host, + embedder_host_view, + native_window_); +} + #if !defined(OS_MACOSX) ui::Layer* OffScreenRenderWidgetHostView::DelegatedFrameHostGetLayer() const { return const_cast(root_layer_.get()); diff --git a/atom/browser/osr/osr_render_widget_host_view.h b/atom/browser/osr/osr_render_widget_host_view.h index f1d6a0066dc..0c2ece40ad3 100644 --- a/atom/browser/osr/osr_render_widget_host_view.h +++ b/atom/browser/osr/osr_render_widget_host_view.h @@ -26,6 +26,7 @@ #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_view_base.h" #include "content/browser/renderer_host/resize_lock.h" +#include "content/browser/web_contents/web_contents_view.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/WebKit/public/platform/WebVector.h" #include "ui/base/ime/text_input_client.h" @@ -152,6 +153,11 @@ class OffScreenRenderWidgetHostView gfx::Size GetPhysicalBackingSize() const override; gfx::Size GetRequestedRendererSize() const override; + content::RenderWidgetHostViewBase* CreateViewForWidget( + content::RenderWidgetHost*, + content::RenderWidgetHost*, + content::WebContentsView*) override; + #if !defined(OS_MACOSX) // content::DelegatedFrameHostClient: int DelegatedFrameHostGetGpuMemoryBufferClientId(void) const; diff --git a/atom/browser/osr/osr_web_contents_view.cc b/atom/browser/osr/osr_web_contents_view.cc index 38dbbe00440..303a73ec5ac 100644 --- a/atom/browser/osr/osr_web_contents_view.cc +++ b/atom/browser/osr/osr_web_contents_view.cc @@ -105,30 +105,6 @@ content::RenderWidgetHostViewBase* relay->window.get()); } -content::RenderWidgetHostViewBase* - OffScreenWebContentsView::CreateViewForWidget( - content::RenderWidgetHost* render_widget_host, - content::RenderWidgetHost* embedder_render_widget_host) { - if (render_widget_host->GetView()) { - return static_cast( - render_widget_host->GetView()); - } - - OffScreenRenderWidgetHostView* embedder_host_view = nullptr; - if (embedder_render_widget_host) { - embedder_host_view = static_cast( - embedder_render_widget_host->GetView()); - } - - auto relay = NativeWindowRelay::FromWebContents(web_contents_); - return new OffScreenRenderWidgetHostView( - transparent_, - callback_, - render_widget_host, - embedder_host_view, - relay->window.get()); -} - content::RenderWidgetHostViewBase* OffScreenWebContentsView::CreateViewForPopupWidget( content::RenderWidgetHost* render_widget_host) { diff --git a/atom/browser/osr/osr_web_contents_view.h b/atom/browser/osr/osr_web_contents_view.h index 57aee80d91f..ffb3b38619c 100644 --- a/atom/browser/osr/osr_web_contents_view.h +++ b/atom/browser/osr/osr_web_contents_view.h @@ -45,9 +45,6 @@ class OffScreenWebContentsView : public content::WebContentsView, content::RenderWidgetHostViewBase* CreateViewForWidget( content::RenderWidgetHost* render_widget_host, bool is_guest_view_hack) override; - content::RenderWidgetHostViewBase* CreateViewForWidget( - content::RenderWidgetHost* render_widget_host, - content::RenderWidgetHost* embedder_render_widget_host) override; content::RenderWidgetHostViewBase* CreateViewForPopupWidget( content::RenderWidgetHost* render_widget_host) override; void SetPageTitle(const base::string16& title) override; From ff053bbe06ba499faab2ecf208cb6e5ff943c6b6 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sun, 9 Apr 2017 01:24:09 +0200 Subject: [PATCH 1103/1195] call InvalidateBounds when popup updates --- atom/browser/osr/osr_render_widget_host_view.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index 22cbd7a15c5..b203d0db96c 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -1099,6 +1099,7 @@ void OffScreenRenderWidgetHostView::OnPopupPaint( const gfx::Rect& damage_rect, const SkBitmap& bitmap) { if (popup_host_view_ && popup_bitmap_.get()) bitmap.deepCopyTo(popup_bitmap_.get()); + InvalidateBounds(popup_host_view_->popup_position_); } void OffScreenRenderWidgetHostView::HoldResize() { From 6b33564056bd18c9661f47dfd61797add6d584fb Mon Sep 17 00:00:00 2001 From: gellert Date: Sun, 9 Apr 2017 23:02:02 +0200 Subject: [PATCH 1104/1195] adds ipc send to disable external popups on macos --- atom/browser/osr/osr_web_contents_view.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/atom/browser/osr/osr_web_contents_view.cc b/atom/browser/osr/osr_web_contents_view.cc index 303a73ec5ac..f5c07c8ed1f 100644 --- a/atom/browser/osr/osr_web_contents_view.cc +++ b/atom/browser/osr/osr_web_contents_view.cc @@ -4,6 +4,7 @@ #include "atom/browser/osr/osr_web_contents_view.h" +#include "content/common/worker_messages.h" #include "content/public/browser/render_view_host.h" #include "third_party/WebKit/public/platform/WebScreenInfo.h" #include "ui/display/screen.h" @@ -124,6 +125,11 @@ void OffScreenWebContentsView::RenderViewCreated( content::RenderViewHost* host) { if (GetView()) GetView()->InstallTransparency(); + +#if defined(OS_MACOSX) + host->Send(new WorkerProcessMsg_DisableExternalPopupMenus( + host->GetRoutingID())); +#endif } void OffScreenWebContentsView::RenderViewSwappedIn( From 155fef99aede6b2314a3c602ec4501c050219401 Mon Sep 17 00:00:00 2001 From: gellert Date: Tue, 11 Apr 2017 14:19:34 +0200 Subject: [PATCH 1105/1195] adds offscreen renderer ipc message to disable external popups --- atom/browser/osr/osr_web_contents_view.cc | 5 ++--- atom/common/api/api_messages.h | 2 ++ atom/renderer/atom_render_view_observer.cc | 5 +++++ atom/renderer/atom_render_view_observer.h | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/atom/browser/osr/osr_web_contents_view.cc b/atom/browser/osr/osr_web_contents_view.cc index f5c07c8ed1f..8fe69683195 100644 --- a/atom/browser/osr/osr_web_contents_view.cc +++ b/atom/browser/osr/osr_web_contents_view.cc @@ -4,7 +4,7 @@ #include "atom/browser/osr/osr_web_contents_view.h" -#include "content/common/worker_messages.h" +#include "atom/common/api/api_messages.h" #include "content/public/browser/render_view_host.h" #include "third_party/WebKit/public/platform/WebScreenInfo.h" #include "ui/display/screen.h" @@ -127,8 +127,7 @@ void OffScreenWebContentsView::RenderViewCreated( GetView()->InstallTransparency(); #if defined(OS_MACOSX) - host->Send(new WorkerProcessMsg_DisableExternalPopupMenus( - host->GetRoutingID())); + host->Send(new AtomViewMsg_Offscreen(host->GetRoutingID())); #endif } diff --git a/atom/common/api/api_messages.h b/atom/common/api/api_messages.h index ef945d9eebe..e25089b869a 100644 --- a/atom/common/api/api_messages.h +++ b/atom/common/api/api_messages.h @@ -35,6 +35,8 @@ IPC_MESSAGE_ROUTED3(AtomViewMsg_Message, base::string16 /* channel */, base::ListValue /* arguments */) +IPC_MESSAGE_ROUTED0(AtomViewMsg_Offscreen) + // Sent by the renderer when the draggable regions are updated. IPC_MESSAGE_ROUTED1(AtomViewHostMsg_UpdateDraggableRegions, std::vector /* regions */) diff --git a/atom/renderer/atom_render_view_observer.cc b/atom/renderer/atom_render_view_observer.cc index a68238ba4ce..6aa26cccaf0 100644 --- a/atom/renderer/atom_render_view_observer.cc +++ b/atom/renderer/atom_render_view_observer.cc @@ -136,6 +136,7 @@ bool AtomRenderViewObserver::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(AtomRenderViewObserver, message) IPC_MESSAGE_HANDLER(AtomViewMsg_Message, OnBrowserMessage) + IPC_MESSAGE_HANDLER(AtomViewMsg_Offscreen, OnOffscreen) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -169,4 +170,8 @@ void AtomRenderViewObserver::OnBrowserMessage(bool send_to_all, } } +void AtomRenderViewObserver::OnOffscreen() { + blink::WebView::setUseExternalPopupMenus(false); +} + } // namespace atom diff --git a/atom/renderer/atom_render_view_observer.h b/atom/renderer/atom_render_view_observer.h index e642bbe9422..4751db2d8c6 100644 --- a/atom/renderer/atom_render_view_observer.h +++ b/atom/renderer/atom_render_view_observer.h @@ -40,6 +40,8 @@ class AtomRenderViewObserver : public content::RenderViewObserver { const base::string16& channel, const base::ListValue& args); + void OnOffscreen(); + AtomRendererClient* renderer_client_; // Whether the document object has been created. From 2f32311292117f5eda05d1f1403548bbaa653eb8 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Wed, 12 Apr 2017 04:11:49 +0200 Subject: [PATCH 1106/1195] fix black bars around popups and scaled images when using gpu rendering --- atom/browser/osr/osr_web_contents_view.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/atom/browser/osr/osr_web_contents_view.cc b/atom/browser/osr/osr_web_contents_view.cc index 8fe69683195..efcdafd51c3 100644 --- a/atom/browser/osr/osr_web_contents_view.cc +++ b/atom/browser/osr/osr_web_contents_view.cc @@ -30,6 +30,8 @@ OffScreenWebContentsView::~OffScreenWebContentsView() { void OffScreenWebContentsView::SetWebContents( content::WebContents* web_contents) { web_contents_ = web_contents; + + RenderViewCreated(web_contents_->GetRenderViewHost()); } #if !defined(OS_MACOSX) @@ -139,23 +141,22 @@ void OffScreenWebContentsView::SetOverscrollControllerEnabled(bool enabled) { } void OffScreenWebContentsView::GetScreenInfo( - content::ScreenInfo* screen_info) const { + content::ScreenInfo* screen_info) const { screen_info->depth = 24; screen_info->depth_per_component = 8; screen_info->orientation_angle = 0; + screen_info->device_scale_factor = 1.0; screen_info->orientation_type = content::SCREEN_ORIENTATION_VALUES_LANDSCAPE_PRIMARY; if (GetView()) { screen_info->rect = gfx::Rect(GetView()->size()); screen_info->available_rect = gfx::Rect(GetView()->size()); - screen_info->device_scale_factor = GetView()->scale_factor(); } else { const display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay(); screen_info->rect = display.bounds(); screen_info->available_rect = display.work_area(); - screen_info->device_scale_factor = display.device_scale_factor(); } } From 704fde1939ff4c41ee2af37e570c8e98b9435e93 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Wed, 12 Apr 2017 16:15:58 +0200 Subject: [PATCH 1107/1195] port CEF pr that speeds up and simplifies GPU rendering --- .../osr/osr_render_widget_host_view.cc | 302 +++++------------- .../browser/osr/osr_render_widget_host_view.h | 2 +- 2 files changed, 75 insertions(+), 229 deletions(-) diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index b203d0db96c..5827a04c31b 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -101,68 +101,23 @@ class AtomResizeLock : public content::ResizeLock { class AtomCopyFrameGenerator { public: - AtomCopyFrameGenerator(int frame_rate_threshold_ms, - OffScreenRenderWidgetHostView* view) - : frame_rate_threshold_ms_(frame_rate_threshold_ms), - view_(view), - frame_pending_(false), - frame_in_progress_(false), + AtomCopyFrameGenerator(OffScreenRenderWidgetHostView* view, + int frame_rate_threshold_us) + : view_(view), frame_retry_count_(0), + next_frame_time_(base::TimeTicks::Now()), + frame_duration_(base::TimeDelta::FromMicroseconds( + frame_rate_threshold_us)), weak_ptr_factory_(this) { last_time_ = base::Time::Now(); } - void GenerateCopyFrame( - bool force_frame, - const gfx::Rect& damage_rect) { - if (force_frame && !frame_pending_) - frame_pending_ = true; - - if (!frame_pending_) - return; - - if (!damage_rect.IsEmpty()) - pending_damage_rect_.Union(damage_rect); - - if (frame_in_progress_) - return; - - frame_in_progress_ = true; - - const int64_t frame_rate_delta = - (base::TimeTicks::Now() - frame_start_time_).InMilliseconds(); - if (frame_rate_delta < frame_rate_threshold_ms_) { - content::BrowserThread::PostDelayedTask(content::BrowserThread::UI, - FROM_HERE, - base::Bind(&AtomCopyFrameGenerator::InternalGenerateCopyFrame, - weak_ptr_factory_.GetWeakPtr()), - base::TimeDelta::FromMilliseconds( - frame_rate_threshold_ms_ - frame_rate_delta)); - return; - } - - InternalGenerateCopyFrame(); - } - - bool frame_pending() const { return frame_pending_; } - - void set_frame_rate_threshold_ms(int frame_rate_threshold_ms) { - frame_rate_threshold_ms_ = frame_rate_threshold_ms; - } - - private: - void InternalGenerateCopyFrame() { - frame_pending_ = false; - frame_start_time_ = base::TimeTicks::Now(); - + void GenerateCopyFrame(const gfx::Rect& damage_rect) { if (!view_->render_widget_host()) return; - const gfx::Rect damage_rect = pending_damage_rect_; - pending_damage_rect_.SetRect(0, 0, 0, 0); - std::unique_ptr request = - cc::CopyOutputRequest::CreateRequest(base::Bind( + cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( &AtomCopyFrameGenerator::CopyFromCompositingSurfaceHasResult, weak_ptr_factory_.GetWeakPtr(), damage_rect)); @@ -170,7 +125,13 @@ class AtomCopyFrameGenerator { request->set_area(gfx::Rect(view_->GetPhysicalBackingSize())); view_->GetRootLayer()->RequestCopyOfOutput(std::move(request)); } + + void set_frame_rate_threshold_us(int frame_rate_threshold_us) { + frame_duration_ = base::TimeDelta::FromMicroseconds( + frame_rate_threshold_us); + } +private: void CopyFromCompositingSurfaceHasResult( const gfx::Rect& damage_rect, std::unique_ptr result) { @@ -179,181 +140,63 @@ class AtomCopyFrameGenerator { OnCopyFrameCaptureFailure(damage_rect); return; } - - if (result->HasTexture()) { - PrepareTextureCopyOutputResult(damage_rect, std::move(result)); - return; - } - - DCHECK(result->HasBitmap()); - PrepareBitmapCopyOutputResult(damage_rect, std::move(result)); - } - - void PrepareTextureCopyOutputResult( - const gfx::Rect& damage_rect, - std::unique_ptr result) { - DCHECK(result->HasTexture()); - base::ScopedClosureRunner scoped_callback_runner( - base::Bind(&AtomCopyFrameGenerator::OnCopyFrameCaptureFailure, - weak_ptr_factory_.GetWeakPtr(), - damage_rect)); - - const gfx::Size& result_size = result->size(); - SkIRect bitmap_size; - if (bitmap_) - bitmap_->getBounds(&bitmap_size); - - if (!bitmap_ || - bitmap_size.width() != result_size.width() || - bitmap_size.height() != result_size.height()) { - bitmap_.reset(new SkBitmap); - bitmap_->allocN32Pixels(result_size.width(), - result_size.height(), - true); - if (bitmap_->drawsNothing()) - return; - } - - content::ImageTransportFactory* factory = - content::ImageTransportFactory::GetInstance(); - display_compositor::GLHelper* gl_helper = factory->GetGLHelper(); - if (!gl_helper) - return; - - std::unique_ptr bitmap_pixels_lock( - new SkAutoLockPixels(*bitmap_)); - uint8_t* pixels = static_cast(bitmap_->getPixels()); - - cc::TextureMailbox texture_mailbox; - std::unique_ptr release_callback; - result->TakeTexture(&texture_mailbox, &release_callback); - DCHECK(texture_mailbox.IsTexture()); - if (!texture_mailbox.IsTexture()) - return; - - ignore_result(scoped_callback_runner.Release()); - - gl_helper->CropScaleReadbackAndCleanMailbox( - texture_mailbox.mailbox(), - texture_mailbox.sync_token(), - result_size, - gfx::Rect(result_size), - result_size, - pixels, - kN32_SkColorType, - base::Bind( - &AtomCopyFrameGenerator::CopyFromCompositingSurfaceFinishedProxy, - weak_ptr_factory_.GetWeakPtr(), - base::Passed(&release_callback), - damage_rect, - base::Passed(&bitmap_), - base::Passed(&bitmap_pixels_lock)), - display_compositor::GLHelper::SCALER_QUALITY_FAST); - } - - static void CopyFromCompositingSurfaceFinishedProxy( - base::WeakPtr generator, - std::unique_ptr release_callback, - const gfx::Rect& damage_rect, - std::unique_ptr bitmap, - std::unique_ptr bitmap_pixels_lock, - bool result) { - gpu::SyncToken sync_token; - if (result) { - display_compositor::GLHelper* gl_helper = - content::ImageTransportFactory::GetInstance()->GetGLHelper(); - if (gl_helper) - gl_helper->GenerateSyncToken(&sync_token); - } - const bool lost_resource = !sync_token.HasData(); - release_callback->Run(sync_token, lost_resource); - - if (generator) { - generator->CopyFromCompositingSurfaceFinished( - damage_rect, std::move(bitmap), std::move(bitmap_pixels_lock), - result); - } else { - bitmap_pixels_lock.reset(); - bitmap.reset(); - } - } - - void CopyFromCompositingSurfaceFinished( - const gfx::Rect& damage_rect, - std::unique_ptr bitmap, - std::unique_ptr bitmap_pixels_lock, - bool result) { - DCHECK(!bitmap_); - bitmap_ = std::move(bitmap); - - if (result) { - OnCopyFrameCaptureSuccess(damage_rect, *bitmap_, - std::move(bitmap_pixels_lock)); - } else { - bitmap_pixels_lock.reset(); - OnCopyFrameCaptureFailure(damage_rect); - } - } - - void PrepareBitmapCopyOutputResult( - const gfx::Rect& damage_rect, - std::unique_ptr result) { + DCHECK(result->HasBitmap()); std::unique_ptr source = result->TakeBitmap(); DCHECK(source); if (source) { - std::unique_ptr bitmap_pixels_lock( - new SkAutoLockPixels(*source)); - OnCopyFrameCaptureSuccess(damage_rect, *source, - std::move(bitmap_pixels_lock)); + base::AutoLock autolock(lock_); + std::shared_ptr bitmap(source.release()); + + base::TimeTicks now = base::TimeTicks::Now(); + base::TimeDelta next_frame_in = next_frame_time_ - now; + if (next_frame_in > frame_duration_ / 4) { + next_frame_time_ += frame_duration_; + content::BrowserThread::PostDelayedTask(content::BrowserThread::UI, + FROM_HERE, + base::Bind(&AtomCopyFrameGenerator::OnCopyFrameCaptureSuccess, + weak_ptr_factory_.GetWeakPtr(), + damage_rect, + bitmap), + next_frame_in); + } else { + next_frame_time_ = now + frame_duration_; + OnCopyFrameCaptureSuccess(damage_rect, bitmap); + } + + frame_retry_count_ = 0; } else { OnCopyFrameCaptureFailure(damage_rect); } } - void OnCopyFrameCaptureFailure( - const gfx::Rect& damage_rect) { - pending_damage_rect_.Union(damage_rect); - + void OnCopyFrameCaptureFailure(const gfx::Rect& damage_rect) { const bool force_frame = (++frame_retry_count_ <= kFrameRetryLimit); - OnCopyFrameCaptureCompletion(force_frame); + if (force_frame) { + // Retry with the same |damage_rect|. + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, + base::Bind(&AtomCopyFrameGenerator::GenerateCopyFrame, + weak_ptr_factory_.GetWeakPtr(), + damage_rect)); + } } void OnCopyFrameCaptureSuccess( const gfx::Rect& damage_rect, - const SkBitmap& bitmap, - std::unique_ptr bitmap_pixels_lock) { - view_->OnPaint(damage_rect, bitmap); - - if (frame_retry_count_ > 0) - frame_retry_count_ = 0; - - OnCopyFrameCaptureCompletion(false); + std::shared_ptr bitmap) { + base::AutoLock lock(onPaintLock_); + view_->OnPaint(damage_rect, *bitmap); } - - void OnCopyFrameCaptureCompletion(bool force_frame) { - frame_in_progress_ = false; - - if (frame_pending_) { - content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, - base::Bind(&AtomCopyFrameGenerator::GenerateCopyFrame, - weak_ptr_factory_.GetWeakPtr(), - force_frame, - gfx::Rect())); - } - } - - int frame_rate_threshold_ms_; + + base::Lock lock_; + base::Lock onPaintLock_; OffScreenRenderWidgetHostView* view_; base::Time last_time_; - base::TimeTicks frame_start_time_; - bool frame_pending_; - bool frame_in_progress_; int frame_retry_count_; - std::unique_ptr bitmap_; - gfx::Rect pending_damage_rect_; + base::TimeTicks next_frame_time_; + base::TimeDelta frame_duration_; base::WeakPtrFactory weak_ptr_factory_; @@ -362,12 +205,15 @@ class AtomCopyFrameGenerator { class AtomBeginFrameTimer : public cc::DelayBasedTimeSourceClient { public: - AtomBeginFrameTimer(int frame_rate_threshold_ms, + AtomBeginFrameTimer(int frame_rate_threshold_us, const base::Closure& callback) : callback_(callback) { time_source_.reset(new cc::DelayBasedTimeSource( content::BrowserThread::GetTaskRunnerForThread( content::BrowserThread::UI).get())); + time_source_->SetTimebaseAndInterval( + base::TimeTicks(), + base::TimeDelta::FromMicroseconds(frame_rate_threshold_us)); time_source_->SetClient(this); } @@ -379,10 +225,10 @@ class AtomBeginFrameTimer : public cc::DelayBasedTimeSourceClient { return time_source_->Active(); } - void SetFrameRateThresholdMs(int frame_rate_threshold_ms) { + void SetFrameRateThresholdUs(int frame_rate_threshold_us) { time_source_->SetTimebaseAndInterval( base::TimeTicks::Now(), - base::TimeDelta::FromMilliseconds(frame_rate_threshold_ms)); + base::TimeDelta::FromMicroseconds(frame_rate_threshold_us)); } private: @@ -412,7 +258,7 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( callback_(callback), parent_callback_(nullptr), frame_rate_(60), - frame_rate_threshold_ms_(0), + frame_rate_threshold_us_(0), last_time_(base::Time::Now()), scale_factor_(kDefaultScaleFactor), size_(native_window->GetSize()), @@ -496,7 +342,7 @@ void OffScreenRenderWidgetHostView::OnWindowClosed() { void OffScreenRenderWidgetHostView::OnBeginFrameTimerTick() { const base::TimeTicks frame_time = base::TimeTicks::Now(); const base::TimeDelta vsync_period = - base::TimeDelta::FromMilliseconds(frame_rate_threshold_ms_); + base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_); SendBeginFrame(frame_time, vsync_period); } @@ -689,7 +535,7 @@ void OffScreenRenderWidgetHostView::OnSwapCompositorFrame( } else { if (!copy_frame_generator_.get()) { copy_frame_generator_.reset( - new AtomCopyFrameGenerator(frame_rate_threshold_ms_, this)); + new AtomCopyFrameGenerator(this, frame_rate_threshold_us_)); } // Determine the damage rectangle for the current frame. This is the same @@ -708,7 +554,7 @@ void OffScreenRenderWidgetHostView::OnSwapCompositorFrame( // Request a copy of the last compositor frame which will eventually call // OnPaint asynchronously. - copy_frame_generator_->GenerateCopyFrame(true, damage_rect); + copy_frame_generator_->GenerateCopyFrame(damage_rect); } } } @@ -1062,7 +908,7 @@ void CopyBitmapTo( for (int i = 0; i < pos.height(); i++) { memcpy(dest + ((pos.y() + i) * destination.width() + pos.x()) * pixelsize, src + (i * source.width()) * pixelsize, - source.width() * pixelsize); + pos.width() * pixelsize); } } @@ -1081,10 +927,10 @@ void OffScreenRenderWidgetHostView::OnPaint( gfx::Rect pos = popup_host_view_->popup_position_; gfx::Rect damage(damage_rect); damage.Union(pos); - + SkBitmap copy = SkBitmapOperations::CreateTiledBitmap(bitmap, pos.x(), pos.y(), pos.width(), pos.height()); - + CopyBitmapTo(bitmap, *popup_bitmap_, pos); callback_.Run(damage, bitmap); CopyBitmapTo(bitmap, copy, pos); @@ -1242,24 +1088,24 @@ OffScreenRenderWidgetHostView::GetDelegatedFrameHost() const { #endif void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) { - if (!force && frame_rate_threshold_ms_ != 0) + if (!force && frame_rate_threshold_us_ != 0) return; - frame_rate_threshold_ms_ = 1000 / frame_rate_; + frame_rate_threshold_us_ = 1000000 / frame_rate_; GetCompositor()->vsync_manager()->SetAuthoritativeVSyncInterval( - base::TimeDelta::FromMilliseconds(frame_rate_threshold_ms_)); + base::TimeDelta::FromMicroseconds(frame_rate_threshold_us_)); - if (copy_frame_generator_) { - copy_frame_generator_->set_frame_rate_threshold_ms( - frame_rate_threshold_ms_); + if (copy_frame_generator_.get()) { + copy_frame_generator_->set_frame_rate_threshold_us( + frame_rate_threshold_us_); } - if (begin_frame_timer_) { - begin_frame_timer_->SetFrameRateThresholdMs(frame_rate_threshold_ms_); + if (begin_frame_timer_.get()) { + begin_frame_timer_->SetFrameRateThresholdUs(frame_rate_threshold_us_); } else { begin_frame_timer_.reset(new AtomBeginFrameTimer( - frame_rate_threshold_ms_, + frame_rate_threshold_us_, base::Bind(&OffScreenRenderWidgetHostView::OnBeginFrameTimerTick, weak_ptr_factory_.GetWeakPtr()))); } @@ -1273,7 +1119,7 @@ void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) { if (software_output_device_) { software_output_device_->OnPaint(bounds_in_pixels); } else if (copy_frame_generator_) { - copy_frame_generator_->GenerateCopyFrame(true, bounds_in_pixels); + copy_frame_generator_->GenerateCopyFrame(bounds_in_pixels); } } diff --git a/atom/browser/osr/osr_render_widget_host_view.h b/atom/browser/osr/osr_render_widget_host_view.h index 0c2ece40ad3..1f8558db1f9 100644 --- a/atom/browser/osr/osr_render_widget_host_view.h +++ b/atom/browser/osr/osr_render_widget_host_view.h @@ -282,7 +282,7 @@ class OffScreenRenderWidgetHostView OnPaintCallback parent_callback_; int frame_rate_; - int frame_rate_threshold_ms_; + int frame_rate_threshold_us_; base::Time last_time_; From 89277dda9054009ebf2bf967ca3f79cd720860fe Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Wed, 12 Apr 2017 16:16:27 +0200 Subject: [PATCH 1108/1195] fix leaking of NativeImage instances --- atom/browser/api/atom_api_web_contents.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 880cdddedf3..48473d75c61 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1578,9 +1578,7 @@ bool WebContents::IsOffScreen() const { } void WebContents::OnPaint(const gfx::Rect& dirty_rect, const SkBitmap& bitmap) { - mate::Handle image = - NativeImage::Create(isolate(), gfx::Image::CreateFrom1xBitmap(bitmap)); - Emit("paint", dirty_rect, image); + Emit("paint", dirty_rect, gfx::Image::CreateFrom1xBitmap(bitmap)); } void WebContents::StartPainting() { From 1fcf6ea73f5a0412774197e405fa47ad8d5d6143 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Wed, 12 Apr 2017 16:17:07 +0200 Subject: [PATCH 1109/1195] add size hints to NativeImages to make node GC aware of the high amount of memory used by the instances --- atom/common/api/atom_api_native_image.cc | 18 ++++++++++++++---- atom/common/api/atom_api_native_image.h | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index 6811ab91930..4e3a37f9e86 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -200,22 +200,29 @@ void Noop(char*, void*) { } // namespace NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image) - : image_(image) { - Init(isolate); + : image_(image), isolate_(isolate) { + Init(isolate_); + isolate_->AdjustAmountOfExternalAllocatedMemory( + image_.Width() * image_.Height() * 4); } #if defined(OS_WIN) NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path) - : hicon_path_(hicon_path) { + : hicon_path_(hicon_path), isolate_(isolate) { // Use the 256x256 icon as fallback icon. gfx::ImageSkia image_skia; ReadImageSkiaFromICO(&image_skia, GetHICON(256)); image_ = gfx::Image(image_skia); Init(isolate); + isolate_->AdjustAmountOfExternalAllocatedMemory( + image_.Width() * image_.Height() * 4); } #endif -NativeImage::~NativeImage() {} +NativeImage::~NativeImage() { + isolate_->AdjustAmountOfExternalAllocatedMemory( + - image_.Width() * image_.Height() * 4); +} #if defined(OS_WIN) HICON NativeImage::GetHICON(int size) { @@ -352,6 +359,9 @@ mate::Handle NativeImage::Resize( bool width_set = options.GetInteger("width", &width); bool height_set = options.GetInteger("height", &height); size.SetSize(width, height); + + isolate_->AdjustAmountOfExternalAllocatedMemory( + (width_set * height_set - width * height) * 4); if (width_set && !height_set) { // Scale height to preserve original aspect ratio diff --git a/atom/common/api/atom_api_native_image.h b/atom/common/api/atom_api_native_image.h index 6ff7a0e29f3..0c2890d86f5 100644 --- a/atom/common/api/atom_api_native_image.h +++ b/atom/common/api/atom_api_native_image.h @@ -99,6 +99,7 @@ class NativeImage : public mate::Wrappable { #endif gfx::Image image_; + v8::Isolate* isolate_; DISALLOW_COPY_AND_ASSIGN(NativeImage); }; From c54f7f2a8d5e04b1d3c168f3d21954a1396bbf2f Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Wed, 12 Apr 2017 19:34:52 +0200 Subject: [PATCH 1110/1195] use bounds instead of bounds_in_pixel --- atom/browser/osr/osr_render_widget_host_view.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index 5827a04c31b..a5de6cfd103 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -1117,9 +1117,9 @@ void OffScreenRenderWidgetHostView::Invalidate() { void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) { if (software_output_device_) { - software_output_device_->OnPaint(bounds_in_pixels); + software_output_device_->OnPaint(bounds); } else if (copy_frame_generator_) { - copy_frame_generator_->GenerateCopyFrame(bounds_in_pixels); + copy_frame_generator_->GenerateCopyFrame(bounds); } } From 3b94d268ebae907c6b9c78cc5cd95a69e8a026a1 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Wed, 12 Apr 2017 20:54:03 +0200 Subject: [PATCH 1111/1195] lint fix :memo: --- .../osr/osr_render_widget_host_view.cc | 20 +++++++++---------- atom/browser/osr/osr_web_contents_view.cc | 4 ++-- atom/common/api/atom_api_native_image.cc | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index a5de6cfd103..a4faa1b6a7e 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -125,13 +125,13 @@ class AtomCopyFrameGenerator { request->set_area(gfx::Rect(view_->GetPhysicalBackingSize())); view_->GetRootLayer()->RequestCopyOfOutput(std::move(request)); } - + void set_frame_rate_threshold_us(int frame_rate_threshold_us) { frame_duration_ = base::TimeDelta::FromMicroseconds( frame_rate_threshold_us); } -private: + private: void CopyFromCompositingSurfaceHasResult( const gfx::Rect& damage_rect, std::unique_ptr result) { @@ -140,22 +140,22 @@ private: OnCopyFrameCaptureFailure(damage_rect); return; } - + DCHECK(result->HasBitmap()); std::unique_ptr source = result->TakeBitmap(); DCHECK(source); if (source) { base::AutoLock autolock(lock_); std::shared_ptr bitmap(source.release()); - + base::TimeTicks now = base::TimeTicks::Now(); base::TimeDelta next_frame_in = next_frame_time_ - now; if (next_frame_in > frame_duration_ / 4) { next_frame_time_ += frame_duration_; content::BrowserThread::PostDelayedTask(content::BrowserThread::UI, - FROM_HERE, + FROM_HERE, base::Bind(&AtomCopyFrameGenerator::OnCopyFrameCaptureSuccess, - weak_ptr_factory_.GetWeakPtr(), + weak_ptr_factory_.GetWeakPtr(), damage_rect, bitmap), next_frame_in); @@ -163,7 +163,7 @@ private: next_frame_time_ = now + frame_duration_; OnCopyFrameCaptureSuccess(damage_rect, bitmap); } - + frame_retry_count_ = 0; } else { OnCopyFrameCaptureFailure(damage_rect); @@ -187,7 +187,7 @@ private: base::AutoLock lock(onPaintLock_); view_->OnPaint(damage_rect, *bitmap); } - + base::Lock lock_; base::Lock onPaintLock_; OffScreenRenderWidgetHostView* view_; @@ -927,10 +927,10 @@ void OffScreenRenderWidgetHostView::OnPaint( gfx::Rect pos = popup_host_view_->popup_position_; gfx::Rect damage(damage_rect); damage.Union(pos); - + SkBitmap copy = SkBitmapOperations::CreateTiledBitmap(bitmap, pos.x(), pos.y(), pos.width(), pos.height()); - + CopyBitmapTo(bitmap, *popup_bitmap_, pos); callback_.Run(damage, bitmap); CopyBitmapTo(bitmap, copy, pos); diff --git a/atom/browser/osr/osr_web_contents_view.cc b/atom/browser/osr/osr_web_contents_view.cc index efcdafd51c3..b9219f17122 100644 --- a/atom/browser/osr/osr_web_contents_view.cc +++ b/atom/browser/osr/osr_web_contents_view.cc @@ -30,7 +30,7 @@ OffScreenWebContentsView::~OffScreenWebContentsView() { void OffScreenWebContentsView::SetWebContents( content::WebContents* web_contents) { web_contents_ = web_contents; - + RenderViewCreated(web_contents_->GetRenderViewHost()); } @@ -141,7 +141,7 @@ void OffScreenWebContentsView::SetOverscrollControllerEnabled(bool enabled) { } void OffScreenWebContentsView::GetScreenInfo( - content::ScreenInfo* screen_info) const { + content::ScreenInfo* screen_info) const { screen_info->depth = 24; screen_info->depth_per_component = 8; screen_info->orientation_angle = 0; diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index 4e3a37f9e86..c2e5bba67e4 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -359,7 +359,7 @@ mate::Handle NativeImage::Resize( bool width_set = options.GetInteger("width", &width); bool height_set = options.GetInteger("height", &height); size.SetSize(width, height); - + isolate_->AdjustAmountOfExternalAllocatedMemory( (width_set * height_set - width * height) * 4); From f03dccadb31d421b18cce5a7a703f96238bf2e04 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Thu, 13 Apr 2017 01:30:46 +0200 Subject: [PATCH 1112/1195] use white gutter color and paint damage rects over when paint starts in software osr --- atom/browser/osr/osr_output_device.cc | 21 +++++++++++++++++-- .../osr/osr_render_widget_host_view.cc | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/atom/browser/osr/osr_output_device.cc b/atom/browser/osr/osr_output_device.cc index 49c4191e21e..d418634272d 100644 --- a/atom/browser/osr/osr_output_device.cc +++ b/atom/browser/osr/osr_output_device.cc @@ -4,7 +4,9 @@ #include "atom/browser/osr/osr_output_device.h" +#include "third_party/skia/src/core/SkColor.h" #include "third_party/skia/src/core/SkDevice.h" +#include "third_party/skia/src/core/SkRect.h" #include "ui/gfx/skia_util.h" namespace atom { @@ -36,8 +38,11 @@ void OffScreenOutputDevice::Resize( return; } - if (transparent_) - bitmap_->eraseARGB(0, 0, 0, 0); + if (transparent_) { + bitmap_->eraseColor(SK_ColorTRANSPARENT); + } else { + bitmap_->eraseColor(SK_ColorWHITE); + } canvas_.reset(new SkCanvas(*bitmap_)); } @@ -47,6 +52,18 @@ SkCanvas* OffScreenOutputDevice::BeginPaint(const gfx::Rect& damage_rect) { DCHECK(bitmap_.get()); damage_rect_ = damage_rect; + SkIRect damage = SkIRect::MakeXYWH( + damage_rect_.x(), + damage_rect_.y(), + damage_rect_.width(), + damage_rect_.height() + ); + + if (transparent_) { + bitmap_->erase(SK_ColorTRANSPARENT, damage); + } else { + bitmap_->erase(SK_ColorWHITE, damage); + } return canvas_.get(); } diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index a4faa1b6a7e..3d3729d1ebf 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -722,7 +722,7 @@ SkColor OffScreenRenderWidgetHostView::DelegatedFrameHostGetGutterColor( SkColor color) const { if (render_widget_host_->delegate() && render_widget_host_->delegate()->IsFullscreenForCurrentTab()) { - return SK_ColorBLACK; + return SK_ColorWHITE; } return color; } From aa89bc0bb871a883d1da63ad44a3b1ee17f7ad57 Mon Sep 17 00:00:00 2001 From: gellert Date: Fri, 14 Apr 2017 23:32:33 +0200 Subject: [PATCH 1113/1195] use outer webcontents for popups --- atom/browser/osr/osr_web_contents_view.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/atom/browser/osr/osr_web_contents_view.cc b/atom/browser/osr/osr_web_contents_view.cc index b9219f17122..0e10abf6a03 100644 --- a/atom/browser/osr/osr_web_contents_view.cc +++ b/atom/browser/osr/osr_web_contents_view.cc @@ -5,6 +5,7 @@ #include "atom/browser/osr/osr_web_contents_view.h" #include "atom/common/api/api_messages.h" +#include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/render_view_host.h" #include "third_party/WebKit/public/platform/WebScreenInfo.h" #include "ui/display/screen.h" @@ -112,11 +113,21 @@ content::RenderWidgetHostViewBase* OffScreenWebContentsView::CreateViewForPopupWidget( content::RenderWidgetHost* render_widget_host) { auto relay = NativeWindowRelay::FromWebContents(web_contents_); + + content::WebContentsImpl *web_contents_impl = + static_cast(web_contents_); + + OffScreenRenderWidgetHostView *view = + static_cast( + web_contents_impl->GetOuterWebContents() + ? web_contents_impl->GetOuterWebContents()->GetRenderWidgetHostView() + : web_contents_impl->GetRenderWidgetHostView()); + return new OffScreenRenderWidgetHostView( transparent_, callback_, render_widget_host, - GetView(), + view, relay->window.get()); } From 92cc6746b1322e00255b881eb767c2ba729da487 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Tue, 2 May 2017 03:57:40 +0200 Subject: [PATCH 1114/1195] resolve errors introduced during rebase --- atom/browser/osr/osr_output_device.cc | 4 ++-- atom/browser/osr/osr_render_widget_host_view.cc | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/atom/browser/osr/osr_output_device.cc b/atom/browser/osr/osr_output_device.cc index d418634272d..c930cb7de98 100644 --- a/atom/browser/osr/osr_output_device.cc +++ b/atom/browser/osr/osr_output_device.cc @@ -4,9 +4,9 @@ #include "atom/browser/osr/osr_output_device.h" -#include "third_party/skia/src/core/SkColor.h" +#include "third_party/skia/include/core/SkColor.h" +#include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/src/core/SkDevice.h" -#include "third_party/skia/src/core/SkRect.h" #include "ui/gfx/skia_util.h" namespace atom { diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index 3d3729d1ebf..f9ea13440fb 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -271,6 +271,7 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( weak_ptr_factory_(this) { DCHECK(render_widget_host_); #if !defined(OS_MACOSX) + bool is_guest_view_hack = parent_host_view_ != nullptr; delegated_frame_host_ = base::MakeUnique( AllocateFrameSinkId(is_guest_view_hack), this); From 576b702e8bf80c530adf3e3da83d100ef23afe65 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Tue, 2 May 2017 04:28:32 +0200 Subject: [PATCH 1115/1195] update native_mate and use the MarkHighMemoryUsage API to speed up garbage collection --- atom/common/api/atom_api_native_image.cc | 2 ++ vendor/native_mate | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index c2e5bba67e4..a2e86186e7a 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -204,6 +204,7 @@ NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image) Init(isolate_); isolate_->AdjustAmountOfExternalAllocatedMemory( image_.Width() * image_.Height() * 4); + MarkHighMemoryUsage(); } #if defined(OS_WIN) @@ -216,6 +217,7 @@ NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path) Init(isolate); isolate_->AdjustAmountOfExternalAllocatedMemory( image_.Width() * image_.Height() * 4); + MarkHighMemoryUsage(); } #endif diff --git a/vendor/native_mate b/vendor/native_mate index fd0e7dc4ab7..7d9c1a80f02 160000 --- a/vendor/native_mate +++ b/vendor/native_mate @@ -1 +1 @@ -Subproject commit fd0e7dc4ab778f0d1ccda6c9640464ea06ee771e +Subproject commit 7d9c1a80f025f4c46f7da8ea73246fe0f1968579 From 5c690ea46e0e6a06ec85e93813253a8eeeaceb9c Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Tue, 2 May 2017 04:29:16 +0200 Subject: [PATCH 1116/1195] don't store isolate_ in NativeImage and tune size hints --- atom/common/api/atom_api_native_image.cc | 25 ++++++++++++------------ atom/common/api/atom_api_native_image.h | 1 - 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index a2e86186e7a..6bc012bc3ab 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -200,30 +200,34 @@ void Noop(char*, void*) { } // namespace NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image) - : image_(image), isolate_(isolate) { - Init(isolate_); - isolate_->AdjustAmountOfExternalAllocatedMemory( - image_.Width() * image_.Height() * 4); + : image_(image) { + Init(isolate); + if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) { + isolate->AdjustAmountOfExternalAllocatedMemory( + image_.ToImageSkia()->bitmap()->getSize()); + } MarkHighMemoryUsage(); } #if defined(OS_WIN) NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path) - : hicon_path_(hicon_path), isolate_(isolate) { + : hicon_path_(hicon_path) { // Use the 256x256 icon as fallback icon. gfx::ImageSkia image_skia; ReadImageSkiaFromICO(&image_skia, GetHICON(256)); image_ = gfx::Image(image_skia); Init(isolate); - isolate_->AdjustAmountOfExternalAllocatedMemory( - image_.Width() * image_.Height() * 4); + isolate->AdjustAmountOfExternalAllocatedMemory( + image_.ToImageSkia()->bitmap()->getSize()); MarkHighMemoryUsage(); } #endif NativeImage::~NativeImage() { - isolate_->AdjustAmountOfExternalAllocatedMemory( - - image_.Width() * image_.Height() * 4); + if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) { + isolate()->AdjustAmountOfExternalAllocatedMemory( + - static_cast(image_.ToImageSkia()->bitmap()->getSize())); + } } #if defined(OS_WIN) @@ -362,9 +366,6 @@ mate::Handle NativeImage::Resize( bool height_set = options.GetInteger("height", &height); size.SetSize(width, height); - isolate_->AdjustAmountOfExternalAllocatedMemory( - (width_set * height_set - width * height) * 4); - if (width_set && !height_set) { // Scale height to preserve original aspect ratio size.set_height(width); diff --git a/atom/common/api/atom_api_native_image.h b/atom/common/api/atom_api_native_image.h index 0c2890d86f5..6ff7a0e29f3 100644 --- a/atom/common/api/atom_api_native_image.h +++ b/atom/common/api/atom_api_native_image.h @@ -99,7 +99,6 @@ class NativeImage : public mate::Wrappable { #endif gfx::Image image_; - v8::Isolate* isolate_; DISALLOW_COPY_AND_ASSIGN(NativeImage); }; From 8d1c17e036af88fe0a22d5489eabd62ba538a2c4 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Tue, 2 May 2017 04:44:30 +0200 Subject: [PATCH 1117/1195] remove GetSizeForNewRenderView --- atom/browser/api/atom_api_web_contents.cc | 10 ---------- atom/browser/api/atom_api_web_contents.h | 1 - 2 files changed, 11 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 48473d75c61..92157e12727 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1642,16 +1642,6 @@ void WebContents::Invalidate() { } } -gfx::Size WebContents::GetSizeForNewRenderView( - content::WebContents* web_contents) const { - auto relay = NativeWindowRelay::FromWebContents(web_contents); - if (relay) { - return relay->window->GetSize(); - } - - return gfx::Size(); -} - void WebContents::SetZoomLevel(double level) { zoom_controller_->SetZoomLevel(level); } diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 1916964fa25..1f926dbd7a5 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -183,7 +183,6 @@ class WebContents : public mate::TrackableObject, void SetFrameRate(int frame_rate); int GetFrameRate() const; void Invalidate(); - gfx::Size GetSizeForNewRenderView(content::WebContents*) const override; // Methods for zoom handling. void SetZoomLevel(double level); From 6f80379b30fc2bc50be1ac3455ffd6d4d4f8243c Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Tue, 2 May 2017 06:08:33 +0200 Subject: [PATCH 1118/1195] use computeSize64 instead of getSize --- atom/common/api/atom_api_native_image.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index 6bc012bc3ab..8597c22bbcb 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -204,7 +204,7 @@ NativeImage::NativeImage(v8::Isolate* isolate, const gfx::Image& image) Init(isolate); if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) { isolate->AdjustAmountOfExternalAllocatedMemory( - image_.ToImageSkia()->bitmap()->getSize()); + image_.ToImageSkia()->bitmap()->computeSize64()); } MarkHighMemoryUsage(); } @@ -218,7 +218,7 @@ NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path) image_ = gfx::Image(image_skia); Init(isolate); isolate->AdjustAmountOfExternalAllocatedMemory( - image_.ToImageSkia()->bitmap()->getSize()); + image_.ToImageSkia()->bitmap()->computeSize64()); MarkHighMemoryUsage(); } #endif @@ -226,7 +226,7 @@ NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path) NativeImage::~NativeImage() { if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) { isolate()->AdjustAmountOfExternalAllocatedMemory( - - static_cast(image_.ToImageSkia()->bitmap()->getSize())); + - image_.ToImageSkia()->bitmap()->computeSize64()); } } From b1095faa712d90f23c0842ec0cedca5aa9a54269 Mon Sep 17 00:00:00 2001 From: gellert Date: Tue, 2 May 2017 20:46:07 +0200 Subject: [PATCH 1119/1195] minor fix for macos --- atom/browser/osr/osr_render_widget_host_view.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index f9ea13440fb..77002358154 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -270,8 +270,8 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( pending_resize_(false), weak_ptr_factory_(this) { DCHECK(render_widget_host_); -#if !defined(OS_MACOSX) bool is_guest_view_hack = parent_host_view_ != nullptr; +#if !defined(OS_MACOSX) delegated_frame_host_ = base::MakeUnique( AllocateFrameSinkId(is_guest_view_hack), this); From 572244272cfce6287ddb14eff4017b2b9790e170 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 9 May 2017 12:52:17 -0700 Subject: [PATCH 1120/1195] Remove brightray submodule --- .gitmodules | 3 --- vendor/brightray | 1 - 2 files changed, 4 deletions(-) delete mode 160000 vendor/brightray diff --git a/.gitmodules b/.gitmodules index 0cabff390f4..9ae1e8306bc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "vendor/brightray"] - path = vendor/brightray - url = https://github.com/electron/brightray.git [submodule "vendor/node"] path = vendor/node url = https://github.com/electron/node.git diff --git a/vendor/brightray b/vendor/brightray deleted file mode 160000 index 3d9ebb54999..00000000000 --- a/vendor/brightray +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3d9ebb549990d50ab67b705b8ff16433a3dbc546 From dde21e76577124c061416a20a82b3269eab95db6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 9 May 2017 12:57:02 -0700 Subject: [PATCH 1121/1195] Remove unused files --- brightray/.clang-format | 8 -------- brightray/.travis.yml | 18 ----------------- brightray/CPPLINT.cfg | 1 - brightray/README.md | 42 ---------------------------------------- brightray/appveyor.yml | 25 ------------------------ brightray/script/cibuild | 29 --------------------------- brightray/script/cpplint | 40 -------------------------------------- 7 files changed, 163 deletions(-) delete mode 100644 brightray/.clang-format delete mode 100644 brightray/.travis.yml delete mode 100644 brightray/CPPLINT.cfg delete mode 100644 brightray/README.md delete mode 100644 brightray/appveyor.yml delete mode 100755 brightray/script/cibuild delete mode 100755 brightray/script/cpplint diff --git a/brightray/.clang-format b/brightray/.clang-format deleted file mode 100644 index 6fdf1dc888c..00000000000 --- a/brightray/.clang-format +++ /dev/null @@ -1,8 +0,0 @@ -# Defines the Chromium style for automatic reformatting. -# http://clang.llvm.org/docs/ClangFormatStyleOptions.html -BasedOnStyle: Chromium -# This defaults to 'Auto'. Explicitly set it for a while, so that -# 'vector >' in existing files gets formatted to -# 'vector>'. ('Auto' means that clang-format will only use -# 'int>>' if the file already contains at least one such instance.) -Standard: Cpp11 diff --git a/brightray/.travis.yml b/brightray/.travis.yml deleted file mode 100644 index 06118787cb7..00000000000 --- a/brightray/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -notifications: - email: false - -language: node_js -node_js: - - "6" -os: - - linux - - osx -env: - - TARGET_ARCH=x64 -osx_image: xcode7.3 - -script: './script/cibuild' - -branches: - only: - - master diff --git a/brightray/CPPLINT.cfg b/brightray/CPPLINT.cfg deleted file mode 100644 index 01e99482f2b..00000000000 --- a/brightray/CPPLINT.cfg +++ /dev/null @@ -1 +0,0 @@ -filter=-build/header_guard,-build/include_what_you_use,-legal/copyright,-runtime/references diff --git a/brightray/README.md b/brightray/README.md deleted file mode 100644 index 655fca98fe6..00000000000 --- a/brightray/README.md +++ /dev/null @@ -1,42 +0,0 @@ -# Brightray - -Brightray is a static library that makes -[libchromiumcontent](https://github.com/electron/libchromiumcontent) easier to -use in applications. - -## Using it in your app - -See [electron](https://github.com/electron/electron) for example of an -application written using Brightray. - -## Development - -### Prerequisites - -* Python 2.7 -* Linux: - * Clang 3.0 -* Mac: - * Xcode -* Windows: - * Visual Studio 2010 SP1 - -### One-time setup - -You must previously have built and uploaded libchromiumcontent using its -`script/upload` script. - - $ script/bootstrap http://base.url.com/used/by/script/upload - -### Building - - $ script/build - -Building Brightray on its own isn’t all that interesting, since it’s just a -static library. Building it into an application is the only way to test it. - -## License - -In general, everything is covered by the [`LICENSE`](LICENSE) file. Some files -specify at the top that they are covered by the -[`LICENSE-CHROMIUM`](LICENSE-CHROMIUM) file instead. diff --git a/brightray/appveyor.yml b/brightray/appveyor.yml deleted file mode 100644 index d623fdc8c64..00000000000 --- a/brightray/appveyor.yml +++ /dev/null @@ -1,25 +0,0 @@ -version: "{build}" - -clone_depth: 10 - -os: Visual Studio 2015 - -init: - - git config --global core.autocrlf input - -platform: - - x64 - -install: - - cmd: SET PATH=C:\Program Files (x86)\MSBuild\14.0\bin\;%PATH% - - cmd: SET PATH=C:\python27;%PATH% - - cmd: git submodule update --init --recursive - - cmd: bash script/cibuild - -branches: - only: - - master - -# disable build and test phases -build: off -test: off diff --git a/brightray/script/cibuild b/brightray/script/cibuild deleted file mode 100755 index c4477368514..00000000000 --- a/brightray/script/cibuild +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -script/cpplint - -# Make cloned repository complete -git fetch --unshallow origin HEAD - -# Clone Electron -git clone https://github.com/electron/electron --depth 1 --recursive - -# Checkout current brightray commit into Electron -cd electron/vendor/brightray -git fetch ../../.. -git reset --hard FETCH_HEAD - -# Commit change -cd ../.. -git add vendor/brightray -git config --local user.email "test@github.com" -git config --local user.name "Test" -git commit --message 'Upgrading brightray' - -# Bootstrap Electron -npm run bootstrap -- --dev - -# Build Electron with brightray commit -npm run build diff --git a/brightray/script/cpplint b/brightray/script/cpplint deleted file mode 100755 index 964f2009fc3..00000000000 --- a/brightray/script/cpplint +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python - -import fnmatch -import os -import subprocess -import sys - - -SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) -CPPLINT = os.path.join(SOURCE_ROOT, 'vendor', 'libchromiumcontent', 'vendor', 'depot_tools', 'cpplint.py') - -IGNORED_FILES = [ - os.path.join('browser', 'mac', 'bry_inspectable_web_contents_view.h'), - os.path.join('browser', 'mac', 'event_dispatching_window.h'), - os.path.join('browser', 'mac', 'notification_center_delegate.h'), -] - -def main(): - os.chdir(SOURCE_ROOT) - files = list_files(['browser', 'common'], - ['*.cc', '*.h']) - return cpplint(set(files) - set(IGNORED_FILES)) - - -def list_files(directories, filters): - matches = [] - for directory in directories: - for root, _, filenames, in os.walk(directory): - for f in filters: - for filename in fnmatch.filter(filenames, f): - matches.append(os.path.join(root, filename)) - return matches - - -def cpplint(files): - return subprocess.call([sys.executable, CPPLINT] + list(files)) - - -if __name__ == '__main__': - sys.exit(main()) From 4dab62dfcfbb57b0065efafd57ccfab2cbb3c0ac Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 9 May 2017 13:26:23 -0700 Subject: [PATCH 1122/1195] Move brightray submodules to root vendor --- .gitmodules | 6 ++++++ brightray/.gitmodules | 6 ------ brightray/vendor/.gitignore | 1 - {brightray/vendor => vendor}/gyp | 0 {brightray/vendor => vendor}/libchromiumcontent | 0 5 files changed, 6 insertions(+), 7 deletions(-) delete mode 100644 brightray/.gitmodules delete mode 100644 brightray/vendor/.gitignore rename {brightray/vendor => vendor}/gyp (100%) rename {brightray/vendor => vendor}/libchromiumcontent (100%) diff --git a/.gitmodules b/.gitmodules index 9ae1e8306bc..73b12931d77 100644 --- a/.gitmodules +++ b/.gitmodules @@ -22,3 +22,9 @@ [submodule "vendor/pdf_viewer"] path = vendor/pdf_viewer url = https://github.com/electron/pdf-viewer.git +[submodule "vendor/gyp"] + path = vendor/gyp + url = https://github.com/electron/gyp +[submodule "vendor/libchromiumcontent"] + path = vendor/libchromiumcontent + url = https://github.com/electron/libchromiumcontent diff --git a/brightray/.gitmodules b/brightray/.gitmodules deleted file mode 100644 index 54ed18cf53b..00000000000 --- a/brightray/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "vendor/libchromiumcontent"] - path = vendor/libchromiumcontent - url = https://github.com/electron/libchromiumcontent -[submodule "vendor/gyp"] - path = vendor/gyp - url = https://github.com/electron/gyp diff --git a/brightray/vendor/.gitignore b/brightray/vendor/.gitignore deleted file mode 100644 index 0920e14cbc0..00000000000 --- a/brightray/vendor/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/download/ diff --git a/brightray/vendor/gyp b/vendor/gyp similarity index 100% rename from brightray/vendor/gyp rename to vendor/gyp diff --git a/brightray/vendor/libchromiumcontent b/vendor/libchromiumcontent similarity index 100% rename from brightray/vendor/libchromiumcontent rename to vendor/libchromiumcontent From 5ea20b5b546df53a96b9a1a11f8a4952a7247528 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 9 May 2017 13:38:14 -0700 Subject: [PATCH 1123/1195] Wire up build for new brightray location --- .gitignore | 2 +- brightray/brightray.gyp | 2 +- brightray/brightray.gypi | 2 +- brightray/script/bootstrap | 99 -------------------------------------- brightray/script/build | 40 --------------- common.gypi | 2 +- electron.gyp | 8 +-- script/bootstrap.py | 47 +++++++++++++++--- script/clean.py | 4 +- script/update.py | 2 +- 10 files changed, 50 insertions(+), 158 deletions(-) delete mode 100755 brightray/script/bootstrap delete mode 100755 brightray/script/build diff --git a/.gitignore b/.gitignore index d9f918d109b..eec2867f230 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ /dist/ /external_binaries/ /out/ -/vendor/brightray/vendor/download/ +/vendor/download/ /vendor/debian_wheezy_amd64-sysroot/ /vendor/debian_wheezy_arm-sysroot/ /vendor/debian_wheezy_i386-sysroot/ diff --git a/brightray/brightray.gyp b/brightray/brightray.gyp index 85b319783a8..efa0f433ba8 100644 --- a/brightray/brightray.gyp +++ b/brightray/brightray.gyp @@ -23,7 +23,7 @@ 'direct_dependent_settings': { 'include_dirs': [ '.', - '..', + '../vendor', '<(libchromiumcontent_src_dir)', '<(libchromiumcontent_src_dir)/gpu', '<(libchromiumcontent_src_dir)/skia/config', diff --git a/brightray/brightray.gypi b/brightray/brightray.gypi index b7fb38be63a..e51774370b7 100644 --- a/brightray/brightray.gypi +++ b/brightray/brightray.gypi @@ -1,6 +1,6 @@ { 'includes': [ - 'vendor/download/libchromiumcontent/filenames.gypi', + '../vendor/download/libchromiumcontent/filenames.gypi', ], 'variables': { 'libchromiumcontent_component%': 1, diff --git a/brightray/script/bootstrap b/brightray/script/bootstrap deleted file mode 100755 index 29786398d72..00000000000 --- a/brightray/script/bootstrap +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/env python - -import argparse -import errno -import os -import subprocess -import sys - - -SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) -VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor') -DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download') - - -def main(): - args = parse_args() - if (args.libcc_source_path != None and - args.libcc_shared_library_path != None and - args.libcc_static_library_path != None): - pass - elif (args.libcc_source_path != None or - args.libcc_shared_library_path != None or - args.libcc_static_library_path != None): - print "Error: All options of libchromiumcontent are required OR let " \ - "brightray choose it" - sys.exit(0) - update_submodules() - setup_libchromiumcontent(args.dev, args.commit, args.target_arch, args.url, - args.libcc_source_path, - args.libcc_shared_library_path, - args.libcc_static_library_path) - - -def parse_args(): - parser = argparse.ArgumentParser(description='Bootstrap this project') - parser.add_argument('-c', '--commit', required=True, - help='The commit of libchromiumcontent to download.') - parser.add_argument('-d', '--dev', action='store_true', - help='Do not download static_library build') - parser.add_argument('--target_arch', required=True, - help='The arch of libchromiumcontent to download.') - parser.add_argument('url', help='The base URL from which to download ' - 'libchromiumcontent (i.e., the URL you passed to ' - 'libchromiumcontent\'s script/upload script') - parser.add_argument('--libcc_source_path', required=False, - help='The source path of libchromiumcontent. ' \ - 'NOTE: All options of libchromiumcontent are ' - 'required OR let brightray choose it') - parser.add_argument('--libcc_shared_library_path', required=False, - help='The shared library path of libchromiumcontent. ' \ - 'NOTE: All options of libchromiumcontent are ' \ - 'required OR let brightray choose it') - parser.add_argument('--libcc_static_library_path', required=False, - help='The static library path of libchromiumcontent. ' \ - 'NOTE: All options of libchromiumcontent are ' \ - 'required OR let brightray choose it') - return parser.parse_args() - - -def update_submodules(): - return (subprocess.call(['git', 'submodule', 'sync', '--quiet'], - cwd=SOURCE_ROOT) or - subprocess.call(['git', 'submodule', 'update', '--init', - '--recursive'], cwd=SOURCE_ROOT)) - - -def setup_libchromiumcontent(is_dev, commit, target_arch, url, - libcc_source_path, - libcc_shared_library_path, - libcc_static_library_path): - target_dir = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') - download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', - 'download') - args = ['-f', '-c', commit, '--target_arch', target_arch, url, target_dir] - if (libcc_source_path != None and - libcc_shared_library_path != None and - libcc_static_library_path != None): - args += ['--libcc_source_path', libcc_source_path, - '--libcc_shared_library_path', libcc_shared_library_path, - '--libcc_static_library_path', libcc_static_library_path] - mkdir_p(target_dir) - else: - mkdir_p(DOWNLOAD_DIR) - if is_dev: - subprocess.check_call([sys.executable, download] + args) - else: - subprocess.check_call([sys.executable, download, '-s'] + args) - - -def mkdir_p(path): - try: - os.makedirs(path) - except OSError as e: - if e.errno != errno.EEXIST: - raise - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/brightray/script/build b/brightray/script/build deleted file mode 100755 index 6ee7da97a92..00000000000 --- a/brightray/script/build +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python - -import os -import subprocess -import sys - - -SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) -GYP = os.path.join(SOURCE_ROOT, 'vendor', 'gyp', 'gyp_main.py') - - -def main(): - os.chdir(SOURCE_ROOT) - return (run_gyp() or build()) - - -def run_gyp(): - env = os.environ.copy() - gyp_pylib = os.path.join(os.path.dirname(GYP), 'pylib') - env['PYTHONPATH'] = os.path.pathsep.join([gyp_pylib, - env.get('PYTHONPATH', '')]) - env['GYP_DEFINES'] = 'libchromiumcontent_component=static_library' - return subprocess.call([sys.executable, GYP, '--depth', '.', - '-Ibrightray.gypi', 'brightray.gyp'], env=env) - - -def build(): - if sys.platform == 'darwin': - return subprocess.call(['xcodebuild']) - if sys.platform == 'linux2': - return subprocess.call(['make']) - - assert sys.platform == 'win32', sys.platform - program_files = os.environ.get('PROGRAMFILES(X86)', os.environ['PROGRAMFILES']) - msbuild = os.path.join(program_files, 'MSBuild', '12.0', 'Bin', 'MSBuild.exe') - return subprocess.call([msbuild, 'brightray.sln']) - - -if __name__ == '__main__': - sys.exit(main()) diff --git a/common.gypi b/common.gypi index d4b7646c28e..ee8b1e85768 100644 --- a/common.gypi +++ b/common.gypi @@ -1,7 +1,7 @@ { 'includes': [ 'toolchain.gypi', - 'vendor/brightray/brightray.gypi', + 'brightray/brightray.gypi', ], 'variables': { # Tell crashpad to build as external project. diff --git a/electron.gyp b/electron.gyp index dd40842bb86..bd47067a3e8 100644 --- a/electron.gyp +++ b/electron.gyp @@ -81,7 +81,7 @@ # is marked for no PIE (ASLR). 'postbuild_name': 'Make More Helpers', 'action': [ - 'vendor/brightray/tools/mac/make_more_helpers.sh', + 'brightray/tools/mac/make_more_helpers.sh', 'Frameworks', '<(product_name)', ], @@ -220,7 +220,7 @@ 'dependencies': [ 'atom_js2c', 'vendor/pdf_viewer/pdf_viewer.gyp:pdf_viewer', - 'vendor/brightray/brightray.gyp:brightray', + 'brightray/brightray.gyp:brightray', 'vendor/node/node.gyp:node', ], 'defines': [ @@ -244,7 +244,7 @@ 'include_dirs': [ '.', 'chromium_src', - 'vendor/brightray', + 'brightray', 'vendor/native_mate', # Include atom_natives.h. '<(SHARED_INTERMEDIATE_DIR)', @@ -271,7 +271,7 @@ ], }, 'export_dependent_settings': [ - 'vendor/brightray/brightray.gyp:brightray', + 'brightray/brightray.gyp:brightray', ], 'conditions': [ ['libchromiumcontent_component', { diff --git a/script/bootstrap.py b/script/bootstrap.py index 08d84cff28e..d1b190a41d7 100755 --- a/script/bootstrap.py +++ b/script/bootstrap.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import argparse +import errno import os import subprocess import sys @@ -12,6 +13,7 @@ from lib.util import execute_stdout, get_electron_version, scoped_cwd SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) VENDOR_DIR = os.path.join(SOURCE_ROOT, 'vendor') +DOWNLOAD_DIR = os.path.join(VENDOR_DIR, 'download') PYTHON_26_URL = 'https://chromium.googlesource.com/chromium/deps/python_26' NPM = 'npm' @@ -40,8 +42,7 @@ def main(): # Redirect to use local libchromiumcontent build. if args.build_libchromiumcontent: build_libchromiumcontent(args.verbose, args.target_arch, defines) - dist_dir = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', - 'libchromiumcontent', 'dist', 'main') + dist_dir = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'dist', 'main') libcc_source_path = os.path.join(dist_dir, 'src') libcc_shared_library_path = os.path.join(dist_dir, 'shared_library') libcc_static_library_path = os.path.join(dist_dir, 'static_library') @@ -53,9 +54,9 @@ def main(): setup_python_libs() update_node_modules('.') - bootstrap_brightray(args.dev, args.url, args.target_arch, - libcc_source_path, libcc_shared_library_path, - libcc_static_library_path) + setup_libchromiumcontent(args.dev, args.target_arch, args.url, + libcc_source_path, libcc_shared_library_path, + libcc_static_library_path) if PLATFORM == 'linux': download_sysroot(args.target_arch) @@ -135,10 +136,33 @@ def setup_python_libs(): execute_stdout([sys.executable, 'setup.py', 'build']) +def setup_libchromiumcontent(is_dev, target_arch, url, + libcc_source_path, + libcc_shared_library_path, + libcc_static_library_path): + target_dir = os.path.join(DOWNLOAD_DIR, 'libchromiumcontent') + download = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'script', + 'download') + args = ['-f', '-c', LIBCHROMIUMCONTENT_COMMIT, '--target_arch', target_arch, + url, target_dir] + if (libcc_source_path != None and + libcc_shared_library_path != None and + libcc_static_library_path != None): + args += ['--libcc_source_path', libcc_source_path, + '--libcc_shared_library_path', libcc_shared_library_path, + '--libcc_static_library_path', libcc_static_library_path] + mkdir_p(target_dir) + else: + mkdir_p(DOWNLOAD_DIR) + if is_dev: + subprocess.check_call([sys.executable, download] + args) + else: + subprocess.check_call([sys.executable, download, '-s'] + args) + def bootstrap_brightray(is_dev, url, target_arch, libcc_source_path, libcc_shared_library_path, libcc_static_library_path): - bootstrap = os.path.join(VENDOR_DIR, 'brightray', 'script', 'bootstrap') + bootstrap = os.path.join(SOURCE_ROOT, 'brightray', 'script', 'bootstrap') args = [ '--commit', LIBCHROMIUMCONTENT_COMMIT, '--target_arch', target_arch, @@ -225,8 +249,7 @@ def download_sysroot(target_arch): '--arch', target_arch]) def create_chrome_version_h(): - version_file = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', - 'libchromiumcontent', 'VERSION') + version_file = os.path.join(VENDOR_DIR, 'libchromiumcontent', 'VERSION') target_file = os.path.join(SOURCE_ROOT, 'atom', 'common', 'chrome_version.h') template_file = os.path.join(SOURCE_ROOT, 'script', 'chrome_version.h.in') @@ -271,5 +294,13 @@ def create_node_headers(): '--version', get_electron_version()]) +def mkdir_p(path): + try: + os.makedirs(path) + except OSError as e: + if e.errno != errno.EEXIST: + raise + + if __name__ == '__main__': sys.exit(main()) diff --git a/script/clean.py b/script/clean.py index c63bdbbadee..d1ccaa252db 100755 --- a/script/clean.py +++ b/script/clean.py @@ -22,8 +22,8 @@ def main(): remove_directory('node_modules') remove_directory('spec/node_modules') - remove_directory('vendor/brightray/vendor/download/libchromiumcontent') - remove_directory('vendor/brightray/vendor/libchromiumcontent/src') + remove_directory('vendor/download/libchromiumcontent') + remove_directory('vendor/libchromiumcontent/src') remove_directory(os.path.expanduser('~/.node-gyp')) diff --git a/script/update.py b/script/update.py index 35331eb9362..b4f08bc28f2 100755 --- a/script/update.py +++ b/script/update.py @@ -63,7 +63,7 @@ def run_gyp(target_arch, component): if sys.platform == 'cygwin': # Force using win32 python on cygwin. python = os.path.join('vendor', 'python_26', 'python.exe') - gyp = os.path.join('vendor', 'brightray', 'vendor', 'gyp', 'gyp_main.py') + gyp = os.path.join('vendor', 'gyp', 'gyp_main.py') gyp_pylib = os.path.join(os.path.dirname(gyp), 'pylib') # Avoid using the old gyp lib in system. env['PYTHONPATH'] = os.path.pathsep.join([gyp_pylib, From de02485d288075eaba80f0e0b2c68113930d37a8 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 9 May 2017 13:39:23 -0700 Subject: [PATCH 1124/1195] Move brightray tools into mains tools folder --- electron.gyp | 2 +- {brightray/tools => tools}/mac/change_mach_o_flags.py | 0 {brightray/tools => tools}/mac/make_more_helpers.sh | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename {brightray/tools => tools}/mac/change_mach_o_flags.py (100%) rename {brightray/tools => tools}/mac/make_more_helpers.sh (100%) diff --git a/electron.gyp b/electron.gyp index bd47067a3e8..a8658b89360 100644 --- a/electron.gyp +++ b/electron.gyp @@ -81,7 +81,7 @@ # is marked for no PIE (ASLR). 'postbuild_name': 'Make More Helpers', 'action': [ - 'brightray/tools/mac/make_more_helpers.sh', + 'tools/mac/make_more_helpers.sh', 'Frameworks', '<(product_name)', ], diff --git a/brightray/tools/mac/change_mach_o_flags.py b/tools/mac/change_mach_o_flags.py similarity index 100% rename from brightray/tools/mac/change_mach_o_flags.py rename to tools/mac/change_mach_o_flags.py diff --git a/brightray/tools/mac/make_more_helpers.sh b/tools/mac/make_more_helpers.sh similarity index 100% rename from brightray/tools/mac/make_more_helpers.sh rename to tools/mac/make_more_helpers.sh From 7ff60364204ecc0f3f1ee88f4fabd47dcf0c7cc9 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 9 May 2017 13:40:05 -0700 Subject: [PATCH 1125/1195] Consolidate ignores --- .gitignore | 7 +++++++ brightray/.gitattributes | 2 -- brightray/.gitignore | 17 ----------------- 3 files changed, 7 insertions(+), 19 deletions(-) delete mode 100644 brightray/.gitattributes delete mode 100644 brightray/.gitignore diff --git a/.gitignore b/.gitignore index eec2867f230..3f1279eebf4 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,10 @@ node_modules/ *.vcxproj.filters *.sln *.log +/brightray/brightray.opensdf +/brightray/brightray.sdf +/brightray/brightray.sln +/brightray/brightray.vcxproj* +/brightray/brightray.suo +/brightray/brightray.v12.suo +/brightray/brightray.xcodeproj/ diff --git a/brightray/.gitattributes b/brightray/.gitattributes deleted file mode 100644 index dfe0770424b..00000000000 --- a/brightray/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/brightray/.gitignore b/brightray/.gitignore deleted file mode 100644 index 859306a729e..00000000000 --- a/brightray/.gitignore +++ /dev/null @@ -1,17 +0,0 @@ -/brightray.opensdf -/brightray.sdf -/brightray.sln -/brightray.vcxproj* -/brightray.suo -/brightray.v12.suo -/brightray.xcodeproj/ -/build/ - -# Vim -*.swp - -# Linux -Makefile -*.Makefile -*.mk -out/ From 94eff35286d7e5540cf682bca6562c0bd65141d3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 13:42:21 -0700 Subject: [PATCH 1126/1195] Update docs for new brightray location --- docs/development/atom-shell-vs-node-webkit.md | 2 +- docs/development/build-system-overview.md | 4 ++-- docs/development/debug-instructions-windows.md | 2 +- docs/development/debugging-instructions-macos.md | 8 ++++---- docs/development/source-code-directory-structure.md | 2 +- docs/development/upgrading-chrome.md | 2 -- docs/glossary.md | 7 ++----- 7 files changed, 11 insertions(+), 16 deletions(-) diff --git a/docs/development/atom-shell-vs-node-webkit.md b/docs/development/atom-shell-vs-node-webkit.md index 0912a8d66e3..4c8cd4ef5fe 100644 --- a/docs/development/atom-shell-vs-node-webkit.md +++ b/docs/development/atom-shell-vs-node-webkit.md @@ -25,7 +25,7 @@ so you can use it for browser testing in place of [PhantomJS](http://phantomjs.o __2. Build System__ -In order to avoid the complexity of building all of Chromium, Electron uses [`libchromiumcontent`](https://github.com/brightray/libchromiumcontent) to access +In order to avoid the complexity of building all of Chromium, Electron uses [`libchromiumcontent`](https://github.com/electron/libchromiumcontent) to access Chromium's Content API. `libchromiumcontent` is a single shared library that includes the Chromium Content module and all of its dependencies. Users don't need a powerful machine to build Electron. diff --git a/docs/development/build-system-overview.md b/docs/development/build-system-overview.md index df12df6ae97..083f52d0047 100644 --- a/docs/development/build-system-overview.md +++ b/docs/development/build-system-overview.md @@ -11,9 +11,9 @@ Following `gyp` files contain the main rules for building Electron: * `electron.gyp` defines how Electron itself is built. * `common.gypi` adjusts the build configurations of Node to make it build together with Chromium. -* `vendor/brightray/brightray.gyp` defines how `brightray` is built and +* `brightray/brightray.gyp` defines how `brightray` is built and includes the default configurations for linking with Chromium. -* `vendor/brightray/brightray.gypi` includes general build configurations about +* `brightray/brightray.gypi` includes general build configurations about building. ## Component Build diff --git a/docs/development/debug-instructions-windows.md b/docs/development/debug-instructions-windows.md index b2d33473934..440cb33e414 100644 --- a/docs/development/debug-instructions-windows.md +++ b/docs/development/debug-instructions-windows.md @@ -47,7 +47,7 @@ source code matches the code running in the attached process and break accordingly. Relevant code files can be found in `./atom/` as well as in Brightray, found in -`./vendor/brightray/browser` and `./vendor/brightray/common`. If you're hardcore, +`./brightray/browser` and `./brightray/common`. If you're hardcore, you can also debug Chromium directly, which is obviously found in `chromium_src`. ### Attaching diff --git a/docs/development/debugging-instructions-macos.md b/docs/development/debugging-instructions-macos.md index e119db466a1..054909773f6 100644 --- a/docs/development/debugging-instructions-macos.md +++ b/docs/development/debugging-instructions-macos.md @@ -18,8 +18,8 @@ to enable step-through debugging with breakpoints inside Electron's source code. tail calls, and other compiler optimizations. * **Xcode**: In addition to Xcode, also install the Xcode command line tools. - They include LLDB, the default debugger in Xcode on Mac OS X. It supports - debugging C, Objective-C and C++ on the desktop and iOS devices and simulator. + They include LLDB, the default debugger in Xcode on Mac OS X. It supports + debugging C, Objective-C and C++ on the desktop and iOS devices and simulator. ## Attaching to and Debugging Electron @@ -40,7 +40,7 @@ that isn't behaving correctly - so you'd like to break on that command's C++ counterpart inside the Electron source. Relevant code files can be found in `./atom/` as well as in Brightray, found in -`./vendor/brightray/browser` and `./vendor/brightray/common`. If you're hardcore, +`./brightray/browser` and `./brightray/common`. If you're hardcore, you can also debug Chromium directly, which is obviously found in `chromium_src`. Let's assume that you want to debug `app.setName()`, which is defined in `browser.cc` @@ -77,7 +77,7 @@ Process 25244 stopped ``` To show the arguments and local variables for the current frame, run `frame variable` (or `fr v`), -which will show you that the app is currently setting the name to "Electron". +which will show you that the app is currently setting the name to "Electron". ```bash (lldb) frame variable diff --git a/docs/development/source-code-directory-structure.md b/docs/development/source-code-directory-structure.md index cc74fe69427..4af519120ee 100644 --- a/docs/development/source-code-directory-structure.md +++ b/docs/development/source-code-directory-structure.md @@ -72,7 +72,7 @@ when running `git status`: ```sh $ git status - modified: vendor/brightray (new commits) + modified: vendor/libchromiumcontent (new commits) modified: vendor/node (new commits) ``` diff --git a/docs/development/upgrading-chrome.md b/docs/development/upgrading-chrome.md index 6e47a8b4f52..1004e6d3645 100644 --- a/docs/development/upgrading-chrome.md +++ b/docs/development/upgrading-chrome.md @@ -19,8 +19,6 @@ Chrome/Node API changes. - Upgrade `vendor/depot_tools` for any build tools changes needed - Update the `libchromiumcontent` SHA-1 to download in `script/lib/config.py` - Open a pull request on `electron/libchromiumcontent` with the changes -- Open a pull request on `electron/brightray` with the changes - - This should include upgrading the `vendor/libchromiumcontent` submodule - Open a pull request on `electron/electron` with the changes - This should include upgrading the submodules in `vendor/` as needed - Verify debug builds succeed on: diff --git a/docs/glossary.md b/docs/glossary.md index b923037f9f0..b5397182387 100644 --- a/docs/glossary.md +++ b/docs/glossary.md @@ -12,10 +12,8 @@ The ASAR format was created primarily to improve performance on Windows... TODO ### Brightray -[Brightray][brightray] is a static library that makes [libchromiumcontent] -easier to use in applications. It was created specifically for Electron, but can -be used to enable Chromium's renderer in native apps that are not based on -Electron. +Brightray is a static library that makes [libchromiumcontent] +easier to use in applications. Brightray is a low-level dependency of Electron that does not concern the majority of Electron users. @@ -142,7 +140,6 @@ embedded content. [addons]: https://nodejs.org/api/addons.html [asar]: https://github.com/electron/asar [autoUpdater]: api/auto-updater.md -[brightray]: https://github.com/electron/brightray [electron-builder]: https://github.com/electron-userland/electron-builder [libchromiumcontent]: #libchromiumcontent [Mac App Store Submission Guide]: tutorials/mac-app-store-submission-guide.md From 500ffdf70031b03b40c95091698df27e104c6d08 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 13:51:57 -0700 Subject: [PATCH 1127/1195] cpplint brightray/ files --- brightray/CPPLINT.cfg | 1 + script/cpplint.py | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 brightray/CPPLINT.cfg diff --git a/brightray/CPPLINT.cfg b/brightray/CPPLINT.cfg new file mode 100644 index 00000000000..01e99482f2b --- /dev/null +++ b/brightray/CPPLINT.cfg @@ -0,0 +1 @@ +filter=-build/header_guard,-build/include_what_you_use,-legal/copyright,-runtime/references diff --git a/script/cpplint.py b/script/cpplint.py index 6c715522f8c..0c91dc06aea 100755 --- a/script/cpplint.py +++ b/script/cpplint.py @@ -17,6 +17,15 @@ IGNORE_FILES = [ os.path.join('atom', 'common', 'api', 'api_messages.h'), os.path.join('atom', 'common', 'common_message_generator.cc'), os.path.join('atom', 'common', 'common_message_generator.h'), + os.path.join('brightray', 'browser', 'mac', + 'bry_inspectable_web_contents_view.h'), + os.path.join('brightray', 'browser', 'mac', 'event_dispatching_window.h'), + os.path.join('brightray', 'browser', 'mac', + 'notification_center_delegate.h'), + os.path.join('brightray', 'browser', 'win', 'win32_desktop_notifications', + 'desktop_notification_controller.cc'), + os.path.join('brightray', 'browser', 'win', 'win32_desktop_notifications', + 'desktop_notification_controller.h') ] SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) @@ -24,15 +33,20 @@ SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) def main(): os.chdir(SOURCE_ROOT) - files = list_files(['app', 'browser', 'common', 'renderer', 'utility'], - ['*.cc', '*.h']) - call_cpplint(list(set(files) - set(IGNORE_FILES))) + atom_files = list_files('atom', + ['app', 'browser', 'common', 'renderer', 'utility'], + ['*.cc', '*.h']) + call_cpplint(list(set(atom_files) - set(IGNORE_FILES))) + + brightray_files = list_files('brightray', ['browser', 'common'], + ['*.cc', '*.h']) + call_cpplint(list(set(brightray_files) - set(IGNORE_FILES))) -def list_files(directories, filters): +def list_files(parent, directories, filters): matches = [] for directory in directories: - for root, _, filenames, in os.walk(os.path.join('atom', directory)): + for root, _, filenames, in os.walk(os.path.join(parent, directory)): for f in filters: for filename in fnmatch.filter(filenames, f): matches.append(os.path.join(root, filename)) From a76a4ddff2a7ed48f5bcd5e9379c14cd77b3e377 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Wed, 10 May 2017 23:04:19 +0200 Subject: [PATCH 1128/1195] :art: lint fix --- atom/browser/osr/osr_output_device.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/atom/browser/osr/osr_output_device.cc b/atom/browser/osr/osr_output_device.cc index c930cb7de98..c35e364236f 100644 --- a/atom/browser/osr/osr_output_device.cc +++ b/atom/browser/osr/osr_output_device.cc @@ -53,12 +53,11 @@ SkCanvas* OffScreenOutputDevice::BeginPaint(const gfx::Rect& damage_rect) { damage_rect_ = damage_rect; SkIRect damage = SkIRect::MakeXYWH( - damage_rect_.x(), - damage_rect_.y(), - damage_rect_.width(), - damage_rect_.height() - ); - + damage_rect_.x(), + damage_rect_.y(), + damage_rect_.width(), + damage_rect_.height()); + if (transparent_) { bitmap_->erase(SK_ColorTRANSPARENT, damage); } else { From e954c60ab823d9b53d26c193e490f516acbc59af Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 14:11:24 -0700 Subject: [PATCH 1129/1195] Update libcc paths to be in root vendor --- script/build-libchromiumcontent.py | 4 ++-- script/create-dist.py | 4 ++-- script/create-node-headers.py | 4 ++-- script/dump-symbols.py | 4 ++-- script/verify-ffmpeg.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/script/build-libchromiumcontent.py b/script/build-libchromiumcontent.py index e0a95f69a46..63d7514de7b 100755 --- a/script/build-libchromiumcontent.py +++ b/script/build-libchromiumcontent.py @@ -22,8 +22,8 @@ def main(): # ./script/update -t x64 --defines='' # ./script/build --no_shared_library -t x64 # ./script/create-dist -c static_library -t x64 --no_zip - script_dir = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', - 'libchromiumcontent', 'script') + script_dir = os.path.join(SOURCE_ROOT, 'vendor', 'libchromiumcontent', + 'script') bootstrap = os.path.join(script_dir, 'bootstrap') update = os.path.join(script_dir, 'update') build = os.path.join(script_dir, 'build') diff --git a/script/create-dist.py b/script/create-dist.py index 2602a9f943d..3c61f06ac06 100755 --- a/script/create-dist.py +++ b/script/create-dist.py @@ -20,8 +20,8 @@ ELECTRON_VERSION = get_electron_version() SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) DIST_DIR = os.path.join(SOURCE_ROOT, 'dist') OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'R') -CHROMIUM_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', - 'download', 'libchromiumcontent', 'static_library') +CHROMIUM_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'download', + 'libchromiumcontent', 'static_library') PROJECT_NAME = electron_gyp()['project_name%'] PRODUCT_NAME = electron_gyp()['product_name%'] diff --git a/script/create-node-headers.py b/script/create-node-headers.py index baf9c86aba3..992cd165751 100755 --- a/script/create-node-headers.py +++ b/script/create-node-headers.py @@ -74,8 +74,8 @@ def copy_headers(dist_headers_dir): dist_headers_dir) # Copy V8 headers from chromium's repository. - src = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', 'download', - 'libchromiumcontent', 'src') + src = os.path.join(SOURCE_ROOT, 'vendor', 'download', 'libchromiumcontent', + 'src') for dirpath, _, filenames in os.walk(os.path.join(src, 'v8')): for filename in filenames: extension = os.path.splitext(filename)[1] diff --git a/script/dump-symbols.py b/script/dump-symbols.py index 76949e95aa9..fdc90b613f6 100755 --- a/script/dump-symbols.py +++ b/script/dump-symbols.py @@ -10,8 +10,8 @@ from lib.util import electron_gyp, execute, rm_rf SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) DIST_DIR = os.path.join(SOURCE_ROOT, 'dist') OUT_DIR = os.path.join(SOURCE_ROOT, 'out', 'R') -CHROMIUM_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', - 'download', 'libchromiumcontent', 'static_library') +CHROMIUM_DIR = os.path.join(SOURCE_ROOT, 'vendor', 'download', + 'libchromiumcontent', 'static_library') def main(destination): diff --git a/script/verify-ffmpeg.py b/script/verify-ffmpeg.py index 9d9dba06703..1d78515a4ad 100755 --- a/script/verify-ffmpeg.py +++ b/script/verify-ffmpeg.py @@ -9,8 +9,8 @@ from lib.util import electron_gyp, rm_rf SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) -FFMPEG_LIBCC_PATH = os.path.join(SOURCE_ROOT, 'vendor', 'brightray', 'vendor', - 'download', 'libchromiumcontent', 'ffmpeg') +FFMPEG_LIBCC_PATH = os.path.join(SOURCE_ROOT, 'vendor', 'download', + 'libchromiumcontent', 'ffmpeg') PROJECT_NAME = electron_gyp()['project_name%'] PRODUCT_NAME = electron_gyp()['product_name%'] From b3eae78b5c901697fc18ad9b8f1d74cdf3221187 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 14:12:47 -0700 Subject: [PATCH 1130/1195] Update brightray references in doc translations --- docs-translations/es/development/build-system-overview.md | 4 ++-- docs-translations/jp/development/atom-shell-vs-node-webkit.md | 2 +- .../ko-KR/development/atom-shell-vs-node-webkit.md | 2 +- docs-translations/ko-KR/development/build-system-overview.md | 4 ++-- .../ko-KR/development/debug-instructions-macos.md | 2 +- .../ko-KR/development/debug-instructions-windows.md | 2 +- .../ko-KR/development/source-code-directory-structure.md | 2 +- .../zh-CN/development/atom-shell-vs-node-webkit.md | 2 +- docs-translations/zh-CN/development/build-system-overview.md | 4 ++-- .../zh-CN/development/debug-instructions-windows.md | 2 +- .../zh-CN/development/debugging-instructions-macos.md | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs-translations/es/development/build-system-overview.md b/docs-translations/es/development/build-system-overview.md index 1e6a42da84b..1996137495e 100644 --- a/docs-translations/es/development/build-system-overview.md +++ b/docs-translations/es/development/build-system-overview.md @@ -6,8 +6,8 @@ los siguientes archivos `gyp` contienen las principales reglas para la contrucci * `atom.gyp` define en si como se compila en Electron. * `common.gypi` ajusta las configuraciones de generación de Node para construir junto con Chromium. - * `vendor/brightray/brightray.gyp` define cómo se construye `brightray` e incluye las configuraciones predeterminadas para linkear con Chromium. - * `vendor/brightray/brightray.gypi` incluye configuraciones de generación generales sobre la construcción. + * `brightray/brightray.gyp` define cómo se construye `brightray` e incluye las configuraciones predeterminadas para linkear con Chromium. + * `brightray/brightray.gypi` incluye configuraciones de generación generales sobre la construcción. #Construir un componente Desde Chromium es un proyecto bastante largo, la etapa de enlace final puede tomar pocos minutos, lo que hace que sea difícil para el desarrollo. Con el fin de resolver esto, Chromium introdujo el "componente de construcción", que se basa en construir cada componente como una libreria compartida por separado, haciendo que se enlace muy rápido, pero sacrificando el tamaño del archivo y el rendimiento. diff --git a/docs-translations/jp/development/atom-shell-vs-node-webkit.md b/docs-translations/jp/development/atom-shell-vs-node-webkit.md index 09a8621a24c..aa5e2d45ef0 100644 --- a/docs-translations/jp/development/atom-shell-vs-node-webkit.md +++ b/docs-translations/jp/development/atom-shell-vs-node-webkit.md @@ -16,7 +16,7 @@ Electron は Node.js ランタイムのように動作します。 Electron の __2. ビルドシステム__ -Chromium の全てのコードをビルドする複雑さを回避するため、Electron は [`libchromiumcontent`](https://github.com/brightray/libchromiumcontent) を通して Chromium の Content API にアクセスします。 +Chromium の全てのコードをビルドする複雑さを回避するため、Electron は [`libchromiumcontent`](https://github.com/electron/libchromiumcontent) を通して Chromium の Content API にアクセスします。 `libchromiumcontent` は Chromium の Content モジュールとそれに依存する全てを含んだ単一の共有ライブラリです。 おかげで Electron をビルドするためにパワフルなマシンを用意する必要はありません。 diff --git a/docs-translations/ko-KR/development/atom-shell-vs-node-webkit.md b/docs-translations/ko-KR/development/atom-shell-vs-node-webkit.md index 97ed0cbf741..3dc71bf7a87 100644 --- a/docs-translations/ko-KR/development/atom-shell-vs-node-webkit.md +++ b/docs-translations/ko-KR/development/atom-shell-vs-node-webkit.md @@ -24,7 +24,7 @@ Electron은 Node.js 런타임과 비슷하게 작동합니다. Electron의 API __2. 빌드 시스템__ Electron은 Chromium의 모든것을 빌드하는 복잡성을 피하기 위해 -[libchromiumcontent](https://github.com/brightray/libchromiumcontent)를 사용하여 +[libchromiumcontent](https://github.com/electron/libchromiumcontent)를 사용하여 Chromium의 Content API에 접근합니다. libchromiumcontent은 단일 공유 라이브러리이고 Chromium Content 모듈과 의존성 라이브러리들을 포함합니다. 유저는 Electron을 빌드 하기 위해 높은 사양의 빌드용 컴퓨터를 구비할 필요가 없습니다. diff --git a/docs-translations/ko-KR/development/build-system-overview.md b/docs-translations/ko-KR/development/build-system-overview.md index 26b4380d43c..fd74ac57c12 100644 --- a/docs-translations/ko-KR/development/build-system-overview.md +++ b/docs-translations/ko-KR/development/build-system-overview.md @@ -10,9 +10,9 @@ Electron을 빌드 할 때 `gyp` 파일들은 다음과 같은 규칙을 따릅 * `electron.gyp`는 Electron의 빌드 과정 자체를 정의합니다. * `common.gypi`는 Node가 Chromium과 함께 빌드될 수 있도록 조정한 빌드 설정입니다. -* `vendor/brightray/brightray.gyp`는 `brightray`의 빌드 과정을 정의하고 Chromium +* `brightray/brightray.gyp`는 `brightray`의 빌드 과정을 정의하고 Chromium 링킹에 대한 기본적인 설정을 포함합니다. -* `vendor/brightray/brightray.gypi`는 빌드에 대한 일반적인 설정이 포함되어 있습니다. +* `brightray/brightray.gypi`는 빌드에 대한 일반적인 설정이 포함되어 있습니다. ## 구성요소 빌드 diff --git a/docs-translations/ko-KR/development/debug-instructions-macos.md b/docs-translations/ko-KR/development/debug-instructions-macos.md index ce2cb98e01d..df42f99fdad 100644 --- a/docs-translations/ko-KR/development/debug-instructions-macos.md +++ b/docs-translations/ko-KR/development/debug-instructions-macos.md @@ -38,7 +38,7 @@ LLDB 는 강력한 도구이며 코드 검사를 위한 다양한 전략을 제 명령의 C++ 부분에서 멈추길 원하며 그것은 Electron 소스 내에 있습니다. 관련 코드는 `./atom/` 에서 찾을 수 있으며 마찬가지로 Brightray 도 -`./vendor/brightray/browser` 와 `./vendor/brightray/common` 에서 찾을 수 +`./brightray/browser` 와 `./brightray/common` 에서 찾을 수 있습니다. 당신이 열정적이라면, Chromium 을 직접 디버깅할 수 있으며, `chromium_src` 에서 찾을 수 있습니다. diff --git a/docs-translations/ko-KR/development/debug-instructions-windows.md b/docs-translations/ko-KR/development/debug-instructions-windows.md index 31e814f3d9e..b80e4d99a19 100644 --- a/docs-translations/ko-KR/development/debug-instructions-windows.md +++ b/docs-translations/ko-KR/development/debug-instructions-windows.md @@ -42,7 +42,7 @@ $ ./out/D/electron.exe ~/my-electron-app/ 중인 프로세스와 중단점을 자동으로 찾아냅니다. 관련된 코드 파일들은 `./atom/`에서 찾을 수 있으며 또한 Brightray 안 -`./vendor/brightray/browser`와 `./vendor/brightray/common`에서도 찾을 수 있습니다. +`./brightray/browser`와 `./brightray/common`에서도 찾을 수 있습니다. 만약 하드코어를 좋아한다면, Chromium을 직접 디버깅할 수도 있습니다. 확실히 `chromium_src` 안에서 찾을 수 있습니다. diff --git a/docs-translations/ko-KR/development/source-code-directory-structure.md b/docs-translations/ko-KR/development/source-code-directory-structure.md index 8d592ddc742..050bc73793d 100644 --- a/docs-translations/ko-KR/development/source-code-directory-structure.md +++ b/docs-translations/ko-KR/development/source-code-directory-structure.md @@ -67,7 +67,7 @@ Electron 저장소는 몇 가지 외부 벤더 의존성을 가지고 있으며 ```sh $ git status - modified: vendor/brightray (new commits) + modified: brightray (new commits) modified: vendor/node (new commits) ``` diff --git a/docs-translations/zh-CN/development/atom-shell-vs-node-webkit.md b/docs-translations/zh-CN/development/atom-shell-vs-node-webkit.md index 68fddb11d23..c97fbae768d 100644 --- a/docs-translations/zh-CN/development/atom-shell-vs-node-webkit.md +++ b/docs-translations/zh-CN/development/atom-shell-vs-node-webkit.md @@ -16,7 +16,7 @@ Electron 的工作方式更像 Node.js 运行时。 Electron 的 APIs 更加底 __2. 构建系统__ -为了避免构建整个 Chromium 带来的复杂度,Electron 通过 [`libchromiumcontent`](https://github.com/brightray/libchromiumcontent) 来访问 Chromium 的 Content API。`libchromiumcontent` 是一个独立的、引入了 Chromium Content 模块及其所有依赖的共享库。用户不需要一个强劲的机器来构建 Electron。 +为了避免构建整个 Chromium 带来的复杂度,Electron 通过 [`libchromiumcontent`](https://github.com/electron/libchromiumcontent) 来访问 Chromium 的 Content API。`libchromiumcontent` 是一个独立的、引入了 Chromium Content 模块及其所有依赖的共享库。用户不需要一个强劲的机器来构建 Electron。 __3. Node 集成__ diff --git a/docs-translations/zh-CN/development/build-system-overview.md b/docs-translations/zh-CN/development/build-system-overview.md index 6bd1452b816..329dc74bd1f 100644 --- a/docs-translations/zh-CN/development/build-system-overview.md +++ b/docs-translations/zh-CN/development/build-system-overview.md @@ -8,8 +8,8 @@ Electron 使用 [gyp](https://gyp.gsrc.io/) 来生成项目 ,使用 [ninja](ht * `atom.gyp` 定义了 Electron 它自己是怎样被构建的. * `common.gypi` 调整 node 的构建配置,来让它结合 Chromium 一起构建. -* `vendor/brightray/brightray.gyp` 定义了 `brightray` 是如何被构建的,并且包含了默认配置来连接到 Chromium. -* `vendor/brightray/brightray.gypi` 包含了常用的创建配置. +* `brightray/brightray.gyp` 定义了 `brightray` 是如何被构建的,并且包含了默认配置来连接到 Chromium. +* `brightray/brightray.gypi` 包含了常用的创建配置. ## 创建组件 diff --git a/docs-translations/zh-CN/development/debug-instructions-windows.md b/docs-translations/zh-CN/development/debug-instructions-windows.md index 0afa03463c5..fd9f6069134 100644 --- a/docs-translations/zh-CN/development/debug-instructions-windows.md +++ b/docs-translations/zh-CN/development/debug-instructions-windows.md @@ -22,7 +22,7 @@ $ ./out/D/electron.exe ~/my-electron-app/ 然后,打开 Visual Studio。 Electron 不是使用 Visual Studio 构建的,因此不包含项目文件 - 但是您可以打开源代码文件 "As File",这意味着 Visual Studio 将自己打开它们。 您仍然可以设置断点 - Visual Studio 将自动确定源代码与附加过程中运行的代码相匹配,并相应地中断。 -相关的代码文件可以在 `./atom/` 以及 Brightray 中找到, 找到 `./vendor/brightray/browser` 和 `./vendor/brightray/common`. 如果是内核,你也可以直接调试 Chromium,这显然在 `chromium_src` 中。 +相关的代码文件可以在 `./atom/` 以及 Brightray 中找到, 找到 `./brightray/browser` 和 `./brightray/common`. 如果是内核,你也可以直接调试 Chromium,这显然在 `chromium_src` 中。 ### 附加 diff --git a/docs-translations/zh-CN/development/debugging-instructions-macos.md b/docs-translations/zh-CN/development/debugging-instructions-macos.md index 0a7929e57e0..bad622438ff 100644 --- a/docs-translations/zh-CN/development/debugging-instructions-macos.md +++ b/docs-translations/zh-CN/development/debugging-instructions-macos.md @@ -22,7 +22,7 @@ Current executable set to './out/D/Electron.app' (x86_64). LLDB是一个强大的工具,支持进行多种策略的代码检查。 在这做一个基本的介绍,让我们假设你从 JavaScript 调用一个不正常的命令 - 所以你想打断该命令的 C++ 对应的 Electron 源。 -相关的代码文件可以在 `./atom/` 以及 Brightray 中找到, 找到 `./vendor/brightray/browser` 和 `./vendor/brightray/common`. 如果是内核,你也可以直接调试 Chromium,这显然在 `chromium_src` 中。 +相关的代码文件可以在 `./atom/` 以及 Brightray 中找到, 找到 `./brightray/browser` 和 `./brightray/common`. 如果是内核,你也可以直接调试 Chromium,这显然在 `chromium_src` 中。 让我们假设你想调试 `app.setName()`, 在 `browser.cc` 中定义为 `Browser::SetName()`. 使用 `breakpoint` 命令进行断点,指定文件和断点位置:: From edac44367377feaaa42422ba39d99f1d2c480136 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 14:26:13 -0700 Subject: [PATCH 1131/1195] Correct property name to pid --- docs/api/structures/memory-info.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/structures/memory-info.md b/docs/api/structures/memory-info.md index 69c67f16cc8..f6b9d17aaa1 100644 --- a/docs/api/structures/memory-info.md +++ b/docs/api/structures/memory-info.md @@ -1,6 +1,6 @@ # MemoryInfo Object -* `workingSetSize` Integer - Process id of the process. +* `pid` Integer - Process id of the process. * `workingSetSize` Integer - The amount of memory currently pinned to actual physical RAM. * `peakWorkingSetSize` Integer - The maximum amount of memory that has ever been pinned to actual physical RAM. @@ -9,4 +9,4 @@ * `sharedBytes` Integer - The amount of memory shared between processes, typically memory consumed by the Electron code itself -Note that all statistics are reported in Kilobytes. \ No newline at end of file +Note that all statistics are reported in Kilobytes. From a44f0620b33459c8b9b7af28c8b9e1e63b15bb09 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 14:27:51 -0700 Subject: [PATCH 1132/1195] : -> - --- docs/api/browser-view.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/browser-view.md b/docs/api/browser-view.md index 3b7e6f9b9bf..bc81bcf56a9 100644 --- a/docs/api/browser-view.md +++ b/docs/api/browser-view.md @@ -57,9 +57,9 @@ Objects created with `new BrowserWindow` have the following instance methods: #### `win.setAutoResize(options)` _Experimental_ * `options` Object - * `width`: If `true`, the view's width will grow and shrink together with + * `width` - If `true`, the view's width will grow and shrink together with the window. `false` by default. - * `height`: If `true`, the view's height will grow and shrink together with + * `height` - If `true`, the view's height will grow and shrink together with the window. `false` by default. #### `win.setBounds(bounds)` _Experimental_ From f46b383824b66166e6e6050e5c36fc163c0904b3 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 14:29:57 -0700 Subject: [PATCH 1133/1195] Add types --- docs/api/browser-view.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api/browser-view.md b/docs/api/browser-view.md index bc81bcf56a9..69c5ca76d72 100644 --- a/docs/api/browser-view.md +++ b/docs/api/browser-view.md @@ -57,10 +57,10 @@ Objects created with `new BrowserWindow` have the following instance methods: #### `win.setAutoResize(options)` _Experimental_ * `options` Object - * `width` - If `true`, the view's width will grow and shrink together with - the window. `false` by default. - * `height` - If `true`, the view's height will grow and shrink together with - the window. `false` by default. + * `width` Boolean - If `true`, the view's width will grow and shrink together + with the window. `false` by default. + * `height` Boolean - If `true`, the view's height will grow and shrink + together with the window. `false` by default. #### `win.setBounds(bounds)` _Experimental_ From 330be2fb165ea66cb9e497d0602c4b4b3d3e1280 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 15:51:28 -0700 Subject: [PATCH 1134/1195] Remove unused bootstrap method --- script/bootstrap.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/script/bootstrap.py b/script/bootstrap.py index d1b190a41d7..0feee9b5002 100755 --- a/script/bootstrap.py +++ b/script/bootstrap.py @@ -159,25 +159,6 @@ def setup_libchromiumcontent(is_dev, target_arch, url, else: subprocess.check_call([sys.executable, download, '-s'] + args) -def bootstrap_brightray(is_dev, url, target_arch, libcc_source_path, - libcc_shared_library_path, - libcc_static_library_path): - bootstrap = os.path.join(SOURCE_ROOT, 'brightray', 'script', 'bootstrap') - args = [ - '--commit', LIBCHROMIUMCONTENT_COMMIT, - '--target_arch', target_arch, - url - ] - if is_dev: - args = ['--dev'] + args - if (libcc_source_path != None and - libcc_shared_library_path != None and - libcc_static_library_path != None): - args += ['--libcc_source_path', libcc_source_path, - '--libcc_shared_library_path', libcc_shared_library_path, - '--libcc_static_library_path', libcc_static_library_path] - execute_stdout([sys.executable, bootstrap] + args) - def set_clang_env(env): llvm_dir = os.path.join(SOURCE_ROOT, 'vendor', 'llvm-build', From 6ace5a8e3e6c6deda6f6621890219bac2c1f1d4e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 15:55:00 -0700 Subject: [PATCH 1135/1195] Use correct .target_arch path --- script/lib/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/lib/config.py b/script/lib/config.py index c920f2acc22..e23c18d9942 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -31,8 +31,8 @@ def get_platform_key(): def get_target_arch(): try: target_arch_path = os.path.join(__file__, '..', '..', '..', 'vendor', - 'brightray', 'vendor', 'download', - 'libchromiumcontent', '.target_arch') + 'download', 'libchromiumcontent', + '.target_arch') with open(os.path.normpath(target_arch_path)) as f: return f.read().strip() except IOError as e: From 6a63028079fa3360c7495ea08e2d1d2f9f69dd3a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 10 May 2017 15:56:10 -0700 Subject: [PATCH 1136/1195] Remove vendor\brightray prefix --- script/upload-windows-pdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/upload-windows-pdb.py b/script/upload-windows-pdb.py index 6e8030337f3..40c38b30739 100755 --- a/script/upload-windows-pdb.py +++ b/script/upload-windows-pdb.py @@ -10,7 +10,7 @@ from lib.util import electron_gyp, execute, rm_rf, safe_mkdir, s3put SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) SYMBOLS_DIR = 'dist\\symbols' -DOWNLOAD_DIR = 'vendor\\brightray\\vendor\\download\\libchromiumcontent' +DOWNLOAD_DIR = 'vendor\\download\\libchromiumcontent' PROJECT_NAME = electron_gyp()['project_name%'] PRODUCT_NAME = electron_gyp()['product_name%'] From b4e356212c18487cb46fa975cf8e15a8eba9cfbc Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Thu, 11 May 2017 09:28:24 +1000 Subject: [PATCH 1137/1195] Fix webcontents capital --- docs/api/browser-view.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/browser-view.md b/docs/api/browser-view.md index 3b7e6f9b9bf..de8950e518a 100644 --- a/docs/api/browser-view.md +++ b/docs/api/browser-view.md @@ -44,7 +44,7 @@ Objects created with `new BrowserView` have the following properties: #### `view.webContents` _Experimental_ -A [`webContents`](web-contents.md) object owned by this view. +A [`WebContents`](web-contents.md) object owned by this view. #### `win.id` _Experimental_ From dcfca610f4be98af538b1223f1dc164e2af1b3e9 Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Wed, 10 May 2017 23:22:30 -0700 Subject: [PATCH 1138/1195] bump electron-typescript-definitions version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d6215fd2f43..cc33e588888 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "browserify": "^13.1.0", "electabul": "~0.0.4", "electron-docs-linter": "^2.1.0", - "electron-typescript-definitions": "^1.2.0", + "electron-typescript-definitions": "^1.2.3", "request": "*", "standard": "^8.4.0", "standard-markdown": "^2.1.1" From 3273a1b42e7a2c60bf96cf3080ee73b0b3bf081c Mon Sep 17 00:00:00 2001 From: Zeke Sikelianos Date: Wed, 10 May 2017 23:22:49 -0700 Subject: [PATCH 1139/1195] add npm scripts for convenience --- package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/package.json b/package.json index cc33e588888..8bddd2b5475 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,8 @@ "lint-py": "python ./script/pylint.py", "lint-api-docs-js": "standard-markdown docs && standard-markdown docs-translations", "lint-api-docs": "electron-docs-linter", + "create-api-json": "electron-docs-linter docs --outfile=out/electron-api.json --version=$npm_package_version", + "create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --in=out/electron-api.json --out=out/electron.d.ts", "preinstall": "node -e 'process.exit(0)'", "release": "./script/upload.py -p", "repl": "python ./script/start.py --interactive", From 7b63409df54754e76c44003eb3924d9b8b26b779 Mon Sep 17 00:00:00 2001 From: Surya Setiyaputra Date: Thu, 11 May 2017 16:55:51 +1000 Subject: [PATCH 1140/1195] =?UTF-8?q?add=20Indonesian=20translation=20of?= =?UTF-8?q?=20README.md=20=E2=80=93=20more=20to=20be=20translated=20on=20a?= =?UTF-8?q?=20later=20date?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs-translations/id/README.md | 84 ++++++ docs-translations/id/faq.md | 162 ------------ docs-translations/id/glossary.md | 0 .../id/project/CODE_OF_CONDUCT.md | 46 ---- docs-translations/id/project/CONTRIBUTING.md | 79 ------ docs-translations/id/project/README.md | 90 ------- docs-translations/id/styleguide.md | 246 ------------------ 7 files changed, 84 insertions(+), 623 deletions(-) delete mode 100644 docs-translations/id/faq.md delete mode 100644 docs-translations/id/glossary.md delete mode 100644 docs-translations/id/project/CODE_OF_CONDUCT.md delete mode 100644 docs-translations/id/project/CONTRIBUTING.md delete mode 100644 docs-translations/id/project/README.md delete mode 100644 docs-translations/id/styleguide.md diff --git a/docs-translations/id/README.md b/docs-translations/id/README.md index e69de29bb2d..56b7cd8af34 100644 --- a/docs-translations/id/README.md +++ b/docs-translations/id/README.md @@ -0,0 +1,84 @@ +[![Electron Logo](https://electron.atom.io/images/electron-logo.svg)](https://electron.atom.io/) + +[![Travis Build Status](https://travis-ci.org/electron/electron.svg?branch=master)](https://travis-ci.org/electron/electron) +[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/bc56v83355fi3369/branch/master?svg=true)](https://ci.appveyor.com/project/electron-bot/electron/branch/master) +[![devDependency Status](https://david-dm.org/electron/electron/dev-status.svg)](https://david-dm.org/electron/electron?type=dev) +[![Join the Electron Community on Slack](http://atom-slack.herokuapp.com/badge.svg)](http://atom-slack.herokuapp.com/) + +:memo: Terjemahan yg tersedia: [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR/project/README.md) | [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN/project/README.md) | [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR/project/README.md) | [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW/project/README.md) | [Spanish](https://github.com/electron/electron/tree/master/docs-translations/es/project/README.md) | [Turkish](https://github.com/electron/electron/tree/master/docs-translations/tr-TR/project/README.md) + +Framework Electron membuat Anda bisa menulis aplikasi desktop yang cross-platform menggunakan JavaScript, HTML dan CSS. Framework ini bersumber dari + +[Node.js](https://nodejs.org/) dan +[Chromium](http://www.chromium.org) dan dipakai dalam +[Atom editor](https://github.com/atom/atom) dan applikasi-applikasi lainnya [apps](https://electron.atom.io/apps). + +Ikuti [@ElectronJS](https://twitter.com/electronjs) lewat Twitter untuk informasi-informasi penting. + +Proyek ini mengikuti perjanjian kontributor [code of conduct](CODE_OF_CONDUCT.md). +Partisipasi Anda di proyek ini harus mengikuti panduan di atas. Harap laporkan perbuatan yg kurang berkenan melalui electron@github.com. + +## Unduhan + +Untuk instalasi versi binari Electron, pakai +[`npm`](https://docs.npmjs.com/): + +```sh +# Install as a development dependency +npm install electron --save-dev + +# Install the `electron` command globally in your $PATH +npm install electron -g +``` + +Ikuti [releases page](https://github.com/electron/electron/releases) untuk prebuilt binaries, debug symbols, dan lain-lain. + +### Mirrors + +- [China](https://npm.taobao.org/mirrors/electron) + +## Dokumentasi + +Panduan dan referensi API bisa ditemukan di direktori +[docs](https://github.com/electron/electron/tree/master/docs). Direktori tersebut juga berisi dokumen-dokumen yg menunjukkan bagaimana Anda bisa berkontribusi ke proyek Electron. + +## Terjemahan Dokumentasi + +- [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR) +- [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR) +- [Japanese](https://github.com/electron/electron/tree/master/docs-translations/jp) +- [Spanish](https://github.com/electron/electron/tree/master/docs-translations/es) +- [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN) +- [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW) +- [Turkish](https://github.com/electron/electron/tree/master/docs-translations/tr-TR) +- [Thai](https://github.com/electron/electron/tree/master/docs-Translations/th-TH) +- [Ukrainian](https://github.com/electron/electron/tree/master/docs-translations/uk-UA) +- [Russian](https://github.com/electron/electron/tree/master/docs-translations/ru-RU) +- [French](https://github.com/electron/electron/tree/master/docs-translations/fr-FR) +- [Indonesian](https://github.com/electron/electron/tree/master/docs-translations/id) + +## Mulai Cepat + +Klon dan jalankan repo [`electron/electron-quick-start`](https://github.com/electron/electron-quick-start) untuk melihat aplikasi sederhana menggunakan Electron. + +## Komunitas + +Anda bisa berinteraksi di lokasi-lokasi ini: +- [`electron`](http://discuss.atom.io/c/electron) kategori forum Atom +- `#atom-shell` channel di Freenode +- [`Atom`](http://atom-slack.herokuapp.com/) channel di Slack +- [`electron-ru`](https://telegram.me/electron_ru) *(Russian)* +- [`electron-br`](https://electron-br.slack.com) *(Brazilian Portuguese)* +- [`electron-kr`](http://www.meetup.com/electron-kr/) *(Korean)* +- [`electron-jp`](https://electron-jp.slack.com) *(Japanese)* +- [`electron-tr`](http://electron-tr.herokuapp.com) *(Turkish)* +- [`electron-id`](https://electron-id.slack.com) *(Indonesia)* + +Cek [awesome-electron](https://github.com/sindresorhus/awesome-electron) +untuk menemukan daftar contoh-contoh aplikasi dan sumber-sumber berguna lainnya. + +## Lisensi + +[MIT](https://github.com/electron/electron/blob/master/LICENSE) + +Kalau menggunakan logo Electro ata logo Github lainnya gunakan panduan berikut [GitHub logo guidelines](https://github.com/logos). diff --git a/docs-translations/id/faq.md b/docs-translations/id/faq.md deleted file mode 100644 index abeac23f76e..00000000000 --- a/docs-translations/id/faq.md +++ /dev/null @@ -1,162 +0,0 @@ -# Electron FAQ - -## When will Electron upgrade to latest Chrome? - -The Chrome version of Electron is usually bumped within one or two weeks after -a new stable Chrome version gets released. This estimate is not guaranteed and -depends on the amount of work involved with upgrading. - -Only the stable channel of Chrome is used. If an important fix is in beta or dev -channel, we will back-port it. - -For more information, please see the [security introduction](tutorial/security.md). - -## When will Electron upgrade to latest Node.js? - -When a new version of Node.js gets released, we usually wait for about a month -before upgrading the one in Electron. So we can avoid getting affected by bugs -introduced in new Node.js versions, which happens very often. - -New features of Node.js are usually brought by V8 upgrades, since Electron is -using the V8 shipped by Chrome browser, the shiny new JavaScript feature of a -new Node.js version is usually already in Electron. - -## How to share data between web pages? - -To share data between web pages (the renderer processes) the simplest way is to -use HTML5 APIs which are already available in browsers. Good candidates are -[Storage API][storage], [`localStorage`][local-storage], -[`sessionStorage`][session-storage], and [IndexedDB][indexed-db]. - -Or you can use the IPC system, which is specific to Electron, to store objects -in the main process as a global variable, and then to access them from the -renderers through the `remote` property of `electron` module: - -```javascript -// In the main process. -global.sharedObject = { - someProperty: 'default value' -} -``` - -```javascript -// In page 1. -require('electron').remote.getGlobal('sharedObject').someProperty = 'new value' -``` - -```javascript -// In page 2. -console.log(require('electron').remote.getGlobal('sharedObject').someProperty) -``` - -## My app's window/tray disappeared after a few minutes. - -This happens when the variable which is used to store the window/tray gets -garbage collected. - -If you encounter this problem, the following articles may prove helpful: - -* [Memory Management][memory-management] -* [Variable Scope][variable-scope] - -If you want a quick fix, you can make the variables global by changing your -code from this: - -```javascript -const {app, Tray} = require('electron') -app.on('ready', () => { - const tray = new Tray('/path/to/icon.png') - tray.setTitle('hello world') -}) -``` - -to this: - -```javascript -const {app, Tray} = require('electron') -let tray = null -app.on('ready', () => { - tray = new Tray('/path/to/icon.png') - tray.setTitle('hello world') -}) -``` - -## I can not use jQuery/RequireJS/Meteor/AngularJS in Electron. - -Due to the Node.js integration of Electron, there are some extra symbols -inserted into the DOM like `module`, `exports`, `require`. This causes problems -for some libraries since they want to insert the symbols with the same names. - -To solve this, you can turn off node integration in Electron: - -```javascript -// In the main process. -const {BrowserWindow} = require('electron') -let win = new BrowserWindow({ - webPreferences: { - nodeIntegration: false - } -}) -win.show() -``` - -But if you want to keep the abilities of using Node.js and Electron APIs, you -have to rename the symbols in the page before including other libraries: - -```html - - - - -``` - -## `require('electron').xxx` is undefined. - -When using Electron's built-in module you might encounter an error like this: - -``` -> require('electron').webFrame.setZoomFactor(1.0) -Uncaught TypeError: Cannot read property 'setZoomLevel' of undefined -``` - -This is because you have the [npm `electron` module][electron-module] installed -either locally or globally, which overrides Electron's built-in module. - -To verify whether you are using the correct built-in module, you can print the -path of the `electron` module: - -```javascript -console.log(require.resolve('electron')) -``` - -and then check if it is in the following form: - -``` -"/path/to/Electron.app/Contents/Resources/atom.asar/renderer/api/lib/exports/electron.js" -``` - -If it is something like `node_modules/electron/index.js`, then you have to -either remove the npm `electron` module, or rename it. - -```bash -npm uninstall electron -npm uninstall -g electron -``` - -However if you are using the built-in module but still getting this error, it -is very likely you are using the module in the wrong process. For example -`electron.app` can only be used in the main process, while `electron.webFrame` -is only available in renderer processes. - -[memory-management]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management -[variable-scope]: https://msdn.microsoft.com/library/bzt2dkta(v=vs.94).aspx -[electron-module]: https://www.npmjs.com/package/electron -[storage]: https://developer.mozilla.org/en-US/docs/Web/API/Storage -[local-storage]: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage -[session-storage]: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage -[indexed-db]: https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API diff --git a/docs-translations/id/glossary.md b/docs-translations/id/glossary.md deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/docs-translations/id/project/CODE_OF_CONDUCT.md b/docs-translations/id/project/CODE_OF_CONDUCT.md deleted file mode 100644 index e4d4c531e5a..00000000000 --- a/docs-translations/id/project/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,46 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [electron@github.com](mailto:electron@github.com). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/docs-translations/id/project/CONTRIBUTING.md b/docs-translations/id/project/CONTRIBUTING.md deleted file mode 100644 index 1deb2e49264..00000000000 --- a/docs-translations/id/project/CONTRIBUTING.md +++ /dev/null @@ -1,79 +0,0 @@ -# Contributing to Electron - -:memo: Available Translations: [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR/project/CONTRIBUTING.md) | [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN/project/CONTRIBUTING.md) | [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR/project/CONTRIBUTING.md) | [Dutch](https://github.com/electron/electron/tree/master/docs-translations/nl/project/CONTRIBUTING.md) - -:+1::tada: First off, thanks for taking the time to contribute! :tada::+1: - -This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md). -By participating, you are expected to uphold this code. Please report unacceptable -behavior to atom@github.com. - -The following is a set of guidelines for contributing to Electron. -These are just guidelines, not rules, use your best judgment and feel free to -propose changes to this document in a pull request. - -## Submitting Issues - -* You can create an issue [here](https://github.com/electron/electron/issues/new), -but before doing that please read the notes below and include as many details as -possible with your report. If you can, please include: - * The version of Electron you are using - * The operating system you are using - * If applicable, what you were doing when the issue arose and what you - expected to happen -* Other things that will help resolve your issue: - * Screenshots and animated GIFs - * Error output that appears in your terminal, dev tools or as an alert - * Perform a [cursory search](https://github.com/electron/electron/issues?utf8=✓&q=is%3Aissue+) - to see if a similar issue has already been submitted - -## Submitting Pull Requests - -* Include screenshots and animated GIFs in your pull request whenever possible. -* Follow the JavaScript, C++, and Python [coding style defined in docs](/docs/development/coding-style.md). -* Write documentation in [Markdown](https://daringfireball.net/projects/markdown). - See the [Documentation Styleguide](/docs/styleguide.md). -* Use short, present tense commit messages. See [Commit Message Styleguide](#git-commit-messages). - -## Styleguides - -### General Code - -* End files with a newline. -* Place requires in the following order: - * Built in Node Modules (such as `path`) - * Built in Electron Modules (such as `ipc`, `app`) - * Local Modules (using relative paths) -* Place class properties in the following order: - * Class methods and properties (methods starting with a `@`) - * Instance methods and properties -* Avoid platform-dependent code: - * Use `path.join()` to concatenate filenames. - * Use `os.tmpdir()` rather than `/tmp` when you need to reference the - temporary directory. -* Using a plain `return` when returning explicitly at the end of a function. - * Not `return null`, `return undefined`, `null`, or `undefined` - -### Git Commit Messages - -* Use the present tense ("Add feature" not "Added feature") -* Use the imperative mood ("Move cursor to..." not "Moves cursor to...") -* Limit the first line to 72 characters or less -* Reference issues and pull requests liberally -* When only changing documentation, include `[ci skip]` in the commit description -* Consider starting the commit message with an applicable emoji: - * :art: `:art:` when improving the format/structure of the code - * :racehorse: `:racehorse:` when improving performance - * :non-potable_water: `:non-potable_water:` when plugging memory leaks - * :memo: `:memo:` when writing docs - * :penguin: `:penguin:` when fixing something on Linux - * :apple: `:apple:` when fixing something on macOS - * :checkered_flag: `:checkered_flag:` when fixing something on Windows - * :bug: `:bug:` when fixing a bug - * :fire: `:fire:` when removing code or files - * :green_heart: `:green_heart:` when fixing the CI build - * :white_check_mark: `:white_check_mark:` when adding tests - * :lock: `:lock:` when dealing with security - * :arrow_up: `:arrow_up:` when upgrading dependencies - * :arrow_down: `:arrow_down:` when downgrading dependencies - * :shirt: `:shirt:` when removing linter warnings diff --git a/docs-translations/id/project/README.md b/docs-translations/id/project/README.md deleted file mode 100644 index 70107cb2317..00000000000 --- a/docs-translations/id/project/README.md +++ /dev/null @@ -1,90 +0,0 @@ -[![Electron Logo](https://electron.atom.io/images/electron-logo.svg)](https://electron.atom.io/) - -[![Travis Build Status](https://travis-ci.org/electron/electron.svg?branch=master)](https://travis-ci.org/electron/electron) -[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/bc56v83355fi3369/branch/master?svg=true)](https://ci.appveyor.com/project/electron-bot/electron/branch/master) -[![devDependency Status](https://david-dm.org/electron/electron/dev-status.svg)](https://david-dm.org/electron/electron?type=dev) -[![Join the Electron Community on Slack](http://atom-slack.herokuapp.com/badge.svg)](http://atom-slack.herokuapp.com/) - -:memo: Available Translations: [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR/project/README.md) | [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN/project/README.md) | [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR/project/README.md) | [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW/project/README.md) | [Spanish](https://github.com/electron/electron/tree/master/docs-translations/es/project/README.md) | [Turkish](https://github.com/electron/electron/tree/master/docs-translations/tr-TR/project/README.md) - -The Electron framework lets you write cross-platform desktop applications -using JavaScript, HTML and CSS. It is based on [Node.js](https://nodejs.org/) and -[Chromium](http://www.chromium.org) and is used by the [Atom -editor](https://github.com/atom/atom) and many other [apps](https://electron.atom.io/apps). - -Follow [@ElectronJS](https://twitter.com/electronjs) on Twitter for important -announcements. - -This project adheres to the Contributor Covenant [code of conduct](CODE_OF_CONDUCT.md). -By participating, you are expected to uphold this code. Please report unacceptable -behavior to electron@github.com. - -## Downloads - -To install prebuilt Electron binaries, use -[`npm`](https://docs.npmjs.com/): - -```sh -# Install as a development dependency -npm install electron --save-dev - -# Install the `electron` command globally in your $PATH -npm install electron -g -``` - -See the [releases page](https://github.com/electron/electron/releases) for -prebuilt binaries, debug symbols, and more. - -### Mirrors - -- [China](https://npm.taobao.org/mirrors/electron) - -## Documentation - -Guides and the API reference are located in the -[docs](https://github.com/electron/electron/tree/master/docs) directory. It also -contains documents describing how to build and contribute to Electron. - -## Documentation Translations - -- [Brazilian Portuguese](https://github.com/electron/electron/tree/master/docs-translations/pt-BR) -- [Korean](https://github.com/electron/electron/tree/master/docs-translations/ko-KR) -- [Japanese](https://github.com/electron/electron/tree/master/docs-translations/jp) -- [Spanish](https://github.com/electron/electron/tree/master/docs-translations/es) -- [Simplified Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-CN) -- [Traditional Chinese](https://github.com/electron/electron/tree/master/docs-translations/zh-TW) -- [Turkish](https://github.com/electron/electron/tree/master/docs-translations/tr-TR) -- [Thai](https://github.com/electron/electron/tree/master/docs-Translations/th-TH) -- [Ukrainian](https://github.com/electron/electron/tree/master/docs-translations/uk-UA) -- [Russian](https://github.com/electron/electron/tree/master/docs-translations/ru-RU) -- [French](https://github.com/electron/electron/tree/master/docs-translations/fr-FR) -- [Indonesian](https://github.com/electron/electron/tree/master/docs-translations/id) - -## Quick Start - -Clone and run the [`electron/electron-quick-start`](https://github.com/electron/electron-quick-start) -repository to see a minimal Electron app in action. - -## Community - -You can ask questions and interact with the community in the following -locations: -- [`electron`](http://discuss.atom.io/c/electron) category on the Atom -forums -- `#atom-shell` channel on Freenode -- [`Atom`](http://atom-slack.herokuapp.com/) channel on Slack -- [`electron-ru`](https://telegram.me/electron_ru) *(Russian)* -- [`electron-br`](https://electron-br.slack.com) *(Brazilian Portuguese)* -- [`electron-kr`](http://www.meetup.com/electron-kr/) *(Korean)* -- [`electron-jp`](https://electron-jp.slack.com) *(Japanese)* -- [`electron-tr`](http://electron-tr.herokuapp.com) *(Turkish)* -- [`electron-id`](https://electron-id.slack.com) *(Indonesia)* - -Check out [awesome-electron](https://github.com/sindresorhus/awesome-electron) -for a community maintained list of useful example apps, tools and resources. - -## License - -[MIT](https://github.com/electron/electron/blob/master/LICENSE) - -When using the Electron or other GitHub logos, be sure to follow the [GitHub logo guidelines](https://github.com/logos). diff --git a/docs-translations/id/styleguide.md b/docs-translations/id/styleguide.md deleted file mode 100644 index 8f59c8a3419..00000000000 --- a/docs-translations/id/styleguide.md +++ /dev/null @@ -1,246 +0,0 @@ -# Electron Documentation Styleguide - -These are the guidelines for writing Electron documentation. - -## Titles - -* Each page must have a single `#`-level title at the top. -* Chapters in the same page must have `##`-level titles. -* Sub-chapters need to increase the number of `#` in the title according to - their nesting depth. -* All words in the page's title must be capitalized, except for conjunctions - like "of" and "and" . -* Only the first word of a chapter title must be capitalized. - -Using `Quick Start` as example: - -```markdown -# Quick Start - -... - -## Main process - -... - -## Renderer process - -... - -## Run your app - -... - -### Run as a distribution - -... - -### Manually downloaded Electron binary - -... -``` - -For API references, there are exceptions to this rule. - -## Markdown rules - -* Use `bash` instead of `cmd` in code blocks (due to the syntax highlighter). -* Lines should be wrapped at 80 columns. -* No nesting lists more than 2 levels (due to the markdown renderer). -* All `js` and `javascript` code blocks are linted with -[standard-markdown](http://npm.im/standard-markdown). - -## Picking words - -* Use "will" over "would" when describing outcomes. -* Prefer "in the ___ process" over "on". - -## API references - -The following rules only apply to the documentation of APIs. - -### Page title - -Each page must use the actual object name returned by `require('electron')` -as the title, such as `BrowserWindow`, `autoUpdater`, and `session`. - -Under the page tile must be a one-line description starting with `>`. - -Using `session` as example: - -```markdown -# session - -> Manage browser sessions, cookies, cache, proxy settings, etc. -``` - -### Module methods and events - -For modules that are not classes, their methods and events must be listed under -the `## Methods` and `## Events` chapters. - -Using `autoUpdater` as an example: - -```markdown -# autoUpdater - -## Events - -### Event: 'error' - -## Methods - -### `autoUpdater.setFeedURL(url[, requestHeaders])` -``` - -### Classes - -* API classes or classes that are part of modules must be listed under a - `## Class: TheClassName` chapter. -* One page can have multiple classes. -* Constructors must be listed with `###`-level titles. -* [Static Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static) must be listed under a `### Static Methods` chapter. -* [Instance Methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Prototype_methods) must be listed under an `### Instance Methods` chapter. -* All methods that have a return value must start their description with "Returns `[TYPE]` - Return description" - * If the method returns an `Object`, its structure can be specified using a colon followed by a newline then an unordered list of properties in the same style as function parameters. -* Instance Events must be listed under an `### Instance Events` chapter. -* Instance Properties must be listed under an `### Instance Properties` chapter. - * Instance properties must start with "A [Property Type] ..." - -Using the `Session` and `Cookies` classes as an example: - -```markdown -# session - -## Methods - -### session.fromPartition(partition) - -## Properties - -### session.defaultSession - -## Class: Session - -### Instance Events - -#### Event: 'will-download' - -### Instance Methods - -#### `ses.getCacheSize(callback)` - -### Instance Properties - -#### `ses.cookies` - -## Class: Cookies - -### Instance Methods - -#### `cookies.get(filter, callback)` -``` - -### Methods - -The methods chapter must be in the following form: - -```markdown -### `objectName.methodName(required[, optional]))` - -* `required` String - A parameter description. -* `optional` Integer (optional) - Another parameter description. - -... -``` - -The title can be `###` or `####`-levels depending on whether it is a method of -a module or a class. - -For modules, the `objectName` is the module's name. For classes, it must be the -name of the instance of the class, and must not be the same as the module's -name. - -For example, the methods of the `Session` class under the `session` module must -use `ses` as the `objectName`. - -The optional arguments are notated by square brackets `[]` surrounding the optional argument -as well as the comma required if this optional argument follows another -argument: - -``` -required[, optional] -``` - -Below the method is more detailed information on each of the arguments. The type -of argument is notated by either the common types: - -* [`String`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) -* [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) -* [`Object`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) -* [`Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) -* [`Boolean`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean) -* Or a custom type like Electron's [`WebContent`](api/web-contents.md) - -If an argument or a method is unique to certain platforms, those platforms are -denoted using a space-delimited italicized list following the datatype. Values -can be `macOS`, `Windows`, or `Linux`. - -```markdown -* `animate` Boolean (optional) _macOS_ _Windows_ - Animate the thing. -``` - -`Array` type arguments must specify what elements the array may include in -the description below. - -The description for `Function` type arguments should make it clear how it may be -called and list the types of the parameters that will be passed to it. - -### Events - -The events chapter must be in following form: - -```markdown -### Event: 'wake-up' - -Returns: - -* `time` String - -... -``` - -The title can be `###` or `####`-levels depending on whether it is an event of -a module or a class. - -The arguments of an event follow the same rules as methods. - -### Properties - -The properties chapter must be in following form: - -```markdown -### session.defaultSession - -... -``` - -The title can be `###` or `####`-levels depending on whether it is a property of -a module or a class. - -## Documentation Translations - -Translations of the Electron docs are located within the `docs-translations` -directory. - -To add another set (or partial set): - -* Create a subdirectory named by language abbreviation. -* Translate the files. -* Update the `README.md` within your language directory to link to the files - you have translated. -* Add a link to your translation directory on the main Electron - [README](https://github.com/electron/electron#documentation-translations). - -Note that the files under `docs-translations` must only include the translated -ones, the original English files should not be copied there. From bf58373a407c49df6f036a1e00d945ee525ba798 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Thu, 11 May 2017 11:38:34 +0200 Subject: [PATCH 1141/1195] fix NativeImage size hint crashing when image is created from path --- atom/common/api/atom_api_native_image.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/atom/common/api/atom_api_native_image.cc b/atom/common/api/atom_api_native_image.cc index 8597c22bbcb..c15e47407b6 100644 --- a/atom/common/api/atom_api_native_image.cc +++ b/atom/common/api/atom_api_native_image.cc @@ -217,8 +217,10 @@ NativeImage::NativeImage(v8::Isolate* isolate, const base::FilePath& hicon_path) ReadImageSkiaFromICO(&image_skia, GetHICON(256)); image_ = gfx::Image(image_skia); Init(isolate); - isolate->AdjustAmountOfExternalAllocatedMemory( - image_.ToImageSkia()->bitmap()->computeSize64()); + if (image_.HasRepresentation(gfx::Image::kImageRepSkia)) { + isolate->AdjustAmountOfExternalAllocatedMemory( + image_.ToImageSkia()->bitmap()->computeSize64()); + } MarkHighMemoryUsage(); } #endif From 4044548f3e64ab127e02b58ee28cf5d69cf5af56 Mon Sep 17 00:00:00 2001 From: 22222 <22222@users.noreply.github.com> Date: Thu, 27 Apr 2017 19:28:48 -0500 Subject: [PATCH 1142/1195] Add 'will-prevent-unload' event. --- atom/browser/api/atom_api_web_contents.cc | 10 +++++++ atom/browser/api/atom_api_web_contents.h | 4 +++ .../browser/atom_javascript_dialog_manager.cc | 11 +++++-- atom/browser/atom_javascript_dialog_manager.h | 7 +++++ atom/browser/common_web_contents_delegate.cc | 10 ------- atom/browser/common_web_contents_delegate.h | 4 --- docs/api/web-contents.md | 30 +++++++++++++++++++ spec/api-web-contents-spec.js | 25 ++++++++++++++++ spec/static/main.js | 4 +++ 9 files changed, 88 insertions(+), 17 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index fedb5af844f..43caf41a7af 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -13,6 +13,7 @@ #include "atom/browser/atom_browser_client.h" #include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_main_parts.h" +#include "atom/browser/atom_javascript_dialog_manager.h" #include "atom/browser/child_web_contents_tracker.h" #include "atom/browser/lib/bluetooth_chooser.h" #include "atom/browser/native_window.h" @@ -683,6 +684,15 @@ std::unique_ptr WebContents::RunBluetoothChooser( return std::move(bluetooth_chooser); } +content::JavaScriptDialogManager* +WebContents::GetJavaScriptDialogManager( + content::WebContents* source) { + if (!dialog_manager_) + dialog_manager_.reset(new AtomJavaScriptDialogManager(this)); + + return dialog_manager_.get(); +} + void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) { // Do nothing, we override this method just to avoid compilation error since // there are two virtual functions named BeforeUnloadFired. diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 1f926dbd7a5..3f7407e1ebb 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -41,6 +41,7 @@ namespace atom { struct SetSizeParams; class AtomBrowserContext; +class AtomJavaScriptDialogManager; class WebContentsZoomController; class WebViewGuestDelegate; @@ -296,6 +297,8 @@ class WebContents : public mate::TrackableObject, std::unique_ptr RunBluetoothChooser( content::RenderFrameHost* frame, const content::BluetoothChooser::EventHandler& handler) override; + content::JavaScriptDialogManager* GetJavaScriptDialogManager( + content::WebContents* source) override; // content::WebContentsObserver: void BeforeUnloadFired(const base::TimeTicks& proceed_time) override; @@ -388,6 +391,7 @@ class WebContents : public mate::TrackableObject, v8::Global devtools_web_contents_; v8::Global debugger_; + std::unique_ptr dialog_manager_; std::unique_ptr guest_delegate_; // The host webcontents that may contain this webcontents. diff --git a/atom/browser/atom_javascript_dialog_manager.cc b/atom/browser/atom_javascript_dialog_manager.cc index 79f82d99441..c593b2bfba1 100644 --- a/atom/browser/atom_javascript_dialog_manager.cc +++ b/atom/browser/atom_javascript_dialog_manager.cc @@ -7,6 +7,7 @@ #include #include +#include "atom/browser/api/atom_api_web_contents.h" #include "atom/browser/native_window.h" #include "atom/browser/ui/message_box.h" #include "base/bind.h" @@ -17,6 +18,10 @@ using content::JavaScriptDialogType; namespace atom { +AtomJavaScriptDialogManager::AtomJavaScriptDialogManager( + api::WebContents* api_web_contents) + : api_web_contents_(api_web_contents) {} + void AtomJavaScriptDialogManager::RunJavaScriptDialog( content::WebContents* web_contents, const GURL& origin_url, @@ -25,7 +30,6 @@ void AtomJavaScriptDialogManager::RunJavaScriptDialog( const base::string16& default_prompt_text, const DialogClosedCallback& callback, bool* did_suppress_message) { - if (dialog_type != JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_ALERT && dialog_type != JavaScriptDialogType::JAVASCRIPT_DIALOG_TYPE_CONFIRM) { callback.Run(false, base::string16()); @@ -49,8 +53,9 @@ void AtomJavaScriptDialogManager::RunBeforeUnloadDialog( content::WebContents* web_contents, bool is_reload, const DialogClosedCallback& callback) { - // FIXME(zcbenz): the |message_text| is removed, figure out what should we do. - callback.Run(false, base::ASCIIToUTF16("This should not be displayed")); + bool default_prevented = api_web_contents_->Emit("will-prevent-unload"); + callback.Run(default_prevented, base::string16()); + return; } void AtomJavaScriptDialogManager::CancelDialogs( diff --git a/atom/browser/atom_javascript_dialog_manager.h b/atom/browser/atom_javascript_dialog_manager.h index 56b62afe877..d5e6c543361 100644 --- a/atom/browser/atom_javascript_dialog_manager.h +++ b/atom/browser/atom_javascript_dialog_manager.h @@ -11,8 +11,14 @@ namespace atom { +namespace api { +class WebContents; +} + class AtomJavaScriptDialogManager : public content::JavaScriptDialogManager { public: + explicit AtomJavaScriptDialogManager(api::WebContents* api_web_contents); + // content::JavaScriptDialogManager implementations. void RunJavaScriptDialog( content::WebContents* web_contents, @@ -33,6 +39,7 @@ class AtomJavaScriptDialogManager : public content::JavaScriptDialogManager { static void OnMessageBoxCallback(const DialogClosedCallback& callback, int code, bool checkbox_checked); + api::WebContents* api_web_contents_; }; } // namespace atom diff --git a/atom/browser/common_web_contents_delegate.cc b/atom/browser/common_web_contents_delegate.cc index 06ac0089714..b0430dafeb8 100644 --- a/atom/browser/common_web_contents_delegate.cc +++ b/atom/browser/common_web_contents_delegate.cc @@ -9,7 +9,6 @@ #include #include "atom/browser/atom_browser_context.h" -#include "atom/browser/atom_javascript_dialog_manager.h" #include "atom/browser/native_window.h" #include "atom/browser/ui/file_dialog.h" #include "atom/browser/web_dialog_helper.h" @@ -230,15 +229,6 @@ bool CommonWebContentsDelegate::CanOverscrollContent() const { return false; } -content::JavaScriptDialogManager* -CommonWebContentsDelegate::GetJavaScriptDialogManager( - content::WebContents* source) { - if (!dialog_manager_) - dialog_manager_.reset(new AtomJavaScriptDialogManager); - - return dialog_manager_.get(); -} - content::ColorChooser* CommonWebContentsDelegate::OpenColorChooser( content::WebContents* web_contents, SkColor color, diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index d1d26314966..fd468afd563 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -20,7 +20,6 @@ using brightray::DevToolsFileSystemIndexer; namespace atom { class AtomBrowserContext; -class AtomJavaScriptDialogManager; class NativeWindow; class WebDialogHelper; @@ -62,8 +61,6 @@ class CommonWebContentsDelegate content::WebContents* source, const content::OpenURLParams& params) override; bool CanOverscrollContent() const override; - content::JavaScriptDialogManager* GetJavaScriptDialogManager( - content::WebContents* source) override; content::ColorChooser* OpenColorChooser( content::WebContents* web_contents, SkColor color, @@ -147,7 +144,6 @@ class CommonWebContentsDelegate bool native_fullscreen_; std::unique_ptr web_dialog_helper_; - std::unique_ptr dialog_manager_; scoped_refptr devtools_file_system_indexer_; // Make sure BrowserContext is alwasys destroyed after WebContents. diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 98b1cbd2f24..d2d3567f141 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -218,6 +218,36 @@ When in-page navigation happens, the page URL changes but does not cause navigation outside of the page. Examples of this occurring are when anchor links are clicked or when the DOM `hashchange` event is triggered. +#### Event: 'will-prevent-unload' + +Returns: + +* `event` Event + +Emitted when a `beforeunload` event handler is attempting to cancel a page unload. + +Calling `event.preventDefault()` will ignore the `beforeunload` event handler +and allow the page to be unloaded. + +```javascript +const {BrowserWindow} = require('electron') +let win = new BrowserWindow({width: 800, height: 600}) +win.webContents.on('will-prevent-unload', (event) => { + let choice = dialog.showMessageBox(mainWindow, { + type: 'question', + buttons: ['Leave', 'Stay'], + title: 'Do you want to leave this site?', + message: 'Changes you made may not be saved.', + defaultId: 0, + cancelId: 1 + }) + let leave = (choice === 0) + if (leave) { + event.preventDefault() + } +}) +``` + #### Event: 'crashed' Returns: diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index 7eac9d3e0e9..6dab70b9c38 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -543,6 +543,31 @@ describe('webContents module', function () { }) }) + describe('will-prevent-unload event', function () { + it('does not emit if beforeunload returns undefined', function (done) { + w.once('closed', function () { + done() + }) + w.webContents.on('will-prevent-unload', function (e) { + assert.fail('should not have fired') + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-undefined.html')) + }) + + it('emits if beforeunload returns false', (done) => { + w.webContents.on('will-prevent-unload', () => { + done() + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html')) + }) + + it('supports calling preventDefault on will-prevent-unload events', function (done) { + ipcRenderer.send('prevent-next-will-prevent-unload', w.webContents.id) + w.once('closed', () => done()) + w.loadURL('file://' + path.join(fixtures, 'api', 'close-beforeunload-false.html')) + }) + }) + describe('destroy()', () => { let server diff --git a/spec/static/main.js b/spec/static/main.js index ba31b61ae07..fcfd08b1aea 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -266,6 +266,10 @@ ipcMain.on('prevent-next-will-attach-webview', (event) => { event.sender.once('will-attach-webview', event => event.preventDefault()) }) +ipcMain.on('prevent-next-will-prevent-unload', (event, id) => { + webContents.fromId(id).once('will-prevent-unload', event => event.preventDefault()) +}) + ipcMain.on('disable-node-on-next-will-attach-webview', (event, id) => { event.sender.once('will-attach-webview', (event, webPreferences, params) => { params.src = `file://${path.join(__dirname, '..', 'fixtures', 'pages', 'c.html')}` From f57c1881dab30cf453a7deab05fae0e0b7ffe2a0 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Thu, 11 May 2017 22:09:37 +1000 Subject: [PATCH 1143/1195] Fix return type of makeSingleInstance --- docs/api/app.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/api/app.md b/docs/api/app.md index cf537474af2..614989dc99c 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -667,6 +667,8 @@ app.setJumpList([ * `argv` String[] - An array of the second instance's command line arguments * `workingDirectory` String - The second instance's working directory +Returns `Boolean`. + This method makes your application a Single Instance Application - instead of allowing multiple instances of your app to run, this will ensure that only a single instance of your app is running, and other instances signal this From 4e1943dfe63411c0338f8177c613f375087fdf50 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 11 May 2017 09:01:51 -0700 Subject: [PATCH 1144/1195] Minor updates to example * const-ing * mainWindow -> win * add dialog require --- docs/api/web-contents.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index d2d3567f141..1d7b9d5e193 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -230,10 +230,10 @@ Calling `event.preventDefault()` will ignore the `beforeunload` event handler and allow the page to be unloaded. ```javascript -const {BrowserWindow} = require('electron') -let win = new BrowserWindow({width: 800, height: 600}) +const {BrowserWindow, dialog} = require('electron') +const win = new BrowserWindow({width: 800, height: 600}) win.webContents.on('will-prevent-unload', (event) => { - let choice = dialog.showMessageBox(mainWindow, { + const choice = dialog.showMessageBox(win, { type: 'question', buttons: ['Leave', 'Stay'], title: 'Do you want to leave this site?', @@ -241,7 +241,7 @@ win.webContents.on('will-prevent-unload', (event) => { defaultId: 0, cancelId: 1 }) - let leave = (choice === 0) + const leave = (choice === 0) if (leave) { event.preventDefault() } From 71b5d946e0f59251e36049cd51040c8825506579 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 3 May 2017 03:58:14 +0530 Subject: [PATCH 1145/1195] protocol: use streaming interface between fetcher and requestjob --- atom/browser/net/url_request_fetch_job.cc | 142 ++++++++++-------- atom/browser/net/url_request_fetch_job.h | 26 ++-- brightray/browser/browser_context.cc | 5 + brightray/browser/browser_context.h | 1 + .../browser/url_request_context_getter.h | 8 + 5 files changed, 106 insertions(+), 76 deletions(-) diff --git a/atom/browser/net/url_request_fetch_job.cc b/atom/browser/net/url_request_fetch_job.cc index ff426dd08c8..0fd598d2ec9 100644 --- a/atom/browser/net/url_request_fetch_job.cc +++ b/atom/browser/net/url_request_fetch_job.cc @@ -9,14 +9,18 @@ #include "atom/browser/api/atom_api_session.h" #include "atom/browser/atom_browser_context.h" +#include "base/guid.h" #include "base/memory/ptr_util.h" #include "base/strings/string_util.h" +#include "brightray/browser/url_request_context_getter.h" +#include "content/browser/streams/stream_context.h" #include "native_mate/dictionary.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" #include "net/http/http_response_headers.h" #include "net/url_request/url_fetcher.h" #include "net/url_request/url_fetcher_response_writer.h" +#include "url/url_constants.h" using content::BrowserThread; @@ -62,7 +66,8 @@ class ResponsePiper : public net::URLFetcherResponseWriter { job_->HeadersCompleted(); first_write_ = false; } - return job_->DataAvailable(buffer, num_bytes, callback); + job_->stream()->AddData(buffer->data(), num_bytes); + return num_bytes; } int Finish(int net_error, const net::CompletionCallback& callback) override { return net::OK; @@ -77,12 +82,11 @@ class ResponsePiper : public net::URLFetcherResponseWriter { } // namespace -URLRequestFetchJob::URLRequestFetchJob( - net::URLRequest* request, net::NetworkDelegate* network_delegate) +URLRequestFetchJob::URLRequestFetchJob(net::URLRequest* request, + net::NetworkDelegate* network_delegate) : JsAsker(request, network_delegate), pending_buffer_size_(0), - write_num_bytes_(0) { -} + total_bytes_read_(0) {} void URLRequestFetchJob::BeforeStartInUI( v8::Isolate* isolate, v8::Local value) { @@ -169,7 +173,22 @@ void URLRequestFetchJob::StartAsync(std::unique_ptr options) { fetcher_->SetExtraRequestHeaders( request()->extra_request_headers().ToString()); - fetcher_->Start(); + // Create readable stream for URLFetcher response. + content::StreamContext* stream_context = + static_cast(request_context_getter()) + ->stream_context(); + + if (stream_context) { + GURL stream_url(std::string(url::kBlobScheme) + ":" + + formated_url.GetOrigin().spec() + base::GenerateGUID()); + stream_ = + new content::Stream(stream_context->registry(), nullptr, stream_url); + stream_->SetReadObserver(this); + fetcher_->Start(); + } else { + NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::CANCELED, + net::ERR_ABORTED)); + } } void URLRequestFetchJob::HeadersCompleted() { @@ -178,53 +197,55 @@ void URLRequestFetchJob::HeadersCompleted() { NotifyHeadersComplete(); } -int URLRequestFetchJob::DataAvailable(net::IOBuffer* buffer, - int num_bytes, - const net::CompletionCallback& callback) { - // When pending_buffer_ is empty, there's no ReadRawData() operation waiting - // for IO completion, we have to save the parameters until the request is - // ready to read data. - if (!pending_buffer_.get()) { - write_buffer_ = buffer; - write_num_bytes_ = num_bytes; - write_callback_ = callback; - return net::ERR_IO_PENDING; - } - - // Write data to the pending buffer and clear them after the writing. - int bytes_read = BufferCopy(buffer, num_bytes, - pending_buffer_.get(), pending_buffer_size_); - ClearPendingBuffer(); - ReadRawDataComplete(bytes_read); - return bytes_read; -} - void URLRequestFetchJob::Kill() { JsAsker::Kill(); + ClearStream(); fetcher_.reset(); } +void URLRequestFetchJob::OnDataAvailable(content::Stream* stream) { + if (!pending_buffer_.get()) + return; + + int result = 0; + auto state = stream_->ReadRawData(pending_buffer_.get(), pending_buffer_size_, + &result); + if (state == content::Stream::STREAM_ABORTED) + result = net::ERR_CONNECTION_RESET; + + // Clear the buffers before notifying the read is complete, so that it is + // safe for the observer to read. + pending_buffer_ = nullptr; + pending_buffer_size_ = 0; + + if (result > 0) + total_bytes_read_ += result; + ReadRawDataComplete(result); +} + int URLRequestFetchJob::ReadRawData(net::IOBuffer* dest, int dest_size) { if (GetResponseCode() == 204) { request()->set_received_response_content_length(prefilter_bytes_read()); return net::OK; } - // When write_buffer_ is empty, there is no data valable yet, we have to save - // the dest buffer util DataAvailable. - if (!write_buffer_.get()) { - pending_buffer_ = dest; - pending_buffer_size_ = dest_size; - return net::ERR_IO_PENDING; + int bytes_read = 0; + switch (stream_->ReadRawData(dest, dest_size, &bytes_read)) { + case content::Stream::STREAM_HAS_DATA: + total_bytes_read_ += bytes_read; + return bytes_read; + case content::Stream::STREAM_COMPLETE: + return stream_->GetStatus(); + case content::Stream::STREAM_EMPTY: + pending_buffer_ = dest; + pending_buffer_size_ = dest_size; + return net::ERR_IO_PENDING; + case content::Stream::STREAM_ABORTED: + // Handle this as connection reset. + return net::ERR_CONNECTION_RESET; } - - // Read from the write buffer and clear them after reading. - int bytes_read = BufferCopy(write_buffer_.get(), write_num_bytes_, - dest, dest_size); - net::CompletionCallback write_callback = write_callback_; - ClearWriteBuffer(); - write_callback.Run(bytes_read); - return bytes_read; + NOTREACHED(); + return net::ERR_FAILED; } bool URLRequestFetchJob::GetMimeType(std::string* mime_type) const { @@ -246,11 +267,18 @@ int URLRequestFetchJob::GetResponseCode() const { return response_info_->headers->response_code(); } -void URLRequestFetchJob::OnURLFetchComplete(const net::URLFetcher* source) { - ClearPendingBuffer(); - ClearWriteBuffer(); +int64_t URLRequestFetchJob::GetTotalReceivedBytes() const { + int64_t total_received_bytes = 0; + if (response_info_) + total_received_bytes = response_info_->headers->raw_headers().size(); + if (stream_.get()) + total_received_bytes += total_bytes_read_; + return total_received_bytes; +} - if (fetcher_->GetStatus().is_success()) { +void URLRequestFetchJob::OnURLFetchComplete(const net::URLFetcher* source) { + auto status = fetcher_->GetStatus(); + if (status.is_success()) { if (!response_info_) { // Since we notify header completion only after first write there will be // no response object constructed for http respones with no content 204. @@ -258,28 +286,16 @@ void URLRequestFetchJob::OnURLFetchComplete(const net::URLFetcher* source) { HeadersCompleted(); return; } - ReadRawDataComplete(0); + stream_->Finalize(0); } else { - NotifyStartError(fetcher_->GetStatus()); + stream_->Finalize(status.error()); + NotifyStartError(status); } } -int URLRequestFetchJob::BufferCopy(net::IOBuffer* source, int num_bytes, - net::IOBuffer* target, int target_size) { - int bytes_written = std::min(num_bytes, target_size); - memcpy(target->data(), source->data(), bytes_written); - return bytes_written; -} - -void URLRequestFetchJob::ClearPendingBuffer() { - pending_buffer_ = nullptr; - pending_buffer_size_ = 0; -} - -void URLRequestFetchJob::ClearWriteBuffer() { - write_buffer_ = nullptr; - write_num_bytes_ = 0; - write_callback_.Reset(); +void URLRequestFetchJob::ClearStream() { + stream_->RemoveReadObserver(this); + stream_ = nullptr; } } // namespace atom diff --git a/atom/browser/net/url_request_fetch_job.h b/atom/browser/net/url_request_fetch_job.h index 906ba68d396..75689c8908d 100644 --- a/atom/browser/net/url_request_fetch_job.h +++ b/atom/browser/net/url_request_fetch_job.h @@ -9,21 +9,23 @@ #include "atom/browser/net/js_asker.h" #include "browser/url_request_context_getter.h" +#include "content/browser/streams/stream.h" +#include "content/browser/streams/stream_read_observer.h" #include "net/url_request/url_fetcher_delegate.h" namespace atom { class URLRequestFetchJob : public JsAsker, public net::URLFetcherDelegate, - public brightray::URLRequestContextGetter::Delegate { + public brightray::URLRequestContextGetter::Delegate, + public content::StreamReadObserver { public: URLRequestFetchJob(net::URLRequest*, net::NetworkDelegate*); // Called by response writer. void HeadersCompleted(); - int DataAvailable(net::IOBuffer* buffer, - int num_bytes, - const net::CompletionCallback& callback); + + content::Stream* stream() const { return stream_.get(); } protected: // JsAsker: @@ -36,28 +38,26 @@ class URLRequestFetchJob : public JsAsker, bool GetMimeType(std::string* mime_type) const override; void GetResponseInfo(net::HttpResponseInfo* info) override; int GetResponseCode() const override; + int64_t GetTotalReceivedBytes() const override; // net::URLFetcherDelegate: void OnURLFetchComplete(const net::URLFetcher* source) override; + // content::StreamReadObserver: + void OnDataAvailable(content::Stream* stream) override; + private: - int BufferCopy(net::IOBuffer* source, int num_bytes, - net::IOBuffer* target, int target_size); - void ClearPendingBuffer(); - void ClearWriteBuffer(); + void ClearStream(); scoped_refptr url_request_context_getter_; std::unique_ptr fetcher_; std::unique_ptr response_info_; + scoped_refptr stream_; // Saved arguments passed to ReadRawData. scoped_refptr pending_buffer_; int pending_buffer_size_; - - // Saved arguments passed to DataAvailable. - scoped_refptr write_buffer_; - int write_num_bytes_; - net::CompletionCallback write_callback_; + int total_bytes_read_; DISALLOW_COPY_AND_ASSIGN(URLRequestFetchJob); }; diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 46f76302d74..88e8bd40848 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -23,6 +23,7 @@ #include "components/prefs/pref_service_factory.h" #include "base/strings/string_util.h" +#include "content/browser/streams/stream_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" @@ -165,6 +166,10 @@ MediaDeviceIDSalt* BrowserContext::GetMediaDeviceIDSalt() { return media_device_id_salt_.get(); } +content::StreamContext* BrowserContext::GetStreamContext() { + return content::StreamContext::GetFor(this); +} + base::FilePath BrowserContext::GetPath() const { return path_; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index 498fe9940ad..704cfb9f33c 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -89,6 +89,7 @@ class BrowserContext : public base::RefCounted, // URLRequestContextGetter::Delegate: net::NetworkDelegate* CreateNetworkDelegate() override; MediaDeviceIDSalt* GetMediaDeviceIDSalt() override; + content::StreamContext* GetStreamContext() override; base::FilePath GetPath() const override; diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index c09824d44be..dab7ae1e872 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -18,6 +18,10 @@ namespace base { class MessageLoop; } +namespace content { +class StreamContext; +} + namespace net { class HostMappingRules; class HostResolver; @@ -58,6 +62,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { return nullptr; } virtual MediaDeviceIDSalt* GetMediaDeviceIDSalt() { return nullptr; } + virtual content::StreamContext* GetStreamContext() { return nullptr; } }; URLRequestContextGetter( @@ -82,6 +87,9 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { MediaDeviceIDSalt* GetMediaDeviceIDSalt() const { return delegate_->GetMediaDeviceIDSalt(); } + content::StreamContext* stream_context() const { + return delegate_->GetStreamContext(); + } private: Delegate* delegate_; From 4824c24fbc7f4b16b7b8ea5b371c534ed3250c03 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 11 May 2017 10:59:51 -0700 Subject: [PATCH 1146/1195] Remove non-functional node debugger usage --- atom/browser/atom_browser_main_parts.cc | 8 -------- atom/browser/atom_browser_main_parts.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index d3f8237d5ec..cc760b46b19 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -12,7 +12,6 @@ #include "atom/browser/bridge_task_runner.h" #include "atom/browser/browser.h" #include "atom/browser/javascript_environment.h" -#include "atom/browser/node_debugger.h" #include "atom/common/api/atom_bindings.h" #include "atom/common/asar/asar_util.h" #include "atom/common/node_bindings.h" @@ -129,18 +128,11 @@ void AtomBrowserMainParts::PostEarlyInitialization() { node_bindings_->Initialize(); - // Support the "--debug" switch. - node_debugger_.reset(new NodeDebugger(js_env_->isolate())); - // Create the global environment. node::Environment* env = node_bindings_->CreateEnvironment(js_env_->context()); node_env_.reset(new NodeEnvironment(env)); - // Make sure node can get correct environment when debugging. - if (node_debugger_->IsRunning()) - env->AssignToContext(v8::Debug::GetDebugContext(js_env_->isolate())); - // Add Electron extended APIs. atom_bindings_->BindTo(js_env_->isolate(), env->process_object()); diff --git a/atom/browser/atom_browser_main_parts.h b/atom/browser/atom_browser_main_parts.h index 2ba7d341f43..4067f542b42 100644 --- a/atom/browser/atom_browser_main_parts.h +++ b/atom/browser/atom_browser_main_parts.h @@ -21,7 +21,6 @@ class AtomBindings; class Browser; class JavascriptEnvironment; class NodeBindings; -class NodeDebugger; class NodeEnvironment; class BridgeTaskRunner; @@ -83,7 +82,6 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { std::unique_ptr node_bindings_; std::unique_ptr atom_bindings_; std::unique_ptr node_env_; - std::unique_ptr node_debugger_; base::Timer gc_timer_; From 9f682ee36bdcb3a6f6b15b8f6b6196638c6da243 Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Thu, 11 May 2017 23:48:14 +0200 Subject: [PATCH 1147/1195] fix osr window initial sizing --- atom/browser/api/atom_api_web_contents.cc | 12 ++++++++++++ atom/browser/api/atom_api_web_contents.h | 1 + 2 files changed, 13 insertions(+) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 1d4ac80498b..b478c3cab40 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1644,6 +1644,18 @@ void WebContents::Invalidate() { } } +gfx::Size WebContents::GetSizeForNewRenderView( + content::WebContents* wc) const { + if (IsOffScreen() && wc == web_contents()) { + auto relay = NativeWindowRelay::FromWebContents(web_contents()); + if (relay) { + return relay->window->GetSize(); + } + } + + return gfx::Size(); +} + void WebContents::SetZoomLevel(double level) { zoom_controller_->SetZoomLevel(level); } diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 1f926dbd7a5..1916964fa25 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -183,6 +183,7 @@ class WebContents : public mate::TrackableObject, void SetFrameRate(int frame_rate); int GetFrameRate() const; void Invalidate(); + gfx::Size GetSizeForNewRenderView(content::WebContents*) const override; // Methods for zoom handling. void SetZoomLevel(double level); From 718cd8d711d568b360dbaa7cf480821090abd372 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 11 May 2017 15:02:27 -0700 Subject: [PATCH 1148/1195] Remove unsupported debugger in node processes --- atom/app/node_main.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/atom/app/node_main.cc b/atom/app/node_main.cc index 9e80ef2e5d2..210d71d01e1 100644 --- a/atom/app/node_main.cc +++ b/atom/app/node_main.cc @@ -6,7 +6,6 @@ #include "atom/app/uv_task_runner.h" #include "atom/browser/javascript_environment.h" -#include "atom/browser/node_debugger.h" #include "atom/common/api/atom_bindings.h" #include "atom/common/crash_reporter/crash_reporter.h" #include "atom/common/native_mate_converters/string16_converter.h" @@ -51,11 +50,6 @@ int NodeMain(int argc, char *argv[]) { &isolate_data, gin_env.context(), argc, argv, exec_argc, exec_argv); - // Start our custom debugger implementation. - NodeDebugger node_debugger(gin_env.isolate()); - if (node_debugger.IsRunning()) - env->AssignToContext(v8::Debug::GetDebugContext(gin_env.isolate())); - mate::Dictionary process(gin_env.isolate(), env->process_object()); #if defined(OS_WIN) process.SetMethod("log", &AtomBindings::Log); From 3c88447be676b8b2de599d6750ba8071c28a6fdb Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 3 May 2017 16:48:02 +0530 Subject: [PATCH 1149/1195] protocol: provide default response code for custom request jobs --- atom/browser/net/js_asker.h | 3 ++ atom/browser/net/url_request_buffer_job.cc | 2 +- spec/chromium-spec.js | 42 ++++++++++++++++++++-- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/atom/browser/net/js_asker.h b/atom/browser/net/js_asker.h index df64a217504..ebe53d982f7 100644 --- a/atom/browser/net/js_asker.h +++ b/atom/browser/net/js_asker.h @@ -82,6 +82,9 @@ class JsAsker : public RequestJob { base::Bind(&JsAsker::OnResponse, weak_factory_.GetWeakPtr()))); } + + int GetResponseCode() const override { return 200; } + void GetResponseInfo(net::HttpResponseInfo* info) override { info->headers = new net::HttpResponseHeaders(""); } diff --git a/atom/browser/net/url_request_buffer_job.cc b/atom/browser/net/url_request_buffer_job.cc index fa848862bb2..117ba96ff1a 100644 --- a/atom/browser/net/url_request_buffer_job.cc +++ b/atom/browser/net/url_request_buffer_job.cc @@ -67,7 +67,7 @@ void URLRequestBufferJob::StartAsync(std::unique_ptr options) { } void URLRequestBufferJob::GetResponseInfo(net::HttpResponseInfo* info) { - std::string status("HTTP/1.1 "); + std::string status("HTTP/1.1 200 OK"); status.append(base::IntToString(status_code_)); status.append(" "); status.append(net::GetHttpReasonPhrase(status_code_)); diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index 1302fbbc433..b2dd89a0e5a 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -149,8 +149,6 @@ describe('chromium feature', function () { }) describe('navigator.serviceWorker', function () { - var url = 'file://' + fixtures + '/pages/service-worker/index.html' - it('should register for file scheme', function (done) { w = new BrowserWindow({ show: false @@ -169,7 +167,45 @@ describe('chromium feature', function () { }) } }) - w.loadURL(url) + w.loadURL(`file://${fixtures}/pages/service-worker/index.html`) + }) + + it('should register for intercepted file scheme', function (done) { + const customSession = session.fromPartition('intercept-file') + customSession.protocol.interceptBufferProtocol('file', function (request, callback) { + const file = url.parse(request.url).pathname + const content = fs.readFileSync(path.normalize(file)) + const ext = path.extname(file) + let type = 'text/html' + if (ext === '.js') { + type = 'application/javascript' + } + callback({data: content, mimeType: type}) + }, function (error) { + if (error) done(error) + }) + + w = new BrowserWindow({ + show: false, + webPreferences: { + session: customSession + } + }) + w.webContents.on('ipc-message', function (event, args) { + if (args[0] === 'reload') { + w.webContents.reload() + } else if (args[0] === 'error') { + done('unexpected error : ' + args[1]) + } else if (args[0] === 'response') { + assert.equal(args[1], 'Hello from serviceWorker!') + customSession.clearStorageData({ + storages: ['serviceworkers'] + }, function () { + customSession.protocol.uninterceptProtocol('file', (error) => done(error)) + }) + } + }) + w.loadURL(`file://${fixtures}/pages/service-worker/index.html`) }) }) From 4fdb884feb7c52731d7195ce5edc7752e8e4e9e4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 11 May 2017 15:18:40 -0700 Subject: [PATCH 1150/1195] Fix windows path in service worker spec --- spec/chromium-spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/chromium-spec.js b/spec/chromium-spec.js index b2dd89a0e5a..8274caf0213 100644 --- a/spec/chromium-spec.js +++ b/spec/chromium-spec.js @@ -173,7 +173,11 @@ describe('chromium feature', function () { it('should register for intercepted file scheme', function (done) { const customSession = session.fromPartition('intercept-file') customSession.protocol.interceptBufferProtocol('file', function (request, callback) { - const file = url.parse(request.url).pathname + let file = url.parse(request.url).pathname + // Remove leading slash before drive letter on Windows + if (file[0] === '/' && process.platform === 'win32') { + file = file.slice(1) + } const content = fs.readFileSync(path.normalize(file)) const ext = path.extname(file) let type = 'text/html' From ef4bf7ed93fd40d4f8bc37427f048117b64e3718 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 11 May 2017 15:30:59 -0700 Subject: [PATCH 1151/1195] Use status code constant --- atom/browser/net/js_asker.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/atom/browser/net/js_asker.h b/atom/browser/net/js_asker.h index ebe53d982f7..f9859f115ad 100644 --- a/atom/browser/net/js_asker.h +++ b/atom/browser/net/js_asker.h @@ -13,6 +13,7 @@ #include "content/public/browser/browser_thread.h" #include "net/base/net_errors.h" #include "net/http/http_response_headers.h" +#include "net/http/http_status_code.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_job.h" #include "v8/include/v8.h" @@ -83,7 +84,7 @@ class JsAsker : public RequestJob { weak_factory_.GetWeakPtr()))); } - int GetResponseCode() const override { return 200; } + int GetResponseCode() const override { return net::HTTP_OK; } void GetResponseInfo(net::HttpResponseInfo* info) override { info->headers = new net::HttpResponseHeaders(""); From ded1adf16548944c4258b99deaee3285933b8e6b Mon Sep 17 00:00:00 2001 From: Xaver Hellauer Date: Fri, 12 May 2017 18:40:46 +0200 Subject: [PATCH 1152/1195] Clang-Format extension for Visual Studio Code --- docs/development/clang-format.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/development/clang-format.md b/docs/development/clang-format.md index 7ad261a2def..34f469c1fbe 100644 --- a/docs/development/clang-format.md +++ b/docs/development/clang-format.md @@ -32,3 +32,4 @@ For further guidance on setting up editor integration, see these pages: * [Atom](https://atom.io/packages/clang-format) * [Vim & Emacs](http://clang.llvm.org/docs/ClangFormat.html#vim-integration) + * [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=xaver.clang-format) From 70539385d1678d5c1f3b11fdd0258e75dd4772c6 Mon Sep 17 00:00:00 2001 From: Andrei K Date: Fri, 12 May 2017 14:07:40 -0700 Subject: [PATCH 1153/1195] Fixed capitalization and punctuation in README Fixed capitalization and punctuation in /ru-RU/README.md --- docs-translations/ru-RU/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs-translations/ru-RU/README.md b/docs-translations/ru-RU/README.md index 96df31da25a..dd674c1c105 100644 --- a/docs-translations/ru-RU/README.md +++ b/docs-translations/ru-RU/README.md @@ -1,10 +1,10 @@ -Пожалуйста, убедитесь, что Вы используете документацию, которая соответствует вашей версии Electron. -Номер версии должен быть частью адреса страницы. Если это не так, Вы -возможно, используете документацию ветки разработки, которая может содержать изменения api, +Пожалуйста, убедитесь, что вы используете документацию, которая соответствует вашей версии Electron. +Номер версии должен быть частью адреса страницы. Если это не так, вы, +возможно, используете документацию ветки разработки, которая может содержать изменения API, которые не совместимы с вашей версией Electron. Если это так, -Вы можете переключиться на другую версию документации в списке +вы можете переключиться на другую версию документации в списке [доступные версии](https://electron.atom.io/docs/) на [atom.io](atom.io), или -если Вы используете интерфейс GitHub, откройте список "переключение ветки/тега" и +если вы используете интерфейс GitHub, откройте список "переключение ветки/тега" и выберите тег, который соответствует вашей версии. ## Руководства From af2c5d1845cc226594934b4efda47e9a43130d04 Mon Sep 17 00:00:00 2001 From: gellert Date: Sat, 13 May 2017 00:59:25 +0200 Subject: [PATCH 1154/1195] fixes not expected scale factor change --- atom/browser/osr/osr_render_widget_host_view.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/atom/browser/osr/osr_render_widget_host_view.cc b/atom/browser/osr/osr_render_widget_host_view.cc index 77002358154..605b42ec1d1 100644 --- a/atom/browser/osr/osr_render_widget_host_view.cc +++ b/atom/browser/osr/osr_render_widget_host_view.cc @@ -858,6 +858,8 @@ std::unique_ptr DCHECK(!copy_frame_generator_); DCHECK(!software_output_device_); + ResizeRootLayer(); + software_output_device_ = new OffScreenOutputDevice( transparent_, base::Bind(&OffScreenRenderWidgetHostView::OnPaint, @@ -1127,8 +1129,8 @@ void OffScreenRenderWidgetHostView::InvalidateBounds(const gfx::Rect& bounds) { void OffScreenRenderWidgetHostView::ResizeRootLayer() { SetupFrameRate(false); - const float orgScaleFactor = scale_factor_; - const bool scaleFactorDidChange = (orgScaleFactor != scale_factor_); + const float compositorScaleFactor = GetCompositor()->device_scale_factor(); + const bool scaleFactorDidChange = (compositorScaleFactor != scale_factor_); gfx::Size size; if (!IsPopupWidget()) From 802501fb04b396d00707e7d4ee7e897de5ddb36f Mon Sep 17 00:00:00 2001 From: Heilig Benedek Date: Sat, 13 May 2017 02:14:30 +0200 Subject: [PATCH 1155/1195] update osr specs --- spec/api-browser-window-spec.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 8d5f329a14c..4d63c32d98f 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -2272,6 +2272,8 @@ describe('BrowserWindow module', function () { beforeEach(function () { if (w != null) w.destroy() w = new BrowserWindow({ + width: 100, + height: 100, show: false, webPreferences: { backgroundThrottling: false, @@ -2280,9 +2282,12 @@ describe('BrowserWindow module', function () { }) }) - it('creates offscreen window', function (done) { - w.webContents.once('paint', function (event, rect, data, size) { + it('creates offscreen window with correct size', function (done) { + w.webContents.once('paint', function (event, rect, data) { assert.notEqual(data.length, 0) + let size = data.getSize() + assertWithinDelta(size.width, 100, 2, 'width') + assertWithinDelta(size.height, 100, 2, 'height') done() }) w.loadURL('file://' + fixtures + '/api/offscreen-rendering.html') @@ -2303,7 +2308,7 @@ describe('BrowserWindow module', function () { describe('window.webContents.isPainting()', function () { it('returns whether is currently painting', function (done) { - w.webContents.once('paint', function (event, rect, data, size) { + w.webContents.once('paint', function (event, rect, data) { assert.equal(w.webContents.isPainting(), true) done() }) @@ -2327,7 +2332,7 @@ describe('BrowserWindow module', function () { w.webContents.on('dom-ready', function () { w.webContents.stopPainting() w.webContents.startPainting() - w.webContents.once('paint', function (event, rect, data, size) { + w.webContents.once('paint', function (event, rect, data) { assert.equal(w.webContents.isPainting(), true) done() }) @@ -2338,7 +2343,7 @@ describe('BrowserWindow module', function () { describe('window.webContents.getFrameRate()', function () { it('has default frame rate', function (done) { - w.webContents.once('paint', function (event, rect, data, size) { + w.webContents.once('paint', function (event, rect, data) { assert.equal(w.webContents.getFrameRate(), 60) done() }) @@ -2350,7 +2355,7 @@ describe('BrowserWindow module', function () { it('sets custom frame rate', function (done) { w.webContents.on('dom-ready', function () { w.webContents.setFrameRate(30) - w.webContents.once('paint', function (event, rect, data, size) { + w.webContents.once('paint', function (event, rect, data) { assert.equal(w.webContents.getFrameRate(), 30) done() }) From 5cfa69730925748d40b01a86b89eab70a6351ef6 Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 14 May 2017 13:41:36 +0300 Subject: [PATCH 1156/1195] Fix postData type definition in docs --- docs/api/browser-window.md | 2 +- docs/api/web-contents.md | 2 +- docs/api/webview-tag.md | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index f3e041778ec..4bb07cbb55d 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1028,7 +1028,7 @@ Same as `webContents.capturePage([rect, ]callback)`. * `httpReferrer` String (optional) - A HTTP Referrer url. * `userAgent` String (optional) - A user agent originating the request. * `extraHeaders` String (optional) - Extra headers separated by "\n" - * `postData` ([UploadRawData](structures/upload-raw-data.md) | [UploadFile](structures/upload-file.md) | [UploadFileSystem](structures/upload-file-system.md) | [UploadBlob](structures/upload-blob.md))[] - (optional) + * `postData` ([UploadRawData[]](structures/upload-raw-data.md) | [UploadFile[]](structures/upload-file.md) | [UploadFileSystem[]](structures/upload-file-system.md) | [UploadBlob[]](structures/upload-blob.md)) - (optional) * `baseURLForDataURL` String (optional) - Base url (with trailing path separator) for files to be loaded by the data url. This is needed only if the specified `url` is a data url and needs to load other files. Same as `webContents.loadURL(url[, options])`. diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 1d7b9d5e193..ec517aabf02 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -567,7 +567,7 @@ that can't be set via `` attributes. * `httpReferrer` String (optional) - A HTTP Referrer url. * `userAgent` String (optional) - A user agent originating the request. * `extraHeaders` String (optional) - Extra headers separated by "\n" - * `postData` ([UploadRawData](structures/upload-raw-data.md) | [UploadFile](structures/upload-file.md) | [UploadFileSystem](structures/upload-file-system.md) | [UploadBlob](structures/upload-blob.md))[] - (optional) + * `postData` ([UploadRawData[]](structures/upload-raw-data.md) | [UploadFile[]](structures/upload-file.md) | [UploadFileSystem[]](structures/upload-file-system.md) | [UploadBlob[]](structures/upload-blob.md)) - (optional) * `baseURLForDataURL` String (optional) - Base url (with trailing path separator) for files to be loaded by the data url. This is needed only if the specified `url` is a data url and needs to load other files. Loads the `url` in the window. The `url` must contain the protocol prefix, diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index 1da5679c18a..0dcbddb36fb 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -312,8 +312,8 @@ webview.addEventListener('dom-ready', () => { * `httpReferrer` String (optional) - A HTTP Referrer url. * `userAgent` String (optional) - A user agent originating the request. * `extraHeaders` String (optional) - Extra headers separated by "\n" - * `postData` ([UploadRawData](structures/upload-raw-data.md) | [UploadFile](structures/upload-file.md) | [UploadFileSystem](structures/upload-file-system.md) | [UploadBlob](structures/upload-blob.md))[] - (optional) - * `baseURLForDataURL` String (optional) - Base url (with trailing path separator) for files to be loaded by the data url. This is needed only if the specified `url` is a data url and needs to load other files. + * `postData` ([UploadRawData[]](structures/upload-raw-data.md) | [UploadFile[]](structures/upload-file.md) | [UploadFileSystem[]](structures/upload-file-system.md) | [UploadBlob[]](structures/upload-blob.md)) - (optional) + * `baseURLForDataURL` String (optional) - Base url (with trailing path separator) for files to be loaded by the data url. This is needed only if the specified `url` is a data url and needs to load other files. Loads the `url` in the webview, the `url` must contain the protocol prefix, e.g. the `http://` or `file://`. From 0153731888be312ef7d63973c170a52a1387b1ae Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Sun, 14 May 2017 13:42:05 +0300 Subject: [PATCH 1157/1195] Make docs for webview.findInPage and webContents.findInPage consistent --- docs/api/webview-tag.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index 0dcbddb36fb..8c5ce3ddd15 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -511,14 +511,14 @@ Inserts `text` to the focused element. * `text` String - Content to be searched, must not be empty. * `options` Object (optional) - * `forward` Boolean - Whether to search forward or backward, defaults to `true`. - * `findNext` Boolean - Whether the operation is first request or a follow up, + * `forward` Boolean - (optional) Whether to search forward or backward, defaults to `true`. + * `findNext` Boolean - (optional) Whether the operation is first request or a follow up, defaults to `false`. - * `matchCase` Boolean - Whether search should be case-sensitive, + * `matchCase` Boolean - (optional) Whether search should be case-sensitive, defaults to `false`. - * `wordStart` Boolean - Whether to look only at the start of words. + * `wordStart` Boolean - (optional) Whether to look only at the start of words. defaults to `false`. - * `medialCapitalAsWordStart` Boolean - When combined with `wordStart`, + * `medialCapitalAsWordStart` Boolean - (optional) When combined with `wordStart`, accepts a match in the middle of a word if the match begins with an uppercase letter followed by a lowercase or non-letter. Accepts several other intra-word matches, defaults to `false`. From d84ddd7fe49c39d113041354292f7c0efe6c7e8e Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Tue, 16 May 2017 01:24:06 +1000 Subject: [PATCH 1158/1195] Fix createFromDataURL return type Fixes #9469 --- docs/api/native-image.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/api/native-image.md b/docs/api/native-image.md index da496436b32..8163c233962 100644 --- a/docs/api/native-image.md +++ b/docs/api/native-image.md @@ -153,6 +153,8 @@ Creates a new `NativeImage` instance from `buffer`. * `dataURL` String +Returns `NativeImage` + Creates a new `NativeImage` instance from `dataURL`. ## Class: NativeImage From 9ce08d08de7c2edb7b3ba798fc45d214a9285ca3 Mon Sep 17 00:00:00 2001 From: Dun Liang Date: Wed, 26 Apr 2017 17:16:25 +0800 Subject: [PATCH 1159/1195] support --disk-cache-size flag #290 --- brightray/browser/url_request_context_getter.cc | 9 ++++++++- brightray/common/switches.cc | 3 +++ brightray/common/switches.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 2e483d62ae5..70c4624b3f0 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -15,6 +15,7 @@ #include "base/command_line.h" #include "base/memory/ptr_util.h" #include "base/strings/string_util.h" +#include "base/strings/string_number_conversions.h" #include "base/threading/sequenced_worker_pool.h" #include "base/threading/worker_pool.h" #include "content/public/browser/browser_thread.h" @@ -92,12 +93,18 @@ URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( net::HttpCache::BackendFactory* URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory( const base::FilePath& base_path) { + auto& command_line = *base::CommandLine::ForCurrentProcess(); + int max_size = 0; + if (command_line.HasSwitch(switches::kDiskCacheSize)) { + base::StringToInt(command_line.GetSwitchValueASCII(switches::kDiskCacheSize), + &max_size); + } base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache")); return new net::HttpCache::DefaultBackend( net::DISK_CACHE, net::CACHE_BACKEND_DEFAULT, cache_path, - 0, + max_size, BrowserThread::GetTaskRunnerForThread(BrowserThread::CACHE)); } diff --git a/brightray/common/switches.cc b/brightray/common/switches.cc index 1f0da2adfdd..17ca0585773 100644 --- a/brightray/common/switches.cc +++ b/brightray/common/switches.cc @@ -53,6 +53,9 @@ const char kAuthNegotiateDelegateWhitelist[] = // Ignores certificate-related errors. const char kIgnoreCertificateErrors[] = "ignore-certificate-errors"; +// Forces the maximum disk space to be used by the disk cache, in bytes. +const char kDiskCacheSize[] = "disk-cache-size"; + } // namespace switches } // namespace brightray diff --git a/brightray/common/switches.h b/brightray/common/switches.h index 3aad50656b7..286c4d633b9 100644 --- a/brightray/common/switches.h +++ b/brightray/common/switches.h @@ -18,6 +18,7 @@ extern const char kDisableHttp2[]; extern const char kAuthServerWhitelist[]; extern const char kAuthNegotiateDelegateWhitelist[]; extern const char kIgnoreCertificateErrors[]; +extern const char kDiskCacheSize[]; } // namespace switches From 5b02974aa89a767a3bc71ecab60bfa7b6b632ef1 Mon Sep 17 00:00:00 2001 From: Dun Liang Date: Mon, 8 May 2017 15:21:39 +0800 Subject: [PATCH 1160/1195] fix line is > 80 characters long --- brightray/browser/url_request_context_getter.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 70c4624b3f0..b574b38d883 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -96,8 +96,9 @@ URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory( auto& command_line = *base::CommandLine::ForCurrentProcess(); int max_size = 0; if (command_line.HasSwitch(switches::kDiskCacheSize)) { - base::StringToInt(command_line.GetSwitchValueASCII(switches::kDiskCacheSize), - &max_size); + base::StringToInt( + command_line.GetSwitchValueASCII(switches::kDiskCacheSize), + &max_size); } base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache")); return new net::HttpCache::DefaultBackend( From ed076a8693cf9f62ea389ca806a7b2652f320a5c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 10:35:11 -0700 Subject: [PATCH 1161/1195] Remove unneeded HasSwitch check --- brightray/browser/url_request_context_getter.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index b574b38d883..209260ace1c 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -93,13 +93,11 @@ URLRequestContextGetter::Delegate::CreateURLRequestJobFactory( net::HttpCache::BackendFactory* URLRequestContextGetter::Delegate::CreateHttpCacheBackendFactory( const base::FilePath& base_path) { - auto& command_line = *base::CommandLine::ForCurrentProcess(); + auto command_line = base::CommandLine::ForCurrentProcess(); int max_size = 0; - if (command_line.HasSwitch(switches::kDiskCacheSize)) { - base::StringToInt( - command_line.GetSwitchValueASCII(switches::kDiskCacheSize), - &max_size); - } + base::StringToInt(command_line->GetSwitchValueASCII(switches::kDiskCacheSize), + &max_size); + base::FilePath cache_path = base_path.Append(FILE_PATH_LITERAL("Cache")); return new net::HttpCache::DefaultBackend( net::DISK_CACHE, From b4fc50e3b2e574cb93b42411c49eb1b878fb8276 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 10:38:20 -0700 Subject: [PATCH 1162/1195] Doc --disk-cache-size --- docs/api/chrome-command-line-switches.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/api/chrome-command-line-switches.md b/docs/api/chrome-command-line-switches.md index 5bc1a99e952..7308c5d4518 100644 --- a/docs/api/chrome-command-line-switches.md +++ b/docs/api/chrome-command-line-switches.md @@ -36,6 +36,10 @@ Debug-related flags, see the [Debugging the Main Process][debugging-main-process Enables remote debugging over HTTP on the specified `port`. +## --disk-cache-size=`size` + +Forces the maximum disk space to be used by the disk cache, in bytes. + ## --js-flags=`flags` Specifies the flags passed to the Node JS engine. It has to be passed when starting From 2f297b18936a846d7e43f12435554fd474858b68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Lach=C3=A8ze?= Date: Mon, 15 May 2017 19:57:19 +0200 Subject: [PATCH 1163/1195] :white_check_mark: Add simple spec for getOSProcessId() --- spec/api-web-contents-spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index f081b390094..166c752f18f 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -324,6 +324,22 @@ describe('webContents module', function () { }) }) + describe('getOSProcessId()', function() { + it('returns a valid procress id', function() { + + // load URL otherwise getOSProcessId() returns 0 + w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html')) + + const specWebContents = w.webContents + let pid = null + assert.doesNotThrow(function () { + pid = specWebContents.getOSProcessId() + }) + assert(typeof pid === 'number', 'is a number') + assert(pid > 0 , 'superior to 0') + }) + }) + describe('zoom api', () => { const zoomScheme = remote.getGlobal('zoomScheme') const hostZoomMap = { From bcbfd0d5c602d0b921c86a18dd75aceb99d6cccb Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 10:57:45 -0700 Subject: [PATCH 1164/1195] Disable crashReporter specs on Linux CI --- spec/api-crash-reporter-spec.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/api-crash-reporter-spec.js b/spec/api-crash-reporter-spec.js index 92020dbea62..a08cbaaa09d 100644 --- a/spec/api-crash-reporter-spec.js +++ b/spec/api-crash-reporter-spec.js @@ -9,6 +9,7 @@ const url = require('url') const {closeWindow} = require('./window-helpers') const {remote} = require('electron') +const isCI = remote.getGlobal('isCi') const {app, BrowserWindow, crashReporter} = remote.require('electron') describe('crashReporter module', function () { @@ -16,6 +17,12 @@ describe('crashReporter module', function () { return } + // FIXME internal Linux CI is failing when it detects a process crashes + // which is a false positive here since crashes are explicitly triggered + if (isCI && process.platform === 'linux') { + return + } + var originalTempDirectory = null var tempDirectory = null From 77bf4c8ebb3ca43307b47ead4ce22ceaacf1d946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Lach=C3=A8ze?= Date: Mon, 15 May 2017 20:02:20 +0200 Subject: [PATCH 1165/1195] :memo: document getOSProcessId() --- docs/api/web-contents.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 98b1cbd2f24..5f86a04048a 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1259,6 +1259,10 @@ Setting the WebRTC IP handling policy allows you to control which IPs are exposed via WebRTC. See [BrowserLeaks](https://browserleaks.com/webrtc) for more details. +#### `contents.getOSProcessId()` + +Returns `Integer` - The `pid` of the associated renderer process. + ### Instance Properties #### `contents.id` From a1e826e4058dc78578f7a7ec7dd617489bc96eab Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 15 May 2017 21:08:55 +0300 Subject: [PATCH 1166/1195] Fix copy paste typos in BrowserView docs --- docs/api/browser-view.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/api/browser-view.md b/docs/api/browser-view.md index 7b722db45e4..2779beebfab 100644 --- a/docs/api/browser-view.md +++ b/docs/api/browser-view.md @@ -46,15 +46,15 @@ Objects created with `new BrowserView` have the following properties: A [`WebContents`](web-contents.md) object owned by this view. -#### `win.id` _Experimental_ +#### `view.id` _Experimental_ A `Integer` representing the unique ID of the view. ### Instance Methods -Objects created with `new BrowserWindow` have the following instance methods: +Objects created with `new BrowserView` have the following instance methods: -#### `win.setAutoResize(options)` _Experimental_ +#### `view.setAutoResize(options)` _Experimental_ * `options` Object * `width` Boolean - If `true`, the view's width will grow and shrink together @@ -62,13 +62,13 @@ Objects created with `new BrowserWindow` have the following instance methods: * `height` Boolean - If `true`, the view's height will grow and shrink together with the window. `false` by default. -#### `win.setBounds(bounds)` _Experimental_ +#### `view.setBounds(bounds)` _Experimental_ * `bounds` [Rectangle](structures/rectangle.md) Resizes and moves the view to the supplied bounds relative to the window. -#### `win.setBackgroundColor(color)` _Experimental_ +#### `view.setBackgroundColor(color)` _Experimental_ * `color` String - Color in `#aarrggbb` or `#argb` form. The alpha channel is optional. From e38e294be31635c085c8e5810b42b596930fd735 Mon Sep 17 00:00:00 2001 From: Daniel Pereira Date: Mon, 15 May 2017 13:38:32 -0500 Subject: [PATCH 1167/1195] :memo:Update use of deprecated getUserMedia[ci skip] --- docs/api/desktop-capturer.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md index 00542f402f4..c581d46e0dc 100644 --- a/docs/api/desktop-capturer.md +++ b/docs/api/desktop-capturer.md @@ -16,7 +16,7 @@ desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => { if (error) throw error for (let i = 0; i < sources.length; ++i) { if (sources[i].name === 'Electron') { - navigator.webkitGetUserMedia({ + navigator.mediaDevices.getUserMedia({ audio: false, video: { mandatory: { @@ -44,11 +44,11 @@ function handleError (e) { ``` To capture video from a source provided by `desktopCapturer` the constraints -passed to [`navigator.webkitGetUserMedia`] must include +passed to [`navigator.mediaDevices.getUserMedia`] must include `chromeMediaSource: 'desktop'`, and `audio: false`. To capture both audio and video from the entire desktop the constraints passed -to [`navigator.webkitGetUserMedia`] must include `chromeMediaSource: 'screen'`, +to [`navigator.mediaDevices.getUserMedia`] must include `chromeMediaSource: 'screen'`, and `audio: true`, but should not include a `chromeMediaSourceId` constraint. ## Methods @@ -73,4 +73,4 @@ and calls `callback(error, sources)` when finished. objects, each `DesktopCapturerSource` represents a screen or an individual window that can be captured. -[`navigator.webkitGetUserMedia`]: https://developer.mozilla.org/en/docs/Web/API/Navigator/getUserMedia +[`navigator.mediaDevices.getUserMedia`]: https://developer.mozilla.org/en/docs/Web/API/MediaDevices/getUserMedia From 37bcc96e9514d52e70147e93fcc56fc2805e8f17 Mon Sep 17 00:00:00 2001 From: Daniel Pereira Date: Mon, 15 May 2017 13:42:47 -0500 Subject: [PATCH 1168/1195] :memo:Update constraints for audio sharing[ci skip] --- docs/api/desktop-capturer.md | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md index c581d46e0dc..590895ce4f1 100644 --- a/docs/api/desktop-capturer.md +++ b/docs/api/desktop-capturer.md @@ -1,7 +1,7 @@ # desktopCapturer > Access information about media sources that can be used to capture audio and -> video from the desktop using the [`navigator.webkitGetUserMedia`] API. +> video from the desktop using the [`navigator.mediaDevices.getUserMedia`] API. Process: [Renderer](../glossary.md#renderer-process) @@ -48,8 +48,23 @@ passed to [`navigator.mediaDevices.getUserMedia`] must include `chromeMediaSource: 'desktop'`, and `audio: false`. To capture both audio and video from the entire desktop the constraints passed -to [`navigator.mediaDevices.getUserMedia`] must include `chromeMediaSource: 'screen'`, -and `audio: true`, but should not include a `chromeMediaSourceId` constraint. +to [`navigator.mediaDevices.getUserMedia`] must include `chromeMediaSource: 'desktop'`, +for both `audio` and `video`, but should not include a `chromeMediaSourceId` constraint. + +``` +const constraints = { + audio: { + mandatory: { + chromeMediaSource: 'desktop' + } + }, + video: { + mandatory: { + chromeMediaSource: 'desktop' + } + } +}; +``` ## Methods From f4d3c169b00f20d8e0f2b4c8d218ea75bca967b8 Mon Sep 17 00:00:00 2001 From: Daniel Pereira Date: Mon, 15 May 2017 13:45:14 -0500 Subject: [PATCH 1169/1195] :memo:Update documentation desktopCapturer to javascript[ci skip] --- docs/api/desktop-capturer.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md index 590895ce4f1..5cc233e6cd9 100644 --- a/docs/api/desktop-capturer.md +++ b/docs/api/desktop-capturer.md @@ -51,7 +51,7 @@ To capture both audio and video from the entire desktop the constraints passed to [`navigator.mediaDevices.getUserMedia`] must include `chromeMediaSource: 'desktop'`, for both `audio` and `video`, but should not include a `chromeMediaSourceId` constraint. -``` +```javascript const constraints = { audio: { mandatory: { From b01bc320511c0a19e5b6bc06d881acef3dd4e7db Mon Sep 17 00:00:00 2001 From: Birunthan Mohanathas Date: Mon, 15 May 2017 21:45:17 +0300 Subject: [PATCH 1170/1195] Update electron-typescript-definitions to latest version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8bddd2b5475..86bd47cfc01 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,8 @@ "asar": "^0.11.0", "browserify": "^13.1.0", "electabul": "~0.0.4", - "electron-docs-linter": "^2.1.0", - "electron-typescript-definitions": "^1.2.3", + "electron-docs-linter": "^2.3.3", + "electron-typescript-definitions": "^1.2.5", "request": "*", "standard": "^8.4.0", "standard-markdown": "^2.1.1" From 9b776369e66b103bf81980dfc36c1171460eb4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Lach=C3=A8ze?= Date: Mon, 15 May 2017 21:00:13 +0200 Subject: [PATCH 1171/1195] :shirt: --- spec/api-web-contents-spec.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index 166c752f18f..457a0b5ffb2 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -324,9 +324,8 @@ describe('webContents module', function () { }) }) - describe('getOSProcessId()', function() { - it('returns a valid procress id', function() { - + describe('getOSProcessId()', function () { + it('returns a valid procress id', function () { // load URL otherwise getOSProcessId() returns 0 w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html')) @@ -336,7 +335,7 @@ describe('webContents module', function () { pid = specWebContents.getOSProcessId() }) assert(typeof pid === 'number', 'is a number') - assert(pid > 0 , 'superior to 0') + assert(pid > 0, 'superior to 0') }) }) From 350528707bb4ca11e9c008a3e6fab829a4b74d3e Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 13:29:34 -0700 Subject: [PATCH 1172/1195] Return base::ProcessId --- atom/browser/api/atom_api_web_contents.cc | 2 +- atom/browser/api/atom_api_web_contents.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 5afecfedd2d..84773aff1cb 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -1008,7 +1008,7 @@ int WebContents::GetProcessID() const { return web_contents()->GetRenderProcessHost()->GetID(); } -int WebContents::GetOSProcessID() const { +base::ProcessId WebContents::GetOSProcessID() const { auto process_handle = web_contents()->GetRenderProcessHost()->GetHandle(); return base::GetProcId(process_handle); } diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 9549950dd42..9c6ffa4f8fd 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -83,7 +83,7 @@ class WebContents : public mate::TrackableObject, int64_t GetID() const; int GetProcessID() const; - int GetOSProcessID() const; + base::ProcessId GetOSProcessID() const; Type GetType() const; bool Equal(const WebContents* web_contents) const; void LoadURL(const GURL& url, const mate::Dictionary& options); From 0ae5f7e62354e2758dbbe2614fefa808f31a6cc1 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 13:34:30 -0700 Subject: [PATCH 1173/1195] Assert PID is 0 with no URL --- spec/api-web-contents-spec.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index 92cbd2bfaf5..186a6458b17 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -326,14 +326,10 @@ describe('webContents module', function () { describe('getOSProcessId()', function () { it('returns a valid procress id', function () { - // load URL otherwise getOSProcessId() returns 0 - w.loadURL('file://' + path.join(__dirname, 'fixtures', 'pages', 'focus-web-contents.html')) + assert.strictEqual(w.webContents.getOSProcessId(), 0) - const specWebContents = w.webContents - let pid = null - assert.doesNotThrow(function () { - pid = specWebContents.getOSProcessId() - }) + w.loadURL('about:blank') + const pid = w.webContents.getOSProcessId() assert(typeof pid === 'number', 'is a number') assert(pid > 0, 'superior to 0') }) From 4f99cb19bdb54ee2c4f2522d07a1de81f7ded56a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 13:38:57 -0700 Subject: [PATCH 1174/1195] :fire: ; --- docs/api/desktop-capturer.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md index 5cc233e6cd9..5f11d94561f 100644 --- a/docs/api/desktop-capturer.md +++ b/docs/api/desktop-capturer.md @@ -63,7 +63,7 @@ const constraints = { chromeMediaSource: 'desktop' } } -}; +} ``` ## Methods @@ -75,7 +75,7 @@ The `desktopCapturer` module has the following methods: * `options` Object * `types` String[] - An array of Strings that lists the types of desktop sources to be captured, available types are `screen` and `window`. - * `thumbnailSize` [Size](structures/size.md) (optional) - The size that the media source thumbnail + * `thumbnailSize` [Size](structures/size.md) (optional) - The size that the media source thumbnail should be scaled to. Default is `150` x `150`. * `callback` Function * `error` Error From 8a2f24c95f3d4db0c14bc87fb793b2618f4256ef Mon Sep 17 00:00:00 2001 From: paulinaika Date: Tue, 16 May 2017 16:28:37 +1000 Subject: [PATCH 1175/1195] :memo: translate to Indonesian using-widevine-cdm-plugin.md and windows-store-guide.md [ci skip] --- .../id/tutorial/using-widevine-cdm-plugin.md | 92 ++++++++++ .../id/tutorial/windows-store-guide.md | 170 ++++++++++++++++++ docs/tutorial/using-widevine-cdm-plugin.md | 4 +- docs/tutorial/windows-store-guide.md | 2 +- 4 files changed, 265 insertions(+), 3 deletions(-) create mode 100644 docs-translations/id/tutorial/using-widevine-cdm-plugin.md create mode 100644 docs-translations/id/tutorial/windows-store-guide.md diff --git a/docs-translations/id/tutorial/using-widevine-cdm-plugin.md b/docs-translations/id/tutorial/using-widevine-cdm-plugin.md new file mode 100644 index 00000000000..4801b7cded7 --- /dev/null +++ b/docs-translations/id/tutorial/using-widevine-cdm-plugin.md @@ -0,0 +1,92 @@ +# Menggunakan *Plugin Widevine CDM* + +Di Electron, anda dapat menggunakan *plugin Widevine CDM* yang disertakan dengan +*browser* Chrome. + +## Mendapatkan *plugin* + +Elektron tidak disertakan dengan *plugin Widevine CDM* karena alasan lisensi, +untuk mendapatkanny, anda perlu menginstal *browser* Chrome resmi terlebih dahulu, +yang seharusnya cocok dengan arsitektur dan versi Chrome dari Elektron yang anda +gunakan. + +**Catatan:** Versi utama *browser* Chrome harus sama dengan versi Chrome yang +digunakan oleh Electron, jika tidak cocok, *plugin* tidak akan bekerja sekalipun +`Navigator.plugins` akan menunjukkan bahwa ia telah dimuat. + +### Windows & macOS + +Buka `chrome://components/` di *browser* Chrome, cari `WidevineCdm` dan pastikan +apabila itu *up-to-date*, maka Anda dapat menemukan semua plugin binari dari direktori +`APP_DATA / Google / Chrome / WidevineCDM / VERSION / _platform_specific / PLATFORM_ARCH /`. + + + +`APP_DATA` adalah lokasi sistem untuk menyimpan data aplikasi, di sistem Windows +itu ada di `% LOCALAPPDATA%`, di macOS itu ada di `~ / Library / Application Support`. +`VERSION` adalah versi *Widevine CDM plugin*, seperti `1.4.8.866`. `PLATFORM` adalah `mac` +atau `win`. `ARCH` adalah` x86` atau `x64`. + +Di Windows, binari yang dibutuhkan adalah `widevinecdm.dll` dan +`Widevinecdmadapter.dll`, di macOS adalah` libwidevinecdm.dylib` dan +`Widevinecdmadapter.plugin`. Anda bisa menyalinnya ke manapun Anda suka, tapi +mereka harus di letakkan bersama. + + +### Linux + + +Di Linux, binari plugin disertakan bersama dengan *browser* Chrome, anda bisa +menemukannya di `/ opt / google / chrome`, nama filenya adalah` libwidevinecdm.so` dan +`Libwidevinecdmadapter.so`. + + + +## Menggunakan *plugin* + +Setelah mendapatkan *file* plugin, anda harus meneruskan `widevinecdmadapter` +ke Electron dengan baris perintah penghubung `--widevine-cdm-path`, dan versi +pluginnya dengan pengubung `--widevine-cdm-version`. + +**Catatan:** Meskipun hanya binari `widevinecdmadapter` yang dilewatkan ke Electron, binari +`Widevinecdm` harus disertakan bersama. + +Penghubung baris perintah harus dilewati sebelum `ready` dari` app` modul dipancarkan, +dan halaman yang menggunakan plugin ini harus mempunyai *plugin* yang sudah diaktifkan. + + +Contoh kode: + +```javascript +const {app, BrowserWindow} = require('electron') + +// You have to pass the filename of `widevinecdmadapter` here, it is +// * `widevinecdmadapter.plugin` on macOS, +// * `libwidevinecdmadapter.so` on Linux, +// * `widevinecdmadapter.dll` on Windows. +app.commandLine.appendSwitch('widevine-cdm-path', '/path/to/widevinecdmadapter.plugin') +// The version of plugin can be got from `chrome://plugins` page in Chrome. +app.commandLine.appendSwitch('widevine-cdm-version', '1.4.8.866') + +let win = null +app.on('ready', () => { + win = new BrowserWindow({ + webPreferences: { + // `plugins` harus diaktifkan. + plugins: true + } + }) + win.show() +}) +``` + +## Verifikasi plugin + +Untuk memverifikasi jika plugin telah berhasil, anda dapat menggunakan cara berikut: + +* Buka *devtools* dan periksa apakah `navigator.plugins` menyertakan *Widevine +Plugin CDM* +* Buka https://shaka-player-demo.appspot.com/ dan muat manifes yang menggunakan +`Widevine`. +* Buka http://www.dash-player.com/demo/drm-test-area/, periksa apakah di halamannya +terdapat `bitdash uses Widevine in your browser`, lalu putar videonya. diff --git a/docs-translations/id/tutorial/windows-store-guide.md b/docs-translations/id/tutorial/windows-store-guide.md new file mode 100644 index 00000000000..3fa81d7c063 --- /dev/null +++ b/docs-translations/id/tutorial/windows-store-guide.md @@ -0,0 +1,170 @@ +# Panduan Windows Store + +Dengan Windows 8, eksekusi win32 yg lama mendapatkan saudara yang baru: *The +Universal Windows Platform*. Format `.appx` yang baru tidak hanya memungkinkan +sejumlah API yang baru dan hebat seperti *Cortana* atau *Push Notifications*, +tetapi juga melalui *Windows Store*, ini akan menyederhanakan instalasi dan update. + +Microsoft [telah mengembangkan sebuah alat yang mengkompilasi aplikasi Elektron sebagai paket `.appx`][electron-windows-store], memungkinkan *developer* untuk menggunakan beberapa +sarana yang dapat ditemukan di model aplikasi baru. Panduan ini menjelaskan cara +menggunakannya - dan kemampuan dan keterbatasan paket Electron AppX. + +## Latar Belakang dan Persyaratan + +Windows 10 "Anniversary Update" dapat menjalankan win32 `.exe` *binaries* dengan cara +meluncurkan mereka bersama-sama dengan *filesystem* virtual dan pendaftaran . Keduanya +dibuat saat kompilasi dengan menjalankan aplikasi and instalasi di dalam *Windows +Container*, memungkinkan *Windows* untuk mengidentifikasi secara tepat modifikasi +sistem operasi mana yang dilakukan saat instalasi. Memasangkan eksekusi +*filesystem* virtual dan pendaftaran virtual yang memungkinkan *Windows* untuk +menjalankan *one-click* instalasi and menghapus instalasi. + +Selain itu, exe diluncurkan di dalam bentuk appx - yang berarti bisa menggunakan +API banyak yang tersedia di *Windows Universal Platform*. Untuk mendapatkan +kemampuan yang lebih, aplikasi Electron dapat dipasangkan dengan *UWP background task* +tersembunyi yang dapat diluncurkan bersamaan dengan `exe` - seperti diluncurkan +sebagai dampingan untuk menjalankan *tasks* yang berjalan di *background*, +menerima *push-notification*, atau untuk berkomunikasi dengan aplikasi UWP lainnya. + +Untuk mengkompilasi aplikasi Elektron yang ada, pastikan anda memenuhi +persyaratan berikut: + +* Windows 10 with Anniversary Update (dikeluarkan August 2nd, 2016) +* The Windows 10 SDK, [unduh disini][windows-sdk] +* Setidaknya Node 4 (untuk mengecek, jalankan `node -v`) + + +Kemudian, instal `electron-windows-store` CLI: + +``` +npm install -g electron-windows-store +``` + +## Step 1: Kemas Aplikasi Elektron Anda + +Kemas aplikasi menggunakan [electron-packager][electron-packager] (atau alat serupa). +Pastikan untuk menghapus `node_modules` yang tidak anda perlukan dalam aplikasi akhir +anda, karena modul yang tidak anda butuhkan hanya akan meningkatkan ukuran aplikasi anda. + +Outputnya kira-kira akan terlihat seperti ini: +``` +├── Ghost.exe +├── LICENSE +├── content_resources_200_percent.pak +├── content_shell.pak +├── d3dcompiler_47.dll +├── ffmpeg.dll +├── icudtl.dat +├── libEGL.dll +├── libGLESv2.dll +├── locales +│   ├── am.pak +│   ├── ar.pak +│   ├── [...] +├── natives_blob.bin +├── node.dll +├── resources +│   ├── app +│   └── atom.asar +├── snapshot_blob.bin +├── squirrel.exe +└── ui_resources_200_percent.pak +``` + + +## 2: Menjalankan *electron-windows-store* + +Dari *PowerShell* (jalankan sebagai "Administrator"), jalankan +`Electron-windows-store` dengan parameter yang dibutuhkan, menggunakan kedua +direktori *input* dan *output*, nama dan versi aplikasi, dan konfirmasi +`Node_modules` harus di *flatten*. + +``` +electron-windows-store ` + --input-directory C:\myelectronapp ` + --output-directory C:\output\myelectronapp ` + --flatten true ` + --package-version 1.0.0.0 ` + --package-name myelectronapp +``` + +Setelah dijalankan, alat ini akan mulai bekerja: Ia akan menerima aplikasi Elektron +anda sebagai *input*, *flattening* `node_modules`. Kemudian, ia akan mengarsipkan +aplikasi anda sebagai `app.zip`. Dengan menggunakan *installer* dan *Windows Container* +, alat ini menciptakan paket AppX yang "diperluas" - termasuk *Windows Application +Manifest* (`AppXManifest.xml`) berserta dengan sistem *virtual file* dan pendaftaran +virtual di dalam map *output* anda. + + +Setelah *file* AppX yang diperluas telah dibuat, alat ini menggunakan +*Windows App Packager* (`MakeAppx.exe`) untuk menggabungkan paket AppX menjadi satu +*file* dari file-file yang ada di *disk*. Akhirnya, alat ini juga bisa digunakan +untuk membuat sertifikat terpercaya di komputer anda untuk menandatangani paket +AppX yang baru. Dengan paket AppX yang telah ditandatangani, CLI juga bisa +secara otomatis menginstal paket di mesin anda. + + +## 3: Menggunakan Paket AppX + +Untuk menjalankan paket, pengguna akan memerlukan Windows 10 dengan apa +yang disebutnya *"Anniversary Update"* - rincian tentang cara memperbarui Windows +dapat ditemukan [di sini][how-to-update]. + +Di sisi lain dari aplikasi-aplikasi UWP tradisional, aplikasi yang terpaket saat ini +perlu menjalani proses verifikasi manual, yang dapat anda terapkan +[disini][centennial-campaigns]. Sementara itu, semua pengguna bisa menginstal +paket anda dengan mengklik dua kali, oleh sebab itu, pengiriman submisi ke toko +tidak diperlukan jika anda hanya mencari metode instalasi yang mudah. Di lingkungan +yang dikelola (biasanya perusahaan), `Add-AppxPackage` [PowerShell Cmdlet dapat digunakan untuk menginstalnya secara otomatis][add-appxpackage]. + +Keterbatasan penting lainnya adalah paket AppX yang telah dikompilasi masih berisi +*Win32 executable* - dan karena itu tidak akan berjalan di *Xbox*, *HoloLens*, +atau Telepon. + + +## Opsional: Tambahkan Fitur UWP menggunakan *BackgroundTask* + +Anda dapat memasangkan aplikasi Elektron Anda dengan tugas *background* UWP yang +tersembunyi yang akan memanfaatkan sepenuhnya fitur Windows 10 - seperti *push-notification*, +integrasi Cortana, atau *live tiles*. + +Untuk mencari tahu bagaimana aplikasi Elektron yang menggunakan *background task* +untuk mengirim *toast notification* dan *live tiles*, [lihat contoh yang disediakan Microsoft][background-task]. + + +## Opsional: Mengkonversi menggunakan *Container Virtualization* + +Untuk menghasilkan paket AppX, `elektron-windows-store` CLI menggunakan *template* +yang seharusnya bekerja untuk sebagian besar aplikasi Electron. Namun, jika anda +menggunakan *custom installer*, atau jika anda mengalami masalah dengan paket +yang dihasilkan, anda dapat mencoba membuat paket menggunakan kompilasi dengan +bantuan Windows Container - di dalam mode itu, CLI akan menginstal dan menjalankan +aplikasi Anda di dalam *Windows Container* yang kosong untuk menentukan +modifikasi apa yang aplikasi Anda lakukan pada sistem operasi. + +Sebelum menjalankan CLI, anda harus mengatur *"Windows Desktop App Converter"*. +Ini akan memakan waktu beberapa menit, tapi jangan khawatir - anda hanya perlu +melakukan ini sekali saja. Unduh *Desktop App Converter* dari [di sini][app-converter]. +Anda akan menerima dua file: `DesktopAppConverter.zip` dan` BaseImage-14316.wim`. + +1. *Unzip* `DesktopAppConverter.zip`. Dari PowerShell (dibuka dengan + "jalankan sebagai Administrator", pastikan bahwa kebijakan eksekusi sistem +anda mengizinkan untuk menjalankan semua yang ingin dijalankan dengan menggunakan `Set-ExecutionPolicy bypass`. +2. Kemudian, jalankan instalasi *Desktop App Converter*, dengan menggunakan lokasi +*Windows Base Image* (di unduh sebagai `BaseImage-14316.wim`), dengan cara memanggil +perintah `. \ DesktopAppConverter.ps1 -Setup -BaseImage. \ BaseImage-14316.wim`. +3. Jika menjalankan perintah tersebut menyebabkan *reboot*, silakan *restart* +mesin anda dan mejalankan perintah yang telah disebutkan diatas setelah berhasil +*restart*. + +Setelah instalasi telah berhasil, anda dapat melajutkan untuk mengkompilasi +aplikasi Electron anda. + +[windows-sdk]: https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk +[app-converter]: https://www.microsoft.com/en-us/download/details.aspx?id=51691 +[add-appxpackage]: https://technet.microsoft.com/en-us/library/hh856048.aspx +[electron-packager]: https://github.com/electron-userland/electron-packager +[electron-windows-store]: https://github.com/catalystcode/electron-windows-store +[background-task]: https://github.com/felixrieseberg/electron-uwp-background +[centennial-campaigns]: https://developer.microsoft.com/en-us/windows/projects/campaigns/desktop-bridge +[how-to-update]: https://blogs.windows.com/windowsexperience/2016/08/02/how-to-get-the-windows-10-anniversary-update diff --git a/docs/tutorial/using-widevine-cdm-plugin.md b/docs/tutorial/using-widevine-cdm-plugin.md index 512da7a041a..0410ab47f6b 100644 --- a/docs/tutorial/using-widevine-cdm-plugin.md +++ b/docs/tutorial/using-widevine-cdm-plugin.md @@ -53,12 +53,12 @@ Example code: ```javascript const {app, BrowserWindow} = require('electron') -// You have to pass the filename of `widevinecdmadapter` here, it is +// Anda harus melewatkan filename `widevinecdmadapter` di sini, yang disebut adalah: // * `widevinecdmadapter.plugin` on macOS, // * `libwidevinecdmadapter.so` on Linux, // * `widevinecdmadapter.dll` on Windows. app.commandLine.appendSwitch('widevine-cdm-path', '/path/to/widevinecdmadapter.plugin') -// The version of plugin can be got from `chrome://plugins` page in Chrome. +// Versi plugin dapat didapatkan dari halaman `chrome://plugins` di Chrome. app.commandLine.appendSwitch('widevine-cdm-version', '1.4.8.866') let win = null diff --git a/docs/tutorial/windows-store-guide.md b/docs/tutorial/windows-store-guide.md index abf96431810..6bcefe40402 100644 --- a/docs/tutorial/windows-store-guide.md +++ b/docs/tutorial/windows-store-guide.md @@ -109,7 +109,7 @@ In order to run your package, your users will need Windows 10 with the so-called In opposition to traditional UWP apps, packaged apps currently need to undergo a manual verification process, for which you can apply [here][centennial-campaigns]. In the meantime, all users will be able to just install your package by double-clicking it, -so a submission to the store might not be necessary if you're simply looking for an +so a submission to the store might not be necessary if you're simply looking for an easier installation method. In managed environments (usually enterprises), the `Add-AppxPackage` [PowerShell Cmdlet can be used to install it in an automated fashion][add-appxpackage]. From b20085fa7ada8ea5ef191e59e283eddcbe7a3cbc Mon Sep 17 00:00:00 2001 From: paulinaika Date: Tue, 16 May 2017 16:49:56 +1000 Subject: [PATCH 1176/1195] :memo: fix typo docs-translations/id/tutorial/using-widevine-cdm-plugin.md and docs/tutorial/using-widevine-cdm-plugin.md from previous commit [ci skip] --- docs-translations/id/tutorial/using-widevine-cdm-plugin.md | 4 ++-- docs/tutorial/using-widevine-cdm-plugin.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs-translations/id/tutorial/using-widevine-cdm-plugin.md b/docs-translations/id/tutorial/using-widevine-cdm-plugin.md index 4801b7cded7..ceae3a25a1f 100644 --- a/docs-translations/id/tutorial/using-widevine-cdm-plugin.md +++ b/docs-translations/id/tutorial/using-widevine-cdm-plugin.md @@ -60,12 +60,12 @@ Contoh kode: ```javascript const {app, BrowserWindow} = require('electron') -// You have to pass the filename of `widevinecdmadapter` here, it is +// Anda harus melewatkan filename `widevinecdmadapter` di sini, yang disebut adalah: // * `widevinecdmadapter.plugin` on macOS, // * `libwidevinecdmadapter.so` on Linux, // * `widevinecdmadapter.dll` on Windows. app.commandLine.appendSwitch('widevine-cdm-path', '/path/to/widevinecdmadapter.plugin') -// The version of plugin can be got from `chrome://plugins` page in Chrome. +// Versi plugin dapat didapatkan dari halaman `chrome://plugins` di Chrome. app.commandLine.appendSwitch('widevine-cdm-version', '1.4.8.866') let win = null diff --git a/docs/tutorial/using-widevine-cdm-plugin.md b/docs/tutorial/using-widevine-cdm-plugin.md index 0410ab47f6b..512da7a041a 100644 --- a/docs/tutorial/using-widevine-cdm-plugin.md +++ b/docs/tutorial/using-widevine-cdm-plugin.md @@ -53,12 +53,12 @@ Example code: ```javascript const {app, BrowserWindow} = require('electron') -// Anda harus melewatkan filename `widevinecdmadapter` di sini, yang disebut adalah: +// You have to pass the filename of `widevinecdmadapter` here, it is // * `widevinecdmadapter.plugin` on macOS, // * `libwidevinecdmadapter.so` on Linux, // * `widevinecdmadapter.dll` on Windows. app.commandLine.appendSwitch('widevine-cdm-path', '/path/to/widevinecdmadapter.plugin') -// Versi plugin dapat didapatkan dari halaman `chrome://plugins` di Chrome. +// The version of plugin can be got from `chrome://plugins` page in Chrome. app.commandLine.appendSwitch('widevine-cdm-version', '1.4.8.866') let win = null From b4dcb6512a123f785625ad0228320d3d2772eb8b Mon Sep 17 00:00:00 2001 From: iamkun Date: Tue, 16 May 2017 16:00:45 +0800 Subject: [PATCH 1177/1195] Update README.md --- docs-translations/zh-CN/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs-translations/zh-CN/README.md b/docs-translations/zh-CN/README.md index 706738d60d2..c6ff17cda90 100644 --- a/docs-translations/zh-CN/README.md +++ b/docs-translations/zh-CN/README.md @@ -93,7 +93,7 @@ * [构建步骤(macOS)](development/build-instructions-osx.md) * [构建步骤(Windows)](development/build-instructions-windows.md) * [构建步骤(Linux)](development/build-instructions-linux.md) -* [调试步骤 (macOS)](development/debug-instructions-macos.md) +* [调试步骤 (macOS)](development/debugging-instructions-macos.md) * [调试步骤 (Windows)](development/debug-instructions-windows.md) * [在调试中使用 Symbol Server](development/setting-up-symbol-server.md) * [文档风格指南](styleguide.md) From 6b5bd3b6ceb9457b091171bbde40700be71c66dd Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Mon, 15 May 2017 08:57:23 -0300 Subject: [PATCH 1178/1195] Fix how rpc-server releases references after page reload In addition to listening for "render-view-deleted", listen for "ELECTRON_BROWSER_CONTEXT_RELEASE" synchronous message, which is sent by the remote module when the page is about to be navigated. This is required to allow child windows running in the same renderer to correctly manage remote object references, since `render-view-deleted` is only called when the renderer exits. Close #9387 --- lib/browser/rpc-server.js | 5 +++++ lib/renderer/api/remote.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index 8d543f2d7d3..815298d3d9d 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -394,6 +394,11 @@ ipcMain.on('ELECTRON_BROWSER_DEREFERENCE', function (event, id) { objectsRegistry.remove(event.sender.getId(), id) }) +ipcMain.on('ELECTRON_BROWSER_CONTEXT_RELEASE', (e) => { + objectsRegistry.clear(e.sender.getId()) + e.returnValue = null +}) + ipcMain.on('ELECTRON_BROWSER_GUEST_WEB_CONTENTS', function (event, guestInstanceId) { try { let guestViewManager = require('./guest-view-manager') diff --git a/lib/renderer/api/remote.js b/lib/renderer/api/remote.js index 5e790133d38..fdc95cdb5cd 100644 --- a/lib/renderer/api/remote.js +++ b/lib/renderer/api/remote.js @@ -304,6 +304,10 @@ ipcRenderer.on('ELECTRON_RENDERER_RELEASE_CALLBACK', function (event, id) { callbacksRegistry.remove(id) }) +process.on('exit', () => { + ipcRenderer.sendSync('ELECTRON_BROWSER_CONTEXT_RELEASE') +}) + // Get remote module. exports.require = function (module) { return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_REQUIRE', module)) From 5654ff0d430b2902aedef4607094e92d4898a39c Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Mon, 15 May 2017 09:17:07 -0300 Subject: [PATCH 1179/1195] Add test for #9387 --- spec/api-browser-window-spec.js | 68 ++++++++++++++++++++++++- spec/fixtures/api/sandbox.html | 20 ++++++-- spec/fixtures/module/hello-child.js | 6 +++ spec/fixtures/module/hello.js | 6 +++ spec/fixtures/module/preload-sandbox.js | 2 +- 5 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 spec/fixtures/module/hello-child.js create mode 100644 spec/fixtures/module/hello.js diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 8d5f329a14c..be8dc30e254 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1161,7 +1161,6 @@ describe('BrowserWindow module', function () { } }) w.loadURL('file://' + path.join(fixtures, 'api', 'sandbox.html?allocate-memory')) - w.webContents.openDevTools({mode: 'detach'}) ipcMain.once('answer', function (event, {bytesBeforeOpen, bytesAfterOpen, bytesAfterClose}) { const memoryIncreaseByOpen = bytesAfterOpen - bytesBeforeOpen const memoryDecreaseByClose = bytesAfterOpen - bytesAfterClose @@ -1173,6 +1172,73 @@ describe('BrowserWindow module', function () { done() }) }) + + // see #9387 + it('properly manages remote object references after page reload', (done) => { + w.destroy() + w = new BrowserWindow({ + show: false, + webPreferences: { + preload: preload, + sandbox: true + } + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'sandbox.html?reload-remote')) + + ipcMain.on('get-remote-module-path', (event) => { + event.returnValue = path.join(fixtures, 'module', 'hello.js') + }) + + let reload = false + ipcMain.on('reloaded', (event) => { + event.returnValue = reload + reload = !reload + }) + + ipcMain.once('reload', (event) => { + event.sender.reload() + }) + + ipcMain.once('answer', (event, arg) => { + ipcMain.removeAllListeners('reloaded') + ipcMain.removeAllListeners('get-remote-module-path') + assert.equal(arg, 'hi') + done() + }) + }) + + it('properly manages remote object references after page reload in child window', (done) => { + w.destroy() + w = new BrowserWindow({ + show: false, + webPreferences: { + preload: preload, + sandbox: true + } + }) + w.loadURL('file://' + path.join(fixtures, 'api', 'sandbox.html?reload-remote-child')) + + ipcMain.on('get-remote-module-path', (event) => { + event.returnValue = path.join(fixtures, 'module', 'hello-child.js') + }) + + let reload = false + ipcMain.on('reloaded', (event) => { + event.returnValue = reload + reload = !reload + }) + + ipcMain.once('reload', (event) => { + event.sender.reload() + }) + + ipcMain.once('answer', (event, arg) => { + ipcMain.removeAllListeners('reloaded') + ipcMain.removeAllListeners('get-remote-module-path') + assert.equal(arg, 'hi child window') + done() + }) + }) }) describe('nativeWindowOpen option', () => { diff --git a/spec/fixtures/api/sandbox.html b/spec/fixtures/api/sandbox.html index f8d7aa7921d..5353d8815a7 100644 --- a/spec/fixtures/api/sandbox.html +++ b/spec/fixtures/api/sandbox.html @@ -13,13 +13,28 @@ await timeout(100) } } - if (window.opener) { + + const [,test] = window.location.href.split('?') + if (window.opener && test !== 'reload-remote') { window.callback = () => { opener.require('electron').ipcRenderer.send('answer', document.body.innerHTML) } } else { - const {ipcRenderer} = require('electron') + const {ipcRenderer, remote} = require('electron') const tests = { + 'reload-remote-child': () => { + open(`${location.protocol}//${location.pathname}?reload-remote`) + }, + 'reload-remote': async () => { + const p = ipcRenderer.sendSync('get-remote-module-path') + const Hello = remote.require(p) + if (!ipcRenderer.sendSync('reloaded')) { + ipcRenderer.send('reload') + return + } + await invokeGc() + ipcRenderer.send('answer', new Hello().say()) + }, 'allocate-memory': async () => { await invokeGc() const {privateBytes: bytesBeforeOpen} = process.getProcessMemoryInfo() @@ -95,7 +110,6 @@ popup.close() }, false) - let [,test] = window.location.href.split('?') if (tests.hasOwnProperty(test)) tests[test]() } diff --git a/spec/fixtures/module/hello-child.js b/spec/fixtures/module/hello-child.js new file mode 100644 index 00000000000..09ac18900e1 --- /dev/null +++ b/spec/fixtures/module/hello-child.js @@ -0,0 +1,6 @@ +class Hello { + say () { + return 'hi child window' + } +} +module.exports = Hello diff --git a/spec/fixtures/module/hello.js b/spec/fixtures/module/hello.js new file mode 100644 index 00000000000..9debd60618e --- /dev/null +++ b/spec/fixtures/module/hello.js @@ -0,0 +1,6 @@ +class Hello { + say () { + return 'hi' + } +} +module.exports = Hello diff --git a/spec/fixtures/module/preload-sandbox.js b/spec/fixtures/module/preload-sandbox.js index 15d6e06a862..f8f88339852 100644 --- a/spec/fixtures/module/preload-sandbox.js +++ b/spec/fixtures/module/preload-sandbox.js @@ -3,9 +3,9 @@ const {ipcRenderer} = require('electron') window.ipcRenderer = ipcRenderer window.setImmediate = setImmediate + window.require = require if (location.protocol === 'file:') { window.test = 'preload' - window.require = require window.process = process } else if (location.href !== 'about:blank') { addEventListener('DOMContentLoaded', () => { From 693f6a24fcc7372789b7d03a00b7ed0874fd9d99 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 16 May 2017 12:42:37 -0700 Subject: [PATCH 1180/1195] Bump v1.7.1 --- atom/browser/resources/mac/Info.plist | 4 ++-- atom/browser/resources/win/atom.rc | 8 ++++---- atom/common/atom_version.h | 2 +- electron.gyp | 2 +- package.json | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/atom/browser/resources/mac/Info.plist b/atom/browser/resources/mac/Info.plist index 989d0410476..e19b6c8e164 100644 --- a/atom/browser/resources/mac/Info.plist +++ b/atom/browser/resources/mac/Info.plist @@ -17,9 +17,9 @@ CFBundleIconFile electron.icns CFBundleVersion - 1.7.0 + 1.7.1 CFBundleShortVersionString - 1.7.0 + 1.7.1 LSApplicationCategoryType public.app-category.developer-tools LSMinimumSystemVersion diff --git a/atom/browser/resources/win/atom.rc b/atom/browser/resources/win/atom.rc index af65704a2ea..3ab0cf2bebf 100644 --- a/atom/browser/resources/win/atom.rc +++ b/atom/browser/resources/win/atom.rc @@ -56,8 +56,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,7,0,0 - PRODUCTVERSION 1,7,0,0 + FILEVERSION 1,7,1,0 + PRODUCTVERSION 1,7,1,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -74,12 +74,12 @@ BEGIN BEGIN VALUE "CompanyName", "GitHub, Inc." VALUE "FileDescription", "Electron" - VALUE "FileVersion", "1.7.0" + VALUE "FileVersion", "1.7.1" VALUE "InternalName", "electron.exe" VALUE "LegalCopyright", "Copyright (C) 2015 GitHub, Inc. All rights reserved." VALUE "OriginalFilename", "electron.exe" VALUE "ProductName", "Electron" - VALUE "ProductVersion", "1.7.0" + VALUE "ProductVersion", "1.7.1" VALUE "SquirrelAwareVersion", "1" END END diff --git a/atom/common/atom_version.h b/atom/common/atom_version.h index 92b79c0c14d..572774358b1 100644 --- a/atom/common/atom_version.h +++ b/atom/common/atom_version.h @@ -7,7 +7,7 @@ #define ATOM_MAJOR_VERSION 1 #define ATOM_MINOR_VERSION 7 -#define ATOM_PATCH_VERSION 0 +#define ATOM_PATCH_VERSION 1 #define ATOM_VERSION_IS_RELEASE 1 diff --git a/electron.gyp b/electron.gyp index a8658b89360..9bfcbcee7c0 100644 --- a/electron.gyp +++ b/electron.gyp @@ -4,7 +4,7 @@ 'product_name%': 'Electron', 'company_name%': 'GitHub, Inc', 'company_abbr%': 'github', - 'version%': '1.7.0', + 'version%': '1.7.1', 'js2c_input_dir': '<(SHARED_INTERMEDIATE_DIR)/js2c', }, 'includes': [ diff --git a/package.json b/package.json index 86bd47cfc01..e9e2dde9a7f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "electron", - "version": "1.7.0", + "version": "1.7.1", "devDependencies": { "asar": "^0.11.0", "browserify": "^13.1.0", From 98cce37e3d976286255a53edf78b623afdf983b4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 09:01:39 -0700 Subject: [PATCH 1181/1195] Upgrade node enable inspector target --- vendor/node | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/node b/vendor/node index df227c3a5db..24ebf0c5bce 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit df227c3a5db7aa8eab64c86f54588c6cd2d6c623 +Subproject commit 24ebf0c5bce0a2e3b34f0fa2ef0995fb5a8bc91b From 7469d09daeecd806cb9511678cdba3b465d302b1 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 09:07:52 -0700 Subject: [PATCH 1182/1195] Build v8 inspector through ndoe --- common.gypi | 2 +- electron.gyp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index ee8b1e85768..6f1ad5f7521 100644 --- a/common.gypi +++ b/common.gypi @@ -43,7 +43,7 @@ 'V8_BASE': '', 'v8_postmortem_support': 'false', 'v8_enable_i18n_support': 'false', - 'v8_inspector': 'false', + 'v8_inspector': 'true', }, # Settings to compile node under Windows. 'target_defaults': { diff --git a/electron.gyp b/electron.gyp index 9bfcbcee7c0..e0c91c151fd 100644 --- a/electron.gyp +++ b/electron.gyp @@ -227,6 +227,7 @@ # We need to access internal implementations of Node. 'NODE_WANT_INTERNALS=1', 'NODE_SHARED_MODE', + 'HAVE_INSPECTOR=1', # This is defined in skia/skia_common.gypi. 'SK_SUPPORT_LEGACY_GETTOPDEVICE', # Disable warnings for g_settings_list_schemas. From a33643c51849d6026b65a5641ff6dda4ffcd55ba Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 09:30:55 -0700 Subject: [PATCH 1183/1195] Start node inspector agent when --inspect is present --- atom/browser/atom_browser_main_parts.cc | 5 + atom/browser/atom_browser_main_parts.h | 2 + atom/browser/node_debugger.cc | 201 ++---------------------- atom/browser/node_debugger.h | 50 +----- atom/common/node_includes.h | 1 + 5 files changed, 32 insertions(+), 227 deletions(-) diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index cc760b46b19..190898fdef9 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -12,6 +12,7 @@ #include "atom/browser/bridge_task_runner.h" #include "atom/browser/browser.h" #include "atom/browser/javascript_environment.h" +#include "atom/browser/node_debugger.h" #include "atom/common/api/atom_bindings.h" #include "atom/common/asar/asar_util.h" #include "atom/common/node_bindings.h" @@ -133,6 +134,10 @@ void AtomBrowserMainParts::PostEarlyInitialization() { node_bindings_->CreateEnvironment(js_env_->context()); node_env_.reset(new NodeEnvironment(env)); + // Enable support for v8 inspector + node_debugger_.reset(new NodeDebugger(env)); + node_debugger_->Start(); + // Add Electron extended APIs. atom_bindings_->BindTo(js_env_->isolate(), env->process_object()); diff --git a/atom/browser/atom_browser_main_parts.h b/atom/browser/atom_browser_main_parts.h index 4067f542b42..2ba7d341f43 100644 --- a/atom/browser/atom_browser_main_parts.h +++ b/atom/browser/atom_browser_main_parts.h @@ -21,6 +21,7 @@ class AtomBindings; class Browser; class JavascriptEnvironment; class NodeBindings; +class NodeDebugger; class NodeEnvironment; class BridgeTaskRunner; @@ -82,6 +83,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { std::unique_ptr node_bindings_; std::unique_ptr atom_bindings_; std::unique_ptr node_env_; + std::unique_ptr node_debugger_; base::Timer gc_timer_; diff --git a/atom/browser/node_debugger.cc b/atom/browser/node_debugger.cc index 9fdeb6099e6..31898d4c251 100644 --- a/atom/browser/node_debugger.cc +++ b/atom/browser/node_debugger.cc @@ -4,202 +4,33 @@ #include "atom/browser/node_debugger.h" -#include - -#include "base/bind.h" #include "base/command_line.h" -#include "base/strings/string_number_conversions.h" -#include "base/strings/stringprintf.h" -#include "base/strings/utf_string_conversions.h" -#include "content/public/browser/browser_thread.h" -#include "net/test/embedded_test_server/tcp_listen_socket.h" - -#include "atom/common/node_includes.h" +#include "libplatform/libplatform.h" namespace atom { -namespace { - -// NodeDebugger is stored in Isolate's data, slots 0, 1, 3 have already been -// taken by gin, blink and node, using 2 is a safe option for now. -const int kIsolateSlot = 2; - -const char* kContentLength = "Content-Length"; - -} // namespace - -NodeDebugger::NodeDebugger(v8::Isolate* isolate) - : isolate_(isolate), - thread_("NodeDebugger"), - content_length_(-1), - weak_factory_(this) { - bool use_debug_agent = false; - int port = 5858; - - std::string port_str; - base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); - if (cmd->HasSwitch("debug")) { - use_debug_agent = true; - port_str = cmd->GetSwitchValueASCII("debug"); - } else if (cmd->HasSwitch("debug-brk")) { - use_debug_agent = true; - port_str = cmd->GetSwitchValueASCII("debug-brk"); - } - - if (use_debug_agent) { - if (!port_str.empty()) - base::StringToInt(port_str, &port); - - isolate_->SetData(kIsolateSlot, this); - v8::Debug::SetMessageHandler(isolate_, DebugMessageHandler); - - weak_up_ui_handle_.data = this; - uv_async_init(uv_default_loop(), &weak_up_ui_handle_, ProcessMessageInUI); - - // Start a new IO thread. - base::Thread::Options options; - options.message_loop_type = base::MessageLoop::TYPE_IO; - if (!thread_.StartWithOptions(options)) { - LOG(ERROR) << "Unable to start debugger thread"; - return; - } - - // Start the server in new IO thread. - thread_.task_runner()->PostTask( - FROM_HERE, - base::Bind(&NodeDebugger::StartServer, weak_factory_.GetWeakPtr(), - port)); - } +NodeDebugger::NodeDebugger(node::Environment* env) : env_(env) { } NodeDebugger::~NodeDebugger() { - thread_.Stop(); } -bool NodeDebugger::IsRunning() const { - return thread_.IsRunning(); -} - -void NodeDebugger::StartServer(int port) { - server_ = net::test_server::TCPListenSocket::CreateAndListen( - "127.0.0.1", port, this); - if (!server_) { - LOG(ERROR) << "Cannot start debugger server"; +void NodeDebugger::Start() { + auto inspector = env_->inspector_agent(); + if (inspector == nullptr) return; + + node::DebugOptions options; + for (auto& arg : base::CommandLine::ForCurrentProcess()->argv()) + options.ParseOption(arg); + + if (options.inspector_enabled()) { + // Use custom platform since the gin platform does not work correctly + // with node's inspector agent + platform_.reset(v8::platform::CreateDefaultPlatform()); + + inspector->Start(platform_.get(), nullptr, options); } } -void NodeDebugger::CloseSession() { - accepted_socket_.reset(); -} - -void NodeDebugger::OnMessage(const std::string& message) { - if (message.find("\"type\":\"request\",\"command\":\"disconnect\"}") != - std::string::npos) - CloseSession(); - - base::string16 message16 = base::UTF8ToUTF16(message); - v8::Debug::SendCommand( - isolate_, - reinterpret_cast(message16.data()), message16.size()); - - uv_async_send(&weak_up_ui_handle_); -} - -void NodeDebugger::SendMessage(const std::string& message) { - if (accepted_socket_) { - std::string header = base::StringPrintf( - "%s: %d\r\n\r\n", kContentLength, static_cast(message.size())); - accepted_socket_->Send(header); - accepted_socket_->Send(message); - } -} - -void NodeDebugger::SendConnectMessage() { - accepted_socket_->Send(base::StringPrintf( - "Type: connect\r\n" - "V8-Version: %s\r\n" - "Protocol-Version: 1\r\n" - "Embedding-Host: %s\r\n" - "%s: 0\r\n", - v8::V8::GetVersion(), ATOM_PRODUCT_NAME, kContentLength), true); -} - -// static -void NodeDebugger::ProcessMessageInUI(uv_async_t* handle) { - NodeDebugger* self = static_cast(handle->data); - v8::Debug::ProcessDebugMessages(self->isolate_); -} - -// static -void NodeDebugger::DebugMessageHandler(const v8::Debug::Message& message) { - NodeDebugger* self = static_cast( - message.GetIsolate()->GetData(kIsolateSlot)); - - if (self) { - std::string message8(*v8::String::Utf8Value(message.GetJSON())); - self->thread_.task_runner()->PostTask( - FROM_HERE, - base::Bind(&NodeDebugger::SendMessage, self->weak_factory_.GetWeakPtr(), - message8)); - } -} - -void NodeDebugger::DidAccept( - net::test_server::StreamListenSocket* server, - std::unique_ptr socket) { - // Only accept one session. - if (accepted_socket_) { - socket->Send(std::string("Remote debugging session already active"), true); - return; - } - - accepted_socket_ = std::move(socket); - SendConnectMessage(); -} - -void NodeDebugger::DidRead(net::test_server::StreamListenSocket* socket, - const char* data, - int len) { - buffer_.append(data, len); - - do { - if (buffer_.empty()) - return; - - // Read the "Content-Length" header. - if (content_length_ < 0) { - size_t pos = buffer_.find("\r\n\r\n"); - if (pos == std::string::npos) - return; - - // We can be sure that the header is "Content-Length: xxx\r\n". - std::string content_length = buffer_.substr(16, pos - 16); - if (!base::StringToInt(content_length, &content_length_)) { - DidClose(accepted_socket_.get()); - return; - } - - // Strip header from buffer. - buffer_ = buffer_.substr(pos + 4); - } - - // Read the message. - if (buffer_.size() >= static_cast(content_length_)) { - std::string message = buffer_.substr(0, content_length_); - buffer_ = buffer_.substr(content_length_); - - OnMessage(message); - - // Get ready for next message. - content_length_ = -1; - } - } while (true); -} - -void NodeDebugger::DidClose(net::test_server::StreamListenSocket* socket) { - // If we lost the connection, then simulate a disconnect msg: - OnMessage("{\"seq\":1,\"type\":\"request\",\"command\":\"disconnect\"}"); -} - } // namespace atom diff --git a/atom/browser/node_debugger.h b/atom/browser/node_debugger.h index 118812a139a..a3553192b4e 100644 --- a/atom/browser/node_debugger.h +++ b/atom/browser/node_debugger.h @@ -6,56 +6,22 @@ #define ATOM_BROWSER_NODE_DEBUGGER_H_ #include -#include -#include "base/memory/weak_ptr.h" -#include "base/threading/thread.h" -#include "net/test/embedded_test_server/stream_listen_socket.h" -#include "v8/include/v8-debug.h" -#include "vendor/node/deps/uv/include/uv.h" +#include "atom/common/node_includes.h" namespace atom { -// Add support for node's "--debug" switch. -class NodeDebugger : public net::test_server::StreamListenSocket::Delegate { +// Add support for node's "--inspect" switch. +class NodeDebugger { public: - explicit NodeDebugger(v8::Isolate* isolate); - virtual ~NodeDebugger(); + explicit NodeDebugger(node::Environment* env); + ~NodeDebugger(); - bool IsRunning() const; + void Start(); private: - void StartServer(int port); - void CloseSession(); - void OnMessage(const std::string& message); - void SendMessage(const std::string& message); - void SendConnectMessage(); - - static void ProcessMessageInUI(uv_async_t* handle); - - static void DebugMessageHandler(const v8::Debug::Message& message); - - // net::test_server::StreamListenSocket::Delegate: - void DidAccept( - net::test_server::StreamListenSocket* server, - std::unique_ptr socket) override; - void DidRead(net::test_server::StreamListenSocket* socket, - const char* data, - int len) override; - void DidClose(net::test_server::StreamListenSocket* socket) override; - - v8::Isolate* isolate_; - - uv_async_t weak_up_ui_handle_; - - base::Thread thread_; - std::unique_ptr server_; - std::unique_ptr accepted_socket_; - - std::string buffer_; - int content_length_; - - base::WeakPtrFactory weak_factory_; + node::Environment* env_; + std::unique_ptr platform_; DISALLOW_COPY_AND_ASSIGN(NodeDebugger); }; diff --git a/atom/common/node_includes.h b/atom/common/node_includes.h index b6cbf36090c..5e9c3fdbec8 100644 --- a/atom/common/node_includes.h +++ b/atom/common/node_includes.h @@ -29,6 +29,7 @@ #include "vendor/node/src/env-inl.h" #include "vendor/node/src/node.h" #include "vendor/node/src/node_buffer.h" +#include "vendor/node/src/node_debug_options.h" #include "vendor/node/src/node_internals.h" #endif // ATOM_COMMON_NODE_INCLUDES_H_ From 690b2e91c47c5825d579acccf02fcc192b43c264 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 09:34:55 -0700 Subject: [PATCH 1184/1195] Update docs for new --inspect support --- .../debugging-main-process-node-inspector.md | 131 ------------------ docs/tutorial/debugging-main-process.md | 18 +-- 2 files changed, 9 insertions(+), 140 deletions(-) delete mode 100644 docs/tutorial/debugging-main-process-node-inspector.md diff --git a/docs/tutorial/debugging-main-process-node-inspector.md b/docs/tutorial/debugging-main-process-node-inspector.md deleted file mode 100644 index 2c42ef3139a..00000000000 --- a/docs/tutorial/debugging-main-process-node-inspector.md +++ /dev/null @@ -1,131 +0,0 @@ -# Debugging the Main Process in node-inspector - -[`node-inspector`][node-inspector] provides a familiar DevTools GUI that can -be used in Chrome to debug Electron's main process, however, because -`node-inspector` relies on some native Node modules they must be rebuilt to -target the version of Electron you wish to debug. You can either rebuild -the `node-inspector` dependencies yourself, or let -[`electron-inspector`][electron-inspector] do it for you, both approaches are -covered in this document. - -**Note**: At the time of writing the latest release of `node-inspector` -(0.12.8) can't be rebuilt to target Electron 1.3.0 or later without patching -one of its dependencies. If you use `electron-inspector` it will take care of -this for you. - - -## Use `electron-inspector` for Debugging - -### 1. Install the [node-gyp required tools][node-gyp-required-tools] - -### 2. Install [`electron-rebuild`][electron-rebuild], if you haven't done so already. - -```shell -npm install electron-rebuild --save-dev -``` - -### 3. Install [`electron-inspector`][electron-inspector] - -```shell -npm install electron-inspector --save-dev -``` - -### 4. Start Electron - -Launch Electron with the `--debug` switch: - -```shell -electron --debug=5858 your/app -``` - -or, to pause execution on the first line of JavaScript: - -```shell -electron --debug-brk=5858 your/app -``` - -### 5. Start electron-inspector - -On macOS / Linux: - -```shell -node_modules/.bin/electron-inspector -``` - -On Windows: - -```shell -node_modules\\.bin\\electron-inspector -``` - -`electron-inspector` will need to rebuild `node-inspector` dependencies on the -first run, and any time you change your Electron version. The rebuild process -may require an internet connection to download Node headers and libs, and may -take a few minutes. - -### 6. Load the debugger UI - -Open http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858 in the Chrome -browser. You may have to click pause if starting with `--debug-brk` to force -the UI to update. - - -## Use `node-inspector` for Debugging - -### 1. Install the [node-gyp required tools][node-gyp-required-tools] - -### 2. Install [`node-inspector`][node-inspector] - -```bash -$ npm install node-inspector -``` - -### 3. Install [`node-pre-gyp`][node-pre-gyp] - -```bash -$ npm install node-pre-gyp -``` - -### 4. Recompile the `node-inspector` `v8` modules for Electron - -**Note:** Update the target argument to be your Electron version number - -```bash -$ node_modules/.bin/node-pre-gyp --target=1.2.5 --runtime=electron --fallback-to-build --directory node_modules/v8-debug/ --dist-url=https://atom.io/download/atom-shell reinstall -$ node_modules/.bin/node-pre-gyp --target=1.2.5 --runtime=electron --fallback-to-build --directory node_modules/v8-profiler/ --dist-url=https://atom.io/download/atom-shell reinstall -``` - -See also [How to install native modules][how-to-install-native-modules]. - -### 5. Enable debug mode for Electron - -You can either start Electron with a debug flag like: - -```bash -$ electron --debug=5858 your/app -``` - -or, to pause your script on the first line: - -```bash -$ electron --debug-brk=5858 your/app -``` - -### 6. Start the [`node-inspector`][node-inspector] server using Electron - -```bash -$ ELECTRON_RUN_AS_NODE=true path/to/electron.exe node_modules/node-inspector/bin/inspector.js -``` - -### 7. Load the debugger UI - -Open http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858 in the Chrome -browser. You may have to click pause if starting with `--debug-brk` to see the -entry line. - -[electron-inspector]: https://github.com/enlight/electron-inspector -[electron-rebuild]: https://github.com/electron/electron-rebuild -[node-inspector]: https://github.com/node-inspector/node-inspector -[node-pre-gyp]: https://github.com/mapbox/node-pre-gyp -[node-gyp-required-tools]: https://github.com/nodejs/node-gyp#installation -[how-to-install-native-modules]: using-native-node-modules.md#how-to-install-native-modules diff --git a/docs/tutorial/debugging-main-process.md b/docs/tutorial/debugging-main-process.md index fb5759e4995..94d7b0e18f0 100644 --- a/docs/tutorial/debugging-main-process.md +++ b/docs/tutorial/debugging-main-process.md @@ -3,31 +3,31 @@ The DevTools in an Electron browser window can only debug JavaScript that's executed in that window (i.e. the web pages). To debug JavaScript that's executed in the main process you will need to use an external debugger and -launch Electron with the `--debug` or `--debug-brk` switch. +launch Electron with the `--inspector` or `--inspector-brk` switch. ## Command Line Switches Use one of the following command line switches to enable debugging of the main process: -### `--debug=[port]` +### `--inspect=[port]` -Electron will listen for V8 debugger protocol messages on the specified `port`, +Electron will listen for V8 inspector protocol messages on the specified `port`, an external debugger will need to connect on this port. The default `port` is `5858`. ```shell -electron --debug=5858 your/app +electron --inspect=5858 your/app ``` -### `--debug-brk=[port]` +### `--inspect-brk=[port]` -Like `--debug` but pauses execution on the first line of JavaScript. +Like `--inspector` but pauses execution on the first line of JavaScript. ## External Debuggers -You will need to use a debugger that supports the V8 debugger protocol, -the following guides should help you to get started: +You will need to use a debugger that supports the V8 inspector protocol. +You can use Chrome to connect a debugger by visiting `chrome://inspect` +and selecting to inspect the launched Electron app present there. - [Debugging the Main Process in VSCode](debugging-main-process-vscode.md) -- [Debugging the Main Process in node-inspector](debugging-main-process-node-inspector.md) From 03c2d6f435a4768e4eaac65dd8ea33dfebc284f0 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 09:40:00 -0700 Subject: [PATCH 1185/1195] Make chrome instructions a list item --- docs/tutorial/debugging-main-process.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/tutorial/debugging-main-process.md b/docs/tutorial/debugging-main-process.md index 94d7b0e18f0..a30760671d0 100644 --- a/docs/tutorial/debugging-main-process.md +++ b/docs/tutorial/debugging-main-process.md @@ -27,7 +27,7 @@ Like `--inspector` but pauses execution on the first line of JavaScript. ## External Debuggers You will need to use a debugger that supports the V8 inspector protocol. -You can use Chrome to connect a debugger by visiting `chrome://inspect` -and selecting to inspect the launched Electron app present there. +- Connect Chrome by visiting `chrome://inspect` and selecting to inspect the + launched Electron app present there. - [Debugging the Main Process in VSCode](debugging-main-process-vscode.md) From e3160126d6a3ebd8c048ffa03e422a52bd248723 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 09:42:57 -0700 Subject: [PATCH 1186/1195] Update debug CLI flags --- docs/api/chrome-command-line-switches.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/chrome-command-line-switches.md b/docs/api/chrome-command-line-switches.md index 7308c5d4518..4aa809b02c1 100644 --- a/docs/api/chrome-command-line-switches.md +++ b/docs/api/chrome-command-line-switches.md @@ -28,7 +28,7 @@ Disables the disk cache for HTTP requests. Disable HTTP/2 and SPDY/3.1 protocols. -## --debug=`port` and --debug-brk=`port` +## --inspect=`port` and --inspect-brk=`port` Debug-related flags, see the [Debugging the Main Process][debugging-main-process] guide for details. From b549b20d2c4803029df1978fc2679186eaf622d9 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 11:16:32 -0700 Subject: [PATCH 1187/1195] Convert arg string to utf8 on Windows --- atom/browser/node_debugger.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/atom/browser/node_debugger.cc b/atom/browser/node_debugger.cc index 31898d4c251..0a7bece6b47 100644 --- a/atom/browser/node_debugger.cc +++ b/atom/browser/node_debugger.cc @@ -5,6 +5,7 @@ #include "atom/browser/node_debugger.h" #include "base/command_line.h" +#include "base/strings/utf_string_conversions.h" #include "libplatform/libplatform.h" namespace atom { @@ -21,8 +22,13 @@ void NodeDebugger::Start() { return; node::DebugOptions options; - for (auto& arg : base::CommandLine::ForCurrentProcess()->argv()) + for (auto& arg : base::CommandLine::ForCurrentProcess()->argv()) { +#if defined(OS_WIN) + options.ParseOption(base::UTF16ToUTF8(arg)); +#else options.ParseOption(arg); +#endif + } if (options.inspector_enabled()) { // Use custom platform since the gin platform does not work correctly From 5337b4ad943495f6eb487e39f282a693fe4115ea Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 19:10:25 -0700 Subject: [PATCH 1188/1195] Only define ICU constants in release builds --- atom/node/osfhandle.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/atom/node/osfhandle.cc b/atom/node/osfhandle.cc index e9ec03a5c81..f21f55a792a 100644 --- a/atom/node/osfhandle.cc +++ b/atom/node/osfhandle.cc @@ -6,9 +6,11 @@ #include +#if !defined(DEBUG) #define U_I18N_IMPLEMENTATION #define U_COMMON_IMPLEMENTATION #define U_COMBINED_IMPLEMENTATION +#endif #include "third_party/icu/source/common/unicode/ubidi.h" #include "third_party/icu/source/common/unicode/uchar.h" From 3f87880990ba4bcaf1555f75d23f8caf9e2725e4 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 15 May 2017 19:10:36 -0700 Subject: [PATCH 1189/1195] Bump node for inspector Windows fixes --- vendor/node | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/node b/vendor/node index 24ebf0c5bce..12445aade4a 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 24ebf0c5bce0a2e3b34f0fa2ef0995fb5a8bc91b +Subproject commit 12445aade4a398da629cdda6311854a0c6446bd5 From c419ebdd6da49579e520f6ea0d530b40d1bf8d39 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 16 May 2017 10:22:21 -0700 Subject: [PATCH 1190/1195] Remove unused test server --- .../stream_listen_socket.cc | 336 ------------------ .../stream_listen_socket.h | 152 -------- .../embedded_test_server/tcp_listen_socket.cc | 120 ------- .../embedded_test_server/tcp_listen_socket.h | 55 --- filenames.gypi | 4 - 5 files changed, 667 deletions(-) delete mode 100644 chromium_src/net/test/embedded_test_server/stream_listen_socket.cc delete mode 100644 chromium_src/net/test/embedded_test_server/stream_listen_socket.h delete mode 100644 chromium_src/net/test/embedded_test_server/tcp_listen_socket.cc delete mode 100644 chromium_src/net/test/embedded_test_server/tcp_listen_socket.h diff --git a/chromium_src/net/test/embedded_test_server/stream_listen_socket.cc b/chromium_src/net/test/embedded_test_server/stream_listen_socket.cc deleted file mode 100644 index 6cdc1e6ea93..00000000000 --- a/chromium_src/net/test/embedded_test_server/stream_listen_socket.cc +++ /dev/null @@ -1,336 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "net/test/embedded_test_server/stream_listen_socket.h" - -#include - -#if defined(OS_WIN) -// winsock2.h must be included first in order to ensure it is included before -// windows.h. -#include -#elif defined(OS_POSIX) -#include -#include -#include -#include -#include -#include "net/base/net_errors.h" -#endif - -#include "base/files/file_util.h" -#include "base/logging.h" -#include "base/memory/ref_counted.h" -#include "base/posix/eintr_wrapper.h" -#include "base/sys_byteorder.h" -#include "base/threading/platform_thread.h" -#include "build/build_config.h" -#include "net/base/ip_endpoint.h" -#include "net/base/net_errors.h" -#include "net/base/network_interfaces.h" -#include "net/base/sockaddr_storage.h" -#include "net/socket/socket_descriptor.h" - -using std::string; - -#if defined(OS_WIN) -typedef int socklen_t; -#endif // defined(OS_WIN) - -namespace net { - -namespace test_server { - -namespace { - -const int kReadBufSize = 4096; - -} // namespace - -#if defined(OS_WIN) -const int StreamListenSocket::kSocketError = SOCKET_ERROR; -#elif defined(OS_POSIX) -const int StreamListenSocket::kSocketError = -1; -#endif - -StreamListenSocket::StreamListenSocket(SocketDescriptor s, - StreamListenSocket::Delegate* del) - : socket_delegate_(del), -#if defined(OS_POSIX) - watcher_(FROM_HERE), -#endif - socket_(s), - reads_paused_(false), - has_pending_reads_(false) { -#if defined(OS_WIN) - socket_event_ = WSACreateEvent(); - // TODO(ibrar): error handling in case of socket_event_ == WSA_INVALID_EVENT. - WatchSocket(NOT_WAITING); -#elif defined(OS_POSIX) - wait_state_ = NOT_WAITING; -#endif -} - -StreamListenSocket::~StreamListenSocket() { - CloseSocket(); -#if defined(OS_WIN) - if (socket_event_) { - WSACloseEvent(socket_event_); - socket_event_ = WSA_INVALID_EVENT; - } -#endif -} - -void StreamListenSocket::Send(const char* bytes, - int len, - bool append_linefeed) { - SendInternal(bytes, len); - if (append_linefeed) - SendInternal("\r\n", 2); -} - -void StreamListenSocket::Send(const string& str, bool append_linefeed) { - Send(str.data(), static_cast(str.length()), append_linefeed); -} - -int StreamListenSocket::GetLocalAddress(IPEndPoint* address) const { - SockaddrStorage storage; - if (getsockname(socket_, storage.addr, &storage.addr_len)) { -#if defined(OS_WIN) - int err = WSAGetLastError(); -#else - int err = errno; -#endif - return MapSystemError(err); - } - if (!address->FromSockAddr(storage.addr, storage.addr_len)) - return ERR_ADDRESS_INVALID; - return OK; -} - -int StreamListenSocket::GetPeerAddress(IPEndPoint* address) const { - SockaddrStorage storage; - if (getpeername(socket_, storage.addr, &storage.addr_len)) { -#if defined(OS_WIN) - int err = WSAGetLastError(); -#else - int err = errno; -#endif - return MapSystemError(err); - } - - if (!address->FromSockAddr(storage.addr, storage.addr_len)) - return ERR_ADDRESS_INVALID; - - return OK; -} - -SocketDescriptor StreamListenSocket::AcceptSocket() { - SocketDescriptor conn = HANDLE_EINTR(accept(socket_, NULL, NULL)); - if (conn == kInvalidSocket) - LOG(ERROR) << "Error accepting connection."; - else - base::SetNonBlocking(conn); - return conn; -} - -void StreamListenSocket::SendInternal(const char* bytes, int len) { - char* send_buf = const_cast(bytes); - int len_left = len; - while (true) { - int sent = HANDLE_EINTR(send(socket_, send_buf, len_left, 0)); - if (sent == len_left) { // A shortcut to avoid extraneous checks. - break; - } - if (sent == kSocketError) { -#if defined(OS_WIN) - if (WSAGetLastError() != WSAEWOULDBLOCK) { - LOG(ERROR) << "send failed: WSAGetLastError()==" << WSAGetLastError(); -#elif defined(OS_POSIX) - if (errno != EWOULDBLOCK && errno != EAGAIN) { - LOG(ERROR) << "send failed: errno==" << errno; -#endif - break; - } - // Otherwise we would block, and now we have to wait for a retry. - // Fall through to PlatformThread::YieldCurrentThread() - } else { - // sent != len_left according to the shortcut above. - // Shift the buffer start and send the remainder after a short while. - send_buf += sent; - len_left -= sent; - } - base::PlatformThread::YieldCurrentThread(); - } -} - -void StreamListenSocket::Listen() { - int backlog = 10; // TODO(erikkay): maybe don't allow any backlog? - if (listen(socket_, backlog) == -1) { - // TODO(erikkay): error handling. - LOG(ERROR) << "Could not listen on socket."; - return; - } -#if defined(OS_POSIX) - WatchSocket(WAITING_ACCEPT); -#endif -} - -void StreamListenSocket::Read() { - char buf[kReadBufSize + 1]; // +1 for null termination. - int len; - do { - len = HANDLE_EINTR(recv(socket_, buf, kReadBufSize, 0)); - if (len == kSocketError) { -#if defined(OS_WIN) - int err = WSAGetLastError(); - if (err == WSAEWOULDBLOCK) { -#elif defined(OS_POSIX) - if (errno == EWOULDBLOCK || errno == EAGAIN) { -#endif - break; - } else { - // TODO(ibrar): some error handling required here. - break; - } - } else if (len == 0) { -#if defined(OS_POSIX) - // In Windows, Close() is called by OnObjectSignaled. In POSIX, we need - // to call it here. - Close(); -#endif - } else { - // TODO(ibrar): maybe change DidRead to take a length instead. - DCHECK_GT(len, 0); - DCHECK_LE(len, kReadBufSize); - buf[len] = 0; // Already create a buffer with +1 length. - socket_delegate_->DidRead(this, buf, len); - } - } while (len == kReadBufSize); -} - -void StreamListenSocket::Close() { -#if defined(OS_POSIX) - if (wait_state_ == NOT_WAITING) - return; - wait_state_ = NOT_WAITING; -#endif - UnwatchSocket(); - socket_delegate_->DidClose(this); -} - -void StreamListenSocket::CloseSocket() { - if (socket_ != kInvalidSocket) { - UnwatchSocket(); -#if defined(OS_WIN) - closesocket(socket_); -#elif defined(OS_POSIX) - close(socket_); -#endif - } -} - -void StreamListenSocket::WatchSocket(WaitState state) { -#if defined(OS_WIN) - WSAEventSelect(socket_, socket_event_, FD_ACCEPT | FD_CLOSE | FD_READ); - watcher_.StartWatchingOnce(socket_event_, this); -#elif defined(OS_POSIX) - // Implicitly calls StartWatchingFileDescriptor(). - base::MessageLoopForIO::current()->WatchFileDescriptor( - socket_, true, base::MessageLoopForIO::WATCH_READ, &watcher_, this); - wait_state_ = state; -#endif -} - -void StreamListenSocket::UnwatchSocket() { -#if defined(OS_WIN) - watcher_.StopWatching(); -#elif defined(OS_POSIX) - watcher_.StopWatchingFileDescriptor(); -#endif -} - -// TODO(ibrar): We can add these functions into OS dependent files. -#if defined(OS_WIN) -// MessageLoop watcher callback. -void StreamListenSocket::OnObjectSignaled(HANDLE object) { - WSANETWORKEVENTS ev; - if (kSocketError == WSAEnumNetworkEvents(socket_, socket_event_, &ev)) { - // TODO - return; - } - - // If both FD_CLOSE and FD_READ are set we only call Read(). - // This will cause OnObjectSignaled to be called immediately again - // unless this socket is destroyed in Read(). - if ((ev.lNetworkEvents & (FD_CLOSE | FD_READ)) == FD_CLOSE) { - Close(); - // Close might have deleted this object. We should return immediately. - return; - } - // The object was reset by WSAEnumNetworkEvents. Watch for the next signal. - watcher_.StartWatchingOnce(object, this); - - if (ev.lNetworkEvents == 0) { - // Occasionally the event is set even though there is no new data. - // The net seems to think that this is ignorable. - return; - } - if (ev.lNetworkEvents & FD_ACCEPT) { - Accept(); - } - if (ev.lNetworkEvents & FD_READ) { - if (reads_paused_) { - has_pending_reads_ = true; - } else { - Read(); - // Read might have deleted this object. We should return immediately. - } - } -} -#elif defined(OS_POSIX) -void StreamListenSocket::OnFileCanReadWithoutBlocking(int fd) { - switch (wait_state_) { - case WAITING_ACCEPT: - Accept(); - break; - case WAITING_READ: - if (reads_paused_) { - has_pending_reads_ = true; - } else { - Read(); - } - break; - default: - // Close() is called by Read() in the Linux case. - NOTREACHED(); - break; - } -} - -void StreamListenSocket::OnFileCanWriteWithoutBlocking(int fd) { - // MessagePumpLibevent callback, we don't listen for write events - // so we shouldn't ever reach here. - NOTREACHED(); -} - -#endif - -void StreamListenSocket::PauseReads() { - DCHECK(!reads_paused_); - reads_paused_ = true; -} - -void StreamListenSocket::ResumeReads() { - DCHECK(reads_paused_); - reads_paused_ = false; - if (has_pending_reads_) { - has_pending_reads_ = false; - Read(); - } -} - -} // namespace test_server - -} // namespace net diff --git a/chromium_src/net/test/embedded_test_server/stream_listen_socket.h b/chromium_src/net/test/embedded_test_server/stream_listen_socket.h deleted file mode 100644 index 00d4b58dcf3..00000000000 --- a/chromium_src/net/test/embedded_test_server/stream_listen_socket.h +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Stream-based listen socket implementation that handles reading and writing -// to the socket, but does not handle creating the socket nor connecting -// sockets, which are handled by subclasses on creation and in Accept, -// respectively. - -// StreamListenSocket handles IO asynchronously in the specified MessageLoop. -// This class is NOT thread safe. It uses WSAEVENT handles to monitor activity -// in a given MessageLoop. This means that callbacks will happen in that loop's -// thread always and that all other methods (including constructor and -// destructor) should also be called from the same thread. - -#ifndef NET_TEST_EMBEDDED_TEST_SERVER_STREAM_LISTEN_SOCKET_H_ -#define NET_TEST_EMBEDDED_TEST_SERVER_STREAM_LISTEN_SOCKET_H_ - -#include - -#include "build/build_config.h" - -#if defined(OS_WIN) -#include -#endif -#include -#if defined(OS_WIN) -#include "base/win/object_watcher.h" -#elif defined(OS_POSIX) -#include "base/message_loop/message_loop.h" -#endif - -#include "base/macros.h" -#include "base/compiler_specific.h" -#include "net/base/net_export.h" -#include "net/socket/socket_descriptor.h" - -namespace net { - -class IPEndPoint; - -namespace test_server { - -class StreamListenSocket : -#if defined(OS_WIN) - public base::win::ObjectWatcher::Delegate { -#elif defined(OS_POSIX) - public base::MessageLoopForIO::Watcher { -#endif - - public: - ~StreamListenSocket() override; - - // TODO(erikkay): this delegate should really be split into two parts - // to split up the listener from the connected socket. Perhaps this class - // should be split up similarly. - class Delegate { - public: - // |server| is the original listening Socket, connection is the new - // Socket that was created. - virtual void DidAccept(StreamListenSocket* server, - std::unique_ptr connection) = 0; - virtual void DidRead(StreamListenSocket* connection, - const char* data, - int len) = 0; - virtual void DidClose(StreamListenSocket* sock) = 0; - - protected: - virtual ~Delegate() {} - }; - - // Send data to the socket. - void Send(const char* bytes, int len, bool append_linefeed = false); - void Send(const std::string& str, bool append_linefeed = false); - - // Copies the local address to |address|. Returns a network error code. - // This method is virtual to support unit testing. - virtual int GetLocalAddress(IPEndPoint* address) const; - // Copies the peer address to |address|. Returns a network error code. - // This method is virtual to support unit testing. - virtual int GetPeerAddress(IPEndPoint* address) const; - - static const int kSocketError; - - protected: - enum WaitState { NOT_WAITING = 0, WAITING_ACCEPT = 1, WAITING_READ = 2 }; - - StreamListenSocket(SocketDescriptor s, Delegate* del); - - SocketDescriptor AcceptSocket(); - virtual void Accept() = 0; - - void Listen(); - void Read(); - void Close(); - void CloseSocket(); - - // Pass any value in case of Windows, because in Windows - // we are not using state. - void WatchSocket(WaitState state); - void UnwatchSocket(); - - Delegate* const socket_delegate_; - - private: - friend class TransportClientSocketTest; - - void SendInternal(const char* bytes, int len); - -#if defined(OS_WIN) - // ObjectWatcher delegate. - void OnObjectSignaled(HANDLE object) override; - base::win::ObjectWatcher watcher_; - HANDLE socket_event_; -#elif defined(OS_POSIX) - // Called by MessagePumpLibevent when the socket is ready to do I/O. - void OnFileCanReadWithoutBlocking(int fd) override; - void OnFileCanWriteWithoutBlocking(int fd) override; - WaitState wait_state_; - // The socket's libevent wrapper. - base::MessageLoopForIO::FileDescriptorWatcher watcher_; -#endif - - // NOTE: This is for unit test use only! - // Pause/Resume calling Read(). Note that ResumeReads() will also call - // Read() if there is anything to read. - void PauseReads(); - void ResumeReads(); - - const SocketDescriptor socket_; - bool reads_paused_; - bool has_pending_reads_; - - DISALLOW_COPY_AND_ASSIGN(StreamListenSocket); -}; - -// Abstract factory that must be subclassed for each subclass of -// StreamListenSocket. -class StreamListenSocketFactory { - public: - virtual ~StreamListenSocketFactory() {} - - // Returns a new instance of StreamListenSocket or NULL if an error occurred. - virtual std::unique_ptr CreateAndListen( - StreamListenSocket::Delegate* delegate) const = 0; -}; - -} // namespace test_server - -} // namespace net - -#endif // NET_TEST_EMBEDDED_TEST_SERVER_STREAM_LISTEN_SOCKET_H_ diff --git a/chromium_src/net/test/embedded_test_server/tcp_listen_socket.cc b/chromium_src/net/test/embedded_test_server/tcp_listen_socket.cc deleted file mode 100644 index 50aac809052..00000000000 --- a/chromium_src/net/test/embedded_test_server/tcp_listen_socket.cc +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "net/test/embedded_test_server/tcp_listen_socket.h" - -#if defined(OS_WIN) -// winsock2.h must be included first in order to ensure it is included before -// windows.h. -#include -#include -#elif defined(OS_POSIX) -#include -#include -#include -#include -#include -#include "net/base/net_errors.h" -#endif - -#include "base/logging.h" -#include "base/sys_byteorder.h" -#include "base/threading/platform_thread.h" -#include "build/build_config.h" -#include "net/base/network_interfaces.h" -#include "net/base/winsock_init.h" -#include "net/socket/socket_descriptor.h" - -using std::string; - -namespace net { - -namespace test_server { - -// static -std::unique_ptr TCPListenSocket::CreateAndListen( - const string& ip, - uint16_t port, - StreamListenSocket::Delegate* del) { - SocketDescriptor s = CreateAndBind(ip, port); - if (s == kInvalidSocket) - return std::unique_ptr(); - std::unique_ptr sock(new TCPListenSocket(s, del)); - sock->Listen(); - return sock; -} - -TCPListenSocket::TCPListenSocket(SocketDescriptor s, - StreamListenSocket::Delegate* del) - : StreamListenSocket(s, del) { -} - -TCPListenSocket::~TCPListenSocket() { -} - -SocketDescriptor TCPListenSocket::CreateAndBind(const string& ip, - uint16_t port) { - SocketDescriptor s = CreatePlatformSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (s != kInvalidSocket) { -#if defined(OS_POSIX) - // Allow rapid reuse. - static const int kOn = 1; - setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &kOn, sizeof(kOn)); -#endif - sockaddr_in addr; - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr.s_addr = inet_addr(ip.c_str()); - addr.sin_port = base::HostToNet16(port); - if (bind(s, reinterpret_cast(&addr), sizeof(addr))) { -#if defined(OS_WIN) - closesocket(s); -#elif defined(OS_POSIX) - close(s); -#endif - LOG(ERROR) << "Could not bind socket to " << ip << ":" << port; - s = kInvalidSocket; - } - } - return s; -} - -SocketDescriptor TCPListenSocket::CreateAndBindAnyPort(const string& ip, - uint16_t* port) { - SocketDescriptor s = CreateAndBind(ip, 0); - if (s == kInvalidSocket) - return kInvalidSocket; - sockaddr_in addr; - socklen_t addr_size = sizeof(addr); - bool failed = getsockname(s, reinterpret_cast(&addr), - &addr_size) != 0; - if (addr_size != sizeof(addr)) - failed = true; - if (failed) { - LOG(ERROR) << "Could not determine bound port, getsockname() failed"; -#if defined(OS_WIN) - closesocket(s); -#elif defined(OS_POSIX) - close(s); -#endif - return kInvalidSocket; - } - *port = base::NetToHost16(addr.sin_port); - return s; -} - -void TCPListenSocket::Accept() { - SocketDescriptor conn = AcceptSocket(); - if (conn == kInvalidSocket) - return; - std::unique_ptr sock(new TCPListenSocket(conn, socket_delegate_)); -#if defined(OS_POSIX) - sock->WatchSocket(WAITING_READ); -#endif - socket_delegate_->DidAccept(this, std::move(sock)); -} - -} // namespace test_server - -} // namespace net diff --git a/chromium_src/net/test/embedded_test_server/tcp_listen_socket.h b/chromium_src/net/test/embedded_test_server/tcp_listen_socket.h deleted file mode 100644 index db18fd0f0eb..00000000000 --- a/chromium_src/net/test/embedded_test_server/tcp_listen_socket.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef NET_TEST_EMBEDDED_TEST_SERVER_TCP_LISTEN_SOCKET_H_ -#define NET_TEST_EMBEDDED_TEST_SERVER_TCP_LISTEN_SOCKET_H_ - -#include - -#include "base/macros.h" -#include "net/base/net_export.h" -#include "net/socket/socket_descriptor.h" -#include "net/test/embedded_test_server/stream_listen_socket.h" - -namespace net { - -namespace test_server { - -// Implements a TCP socket. -class TCPListenSocket : public StreamListenSocket { - public: - ~TCPListenSocket() override; - - // Listen on port for the specified IP address. Use 127.0.0.1 to only - // accept local connections. - static std::unique_ptr CreateAndListen( - const std::string& ip, - uint16_t port, - StreamListenSocket::Delegate* del); - - protected: - TCPListenSocket(SocketDescriptor s, StreamListenSocket::Delegate* del); - - // Implements StreamListenSocket::Accept. - void Accept() override; - - private: - friend class EmbeddedTestServer; - friend class TCPListenSocketTester; - - // Get raw TCP socket descriptor bound to ip:port. - static SocketDescriptor CreateAndBind(const std::string& ip, uint16_t port); - - // Get raw TCP socket descriptor bound to ip and return port it is bound to. - static SocketDescriptor CreateAndBindAnyPort(const std::string& ip, - uint16_t* port); - - DISALLOW_COPY_AND_ASSIGN(TCPListenSocket); -}; - -} // namespace test_server - -} // namespace net - -#endif // NET_TEST_EMBEDDED_TEST_SERVER_TCP_LISTEN_SOCKET_H_ diff --git a/filenames.gypi b/filenames.gypi index 54ddf4dde19..570d20ab10c 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -634,10 +634,6 @@ 'chromium_src/extensions/common/url_pattern.h', 'chromium_src/library_loaders/libspeechd_loader.cc', 'chromium_src/library_loaders/libspeechd.h', - 'chromium_src/net/test/embedded_test_server/stream_listen_socket.cc', - 'chromium_src/net/test/embedded_test_server/stream_listen_socket.h', - 'chromium_src/net/test/embedded_test_server/tcp_listen_socket.cc', - 'chromium_src/net/test/embedded_test_server/tcp_listen_socket.h', '<@(native_mate_files)', '<(SHARED_INTERMEDIATE_DIR)/atom_natives.h', '<(SHARED_INTERMEDIATE_DIR)/grit/pdf_viewer_resources_map.cc', From d8aca08da71b71c980bb2a774bdca484727d86d7 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 16 May 2017 14:50:49 -0700 Subject: [PATCH 1191/1195] Set _debugWaitConnect on --inspect-brk --- atom/browser/node_debugger.cc | 8 ++++++++ atom/common/node_bindings.cc | 6 ------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/atom/browser/node_debugger.cc b/atom/browser/node_debugger.cc index 0a7bece6b47..2f17d468011 100644 --- a/atom/browser/node_debugger.cc +++ b/atom/browser/node_debugger.cc @@ -7,6 +7,7 @@ #include "base/command_line.h" #include "base/strings/utf_string_conversions.h" #include "libplatform/libplatform.h" +#include "native_mate/dictionary.h" namespace atom { @@ -35,6 +36,13 @@ void NodeDebugger::Start() { // with node's inspector agent platform_.reset(v8::platform::CreateDefaultPlatform()); + // Set process._debugWaitConnect if --inspect-brk was specified to stop + // the debugger on the first line + if (options.wait_for_connect()) { + mate::Dictionary process(env_->isolate(), env_->process_object()); + process.Set("_debugWaitConnect", true); + } + inspector->Start(platform_.get(), nullptr, options); } } diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index ae757b1da88..2a7be576276 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -198,12 +198,6 @@ node::Environment* NodeBindings::CreateEnvironment( PathService::Get(content::CHILD_PROCESS_EXE, &helper_exec_path); process.Set("helperExecPath", helper_exec_path); - // Set process._debugWaitConnect if --debug-brk was specified to stop - // the debugger on the first line - if (browser_env_ == BROWSER && - base::CommandLine::ForCurrentProcess()->HasSwitch("debug-brk")) - process.Set("_debugWaitConnect", true); - return env; } From d34be4c0a6a05225556aa604c2c27e634cedcd02 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 16 May 2017 15:01:53 -0700 Subject: [PATCH 1192/1195] Upgrade node for protocol from libcc --- vendor/node | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/node b/vendor/node index 12445aade4a..3cdf4532cf3 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 12445aade4a398da629cdda6311854a0c6446bd5 +Subproject commit 3cdf4532cf3da20af37e57cbbd59eb860be233aa From 3f4abc6323717ab1158b193b44996eb783cab203 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 17 May 2017 08:52:25 -0700 Subject: [PATCH 1193/1195] Upgrade to electron/libchromiumcontent@ecc5298428a --- script/lib/config.py | 2 +- vendor/libchromiumcontent | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/lib/config.py b/script/lib/config.py index e23c18d9942..4a55bf1fb06 100644 --- a/script/lib/config.py +++ b/script/lib/config.py @@ -9,7 +9,7 @@ import sys BASE_URL = os.getenv('LIBCHROMIUMCONTENT_MIRROR') or \ 'https://s3.amazonaws.com/github-janky-artifacts/libchromiumcontent' LIBCHROMIUMCONTENT_COMMIT = os.getenv('LIBCHROMIUMCONTENT_COMMIT') or \ - '44a803957cb27610c38f7e859016ac257959aeb5' + 'ecc5298428a02f8acb9af285c75e1491715ae4dd' PLATFORM = { 'cygwin': 'win32', diff --git a/vendor/libchromiumcontent b/vendor/libchromiumcontent index 44a803957cb..ecc5298428a 160000 --- a/vendor/libchromiumcontent +++ b/vendor/libchromiumcontent @@ -1 +1 @@ -Subproject commit 44a803957cb27610c38f7e859016ac257959aeb5 +Subproject commit ecc5298428a02f8acb9af285c75e1491715ae4dd From e75c0e47c29815d99b071a68aae82f765b999fd9 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 17 May 2017 14:58:09 -0700 Subject: [PATCH 1194/1195] atom-shell -> electron in node_release_urlbase --- common.gypi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common.gypi b/common.gypi index 6f1ad5f7521..fff12d9b366 100644 --- a/common.gypi +++ b/common.gypi @@ -16,7 +16,7 @@ 'openssl_no_asm': 1, 'use_openssl_def': 0, 'OPENSSL_PRODUCT': 'libopenssl.a', - 'node_release_urlbase': 'https://atom.io/download/atom-shell', + 'node_release_urlbase': 'https://atom.io/download/electron', 'node_byteorder': ' Date: Wed, 17 May 2017 16:53:30 -0700 Subject: [PATCH 1195/1195] Assert pid after load finishes --- spec/api-web-contents-spec.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spec/api-web-contents-spec.js b/spec/api-web-contents-spec.js index 186a6458b17..9bbeefc4d7a 100644 --- a/spec/api-web-contents-spec.js +++ b/spec/api-web-contents-spec.js @@ -325,13 +325,16 @@ describe('webContents module', function () { }) describe('getOSProcessId()', function () { - it('returns a valid procress id', function () { + it('returns a valid procress id', function (done) { assert.strictEqual(w.webContents.getOSProcessId(), 0) + w.webContents.once('did-finish-load', () => { + const pid = w.webContents.getOSProcessId() + assert.equal(typeof pid, 'number') + assert(pid > 0, `pid ${pid} is not greater than 0`) + done() + }) w.loadURL('about:blank') - const pid = w.webContents.getOSProcessId() - assert(typeof pid === 'number', 'is a number') - assert(pid > 0, 'superior to 0') }) })