OLD | NEW |
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 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 5 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cctype> | 8 #include <cctype> |
9 #include <iterator> | 9 #include <iterator> |
10 #include <set> | 10 #include <set> |
(...skipping 1843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1854 new base::FundamentalValue( | 1854 new base::FundamentalValue( |
1855 static_cast<int>(download_item->GetId()))); | 1855 static_cast<int>(download_item->GetId()))); |
1856 } | 1856 } |
1857 | 1857 |
1858 void ExtensionDownloadsEventRouter::DispatchEvent( | 1858 void ExtensionDownloadsEventRouter::DispatchEvent( |
1859 const std::string& event_name, | 1859 const std::string& event_name, |
1860 bool include_incognito, | 1860 bool include_incognito, |
1861 const extensions::Event::WillDispatchCallback& will_dispatch_callback, | 1861 const extensions::Event::WillDispatchCallback& will_dispatch_callback, |
1862 base::Value* arg) { | 1862 base::Value* arg) { |
1863 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1863 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1864 if (!extensions::ExtensionSystem::Get(profile_)->event_router()) | 1864 if (!extensions::EventRouter::Get(profile_)) |
1865 return; | 1865 return; |
1866 scoped_ptr<base::ListValue> args(new base::ListValue()); | 1866 scoped_ptr<base::ListValue> args(new base::ListValue()); |
1867 args->Append(arg); | 1867 args->Append(arg); |
1868 std::string json_args; | 1868 std::string json_args; |
1869 base::JSONWriter::Write(args.get(), &json_args); | 1869 base::JSONWriter::Write(args.get(), &json_args); |
1870 scoped_ptr<extensions::Event> event(new extensions::Event( | 1870 scoped_ptr<extensions::Event> event(new extensions::Event( |
1871 event_name, args.Pass())); | 1871 event_name, args.Pass())); |
1872 // The downloads system wants to share on-record events with off-record | 1872 // The downloads system wants to share on-record events with off-record |
1873 // extension renderers even in incognito_split_mode because that's how | 1873 // extension renderers even in incognito_split_mode because that's how |
1874 // chrome://downloads works. The "restrict_to_profile" mechanism does not | 1874 // chrome://downloads works. The "restrict_to_profile" mechanism does not |
1875 // anticipate this, so it does not automatically prevent sharing off-record | 1875 // anticipate this, so it does not automatically prevent sharing off-record |
1876 // events with on-record extension renderers. | 1876 // events with on-record extension renderers. |
1877 event->restrict_to_browser_context = | 1877 event->restrict_to_browser_context = |
1878 (include_incognito && !profile_->IsOffTheRecord()) ? NULL : profile_; | 1878 (include_incognito && !profile_->IsOffTheRecord()) ? NULL : profile_; |
1879 event->will_dispatch_callback = will_dispatch_callback; | 1879 event->will_dispatch_callback = will_dispatch_callback; |
1880 extensions::ExtensionSystem::Get(profile_)->event_router()-> | 1880 extensions::EventRouter::Get(profile_)->BroadcastEvent(event.Pass()); |
1881 BroadcastEvent(event.Pass()); | |
1882 DownloadsNotificationSource notification_source; | 1881 DownloadsNotificationSource notification_source; |
1883 notification_source.event_name = event_name; | 1882 notification_source.event_name = event_name; |
1884 notification_source.profile = profile_; | 1883 notification_source.profile = profile_; |
1885 content::Source<DownloadsNotificationSource> content_source( | 1884 content::Source<DownloadsNotificationSource> content_source( |
1886 ¬ification_source); | 1885 ¬ification_source); |
1887 content::NotificationService::current()->Notify( | 1886 content::NotificationService::current()->Notify( |
1888 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, | 1887 chrome::NOTIFICATION_EXTENSION_DOWNLOADS_EVENT, |
1889 content_source, | 1888 content_source, |
1890 content::Details<std::string>(&json_args)); | 1889 content::Details<std::string>(&json_args)); |
1891 } | 1890 } |
1892 | 1891 |
1893 void ExtensionDownloadsEventRouter::Observe( | 1892 void ExtensionDownloadsEventRouter::Observe( |
1894 int type, | 1893 int type, |
1895 const content::NotificationSource& source, | 1894 const content::NotificationSource& source, |
1896 const content::NotificationDetails& details) { | 1895 const content::NotificationDetails& details) { |
1897 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1896 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1898 switch (type) { | 1897 switch (type) { |
1899 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 1898 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
1900 extensions::UnloadedExtensionInfo* unloaded = | 1899 extensions::UnloadedExtensionInfo* unloaded = |
1901 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); | 1900 content::Details<extensions::UnloadedExtensionInfo>(details).ptr(); |
1902 std::set<const extensions::Extension*>::iterator iter = | 1901 std::set<const extensions::Extension*>::iterator iter = |
1903 shelf_disabling_extensions_.find(unloaded->extension); | 1902 shelf_disabling_extensions_.find(unloaded->extension); |
1904 if (iter != shelf_disabling_extensions_.end()) | 1903 if (iter != shelf_disabling_extensions_.end()) |
1905 shelf_disabling_extensions_.erase(iter); | 1904 shelf_disabling_extensions_.erase(iter); |
1906 break; | 1905 break; |
1907 } | 1906 } |
1908 } | 1907 } |
1909 } | 1908 } |
OLD | NEW |