| 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 #ifndef IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_DELEGATE_BRIDGE_H_ | 5 #ifndef IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_DELEGATE_BRIDGE_H_ |
| 6 #define IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_DELEGATE_BRIDGE_H_ | 6 #define IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_DELEGATE_BRIDGE_H_ |
| 7 | 7 |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 | 9 |
| 10 #import "base/ios/weak_nsobject.h" | 10 #import "base/ios/weak_nsobject.h" |
| 11 #include "ios/web/public/web_state/web_state_delegate.h" | 11 #include "ios/web/public/web_state/web_state_delegate.h" |
| 12 | 12 |
| 13 // Objective-C interface for web::WebStateDelegate. | 13 // Objective-C interface for web::WebStateDelegate. |
| 14 @protocol CRWWebStateDelegate<NSObject> | 14 @protocol CRWWebStateDelegate<NSObject> |
| 15 @optional | 15 @optional |
| 16 | 16 |
| 17 // Returns the WebState the URL is opened in, or nullptr if the URL wasn't |
| 18 // opened immediately. |
| 19 - (web::WebState*)webState:(web::WebState*)webState |
| 20 openURLWithParams:(const web::WebState::OpenURLParams&)params; |
| 21 |
| 17 // Called when the page has made some progress loading. |progress| is a value | 22 // Called when the page has made some progress loading. |progress| is a value |
| 18 // between 0.0 (nothing loaded) to 1.0 (page fully loaded). | 23 // between 0.0 (nothing loaded) to 1.0 (page fully loaded). |
| 19 - (void)webState:(web::WebState*)webState didChangeProgress:(double)progress; | 24 - (void)webState:(web::WebState*)webState didChangeProgress:(double)progress; |
| 20 | 25 |
| 21 // Called when the user triggers the context menu with the given | 26 // Called when the user triggers the context menu with the given |
| 22 // |ContextMenuParams|. Returns YES if the context menu operation was | 27 // |ContextMenuParams|. Returns YES if the context menu operation was |
| 23 // handled by the delegate. If this method is not implemented, the system | 28 // handled by the delegate. If this method is not implemented, the system |
| 24 // context menu will be displayed. | 29 // context menu will be displayed. |
| 25 - (BOOL)webState:(web::WebState*)webState | 30 - (BOOL)webState:(web::WebState*)webState |
| 26 handleContextMenu:(const web::ContextMenuParams&)params; | 31 handleContextMenu:(const web::ContextMenuParams&)params; |
| 27 | 32 |
| 28 // Returns a pointer to a service to manage dialogs. May return null in which | 33 // Returns a pointer to a service to manage dialogs. May return null in which |
| 29 // case dialogs aren't shown. | 34 // case dialogs aren't shown. |
| 30 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState: | 35 - (web::JavaScriptDialogPresenter*)javaScriptDialogPresenterForWebState: |
| 31 (web::WebState*)webState; | 36 (web::WebState*)webState; |
| 32 | 37 |
| 33 @end | 38 @end |
| 34 | 39 |
| 35 namespace web { | 40 namespace web { |
| 36 | 41 |
| 37 // Adapter to use an id<CRWWebStateDelegate> as a web::WebStateDelegate. | 42 // Adapter to use an id<CRWWebStateDelegate> as a web::WebStateDelegate. |
| 38 class WebStateDelegateBridge : public web::WebStateDelegate { | 43 class WebStateDelegateBridge : public web::WebStateDelegate { |
| 39 public: | 44 public: |
| 40 explicit WebStateDelegateBridge(id<CRWWebStateDelegate> delegate); | 45 explicit WebStateDelegateBridge(id<CRWWebStateDelegate> delegate); |
| 41 ~WebStateDelegateBridge() override; | 46 ~WebStateDelegateBridge() override; |
| 42 | 47 |
| 43 // web::WebStateDelegate methods. | 48 // web::WebStateDelegate methods. |
| 49 WebState* OpenURLFromWebState(WebState*, |
| 50 const WebState::OpenURLParams&) override; |
| 44 void LoadProgressChanged(WebState* source, double progress) override; | 51 void LoadProgressChanged(WebState* source, double progress) override; |
| 45 bool HandleContextMenu(WebState* source, | 52 bool HandleContextMenu(WebState* source, |
| 46 const ContextMenuParams& params) override; | 53 const ContextMenuParams& params) override; |
| 47 JavaScriptDialogPresenter* GetJavaScriptDialogPresenter( | 54 JavaScriptDialogPresenter* GetJavaScriptDialogPresenter( |
| 48 WebState* source) override; | 55 WebState* source) override; |
| 49 | 56 |
| 50 private: | 57 private: |
| 51 // CRWWebStateDelegate which receives forwarded calls. | 58 // CRWWebStateDelegate which receives forwarded calls. |
| 52 base::WeakNSProtocol<id<CRWWebStateDelegate>> delegate_; | 59 base::WeakNSProtocol<id<CRWWebStateDelegate>> delegate_; |
| 53 DISALLOW_COPY_AND_ASSIGN(WebStateDelegateBridge); | 60 DISALLOW_COPY_AND_ASSIGN(WebStateDelegateBridge); |
| 54 }; | 61 }; |
| 55 | 62 |
| 56 } // web | 63 } // web |
| 57 | 64 |
| 58 #endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_DELEGATE_BRIDGE_H_ | 65 #endif // IOS_WEB_PUBLIC_WEB_STATE_WEB_STATE_DELEGATE_BRIDGE_H_ |
| OLD | NEW |