| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_COMPONENT_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_DELE
GATE_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_COMPONENT_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_DELE
GATE_ANDROID_H_ |
| 6 #define CHROME_BROWSER_COMPONENT_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_DELE
GATE_ANDROID_H_ | 6 #define CHROME_BROWSER_COMPONENT_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_DELE
GATE_ANDROID_H_ |
| 7 | 7 |
| 8 #include "base/android/jni_helper.h" | 8 #include "base/android/jni_helper.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/public/browser/native_web_keyboard_event.h" | 12 #include "content/public/browser/native_web_keyboard_event.h" |
| 13 #include "content/public/browser/web_contents_delegate.h" | 13 #include "content/public/browser/web_contents_delegate.h" |
| 14 #include "content/public/browser/web_contents_observer.h" | 14 #include "content/public/browser/web_contents_observer.h" |
| 15 #include "content/public/common/javascript_message_type.h" | 15 #include "content/public/common/javascript_message_type.h" |
| 16 #include "content/public/common/referrer.h" | 16 #include "content/public/common/referrer.h" |
| 17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 class JavaScriptDialogCreator; | 21 class JavaScriptDialogCreator; |
| 22 class RenderViewHost; | 22 class RenderViewHost; |
| 23 class WebContents; | 23 class WebContents; |
| 24 class WebContentsObserver; | 24 class WebContentsObserver; |
| 25 struct NativeWebKeyboardEvent; | 25 struct NativeWebKeyboardEvent; |
| 26 } | |
| 27 | |
| 28 namespace web_contents_delegate_android { | |
| 29 | 26 |
| 30 enum WebContentsDelegateLogLevel { | 27 enum WebContentsDelegateLogLevel { |
| 31 // Equivalent of WebCore::WebConsoleMessage::LevelTip. | 28 // Equivalent of WebCore::WebConsoleMessage::LevelTip. |
| 32 WEB_CONTENTS_DELEGATE_LOG_LEVEL_TIP = 0, | 29 WEB_CONTENTS_DELEGATE_LOG_LEVEL_TIP = 0, |
| 33 // Equivalent of WebCore::WebConsoleMessage::LevelLog. | 30 // Equivalent of WebCore::WebConsoleMessage::LevelLog. |
| 34 WEB_CONTENTS_DELEGATE_LOG_LEVEL_LOG = 1, | 31 WEB_CONTENTS_DELEGATE_LOG_LEVEL_LOG = 1, |
| 35 // Equivalent of WebCore::WebConsoleMessage::LevelWarning. | 32 // Equivalent of WebCore::WebConsoleMessage::LevelWarning. |
| 36 WEB_CONTENTS_DELEGATE_LOG_LEVEL_WARNING = 2, | 33 WEB_CONTENTS_DELEGATE_LOG_LEVEL_WARNING = 2, |
| 37 // Equivalent of WebCore::WebConsoleMessage::LevelError. | 34 // Equivalent of WebCore::WebConsoleMessage::LevelError. |
| 38 WEB_CONTENTS_DELEGATE_LOG_LEVEL_ERROR = 3, | 35 WEB_CONTENTS_DELEGATE_LOG_LEVEL_ERROR = 3, |
| 39 }; | 36 }; |
| 40 | 37 |
| 41 | 38 |
| 42 // Native underpinnings of WebContentsDelegateAndroid.java. Provides a default | 39 // Native underpinnings of WebContentsDelegateAndroid.java. Provides a default |
| 43 // delegate for WebContents to forward calls to the java peer. The embedding | 40 // delegate for WebContents to forward calls to the java peer. The embedding |
| 44 // application may subclass and override methods on either the C++ or Java side | 41 // application may subclass and override methods on either the C++ or Java side |
| 45 // as required. | 42 // as required. |
| 46 class WebContentsDelegateAndroid : public content::WebContentsDelegate { | 43 class WebContentsDelegateAndroid : public WebContentsDelegate { |
| 47 public: | 44 public: |
| 48 WebContentsDelegateAndroid(JNIEnv* env, jobject obj); | 45 WebContentsDelegateAndroid(JNIEnv* env, jobject obj); |
| 49 virtual ~WebContentsDelegateAndroid(); | 46 virtual ~WebContentsDelegateAndroid(); |
| 50 | 47 |
| 51 // Binds this WebContentsDelegateAndroid to the passed WebContents instance, | 48 // Binds this WebContentsDelegateAndroid to the passed WebContents instance, |
| 52 // such that when that WebContents is destroyed, this | 49 // such that when that WebContents is destroyed, this |
| 53 // WebContentsDelegateAndroid instance will be destroyed too. | 50 // WebContentsDelegateAndroid instance will be destroyed too. |
| 54 void SetOwnerWebContents(content::WebContents* contents); | 51 void SetOwnerWebContents(WebContents* contents); |
| 55 | 52 |
| 56 // Overridden from WebContentsDelegate: | 53 // Overridden from WebContentsDelegate: |
| 57 virtual content::WebContents* OpenURLFromTab( | 54 virtual WebContents* OpenURLFromTab( |
| 58 content::WebContents* source, | 55 WebContents* source, |
| 59 const content::OpenURLParams& params) OVERRIDE; | 56 const OpenURLParams& params) OVERRIDE; |
| 60 | 57 |
| 61 virtual void NavigationStateChanged(const content::WebContents* source, | 58 virtual void NavigationStateChanged(const WebContents* source, |
| 62 unsigned changed_flags) OVERRIDE; | 59 unsigned changed_flags) OVERRIDE; |
| 63 virtual void AddNewContents(content::WebContents* source, | 60 virtual void AddNewContents(WebContents* source, |
| 64 content::WebContents* new_contents, | 61 WebContents* new_contents, |
| 65 WindowOpenDisposition disposition, | 62 WindowOpenDisposition disposition, |
| 66 const gfx::Rect& initial_pos, | 63 const gfx::Rect& initial_pos, |
| 67 bool user_gesture, | 64 bool user_gesture, |
| 68 bool* was_blocked) OVERRIDE; | 65 bool* was_blocked) OVERRIDE; |
| 69 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; | 66 virtual void ActivateContents(WebContents* contents) OVERRIDE; |
| 70 virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; | 67 virtual void DeactivateContents(WebContents* contents) OVERRIDE; |
| 71 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; | 68 virtual void LoadingStateChanged(WebContents* source) OVERRIDE; |
| 72 virtual void LoadProgressChanged(content::WebContents* source, | 69 virtual void LoadProgressChanged(WebContents* source, |
| 73 double load_progress) OVERRIDE; | 70 double load_progress) OVERRIDE; |
| 74 virtual void CloseContents(content::WebContents* source) OVERRIDE; | 71 virtual void CloseContents(WebContents* source) OVERRIDE; |
| 75 virtual void MoveContents(content::WebContents* source, | 72 virtual void MoveContents(WebContents* source, |
| 76 const gfx::Rect& pos) OVERRIDE; | 73 const gfx::Rect& pos) OVERRIDE; |
| 77 virtual bool AddMessageToConsole(content::WebContents* source, | 74 virtual bool AddMessageToConsole(WebContents* source, |
| 78 int32 level, | 75 int32 level, |
| 79 const string16& message, | 76 const string16& message, |
| 80 int32 line_no, | 77 int32 line_no, |
| 81 const string16& source_id) OVERRIDE; | 78 const string16& source_id) OVERRIDE; |
| 82 // TODO(merge): WARNING! method no longer available on the base class. | 79 // TODO(merge): WARNING! method no longer available on the base class. |
| 83 // See http://crbug.com/149477 | 80 // See http://crbug.com/149477 |
| 84 virtual void URLStarredChanged(content::WebContents* source, bool starred); | 81 virtual void URLStarredChanged(WebContents* source, bool starred); |
| 85 virtual void UpdateTargetURL(content::WebContents* source, | 82 virtual void UpdateTargetURL(WebContents* source, |
| 86 int32 page_id, | 83 int32 page_id, |
| 87 const GURL& url) OVERRIDE; | 84 const GURL& url) OVERRIDE; |
| 88 virtual void HandleKeyboardEvent( | 85 virtual void HandleKeyboardEvent( |
| 89 content::WebContents* source, | 86 WebContents* source, |
| 90 const content::NativeWebKeyboardEvent& event) OVERRIDE; | 87 const NativeWebKeyboardEvent& event) OVERRIDE; |
| 91 virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE; | 88 virtual bool TakeFocus(WebContents* source, bool reverse) OVERRIDE; |
| 92 | 89 |
| 93 virtual void ShowRepostFormWarningDialog( | 90 virtual void ShowRepostFormWarningDialog(WebContents* source) OVERRIDE; |
| 94 content::WebContents* source) OVERRIDE; | |
| 95 | 91 |
| 96 virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents, | 92 virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents, |
| 97 bool enter_fullscreen) OVERRIDE; | 93 bool enter_fullscreen) OVERRIDE; |
| 98 virtual bool IsFullscreenForTabOrPending( | 94 virtual bool IsFullscreenForTabOrPending( |
| 99 const content::WebContents* web_contents) const OVERRIDE; | 95 const content::WebContents* web_contents) const OVERRIDE; |
| 100 | 96 |
| 101 protected: | 97 protected: |
| 102 base::android::ScopedJavaLocalRef<jobject> GetJavaDelegate(JNIEnv* env) const; | 98 base::android::ScopedJavaLocalRef<jobject> GetJavaDelegate(JNIEnv* env) const; |
| 103 | 99 |
| 104 private: | 100 private: |
| 105 // We depend on the java side user of WebContentDelegateAndroid to hold a | 101 // We depend on the java side user of WebContentDelegateAndroid to hold a |
| 106 // strong reference to that object as long as they want to receive callbacks | 102 // strong reference to that object as long as they want to receive callbacks |
| 107 // on it. Using a weak ref here allows it to be correctly GCed. | 103 // on it. Using a weak ref here allows it to be correctly GCed. |
| 108 JavaObjectWeakGlobalRef weak_java_delegate_; | 104 JavaObjectWeakGlobalRef weak_java_delegate_; |
| 109 }; | 105 }; |
| 110 | 106 |
| 111 bool RegisterWebContentsDelegateAndroid(JNIEnv* env); | 107 bool RegisterWebContentsDelegateAndroid(JNIEnv* env); |
| 112 | 108 |
| 113 } // namespace web_contents_delegate_android | 109 } // namespace content |
| 114 | 110 |
| 115 #endif // CHROME_BROWSER_COMPONENT_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_D
ELEGATE_ANDROID_H_ | 111 #endif // CHROME_BROWSER_COMPONENT_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_D
ELEGATE_ANDROID_H_ |
| OLD | NEW |