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.
5 #ifndef COMPONENTS_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_DELEGATE_ANDROID_H_
6 #define COMPONENTS_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_DELEGATE_ANDROID_H_
8 #include "base/android/jni_weak_ref.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/web_contents_delegate.h"
18 class WebContentsDelegate
;
19 struct NativeWebKeyboardEvent
;
23 namespace web_contents_delegate_android
{
25 class ValidationMessageBubbleAndroid
;
27 enum WebContentsDelegateLogLevel
{
28 // Equivalent of WebCore::WebConsoleMessage::LevelDebug.
29 WEB_CONTENTS_DELEGATE_LOG_LEVEL_DEBUG
= 0,
30 // Equivalent of WebCore::WebConsoleMessage::LevelLog.
31 WEB_CONTENTS_DELEGATE_LOG_LEVEL_LOG
= 1,
32 // Equivalent of WebCore::WebConsoleMessage::LevelWarning.
33 WEB_CONTENTS_DELEGATE_LOG_LEVEL_WARNING
= 2,
34 // Equivalent of WebCore::WebConsoleMessage::LevelError.
35 WEB_CONTENTS_DELEGATE_LOG_LEVEL_ERROR
= 3,
39 // Native underpinnings of WebContentsDelegateAndroid.java. Provides a default
40 // 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
43 class WebContentsDelegateAndroid
: public content::WebContentsDelegate
{
45 WebContentsDelegateAndroid(JNIEnv
* env
, jobject obj
);
46 ~WebContentsDelegateAndroid() override
;
48 // Binds this WebContentsDelegateAndroid to the passed WebContents instance,
49 // such that when that WebContents is destroyed, this
50 // WebContentsDelegateAndroid instance will be destroyed too.
51 void SetOwnerWebContents(content::WebContents
* contents
);
53 // Overridden from WebContentsDelegate:
54 content::WebContents
* OpenURLFromTab(
55 content::WebContents
* source
,
56 const content::OpenURLParams
& params
) override
;
57 content::ColorChooser
* OpenColorChooser(
58 content::WebContents
* source
,
60 const std::vector
<content::ColorSuggestion
>& suggestions
) override
;
61 void NavigationStateChanged(content::WebContents
* source
,
62 content::InvalidateTypes changed_flags
) override
;
63 void VisibleSSLStateChanged(const content::WebContents
* source
) override
;
64 void ActivateContents(content::WebContents
* contents
) override
;
65 void DeactivateContents(content::WebContents
* contents
) override
;
66 void LoadingStateChanged(content::WebContents
* source
,
67 bool to_different_document
) override
;
68 void LoadProgressChanged(content::WebContents
* source
,
69 double load_progress
) override
;
70 void RendererUnresponsive(content::WebContents
* source
) override
;
71 void RendererResponsive(content::WebContents
* source
) override
;
72 void WebContentsCreated(content::WebContents
* source_contents
,
73 int opener_render_frame_id
,
74 const base::string16
& frame_name
,
75 const GURL
& target_url
,
76 content::WebContents
* new_contents
) override
;
77 bool ShouldCreateWebContents(
78 content::WebContents
* web_contents
,
80 int main_frame_route_id
,
81 WindowContainerType window_container_type
,
82 const base::string16
& frame_name
,
83 const GURL
& target_url
,
84 const std::string
& partition_id
,
85 content::SessionStorageNamespace
* session_storage_namespace
) override
;
86 bool OnGoToEntryOffset(int offset
) override
;
87 void CloseContents(content::WebContents
* source
) override
;
88 void MoveContents(content::WebContents
* source
,
89 const gfx::Rect
& pos
) override
;
90 bool AddMessageToConsole(content::WebContents
* source
,
92 const base::string16
& message
,
94 const base::string16
& source_id
) override
;
95 void UpdateTargetURL(content::WebContents
* source
, const GURL
& url
) override
;
96 void HandleKeyboardEvent(
97 content::WebContents
* source
,
98 const content::NativeWebKeyboardEvent
& event
) override
;
99 bool TakeFocus(content::WebContents
* source
, bool reverse
) override
;
100 void ShowRepostFormWarningDialog(content::WebContents
* source
) override
;
101 void EnterFullscreenModeForTab(content::WebContents
* web_contents
,
102 const GURL
& origin
) override
;
103 void ExitFullscreenModeForTab(content::WebContents
* web_contents
) override
;
104 bool IsFullscreenForTabOrPending(
105 const content::WebContents
* web_contents
) const override
;
106 void ShowValidationMessage(content::WebContents
* web_contents
,
107 const gfx::Rect
& anchor_in_root_view
,
108 const base::string16
& main_text
,
109 const base::string16
& sub_text
) override
;
110 void HideValidationMessage(content::WebContents
* web_contents
) override
;
111 void MoveValidationMessage(content::WebContents
* web_contents
,
112 const gfx::Rect
& anchor_in_root_view
) override
;
115 base::android::ScopedJavaLocalRef
<jobject
> GetJavaDelegate(JNIEnv
* env
) const;
118 // We depend on the java side user of WebContentDelegateAndroid to hold a
119 // strong reference to that object as long as they want to receive callbacks
120 // on it. Using a weak ref here allows it to be correctly GCed.
121 JavaObjectWeakGlobalRef weak_java_delegate_
;
123 scoped_ptr
<ValidationMessageBubbleAndroid
> validation_message_bubble_
;
126 bool RegisterWebContentsDelegateAndroid(JNIEnv
* env
);
128 } // namespace web_contents_delegate_android
130 #endif // COMPONENTS_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_DELEGATE_ANDROID_H_