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