diff options
author | steveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-30 14:23:41 +0000 |
---|---|---|
committer | steveblock@chromium.org <steveblock@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-30 14:23:41 +0000 |
commit | 72520f5738f24539e1cecfcf8670a91486144b03 (patch) | |
tree | 298aedc06940704318255d253bea1f6f39d08148 /content | |
parent | b83e0abab41c3f5689aeac420709e92e3ed4bdca (diff) | |
download | chromium_src-72520f5738f24539e1cecfcf8670a91486144b03.zip chromium_src-72520f5738f24539e1cecfcf8670a91486144b03.tar.gz chromium_src-72520f5738f24539e1cecfcf8670a91486144b03.tar.bz2 |
Revert "Hook up ContentViewCore.add/removeJavascriptInterface()"
This reverts commit 4c4c2a2efc00cdea3b62c5ff4baf8563ed19711f.
This commit included inintended changes not present in code review.
BUG=110637
Review URL: https://chromiumcodereview.appspot.com/10827085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148949 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
4 files changed, 62 insertions, 141 deletions
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index d0e5bd2..21d3bd7 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -10,8 +10,6 @@ #include "base/android/scoped_java_ref.h" #include "content/browser/android/content_view_client.h" #include "content/browser/android/touch_point.h" -#include "content/browser/renderer_host/java/java_bound_object.h" -#include "content/browser/renderer_host/java/java_bridge_dispatcher_host_manager.h" #include "content/browser/renderer_host/render_view_host_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_view_android.h" @@ -20,13 +18,11 @@ #include "content/public/browser/interstitial_page.h" #include "content/public/browser/web_contents.h" #include "jni/ContentViewCore_jni.h" -#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEventFactory.h" #include "webkit/glue/webmenuitem.h" using base::android::AttachCurrentThread; -using base::android::ConvertJavaStringToUTF16; using base::android::ConvertUTF16ToJavaString; using base::android::ConvertUTF8ToJavaString; using base::android::GetClass; @@ -76,7 +72,7 @@ ContentViewCore* ContentViewCore::GetNativeContentViewCore(JNIEnv* env, ContentViewCoreImpl::ContentViewCoreImpl(JNIEnv* env, jobject obj, WebContents* web_contents) - : web_contents_(static_cast<WebContentsImpl*>(web_contents)), + : web_contents_(web_contents), tab_crashed_(false) { DCHECK(web_contents) << "A ContentViewCoreImpl should be created with a valid WebContents."; @@ -120,25 +116,6 @@ RenderWidgetHostViewAndroid* // Methods called from Java via JNI // ---------------------------------------------------------------------------- -void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj, - jintArray indices) { - RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( - web_contents_->GetRenderViewHost()); - DCHECK(rvhi); - if (indices == NULL) { - rvhi->DidCancelPopupMenu(); - return; - } - - int selected_count = env->GetArrayLength(indices); - std::vector<int> selected_indices; - jint* indices_ptr = env->GetIntArrayElements(indices, NULL); - for (int i = 0; i < selected_count; ++i) - selected_indices.push_back(indices_ptr[i]); - env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); - rvhi->DidSelectPopupMenuItems(selected_indices); -} - void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, jobject, jstring jurl, @@ -336,29 +313,6 @@ void ContentViewCoreImpl::SetClient(JNIEnv* env, jobject obj, jobject jclient) { content_view_client_.swap(client); } -void ContentViewCoreImpl::AddJavascriptInterface( - JNIEnv* env, - jobject /* obj */, - jobject object, - jstring name, - jboolean allow_inherited_methods) { - ScopedJavaLocalRef<jobject> scoped_object(env, object); - // JavaBoundObject creates the NPObject with a ref count of 1, and - // JavaBridgeDispatcherHostManager takes its own ref. - NPObject* bound_object = JavaBoundObject::Create(scoped_object, - allow_inherited_methods); - web_contents_->java_bridge_dispatcher_host_manager()->AddNamedObject( - ConvertJavaStringToUTF16(env, name), bound_object); - WebKit::WebBindings::releaseObject(bound_object); -} - -void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env, - jobject /* obj */, - jstring name) { - web_contents_->java_bridge_dispatcher_host_manager()->RemoveNamedObject( - ConvertJavaStringToUTF16(env, name)); -} - // -------------------------------------------------------------------------- // Methods called from native code // -------------------------------------------------------------------------- @@ -512,6 +466,29 @@ void ContentViewCoreImpl::StartContentIntent(const GURL& content_url) { } // -------------------------------------------------------------------------- +// Methods called from Java via JNI +// -------------------------------------------------------------------------- + +void ContentViewCoreImpl::SelectPopupMenuItems(JNIEnv* env, jobject obj, + jintArray indices) { + RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>( + web_contents_->GetRenderViewHost()); + DCHECK(rvhi); + if (indices == NULL) { + rvhi->DidCancelPopupMenu(); + return; + } + + int selected_count = env->GetArrayLength(indices); + std::vector<int> selected_indices; + jint* indices_ptr = env->GetIntArrayElements(indices, NULL); + for (int i = 0; i < selected_count; ++i) + selected_indices.push_back(indices_ptr[i]); + env->ReleaseIntArrayElements(indices, indices_ptr, JNI_ABORT); + rvhi->DidSelectPopupMenuItems(selected_indices); +} + +// -------------------------------------------------------------------------- // Methods called from native code // -------------------------------------------------------------------------- diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h index 7c6a697..796c148 100644 --- a/content/browser/android/content_view_core_impl.h +++ b/content/browser/android/content_view_core_impl.h @@ -14,7 +14,6 @@ #include "base/memory/scoped_ptr.h" #include "base/process.h" #include "content/browser/renderer_host/render_widget_host_view_android.h" -#include "content/browser/web_contents/web_contents_impl.h" #include "content/public/browser/android/content_view_core.h" #include "content/public/browser/notification_observer.h" #include "googleurl/src/gurl.h" @@ -34,8 +33,6 @@ class ContentViewCoreImpl : public ContentViewCore, ContentViewCoreImpl(JNIEnv* env, jobject obj, WebContents* web_contents); - - // ContentViewCore overrides virtual void Destroy(JNIEnv* env, jobject obj) OVERRIDE; // -------------------------------------------------------------------------- @@ -111,12 +108,6 @@ class ContentViewCoreImpl : public ContentViewCore, jboolean NeedsReload(JNIEnv* env, jobject obj); void ClearHistory(JNIEnv* env, jobject obj); void SetClient(JNIEnv* env, jobject obj, jobject jclient); - void AddJavascriptInterface(JNIEnv* env, - jobject obj, - jobject object, - jstring name, - jboolean allow_inherited_methods); - void RemoveJavascriptInterface(JNIEnv* env, jobject obj, jstring name); // -------------------------------------------------------------------------- // Public methods that call to Java via JNI @@ -150,7 +141,7 @@ class ContentViewCoreImpl : public ContentViewCore, void OnAcceleratedCompositingStateChange(RenderWidgetHostViewAndroid* rwhva, bool activated, bool force); - void StartContentIntent(const GURL& content_url); + virtual void StartContentIntent(const GURL& content_url) OVERRIDE; // -------------------------------------------------------------------------- // Methods called from native code @@ -195,7 +186,7 @@ class ContentViewCoreImpl : public ContentViewCore, // Reference to the current WebContents used to determine how and what to // display in the ContentViewCore. - WebContentsImpl* web_contents_; + WebContents* web_contents_; // We only set this to be the delegate of the web_contents if we own it. scoped_ptr<ContentViewClient> content_view_client_; diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java index d97b6d1..ee08d3a 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java @@ -54,9 +54,9 @@ public class ContentViewCore implements MotionEventDelegate { // Used for Chrome. public static final int PERSONALITY_CHROME = 1; - // Used to avoid enabling zooming in / out if resulting zooming will - // produce little visible difference. - private static float ZOOM_CONTROLS_EPSILON = 0.007f; + // Used to avoid enabling zooming in / out in WebView zoom controls + // if resulting zooming will produce little visible difference. + private static float WEBVIEW_ZOOM_CONTROLS_EPSILON = 0.007f; // To avoid checkerboard, we clamp the fling velocity based on the maximum number of tiles // should be allowed to upload per 100ms. @@ -130,7 +130,7 @@ public class ContentViewCore implements MotionEventDelegate { private ContentSettings mContentSettings; - // Native pointer to C++ ContentViewCoreImpl object which will be set by nativeInit(). + // Native pointer to C++ ContentView object which will be set by nativeInit() private int mNativeContentViewCore = 0; private ContentViewGestureHandler mContentViewGestureHandler; @@ -180,6 +180,7 @@ public class ContentViewCore implements MotionEventDelegate { * @param context Context used to obtain the application context. * @param maxRendererProcesses Same as ContentView.enableMultiProcess() * @return Whether the process actually needed to be initialized (false if already running). + * @hide Only used by the platform browser. */ public static boolean initChromiumBrowserProcess(Context context, int maxRendererProcesses) { return AndroidBrowserProcess.initChromiumBrowserProcess(context, maxRendererProcesses); @@ -264,10 +265,9 @@ public class ContentViewCore implements MotionEventDelegate { } /** - * Destroy the internal state of the ContentView. This method may only be - * called after the ContentView has been removed from the view system. No - * other methods may be called on this ContentView after this method has - * been called. + * Destroy the internal state of the WebView. This method may only be called + * after the WebView has been removed from the view system. No other methods + * may be called on this WebView after this method has been called. */ public void destroy() { hidePopupDialog(); @@ -465,8 +465,8 @@ public class ContentViewCore implements MotionEventDelegate { } /** - * Clears the ContentViewCore's page history in both the backwards and - * forwards directions. + * Clears the WebView's page history in both the backwards and forwards + * directions. */ public void clearHistory() { if (mNativeContentViewCore != 0) nativeClearHistory(mNativeContentViewCore); @@ -564,7 +564,9 @@ public class ContentViewCore implements MotionEventDelegate { /** * This method should be called when the containing activity is paused - */ + * + * @hide + **/ public void onActivityPause() { TraceEvent.begin(); hidePopupDialog(); @@ -572,21 +574,23 @@ public class ContentViewCore implements MotionEventDelegate { } /** - * Called when the ContentView is hidden. - */ + * Called when the WebView is hidden. + * + * @hide + **/ public void onHide() { hidePopupDialog(); } /** * Return the ContentSettings object used to control the settings for this - * ContentViewCore. + * WebView. * * Note that when ContentView is used in the PERSONALITY_CHROME role, * ContentSettings can only be used for retrieving settings values. For * modifications, ChromeNativePreferences is to be used. - * @return A ContentSettings object that can be used to control this - * ContentViewCore's settings. + * @return A ContentSettings object that can be used to control this WebView's + * settings. */ public ContentSettings getContentSettings() { return mContentSettings; @@ -755,30 +759,30 @@ public class ContentViewCore implements MotionEventDelegate { } /** - * Checks whether the ContentViewCore can be zoomed in. + * Checks whether the WebView can be zoomed in. * - * @return True if the ContentViewCore can be zoomed in. + * @return True if the WebView can be zoomed in. */ // This method uses the term 'zoom' for legacy reasons, but relates // to what chrome calls the 'page scale factor'. public boolean canZoomIn() { - return mNativeMaximumScale - mNativePageScaleFactor > ZOOM_CONTROLS_EPSILON; + return mNativeMaximumScale - mNativePageScaleFactor > WEBVIEW_ZOOM_CONTROLS_EPSILON; } /** - * Checks whether the ContentViewCore can be zoomed out. + * Checks whether the WebView can be zoomed out. * - * @return True if the ContentViewCore can be zoomed out. + * @return True if the WebView can be zoomed out. */ // This method uses the term 'zoom' for legacy reasons, but relates // to what chrome calls the 'page scale factor'. public boolean canZoomOut() { - return mNativePageScaleFactor - mNativeMinimumScale > ZOOM_CONTROLS_EPSILON; + return mNativePageScaleFactor - mNativeMinimumScale > WEBVIEW_ZOOM_CONTROLS_EPSILON; } /** - * Zooms in the ContentViewCore by 25% (or less if that would result in - * zooming in more than possible). + * Zooms in the WebView by 25% (or less if that would result in zooming in + * more than possible). * * @return True if there was a zoom change, false otherwise. */ @@ -806,8 +810,8 @@ public class ContentViewCore implements MotionEventDelegate { } /** - * Zooms out the ContentViewCore by 20% (or less if that would result in - * zooming out more than possible). + * Zooms out the WebView by 20% (or less if that would result in zooming out + * more than possible). * * @return True if there was a zoom change, false otherwise. */ @@ -850,58 +854,6 @@ public class ContentViewCore implements MotionEventDelegate { return mZoomManager.getZoomControlsViewForTest(); } - /** - * This method injects the supplied Java object into the ContentViewCore. - * The object is injected into the JavaScript context of the main frame, - * using the supplied name. This allows the Java object to be accessed from - * JavaScript. Note that that injected objects will not appear in - * JavaScript until the page is next (re)loaded. For example: - * <pre> view.addJavascriptInterface(new Object(), "injectedObject"); - * view.loadData("<!DOCTYPE html><title></title>", "text/html", null); - * view.loadUrl("javascript:alert(injectedObject.toString())");</pre> - * <p><strong>IMPORTANT:</strong> - * <ul> - * <li> addJavascriptInterface() can be used to allow JavaScript to control - * the host application. This is a powerful feature, but also presents a - * security risk. Use of this method in a ContentViewCore containing - * untrusted content could allow an attacker to manipulate the host - * application in unintended ways, executing Java code with the permissions - * of the host application. Use extreme care when using this method in a - * ContentViewCore which could contain untrusted content. Particular care - * should be taken to avoid unintentional access to inherited methods, such - * as {@link Object#getClass()}. To prevent access to inherited methods, - * set {@code allowInheritedMethods} to {@code false}. In addition, ensure - * that the injected object's public methods return only objects designed - * to be used by untrusted code, and never return a raw Object instance. - * <li> JavaScript interacts with Java objects on a private, background - * thread of the ContentViewCore. Care is therefore required to maintain - * thread safety.</li> - * </ul></p> - * - * @param object The Java object to inject into the ContentViewCore's - * JavaScript context. Null values are ignored. - * @param name The name used to expose the instance in JavaScript. - * @param allowInheritedMethods Whether or not inherited methods may be - * called from JavaScript. - */ - public void addJavascriptInterface(Object object, String name, boolean allowInheritedMethods) { - if (mNativeContentViewCore != 0 && object != null) { - nativeAddJavascriptInterface(mNativeContentViewCore, object, name, - allowInheritedMethods); - } - } - - /** - * Removes a previously added JavaScript interface with the given name. - * - * @param name The name of the interface to remove. - */ - public void removeJavascriptInterface(String name) { - if (mNativeContentViewCore != 0) { - nativeRemoveJavascriptInterface(mNativeContentViewCore, name); - } - } - @CalledByNative private void startContentIntent(String contentUrl) { getContentViewClient().onStartContentIntent(getContext(), contentUrl); @@ -996,9 +948,4 @@ public class ContentViewCore implements MotionEventDelegate { private native boolean nativeNeedsReload(int nativeContentViewCoreImpl); private native void nativeClearHistory(int nativeContentViewCoreImpl); - - private native void nativeAddJavascriptInterface(int nativeContentViewCoreImpl, Object object, - String name, boolean allowInheritedMethods); - - private native void nativeRemoveJavascriptInterface(int nativeContentViewCoreImpl, String name); } diff --git a/content/public/browser/android/content_view_core.h b/content/public/browser/android/content_view_core.h index a187196..d3871b8 100644 --- a/content/public/browser/android/content_view_core.h +++ b/content/public/browser/android/content_view_core.h @@ -35,6 +35,12 @@ class ContentViewCore { WebContents* web_contents); static ContentViewCore* GetNativeContentViewCore(JNIEnv* env, jobject obj); + // -------------------------------------------------------------------------- + // Public methods that call to Java via JNI + // -------------------------------------------------------------------------- + + virtual void StartContentIntent(const GURL& content_url) = 0; + protected: virtual ~ContentViewCore() {}; }; |