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 CHROME_BROWSER_COMPONENT_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_DELEGATE_ANDROID_H_
6 #define CHROME_BROWSER_COMPONENT_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/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"
21 class JavaScriptDialogCreator
;
24 class WebContentsObserver
;
25 struct NativeWebKeyboardEvent
;
27 enum WebContentsDelegateLogLevel
{
28 // Equivalent of WebCore::WebConsoleMessage::LevelTip.
29 WEB_CONTENTS_DELEGATE_LOG_LEVEL_TIP
= 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 WebContentsDelegate
{
45 WebContentsDelegateAndroid(JNIEnv
* env
, jobject obj
);
46 virtual ~WebContentsDelegateAndroid();
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(WebContents
* contents
);
53 // Overridden from WebContentsDelegate:
54 virtual WebContents
* OpenURLFromTab(
56 const OpenURLParams
& params
) OVERRIDE
;
58 virtual content::ColorChooser
* OpenColorChooser(
59 content::WebContents
* source
, int color_chooser_id
,
60 SkColor color
) OVERRIDE
;
61 virtual void NavigationStateChanged(const WebContents
* source
,
62 unsigned changed_flags
) OVERRIDE
;
63 virtual void AddNewContents(WebContents
* source
,
64 WebContents
* new_contents
,
65 WindowOpenDisposition disposition
,
66 const gfx::Rect
& initial_pos
,
68 bool* was_blocked
) OVERRIDE
;
69 virtual void ActivateContents(WebContents
* contents
) OVERRIDE
;
70 virtual void DeactivateContents(WebContents
* contents
) OVERRIDE
;
71 virtual void LoadingStateChanged(WebContents
* source
) OVERRIDE
;
72 virtual void LoadProgressChanged(WebContents
* source
,
73 double load_progress
) OVERRIDE
;
74 virtual void CloseContents(WebContents
* source
) OVERRIDE
;
75 virtual void MoveContents(WebContents
* source
,
76 const gfx::Rect
& pos
) OVERRIDE
;
77 virtual bool AddMessageToConsole(WebContents
* source
,
79 const string16
& message
,
81 const string16
& source_id
) OVERRIDE
;
82 virtual void UpdateTargetURL(WebContents
* source
,
84 const GURL
& url
) OVERRIDE
;
85 virtual void HandleKeyboardEvent(
87 const NativeWebKeyboardEvent
& event
) OVERRIDE
;
88 virtual bool TakeFocus(WebContents
* source
, bool reverse
) OVERRIDE
;
90 virtual void ShowRepostFormWarningDialog(WebContents
* source
) OVERRIDE
;
92 virtual void ToggleFullscreenModeForTab(content::WebContents
* web_contents
,
93 bool enter_fullscreen
) OVERRIDE
;
94 virtual bool IsFullscreenForTabOrPending(
95 const content::WebContents
* web_contents
) const OVERRIDE
;
98 base::android::ScopedJavaLocalRef
<jobject
> GetJavaDelegate(JNIEnv
* env
) const;
101 // 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
103 // on it. Using a weak ref here allows it to be correctly GCed.
104 JavaObjectWeakGlobalRef weak_java_delegate_
;
107 bool RegisterWebContentsDelegateAndroid(JNIEnv
* env
);
109 } // namespace content
111 #endif // CHROME_BROWSER_COMPONENT_WEB_CONTENTS_DELEGATE_ANDROID_WEB_CONTENTS_DELEGATE_ANDROID_H_