1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef IOS_WEB_WEB_STATE_WEB_CONTROLLER_OBSERVER_BRIDGE_H_
6 #define IOS_WEB_WEB_STATE_WEB_CONTROLLER_OBSERVER_BRIDGE_H_
10 #import "base/ios/weak_nsobject.h"
11 #include "ios/web/public/web_state/web_state_observer.h"
13 @
class CRWWebController
;
14 @protocol CRWWebControllerObserver
;
18 class DictionaryValue
;
25 // This class allows to register a CRWWebControllerObserver instance as
26 // a WebStateObserver.
27 // It listens to WebStateObserver calls and forwards them to the underlying
28 // CRWWebControllerObserver.
29 // TODO(droger): Remove this class once all CRWWebControllerObserver have been
30 // converted to WebStateObserver and WebState::ScriptCommandCallback.
31 class WebControllerObserverBridge
: public WebStateObserver
{
33 // |web_controller_observer| and |web_controller| must not be nil, and must
34 // outlive this WebControllerObserverBridge.
35 WebControllerObserverBridge(
36 id
<CRWWebControllerObserver
> web_controller_observer
,
38 CRWWebController
* web_controller
);
40 ~WebControllerObserverBridge() override
;
42 // Gets the underlying CRWWebControllerObserver.
43 id
<CRWWebControllerObserver
> web_controller_observer() const {
44 return web_controller_observer_
;
48 // WebStateObserver implementation.
49 void PageLoaded(PageLoadCompletionStatus load_completion_status
) override
;
51 // Callback for script commands.
52 bool ScriptCommandReceived(const base::DictionaryValue
& value
,
54 bool user_is_interacting
);
56 base::WeakNSProtocol
<id
<CRWWebControllerObserver
>> web_controller_observer_
;
57 base::WeakNSObject
<CRWWebController
> web_controller_
;
58 std::string script_command_callback_prefix_
;
60 DISALLOW_COPY_AND_ASSIGN(WebControllerObserverBridge
);
65 #endif // IOS_WEB_WEB_STATE_WEB_CONTROLLER_OBSERVER_BRIDGE_H_