OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chrome/browser/ui/dialogs/javascript_dialog_blocking_util.h" | 5 #import "ios/chrome/browser/ui/dialogs/javascript_dialog_blocking_util.h" |
6 | 6 |
7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | |
10 #include "ios/web/public/web_state/web_state.h" | 11 #include "ios/web/public/web_state/web_state.h" |
11 #include "ios/web/public/web_state/web_state_observer.h" | 12 #include "ios/web/public/web_state/web_state_observer.h" |
12 | 13 |
13 #if !defined(__has_feature) || !__has_feature(objc_arc) | 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
14 #error "This file requires ARC support." | 15 #error "This file requires ARC support." |
15 #endif | 16 #endif |
16 | 17 |
17 namespace { | 18 namespace { |
18 // The key under which JavaScriptDialogBlockingStates are associated with | 19 // The key under which JavaScriptDialogBlockingStates are associated with |
19 // their WebStates. | 20 // their WebStates. |
(...skipping 23 matching lines...) Expand all Loading... | |
43 | 44 |
44 // The JavaScriptDialogBlockingState owned by this wrapper. | 45 // The JavaScriptDialogBlockingState owned by this wrapper. |
45 JavaScriptDialogBlockingState* state() const { return state_.get(); } | 46 JavaScriptDialogBlockingState* state() const { return state_.get(); } |
46 void set_state(JavaScriptDialogBlockingState* state) { state_.reset(state); } | 47 void set_state(JavaScriptDialogBlockingState* state) { state_.reset(state); } |
47 | 48 |
48 private: | 49 private: |
49 std::unique_ptr<JavaScriptDialogBlockingState> state_; | 50 std::unique_ptr<JavaScriptDialogBlockingState> state_; |
50 | 51 |
51 // Private constructor associating the newly created object with |web_state| | 52 // Private constructor associating the newly created object with |web_state| |
52 // via its SupportsUserData. | 53 // via its SupportsUserData. |
53 explicit JavaScriptDialogBlockingStateWrapper(web::WebState* web_state) | 54 explicit JavaScriptDialogBlockingStateWrapper(web::WebState* web_state) |
sdefresne
2017/04/28 10:07:05
Can you change this constructor to not take the we
| |
54 : state_(nullptr) { | 55 : state_(nullptr) { |
55 DCHECK(web_state); | 56 DCHECK(web_state); |
56 web_state->SetUserData(kBlockingStateKey, this); | 57 web_state->SetUserData(kBlockingStateKey, base::WrapUnique(this)); |
57 } | 58 } |
58 }; | 59 }; |
59 | 60 |
60 #pragma mark - JavaScriptDialogBlockingState | 61 #pragma mark - JavaScriptDialogBlockingState |
61 | 62 |
62 // Wrapper class used to associated JavaScriptDialogBlockingStates with their | 63 // Wrapper class used to associated JavaScriptDialogBlockingStates with their |
63 // WebStates. | 64 // WebStates. |
64 class JavaScriptDialogBlockingState : public web::WebStateObserver { | 65 class JavaScriptDialogBlockingState : public web::WebStateObserver { |
65 public: | 66 public: |
66 // Factory method. Guaranteed to return a non-null value. | 67 // Factory method. Guaranteed to return a non-null value. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 DCHECK(web_state); | 132 DCHECK(web_state); |
132 return JavaScriptDialogBlockingState::FromWebState(web_state) | 133 return JavaScriptDialogBlockingState::FromWebState(web_state) |
133 ->ShouldBlockDialogs(); | 134 ->ShouldBlockDialogs(); |
134 } | 135 } |
135 | 136 |
136 void DialogBlockingOptionSelected(web::WebState* web_state) { | 137 void DialogBlockingOptionSelected(web::WebState* web_state) { |
137 DCHECK(web_state); | 138 DCHECK(web_state); |
138 JavaScriptDialogBlockingState::FromWebState(web_state)->SetShouldBlockDialogs( | 139 JavaScriptDialogBlockingState::FromWebState(web_state)->SetShouldBlockDialogs( |
139 true); | 140 true); |
140 } | 141 } |
OLD | NEW |