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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Implements the Chrome Extensions Media Galleries API. 5 // Implements the Chrome Extensions Media Galleries API.
6 6
7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h" 7 #include "chrome/browser/extensions/api/media_galleries/media_galleries_api.h"
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "apps/shell_window.h" 13 #include "apps/shell_window.h"
14 #include "apps/shell_window_registry.h" 14 #include "apps/shell_window_registry.h"
15 #include "base/platform_file.h" 15 #include "base/platform_file.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/extensions/api/file_system/file_system_api.h" 21 #include "chrome/browser/extensions/api/file_system/file_system_api.h"
22 #include "chrome/browser/extensions/api/messaging/message_service.h"
22 #include "chrome/browser/extensions/blob_reader.h" 23 #include "chrome/browser/extensions/blob_reader.h"
23 #include "chrome/browser/extensions/extension_prefs.h" 24 #include "chrome/browser/extensions/extension_prefs.h"
25 #include "chrome/browser/extensions/extension_tab_util.h"
24 #include "chrome/browser/media_galleries/media_file_system_registry.h" 26 #include "chrome/browser/media_galleries/media_file_system_registry.h"
25 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h" 27 #include "chrome/browser/media_galleries/media_galleries_dialog_controller.h"
26 #include "chrome/browser/media_galleries/media_galleries_histograms.h" 28 #include "chrome/browser/media_galleries/media_galleries_histograms.h"
27 #include "chrome/browser/media_galleries/media_galleries_preferences.h" 29 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
28 #include "chrome/browser/platform_util.h" 30 #include "chrome/browser/platform_util.h"
29 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/storage_monitor/storage_info.h" 32 #include "chrome/browser/storage_monitor/storage_info.h"
31 #include "chrome/browser/ui/chrome_select_file_policy.h" 33 #include "chrome/browser/ui/chrome_select_file_policy.h"
32 #include "chrome/common/extensions/api/media_galleries.h" 34 #include "chrome/common/extensions/api/media_galleries.h"
33 #include "chrome/common/extensions/permissions/media_galleries_permission.h" 35 #include "chrome/common/extensions/permissions/media_galleries_permission.h"
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 398
397 SetResult(list); 399 SetResult(list);
398 SendResponse(true); 400 SendResponse(true);
399 } 401 }
400 402
401 MediaGalleriesAddUserSelectedFolderFunction:: 403 MediaGalleriesAddUserSelectedFolderFunction::
402 ~MediaGalleriesAddUserSelectedFolderFunction() {} 404 ~MediaGalleriesAddUserSelectedFolderFunction() {}
403 405
404 bool MediaGalleriesAddUserSelectedFolderFunction::RunImpl() { 406 bool MediaGalleriesAddUserSelectedFolderFunction::RunImpl() {
405 media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER); 407 media_galleries::UsageCount(media_galleries::ADD_USER_SELECTED_FOLDER);
408
409 // Need to do this before OnPreferencesInit() because OnPreferencesInit() can
410 // be deferred, by which time, extensions::MessageService() no longer knows
411 // 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
412 bool can_access_source_tab = false;
413 if (source_tab_id() >= 0) {
414 Profile* profile = GetProfile();
415 can_access_source_tab =
416 extensions::MessageService::Get(profile)->CanPlatformAppAccessTab(
417 GetExtension()->id(), source_tab_id());
418 }
406 return Setup(GetProfile(), &error_, base::Bind( 419 return Setup(GetProfile(), &error_, base::Bind(
407 &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit, this)); 420 &MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit,
421 this,
422 can_access_source_tab));
408 } 423 }
409 424
410 void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit() { 425 void MediaGalleriesAddUserSelectedFolderFunction::OnPreferencesInit(
426 bool can_access_source_tab) {
411 Profile* profile = GetProfile(); 427 Profile* profile = GetProfile();
412 const std::string& app_id = GetExtension()->id(); 428 const std::string& app_id = GetExtension()->id();
413 WebContents* contents = GetWebContents(render_view_host(), profile, app_id); 429 WebContents* contents = GetWebContents(render_view_host(), profile, app_id);
414 if (!contents) { 430 if (!contents) {
415 SendResponse(false); 431 bool found_tab = false;
416 return; 432 if (can_access_source_tab) {
433 found_tab = extensions::ExtensionTabUtil::GetTabById(
434 source_tab_id(), profile, profile->IsOffTheRecord(),
435 NULL, NULL, &contents, NULL);
436 }
437 if (!found_tab || !contents) {
438 SendResponse(false);
439 return;
440 }
417 } 441 }
418 442
419 if (!user_gesture()) { 443 if (!user_gesture()) {
420 OnDirectorySelected(base::FilePath()); 444 OnDirectorySelected(base::FilePath());
421 return; 445 return;
422 } 446 }
423 447
424 base::FilePath last_used_path = 448 base::FilePath last_used_path =
425 extensions::file_system_api::GetLastChooseEntryDirectory( 449 extensions::file_system_api::GetLastChooseEntryDirectory(
426 extensions::ExtensionPrefs::Get(profile), app_id); 450 extensions::ExtensionPrefs::Get(profile), app_id);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 if (mime_type_sniffed) 613 if (mime_type_sniffed)
590 metadata.mime_type = mime_type; 614 metadata.mime_type = mime_type;
591 615
592 // TODO(tommycli): Kick off SafeMediaMetadataParser if |mime_type_only| false. 616 // TODO(tommycli): Kick off SafeMediaMetadataParser if |mime_type_only| false.
593 617
594 SetResult(metadata.ToValue().release()); 618 SetResult(metadata.ToValue().release());
595 SendResponse(true); 619 SendResponse(true);
596 } 620 }
597 621
598 } // namespace extensions 622 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698