| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/first_run/drive_first_run_controller.h" | 5 #include "chrome/browser/chromeos/first_run/drive_first_run_controller.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/system/tray/system_tray_delegate.h" | 8 #include "ash/system/tray/system_tray_delegate.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 155 |
| 156 void DidFailLoad(content::RenderFrameHost* render_frame_host, | 156 void DidFailLoad(content::RenderFrameHost* render_frame_host, |
| 157 const GURL& validated_url, | 157 const GURL& validated_url, |
| 158 int error_code, | 158 int error_code, |
| 159 const base::string16& error_description, | 159 const base::string16& error_description, |
| 160 bool was_ignored_by_handler) override; | 160 bool was_ignored_by_handler) override; |
| 161 | 161 |
| 162 // content::WebContentsDelegate overrides: | 162 // content::WebContentsDelegate overrides: |
| 163 bool ShouldCreateWebContents( | 163 bool ShouldCreateWebContents( |
| 164 content::WebContents* web_contents, | 164 content::WebContents* web_contents, |
| 165 int route_id, | 165 int32 route_id, |
| 166 int main_frame_route_id, | 166 int32 main_frame_route_id, |
| 167 int32 main_frame_widget_route_id, |
| 167 WindowContainerType window_container_type, | 168 WindowContainerType window_container_type, |
| 168 const std::string& frame_name, | 169 const std::string& frame_name, |
| 169 const GURL& target_url, | 170 const GURL& target_url, |
| 170 const std::string& partition_id, | 171 const std::string& partition_id, |
| 171 content::SessionStorageNamespace* session_storage_namespace) override; | 172 content::SessionStorageNamespace* session_storage_namespace) override; |
| 172 | 173 |
| 173 // content::NotificationObserver overrides: | 174 // content::NotificationObserver overrides: |
| 174 void Observe(int type, | 175 void Observe(int type, |
| 175 const content::NotificationSource& source, | 176 const content::NotificationSource& source, |
| 176 const content::NotificationDetails& details) override; | 177 const content::NotificationDetails& details) override; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 bool was_ignored_by_handler) { | 272 bool was_ignored_by_handler) { |
| 272 if (!render_frame_host->GetParent()) { | 273 if (!render_frame_host->GetParent()) { |
| 273 LOG(WARNING) << "Failed to load WebContents to enable offline mode."; | 274 LOG(WARNING) << "Failed to load WebContents to enable offline mode."; |
| 274 OnOfflineInit(false, | 275 OnOfflineInit(false, |
| 275 DriveFirstRunController::OUTCOME_WEB_CONTENTS_LOAD_FAILED); | 276 DriveFirstRunController::OUTCOME_WEB_CONTENTS_LOAD_FAILED); |
| 276 } | 277 } |
| 277 } | 278 } |
| 278 | 279 |
| 279 bool DriveWebContentsManager::ShouldCreateWebContents( | 280 bool DriveWebContentsManager::ShouldCreateWebContents( |
| 280 content::WebContents* web_contents, | 281 content::WebContents* web_contents, |
| 281 int route_id, | 282 int32 route_id, |
| 282 int main_frame_route_id, | 283 int32 main_frame_route_id, |
| 284 int32 main_frame_widget_route_id, |
| 283 WindowContainerType window_container_type, | 285 WindowContainerType window_container_type, |
| 284 const std::string& frame_name, | 286 const std::string& frame_name, |
| 285 const GURL& target_url, | 287 const GURL& target_url, |
| 286 const std::string& partition_id, | 288 const std::string& partition_id, |
| 287 content::SessionStorageNamespace* session_storage_namespace) { | 289 content::SessionStorageNamespace* session_storage_namespace) { |
| 288 if (window_container_type == WINDOW_CONTAINER_TYPE_NORMAL) | 290 if (window_container_type == WINDOW_CONTAINER_TYPE_NORMAL) |
| 289 return true; | 291 return true; |
| 290 | 292 |
| 291 // Check that the target URL is for the Drive app. | 293 // Check that the target URL is for the Drive app. |
| 292 const extensions::Extension* extension = | 294 const extensions::Extension* extension = |
| 293 extensions::ExtensionRegistry::Get(profile_) | 295 extensions::ExtensionRegistry::Get(profile_) |
| 294 ->enabled_extensions().GetAppByURL(target_url); | 296 ->enabled_extensions().GetAppByURL(target_url); |
| 295 if (!extension || extension->id() != app_id_) | 297 if (!extension || extension->id() != app_id_) |
| 296 return true; | 298 return true; |
| 297 | 299 |
| 298 // The background contents creation is normally done in Browser, but | 300 // The background contents creation is normally done in Browser, but |
| 299 // because we're using a detached WebContents, we need to do it ourselves. | 301 // because we're using a detached WebContents, we need to do it ourselves. |
| 300 BackgroundContentsService* background_contents_service = | 302 BackgroundContentsService* background_contents_service = |
| 301 BackgroundContentsServiceFactory::GetForProfile(profile_); | 303 BackgroundContentsServiceFactory::GetForProfile(profile_); |
| 302 | 304 |
| 303 // Prevent redirection if background contents already exists. | 305 // Prevent redirection if background contents already exists. |
| 304 if (background_contents_service->GetAppBackgroundContents( | 306 if (background_contents_service->GetAppBackgroundContents( |
| 305 base::UTF8ToUTF16(app_id_))) { | 307 base::UTF8ToUTF16(app_id_))) { |
| 306 return false; | 308 return false; |
| 307 } | 309 } |
| 308 BackgroundContents* contents = background_contents_service | 310 BackgroundContents* contents = |
| 309 ->CreateBackgroundContents(content::SiteInstance::Create(profile_), | 311 background_contents_service->CreateBackgroundContents( |
| 310 route_id, | 312 content::SiteInstance::Create(profile_), route_id, |
| 311 main_frame_route_id, | 313 main_frame_route_id, main_frame_widget_route_id, profile_, frame_name, |
| 312 profile_, | 314 base::ASCIIToUTF16(app_id_), partition_id, session_storage_namespace); |
| 313 frame_name, | |
| 314 base::ASCIIToUTF16(app_id_), | |
| 315 partition_id, | |
| 316 session_storage_namespace); | |
| 317 | 315 |
| 318 contents->web_contents()->GetController().LoadURL( | 316 contents->web_contents()->GetController().LoadURL( |
| 319 target_url, | 317 target_url, |
| 320 content::Referrer(), | 318 content::Referrer(), |
| 321 ui::PAGE_TRANSITION_LINK, | 319 ui::PAGE_TRANSITION_LINK, |
| 322 std::string()); | 320 std::string()); |
| 323 | 321 |
| 324 // Return false as we already created the WebContents here. | 322 // Return false as we already created the WebContents here. |
| 325 return false; | 323 return false; |
| 326 } | 324 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 resource_bundle.GetImageNamed(IDR_NOTIFICATION_DRIVE), | 466 resource_bundle.GetImageNamed(IDR_NOTIFICATION_DRIVE), |
| 469 base::UTF8ToUTF16(extension->name()), GURL(), | 467 base::UTF8ToUTF16(extension->name()), GURL(), |
| 470 message_center::NotifierId(message_center::NotifierId::APPLICATION, | 468 message_center::NotifierId(message_center::NotifierId::APPLICATION, |
| 471 kDriveHostedAppId), | 469 kDriveHostedAppId), |
| 472 data, new DriveOfflineNotificationDelegate(profile_))); | 470 data, new DriveOfflineNotificationDelegate(profile_))); |
| 473 notification->set_priority(message_center::LOW_PRIORITY); | 471 notification->set_priority(message_center::LOW_PRIORITY); |
| 474 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); | 472 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); |
| 475 } | 473 } |
| 476 | 474 |
| 477 } // namespace chromeos | 475 } // namespace chromeos |
| OLD | NEW |