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 JavaScriptDialogCreator; | |
22 class RenderViewHost; | |
23 class WebContents; | |
24 class WebContentsObserver; | |
25 struct NativeWebKeyboardEvent; | |
26 } | |
27 | |
28 namespace web_contents_delegate_android { | |
29 | |
30 enum WebContentsDelegateLogLevel { | |
31 // Equivalent of WebCore::WebConsoleMessage::LevelTip. | |
32 WEB_CONTENTS_DELEGATE_LOG_LEVEL_TIP = 0, | |
33 // Equivalent of WebCore::WebConsoleMessage::LevelLog. | |
34 WEB_CONTENTS_DELEGATE_LOG_LEVEL_LOG = 1, | |
35 // Equivalent of WebCore::WebConsoleMessage::LevelWarning. | |
36 WEB_CONTENTS_DELEGATE_LOG_LEVEL_WARNING = 2, | |
37 // Equivalent of WebCore::WebConsoleMessage::LevelError. | |
38 WEB_CONTENTS_DELEGATE_LOG_LEVEL_ERROR = 3, | |
39 }; | |
40 | |
41 | |
42 // Native underpinnings of WebContentsDelegateAndroid.java. Provides a default | |
43 // 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 | |
45 // as required. | |
46 class WebContentsDelegateAndroid : public content::WebContentsDelegate { | |
47 public: | |
48 WebContentsDelegateAndroid(JNIEnv* env, jobject obj); | |
49 virtual ~WebContentsDelegateAndroid(); | |
50 | |
51 // Binds this WebContentsDelegateAndroid to the passed WebContents instance, | |
52 // such that when that WebContents is destroyed, this | |
53 // WebContentsDelegateAndroid instance will be destroyed too. | |
54 void SetOwnerWebContents(content::WebContents* contents); | |
55 | |
56 // Overridden from WebContentsDelegate: | |
57 virtual content::WebContents* OpenURLFromTab( | |
58 content::WebContents* source, | |
59 const content::OpenURLParams& params) OVERRIDE; | |
60 | |
61 virtual void NavigationStateChanged(const content::WebContents* source, | |
62 unsigned changed_flags) OVERRIDE; | |
63 virtual void AddNewContents(content::WebContents* source, | |
64 content::WebContents* new_contents, | |
65 WindowOpenDisposition disposition, | |
66 const gfx::Rect& initial_pos, | |
67 bool user_gesture, | |
68 bool* was_blocked) OVERRIDE; | |
69 virtual void ActivateContents(content::WebContents* contents) OVERRIDE; | |
70 virtual void DeactivateContents(content::WebContents* contents) OVERRIDE; | |
71 virtual void LoadingStateChanged(content::WebContents* source) OVERRIDE; | |
72 virtual void LoadProgressChanged(content::WebContents* source, | |
73 double load_progress) OVERRIDE; | |
74 virtual void CloseContents(content::WebContents* source) OVERRIDE; | |
75 virtual void MoveContents(content::WebContents* source, | |
76 const gfx::Rect& pos) OVERRIDE; | |
77 virtual bool AddMessageToConsole(content::WebContents* source, | |
78 int32 level, | |
79 const string16& message, | |
80 int32 line_no, | |
81 const string16& source_id) OVERRIDE; | |
82 // TODO(merge): WARNING! method no longer available on the base class. | |
83 // See http://crbug.com/149477 | |
84 virtual void URLStarredChanged(content::WebContents* source, bool starred); | |
85 virtual void UpdateTargetURL(content::WebContents* source, | |
86 int32 page_id, | |
87 const GURL& url) OVERRIDE; | |
88 virtual void HandleKeyboardEvent( | |
89 content::WebContents* source, | |
90 const content::NativeWebKeyboardEvent& event) OVERRIDE; | |
91 virtual bool TakeFocus(content::WebContents* source, bool reverse) OVERRIDE; | |
92 | |
93 virtual void ShowRepostFormWarningDialog( | |
94 content::WebContents* source) OVERRIDE; | |
95 | |
96 virtual void ToggleFullscreenModeForTab(content::WebContents* web_contents, | |
97 bool enter_fullscreen) OVERRIDE; | |
98 virtual bool IsFullscreenForTabOrPending( | |
99 const content::WebContents* web_contents) const OVERRIDE; | |
100 | |
101 protected: | |
102 base::android::ScopedJavaLocalRef<jobject> GetJavaDelegate(JNIEnv* env) const; | |
103 | |
104 private: | |
105 // 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 | |
107 // on it. Using a weak ref here allows it to be correctly GCed. | |
108 JavaObjectWeakGlobalRef weak_java_delegate_; | |
109 }; | |
110 | |
111 bool RegisterWebContentsDelegateAndroid(JNIEnv* env); | |
112 | |
113 } // namespace web_contents_delegate_android | |
114 | |
115 #endif // CHROME_BROWSER_COMPONENT_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_D
ELEGATE_ANDROID_H_ | |
OLD | NEW |