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_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/web_contents_delegate.h"
18 class WebContentsDelegate
;
19 struct NativeWebKeyboardEvent
;
23 namespace web_contents_delegate_android
{
25 enum WebContentsDelegateLogLevel
{
26 // Equivalent of WebCore::WebConsoleMessage::LevelDebug.
27 WEB_CONTENTS_DELEGATE_LOG_LEVEL_DEBUG
= 0,
28 // Equivalent of WebCore::WebConsoleMessage::LevelLog.
29 WEB_CONTENTS_DELEGATE_LOG_LEVEL_LOG
= 1,
30 // Equivalent of WebCore::WebConsoleMessage::LevelWarning.
31 WEB_CONTENTS_DELEGATE_LOG_LEVEL_WARNING
= 2,
32 // Equivalent of WebCore::WebConsoleMessage::LevelError.
33 WEB_CONTENTS_DELEGATE_LOG_LEVEL_ERROR
= 3,
37 // Native underpinnings of WebContentsDelegateAndroid.java. Provides a default
38 // delegate for WebContents to forward calls to the java peer. The embedding
39 // application may subclass and override methods on either the C++ or Java side
41 class WebContentsDelegateAndroid
: public content::WebContentsDelegate
{
43 WebContentsDelegateAndroid(JNIEnv
* env
, jobject obj
);
44 virtual ~WebContentsDelegateAndroid();
46 // Binds this WebContentsDelegateAndroid to the passed WebContents instance,
47 // such that when that WebContents is destroyed, this
48 // WebContentsDelegateAndroid instance will be destroyed too.
49 void SetOwnerWebContents(content::WebContents
* contents
);
51 // Overridden from WebContentsDelegate:
52 virtual content::WebContents
* OpenURLFromTab(
53 content::WebContents
* source
,
54 const content::OpenURLParams
& params
) OVERRIDE
;
55 virtual content::ColorChooser
* OpenColorChooser(content::WebContents
* source
,
56 SkColor color
) OVERRIDE
;
57 virtual void NavigationStateChanged(const content::WebContents
* source
,
58 unsigned changed_flags
) OVERRIDE
;
59 virtual void ActivateContents(content::WebContents
* contents
) OVERRIDE
;
60 virtual void DeactivateContents(content::WebContents
* contents
) OVERRIDE
;
61 virtual void LoadingStateChanged(content::WebContents
* source
) OVERRIDE
;
62 virtual void LoadProgressChanged(content::WebContents
* source
,
63 double load_progress
) OVERRIDE
;
64 virtual void RendererUnresponsive(content::WebContents
* source
) OVERRIDE
;
65 virtual void RendererResponsive(content::WebContents
* source
) OVERRIDE
;
66 virtual void CloseContents(content::WebContents
* source
) OVERRIDE
;
67 virtual void MoveContents(content::WebContents
* source
,
68 const gfx::Rect
& pos
) OVERRIDE
;
69 virtual bool AddMessageToConsole(content::WebContents
* source
,
71 const base::string16
& message
,
73 const base::string16
& source_id
) OVERRIDE
;
74 virtual void UpdateTargetURL(content::WebContents
* source
,
76 const GURL
& url
) OVERRIDE
;
77 virtual void HandleKeyboardEvent(
78 content::WebContents
* source
,
79 const content::NativeWebKeyboardEvent
& event
) OVERRIDE
;
80 virtual bool TakeFocus(content::WebContents
* source
, bool reverse
) OVERRIDE
;
81 virtual void ShowRepostFormWarningDialog(
82 content::WebContents
* source
) OVERRIDE
;
83 virtual void ToggleFullscreenModeForTab(content::WebContents
* web_contents
,
84 bool enter_fullscreen
) OVERRIDE
;
85 virtual bool IsFullscreenForTabOrPending(
86 const content::WebContents
* web_contents
) const OVERRIDE
;
89 base::android::ScopedJavaLocalRef
<jobject
> GetJavaDelegate(JNIEnv
* env
) const;
92 // We depend on the java side user of WebContentDelegateAndroid to hold a
93 // strong reference to that object as long as they want to receive callbacks
94 // on it. Using a weak ref here allows it to be correctly GCed.
95 JavaObjectWeakGlobalRef weak_java_delegate_
;
98 bool RegisterWebContentsDelegateAndroid(JNIEnv
* env
);
100 } // namespace web_contents_delegate_android
102 #endif // COMPONENTS_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_DELEGATE_ANDROID_H_