Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1809)

Unified Diff: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc

Issue 145463002: Extensions: Send the tab id to platform apps. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/media_galleries/media_galleries_api.cc
===================================================================
--- chrome/browser/extensions/api/media_galleries/media_galleries_api.cc (revision 246091)
+++ chrome/browser/extensions/api/media_galleries/media_galleries_api.cc (working copy)
@@ -19,8 +19,10 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/file_system/file_system_api.h"
+#include "chrome/browser/extensions/api/messaging/message_service.h"
#include "chrome/browser/extensions/blob_reader.h"
#include "chrome/browser/extensions/extension_prefs.h"
+#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/media_galleries/media_file_system_registry.h"
#include "chrome/browser/media_galleries/media_galleries_dialog_controller.h"
#include "chrome/browser/media_galleries/media_galleries_histograms.h"
@@ -403,17 +405,39 @@
bool MediaGalleriesAddUserSelectedFolderFunction::RunImpl() {
media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER);
+
+ // Need to do this before OnPreferencesInit() because OnPreferencesInit() can
+ // be deferred, by which time, extensions::MessageService() no longer knows
+ // whether this API can access the source tab or not.
not at google - send to devlin 2014/01/23 16:41:59 I'm being dense and can't follow why this (and the
Lei Zhang 2014/01/23 20:53:12 Yes, I'm being paranoid, but if you say we don't n
not at google - send to devlin 2014/01/23 21:07:43 Thanks for being paranoid. The bug, if it can be c
+ bool can_access_source_tab = false;
+ if (source_tab_id() >= 0) {
+ Profile* profile = GetProfile();
+ can_access_source_tab =
+ extensions::MessageService::Get(profile)->CanPlatformAppAccessTab(
+ GetExtension()->id(), source_tab_id());
+ }
return Setup(GetProfile(), &error_, base::Bind(
- &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this));
+ &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit,
+ this,
+ can_access_source_tab));
}
-void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() {
+void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit(
+ bool can_access_source_tab) {
Profile* profile = GetProfile();
const std::string& app_id = GetExtension()->id();
WebContents* contents = GetWebContents(render_view_host(), profile, app_id);
if (!contents) {
- SendResponse(false);
- return;
+ bool found_tab = false;
+ if (can_access_source_tab) {
+ found_tab = extensions::ExtensionTabUtil::GetTabById(
+ source_tab_id(), profile, profile->IsOffTheRecord(),
+ NULL, NULL, &contents, NULL);
+ }
+ if (!found_tab || !contents) {
+ SendResponse(false);
+ return;
+ }
}
if (!user_gesture()) {

Powered by Google App Engine
This is Rietveld 408576698