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

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

Issue 2853443002: Switch SupportsUserData uses to use unique_ptr. (Closed)
Patch Set: Created 3 years, 7 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 "base/memory/ptr_util.h"
12 #include "ios/web/public/browser_state.h" 13 #include "ios/web/public/browser_state.h"
13 #import "ios/web/web_state/js/page_script_util.h" 14 #import "ios/web/web_state/js/page_script_util.h"
14 #import "ios/web/web_state/ui/crw_wk_script_message_router.h" 15 #import "ios/web/web_state/ui/crw_wk_script_message_router.h"
15 16
16 namespace web { 17 namespace web {
17 18
18 namespace { 19 namespace {
19 // A key used to associate a WKWebViewConfigurationProvider with a BrowserState. 20 // A key used to associate a WKWebViewConfigurationProvider with a BrowserState.
20 const char kWKWebViewConfigProviderKeyName[] = "wk_web_view_config_provider"; 21 const char kWKWebViewConfigProviderKeyName[] = "wk_web_view_config_provider";
21 22
22 // Returns an autoreleased instance of WKUserScript to be added to 23 // Returns an autoreleased instance of WKUserScript to be added to
23 // configuration's userContentController. 24 // configuration's userContentController.
24 WKUserScript* InternalGetEarlyPageScript(BrowserState* browser_state) { 25 WKUserScript* InternalGetEarlyPageScript(BrowserState* browser_state) {
25 return [[[WKUserScript alloc] 26 return [[[WKUserScript alloc]
26 initWithSource:GetEarlyPageScript(browser_state) 27 initWithSource:GetEarlyPageScript(browser_state)
27 injectionTime:WKUserScriptInjectionTimeAtDocumentStart 28 injectionTime:WKUserScriptInjectionTimeAtDocumentStart
28 forMainFrameOnly:YES] autorelease]; 29 forMainFrameOnly:YES] autorelease];
29 } 30 }
30 31
31 } // namespace 32 } // namespace
32 33
33 // static 34 // static
34 WKWebViewConfigurationProvider& 35 WKWebViewConfigurationProvider&
35 WKWebViewConfigurationProvider::FromBrowserState(BrowserState* browser_state) { 36 WKWebViewConfigurationProvider::FromBrowserState(BrowserState* browser_state) {
36 DCHECK([NSThread isMainThread]); 37 DCHECK([NSThread isMainThread]);
37 DCHECK(browser_state); 38 DCHECK(browser_state);
38 if (!browser_state->GetUserData(kWKWebViewConfigProviderKeyName)) { 39 if (!browser_state->GetUserData(kWKWebViewConfigProviderKeyName)) {
39 browser_state->SetUserData( 40 browser_state->SetUserData(
40 kWKWebViewConfigProviderKeyName, 41 kWKWebViewConfigProviderKeyName,
41 new WKWebViewConfigurationProvider(browser_state)); 42 base::WrapUnique(new WKWebViewConfigurationProvider(browser_state)));
42 } 43 }
43 return *(static_cast<WKWebViewConfigurationProvider*>( 44 return *(static_cast<WKWebViewConfigurationProvider*>(
44 browser_state->GetUserData(kWKWebViewConfigProviderKeyName))); 45 browser_state->GetUserData(kWKWebViewConfigProviderKeyName)));
45 } 46 }
46 47
47 WKWebViewConfigurationProvider::WKWebViewConfigurationProvider( 48 WKWebViewConfigurationProvider::WKWebViewConfigurationProvider(
48 BrowserState* browser_state) 49 BrowserState* browser_state)
49 : browser_state_(browser_state) {} 50 : browser_state_(browser_state) {}
50 51
51 WKWebViewConfigurationProvider::~WKWebViewConfigurationProvider() { 52 WKWebViewConfigurationProvider::~WKWebViewConfigurationProvider() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 configuration_.reset(); 95 configuration_.reset();
95 router_.reset(); 96 router_.reset();
96 // Make sure that no one retains configuration, router, processPool. 97 // Make sure that no one retains configuration, router, processPool.
97 DCHECK(!weak_configuration); 98 DCHECK(!weak_configuration);
98 DCHECK(!weak_router); 99 DCHECK(!weak_router);
99 // TODO(crbug.com/522672): Enable this DCHECK. 100 // TODO(crbug.com/522672): Enable this DCHECK.
100 // DCHECK(!weak_process_pool); 101 // DCHECK(!weak_process_pool);
101 } 102 }
102 103
103 } // namespace web 104 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698