Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: ios/web/web_state/ui/wk_web_view_configuration_provider.mm

Issue 2741343015: Add a BrowserState* parameter to GetEarlyPageScript(). (Closed)
Patch Set: Fix errors. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h" 5 #import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
6 6
7 #import <Foundation/Foundation.h> 7 #import <Foundation/Foundation.h>
8 #import <WebKit/WebKit.h> 8 #import <WebKit/WebKit.h>
9 9
10 #import "base/ios/weak_nsobject.h" 10 #import "base/ios/weak_nsobject.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "ios/web/public/browser_state.h" 12 #include "ios/web/public/browser_state.h"
13 #import "ios/web/web_state/js/page_script_util.h" 13 #import "ios/web/web_state/js/page_script_util.h"
14 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" 14 #import "ios/web/web_state/ui/crw_wk_script_message_router.h"
15 15
16 namespace web { 16 namespace web {
17 17
18 namespace { 18 namespace {
19 // A key used to associate a WKWebViewConfigurationProvider with a BrowserState. 19 // A key used to associate a WKWebViewConfigurationProvider with a BrowserState.
20 const char kWKWebViewConfigProviderKeyName[] = "wk_web_view_config_provider"; 20 const char kWKWebViewConfigProviderKeyName[] = "wk_web_view_config_provider";
21 21
22 // Returns an autoreleased instance of WKUserScript to be added to 22 // Returns an autoreleased instance of WKUserScript to be added to
23 // configuration's userContentController. 23 // configuration's userContentController.
24 WKUserScript* InternalGetEarlyPageScript() { 24 WKUserScript* InternalGetEarlyPageScript(BrowserState* browser_state) {
25 return [[[WKUserScript alloc] 25 return [[[WKUserScript alloc]
26 initWithSource:GetEarlyPageScript() 26 initWithSource:GetEarlyPageScript(browser_state)
27 injectionTime:WKUserScriptInjectionTimeAtDocumentStart 27 injectionTime:WKUserScriptInjectionTimeAtDocumentStart
28 forMainFrameOnly:YES] autorelease]; 28 forMainFrameOnly:YES] autorelease];
29 } 29 }
30 30
31 } // namespace 31 } // namespace
32 32
33 // static 33 // static
34 WKWebViewConfigurationProvider& 34 WKWebViewConfigurationProvider&
35 WKWebViewConfigurationProvider::FromBrowserState(BrowserState* browser_state) { 35 WKWebViewConfigurationProvider::FromBrowserState(BrowserState* browser_state) {
36 DCHECK([NSThread isMainThread]); 36 DCHECK([NSThread isMainThread]);
37 DCHECK(browser_state); 37 DCHECK(browser_state);
38 if (!browser_state->GetUserData(kWKWebViewConfigProviderKeyName)) { 38 if (!browser_state->GetUserData(kWKWebViewConfigProviderKeyName)) {
39 bool is_off_the_record = browser_state->IsOffTheRecord(); 39 bool is_off_the_record = browser_state->IsOffTheRecord();
40 browser_state->SetUserData( 40 browser_state->SetUserData(
41 kWKWebViewConfigProviderKeyName, 41 kWKWebViewConfigProviderKeyName,
42 new WKWebViewConfigurationProvider(is_off_the_record)); 42 new WKWebViewConfigurationProvider(is_off_the_record, browser_state));
43 } 43 }
44 return *(static_cast<WKWebViewConfigurationProvider*>( 44 return *(static_cast<WKWebViewConfigurationProvider*>(
45 browser_state->GetUserData(kWKWebViewConfigProviderKeyName))); 45 browser_state->GetUserData(kWKWebViewConfigProviderKeyName)));
46 } 46 }
47 47
48 WKWebViewConfigurationProvider::WKWebViewConfigurationProvider( 48 WKWebViewConfigurationProvider::WKWebViewConfigurationProvider(
49 bool is_off_the_record) 49 bool is_off_the_record,
50 : is_off_the_record_(is_off_the_record) {} 50 BrowserState* browser_state)
51 : is_off_the_record_(is_off_the_record), browser_state_(browser_state) {}
51 52
52 WKWebViewConfigurationProvider::~WKWebViewConfigurationProvider() { 53 WKWebViewConfigurationProvider::~WKWebViewConfigurationProvider() {
53 } 54 }
54 55
55 WKWebViewConfiguration* 56 WKWebViewConfiguration*
56 WKWebViewConfigurationProvider::GetWebViewConfiguration() { 57 WKWebViewConfigurationProvider::GetWebViewConfiguration() {
57 DCHECK([NSThread isMainThread]); 58 DCHECK([NSThread isMainThread]);
58 if (!configuration_) { 59 if (!configuration_) {
59 configuration_.reset([[WKWebViewConfiguration alloc] init]); 60 configuration_.reset([[WKWebViewConfiguration alloc] init]);
60 if (is_off_the_record_) { 61 if (is_off_the_record_) {
61 [configuration_ 62 [configuration_
62 setWebsiteDataStore:[WKWebsiteDataStore nonPersistentDataStore]]; 63 setWebsiteDataStore:[WKWebsiteDataStore nonPersistentDataStore]];
63 } 64 }
64 // API available on iOS 9, although doesn't appear to enable inline playback 65 // API available on iOS 9, although doesn't appear to enable inline playback
65 // Works as intended on iOS 10+ 66 // Works as intended on iOS 10+
66 [configuration_ setAllowsInlineMediaPlayback:YES]; 67 [configuration_ setAllowsInlineMediaPlayback:YES];
67 // setJavaScriptCanOpenWindowsAutomatically is required to support popups. 68 // setJavaScriptCanOpenWindowsAutomatically is required to support popups.
68 [[configuration_ preferences] setJavaScriptCanOpenWindowsAutomatically:YES]; 69 [[configuration_ preferences] setJavaScriptCanOpenWindowsAutomatically:YES];
69 [[configuration_ userContentController] 70 [[configuration_ userContentController]
70 addUserScript:InternalGetEarlyPageScript()]; 71 addUserScript:InternalGetEarlyPageScript(browser_state_)];
71 } 72 }
72 // Prevent callers from changing the internals of configuration. 73 // Prevent callers from changing the internals of configuration.
73 return [[configuration_ copy] autorelease]; 74 return [[configuration_ copy] autorelease];
74 } 75 }
75 76
76 CRWWKScriptMessageRouter* 77 CRWWKScriptMessageRouter*
77 WKWebViewConfigurationProvider::GetScriptMessageRouter() { 78 WKWebViewConfigurationProvider::GetScriptMessageRouter() {
78 DCHECK([NSThread isMainThread]); 79 DCHECK([NSThread isMainThread]);
79 if (!router_) { 80 if (!router_) {
80 WKUserContentController* userContentController = 81 WKUserContentController* userContentController =
(...skipping 14 matching lines...) Expand all
95 configuration_.reset(); 96 configuration_.reset();
96 router_.reset(); 97 router_.reset();
97 // Make sure that no one retains configuration, router, processPool. 98 // Make sure that no one retains configuration, router, processPool.
98 DCHECK(!weak_configuration); 99 DCHECK(!weak_configuration);
99 DCHECK(!weak_router); 100 DCHECK(!weak_router);
100 // TODO(crbug.com/522672): Enable this DCHECK. 101 // TODO(crbug.com/522672): Enable this DCHECK.
101 // DCHECK(!weak_process_pool); 102 // DCHECK(!weak_process_pool);
102 } 103 }
103 104
104 } // namespace web 105 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698