#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/web/WebDataSource.h"
#include "third_party/WebKit/public/web/WebDocument.h"
-#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebFrameClient.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebSecurityOrigin.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "chrome/common/extensions/chrome_extension_messages.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
+#include "extensions/common/permissions/api_permission.h"
+#include "extensions/common/permissions/permissions_data.h"
#include "extensions/renderer/dispatcher.h"
#endif
bool ContentSettingsObserver::allowReadFromClipboard(bool default_value) {
bool allowed = false;
#if defined(ENABLE_EXTENSIONS)
- WebFrame* frame = render_frame()->GetWebFrame();
- // TODO(dcheng): Should we consider a toURL() method on WebSecurityOrigin?
- Send(new ChromeViewHostMsg_CanTriggerClipboardRead(
- GURL(frame->document().securityOrigin().toString()), &allowed));
+ extensions::ScriptContext* calling_context =
+ extension_dispatcher_->script_context_set().GetCalling();
+ if (calling_context) {
+ const extensions::Extension* extension =
+ calling_context->effective_extension();
+ allowed = extension &&
+ extension->permissions_data()->HasAPIPermission(
+ extensions::APIPermission::kClipboardRead);
+ }
#endif
return allowed;
}
bool ContentSettingsObserver::allowWriteToClipboard(bool default_value) {
bool allowed = false;
#if defined(ENABLE_EXTENSIONS)
- WebFrame* frame = render_frame()->GetWebFrame();
- Send(new ChromeViewHostMsg_CanTriggerClipboardWrite(
- GURL(frame->document().securityOrigin().toString()), &allowed));
+ // All blessed extension pages could historically write to the clipboard, so
+ // preserve that for compatibility.
+ extensions::ScriptContext* calling_context =
+ extension_dispatcher_->script_context_set().GetCalling();
+ if (calling_context) {
+ if (calling_context->effective_context_type() ==
+ extensions::Feature::BLESSED_EXTENSION_CONTEXT) {
+ allowed = true;
+ } else {
+ const extensions::Extension* extension =
+ calling_context->effective_extension();
+ allowed = extension &&
+ extension->permissions_data()->HasAPIPermission(
+ extensions::APIPermission::kClipboardWrite);
+ }
+ }
#endif
return allowed;
}