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