| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <set> | 6 #include <set> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "chrome/browser/tab_contents/render_view_context_menu.h" | 9 #include "chrome/browser/tab_contents/render_view_context_menu.h" |
| 10 | 10 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 using content::DownloadManager; | 100 using content::DownloadManager; |
| 101 using content::DownloadUrlParameters; | 101 using content::DownloadUrlParameters; |
| 102 using content::NavigationController; | 102 using content::NavigationController; |
| 103 using content::NavigationEntry; | 103 using content::NavigationEntry; |
| 104 using content::OpenURLParams; | 104 using content::OpenURLParams; |
| 105 using content::RenderViewHost; | 105 using content::RenderViewHost; |
| 106 using content::SSLStatus; | 106 using content::SSLStatus; |
| 107 using content::UserMetricsAction; | 107 using content::UserMetricsAction; |
| 108 using content::WebContents; | 108 using content::WebContents; |
| 109 using extensions::Extension; | 109 using extensions::Extension; |
| 110 using extensions::MenuItem; |
| 111 using extensions::MenuManager; |
| 110 | 112 |
| 111 namespace { | 113 namespace { |
| 112 | 114 |
| 113 // Usually a new tab is expected where this function is used, | 115 // Usually a new tab is expected where this function is used, |
| 114 // however users should be able to open a tab in background | 116 // however users should be able to open a tab in background |
| 115 // or in a new window. | 117 // or in a new window. |
| 116 WindowOpenDisposition ForceNewTabDispositionFromEventFlags( | 118 WindowOpenDisposition ForceNewTabDispositionFromEventFlags( |
| 117 int event_flags) { | 119 int event_flags) { |
| 118 WindowOpenDisposition disposition = | 120 WindowOpenDisposition disposition = |
| 119 chrome::DispositionFromEventFlags(event_flags); | 121 chrome::DispositionFromEventFlags(event_flags); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 const GURL& url) { | 276 const GURL& url) { |
| 275 // No patterns means no restriction, so that implicitly matches. | 277 // No patterns means no restriction, so that implicitly matches. |
| 276 if (patterns.is_empty()) | 278 if (patterns.is_empty()) |
| 277 return true; | 279 return true; |
| 278 return patterns.MatchesURL(url); | 280 return patterns.MatchesURL(url); |
| 279 } | 281 } |
| 280 | 282 |
| 281 // static | 283 // static |
| 282 bool RenderViewContextMenu::ExtensionContextAndPatternMatch( | 284 bool RenderViewContextMenu::ExtensionContextAndPatternMatch( |
| 283 const content::ContextMenuParams& params, | 285 const content::ContextMenuParams& params, |
| 284 ExtensionMenuItem::ContextList contexts, | 286 MenuItem::ContextList contexts, |
| 285 const URLPatternSet& target_url_patterns) { | 287 const URLPatternSet& target_url_patterns) { |
| 286 bool has_link = !params.link_url.is_empty(); | 288 bool has_link = !params.link_url.is_empty(); |
| 287 bool has_selection = !params.selection_text.empty(); | 289 bool has_selection = !params.selection_text.empty(); |
| 288 bool in_frame = !params.frame_url.is_empty(); | 290 bool in_frame = !params.frame_url.is_empty(); |
| 289 | 291 |
| 290 if (contexts.Contains(ExtensionMenuItem::ALL) || | 292 if (contexts.Contains(MenuItem::ALL) || |
| 291 (has_selection && contexts.Contains(ExtensionMenuItem::SELECTION)) || | 293 (has_selection && contexts.Contains(MenuItem::SELECTION)) || |
| 292 (params.is_editable && contexts.Contains(ExtensionMenuItem::EDITABLE)) || | 294 (params.is_editable && contexts.Contains(MenuItem::EDITABLE)) || |
| 293 (in_frame && contexts.Contains(ExtensionMenuItem::FRAME))) | 295 (in_frame && contexts.Contains(MenuItem::FRAME))) |
| 294 return true; | 296 return true; |
| 295 | 297 |
| 296 if (has_link && contexts.Contains(ExtensionMenuItem::LINK) && | 298 if (has_link && contexts.Contains(MenuItem::LINK) && |
| 297 ExtensionPatternMatch(target_url_patterns, params.link_url)) | 299 ExtensionPatternMatch(target_url_patterns, params.link_url)) |
| 298 return true; | 300 return true; |
| 299 | 301 |
| 300 switch (params.media_type) { | 302 switch (params.media_type) { |
| 301 case WebContextMenuData::MediaTypeImage: | 303 case WebContextMenuData::MediaTypeImage: |
| 302 if (contexts.Contains(ExtensionMenuItem::IMAGE) && | 304 if (contexts.Contains(MenuItem::IMAGE) && |
| 303 ExtensionPatternMatch(target_url_patterns, params.src_url)) | 305 ExtensionPatternMatch(target_url_patterns, params.src_url)) |
| 304 return true; | 306 return true; |
| 305 break; | 307 break; |
| 306 | 308 |
| 307 case WebContextMenuData::MediaTypeVideo: | 309 case WebContextMenuData::MediaTypeVideo: |
| 308 if (contexts.Contains(ExtensionMenuItem::VIDEO) && | 310 if (contexts.Contains(MenuItem::VIDEO) && |
| 309 ExtensionPatternMatch(target_url_patterns, params.src_url)) | 311 ExtensionPatternMatch(target_url_patterns, params.src_url)) |
| 310 return true; | 312 return true; |
| 311 break; | 313 break; |
| 312 | 314 |
| 313 case WebContextMenuData::MediaTypeAudio: | 315 case WebContextMenuData::MediaTypeAudio: |
| 314 if (contexts.Contains(ExtensionMenuItem::AUDIO) && | 316 if (contexts.Contains(MenuItem::AUDIO) && |
| 315 ExtensionPatternMatch(target_url_patterns, params.src_url)) | 317 ExtensionPatternMatch(target_url_patterns, params.src_url)) |
| 316 return true; | 318 return true; |
| 317 break; | 319 break; |
| 318 | 320 |
| 319 default: | 321 default: |
| 320 break; | 322 break; |
| 321 } | 323 } |
| 322 | 324 |
| 323 // PAGE is the least specific context, so we only examine that if none of the | 325 // PAGE is the least specific context, so we only examine that if none of the |
| 324 // other contexts apply (except for FRAME, which is included in PAGE for | 326 // other contexts apply (except for FRAME, which is included in PAGE for |
| 325 // backwards compatibility). | 327 // backwards compatibility). |
| 326 if (!has_link && !has_selection && !params.is_editable && | 328 if (!has_link && !has_selection && !params.is_editable && |
| 327 params.media_type == WebContextMenuData::MediaTypeNone && | 329 params.media_type == WebContextMenuData::MediaTypeNone && |
| 328 contexts.Contains(ExtensionMenuItem::PAGE)) | 330 contexts.Contains(MenuItem::PAGE)) |
| 329 return true; | 331 return true; |
| 330 | 332 |
| 331 return false; | 333 return false; |
| 332 } | 334 } |
| 333 | 335 |
| 334 static const GURL& GetDocumentURL(const content::ContextMenuParams& params) { | 336 static const GURL& GetDocumentURL(const content::ContextMenuParams& params) { |
| 335 return params.frame_url.is_empty() ? params.page_url : params.frame_url; | 337 return params.frame_url.is_empty() ? params.page_url : params.frame_url; |
| 336 } | 338 } |
| 337 | 339 |
| 338 // Given a list of items, returns the ones that match given the contents | 340 // Given a list of items, returns the ones that match given the contents |
| 339 // of |params| and the profile. | 341 // of |params| and the profile. |
| 340 // static | 342 // static |
| 341 ExtensionMenuItem::List RenderViewContextMenu::GetRelevantExtensionItems( | 343 MenuItem::List RenderViewContextMenu::GetRelevantExtensionItems( |
| 342 const ExtensionMenuItem::List& items, | 344 const MenuItem::List& items, |
| 343 const content::ContextMenuParams& params, | 345 const content::ContextMenuParams& params, |
| 344 Profile* profile, | 346 Profile* profile, |
| 345 bool can_cross_incognito) { | 347 bool can_cross_incognito) { |
| 346 ExtensionMenuItem::List result; | 348 MenuItem::List result; |
| 347 for (ExtensionMenuItem::List::const_iterator i = items.begin(); | 349 for (MenuItem::List::const_iterator i = items.begin(); |
| 348 i != items.end(); ++i) { | 350 i != items.end(); ++i) { |
| 349 const ExtensionMenuItem* item = *i; | 351 const MenuItem* item = *i; |
| 350 | 352 |
| 351 if (!ExtensionContextAndPatternMatch(params, item->contexts(), | 353 if (!ExtensionContextAndPatternMatch(params, item->contexts(), |
| 352 item->target_url_patterns())) | 354 item->target_url_patterns())) |
| 353 continue; | 355 continue; |
| 354 | 356 |
| 355 const GURL& document_url = GetDocumentURL(params); | 357 const GURL& document_url = GetDocumentURL(params); |
| 356 if (!ExtensionPatternMatch(item->document_url_patterns(), document_url)) | 358 if (!ExtensionPatternMatch(item->document_url_patterns(), document_url)) |
| 357 continue; | 359 continue; |
| 358 | 360 |
| 359 if (item->id().incognito == profile->IsOffTheRecord() || | 361 if (item->id().incognito == profile->IsOffTheRecord() || |
| 360 can_cross_incognito) | 362 can_cross_incognito) |
| 361 result.push_back(*i); | 363 result.push_back(*i); |
| 362 } | 364 } |
| 363 return result; | 365 return result; |
| 364 } | 366 } |
| 365 | 367 |
| 366 void RenderViewContextMenu::AppendExtensionItems( | 368 void RenderViewContextMenu::AppendExtensionItems( |
| 367 const std::string& extension_id, int* index) { | 369 const std::string& extension_id, int* index) { |
| 368 ExtensionService* service = profile_->GetExtensionService(); | 370 ExtensionService* service = profile_->GetExtensionService(); |
| 369 ExtensionMenuManager* manager = service->menu_manager(); | 371 MenuManager* manager = service->menu_manager(); |
| 370 const Extension* extension = service->GetExtensionById(extension_id, false); | 372 const Extension* extension = service->GetExtensionById(extension_id, false); |
| 371 DCHECK_GE(*index, 0); | 373 DCHECK_GE(*index, 0); |
| 372 int max_index = | 374 int max_index = |
| 373 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; | 375 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; |
| 374 if (!extension || *index >= max_index) | 376 if (!extension || *index >= max_index) |
| 375 return; | 377 return; |
| 376 | 378 |
| 377 // Find matching items. | 379 // Find matching items. |
| 378 const ExtensionMenuItem::List* all_items = manager->MenuItems(extension_id); | 380 const MenuItem::List* all_items = manager->MenuItems(extension_id); |
| 379 if (!all_items || all_items->empty()) | 381 if (!all_items || all_items->empty()) |
| 380 return; | 382 return; |
| 381 bool can_cross_incognito = service->CanCrossIncognito(extension); | 383 bool can_cross_incognito = service->CanCrossIncognito(extension); |
| 382 ExtensionMenuItem::List items = | 384 MenuItem::List items = |
| 383 GetRelevantExtensionItems(*all_items, params_, profile_, | 385 GetRelevantExtensionItems(*all_items, params_, profile_, |
| 384 can_cross_incognito); | 386 can_cross_incognito); |
| 385 if (items.empty()) | 387 if (items.empty()) |
| 386 return; | 388 return; |
| 387 | 389 |
| 388 // If this is the first extension-provided menu item, and there are other | 390 // If this is the first extension-provided menu item, and there are other |
| 389 // items in the menu, add a separator. | 391 // items in the menu, add a separator. |
| 390 if (*index == 0 && menu_model_.GetItemCount()) | 392 if (*index == 0 && menu_model_.GetItemCount()) |
| 391 menu_model_.AddSeparator(); | 393 menu_model_.AddSeparator(); |
| 392 | 394 |
| 393 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; | 395 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; |
| 394 | 396 |
| 395 // Extensions are only allowed one top-level slot (and it can't be a radio or | 397 // Extensions are only allowed one top-level slot (and it can't be a radio or |
| 396 // checkbox item because we are going to put the extension icon next to it). | 398 // checkbox item because we are going to put the extension icon next to it). |
| 397 // If they have more than that, we automatically push them into a submenu. | 399 // If they have more than that, we automatically push them into a submenu. |
| 398 string16 title; | 400 string16 title; |
| 399 ExtensionMenuItem::List submenu_items; | 401 MenuItem::List submenu_items; |
| 400 if (items.size() > 1 || items[0]->type() != ExtensionMenuItem::NORMAL) { | 402 if (items.size() > 1 || items[0]->type() != MenuItem::NORMAL) { |
| 401 title = UTF8ToUTF16(extension->name()); | 403 title = UTF8ToUTF16(extension->name()); |
| 402 submenu_items = items; | 404 submenu_items = items; |
| 403 } else { | 405 } else { |
| 404 ExtensionMenuItem* item = items[0]; | 406 MenuItem* item = items[0]; |
| 405 extension_item_map_[menu_id] = item->id(); | 407 extension_item_map_[menu_id] = item->id(); |
| 406 title = item->TitleWithReplacement(PrintableSelectionText(), | 408 title = item->TitleWithReplacement(PrintableSelectionText(), |
| 407 kMaxExtensionItemTitleLength); | 409 kMaxExtensionItemTitleLength); |
| 408 submenu_items = GetRelevantExtensionItems(item->children(), params_, | 410 submenu_items = GetRelevantExtensionItems(item->children(), params_, |
| 409 profile_, can_cross_incognito); | 411 profile_, can_cross_incognito); |
| 410 } | 412 } |
| 411 | 413 |
| 412 // Now add our item(s) to the menu_model_. | 414 // Now add our item(s) to the menu_model_. |
| 413 if (submenu_items.empty()) { | 415 if (submenu_items.empty()) { |
| 414 menu_model_.AddItem(menu_id, title); | 416 menu_model_.AddItem(menu_id, title); |
| 415 } else { | 417 } else { |
| 416 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); | 418 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); |
| 417 extension_menu_models_.push_back(submenu); | 419 extension_menu_models_.push_back(submenu); |
| 418 menu_model_.AddSubMenu(menu_id, title, submenu); | 420 menu_model_.AddSubMenu(menu_id, title, submenu); |
| 419 RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito, submenu, | 421 RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito, submenu, |
| 420 index); | 422 index); |
| 421 } | 423 } |
| 422 SetExtensionIcon(extension_id); | 424 SetExtensionIcon(extension_id); |
| 423 } | 425 } |
| 424 | 426 |
| 425 void RenderViewContextMenu::RecursivelyAppendExtensionItems( | 427 void RenderViewContextMenu::RecursivelyAppendExtensionItems( |
| 426 const ExtensionMenuItem::List& items, | 428 const MenuItem::List& items, |
| 427 bool can_cross_incognito, | 429 bool can_cross_incognito, |
| 428 ui::SimpleMenuModel* menu_model, | 430 ui::SimpleMenuModel* menu_model, |
| 429 int* index) { | 431 int* index) { |
| 430 string16 selection_text = PrintableSelectionText(); | 432 string16 selection_text = PrintableSelectionText(); |
| 431 ExtensionMenuItem::Type last_type = ExtensionMenuItem::NORMAL; | 433 MenuItem::Type last_type = MenuItem::NORMAL; |
| 432 int radio_group_id = 1; | 434 int radio_group_id = 1; |
| 433 | 435 |
| 434 for (ExtensionMenuItem::List::const_iterator i = items.begin(); | 436 for (MenuItem::List::const_iterator i = items.begin(); |
| 435 i != items.end(); ++i) { | 437 i != items.end(); ++i) { |
| 436 ExtensionMenuItem* item = *i; | 438 MenuItem* item = *i; |
| 437 | 439 |
| 438 // If last item was of type radio but the current one isn't, auto-insert | 440 // If last item was of type radio but the current one isn't, auto-insert |
| 439 // a separator. The converse case is handled below. | 441 // a separator. The converse case is handled below. |
| 440 if (last_type == ExtensionMenuItem::RADIO && | 442 if (last_type == MenuItem::RADIO && |
| 441 item->type() != ExtensionMenuItem::RADIO) { | 443 item->type() != MenuItem::RADIO) { |
| 442 menu_model->AddSeparator(); | 444 menu_model->AddSeparator(); |
| 443 last_type = ExtensionMenuItem::SEPARATOR; | 445 last_type = MenuItem::SEPARATOR; |
| 444 } | 446 } |
| 445 | 447 |
| 446 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; | 448 int menu_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + (*index)++; |
| 447 if (menu_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) | 449 if (menu_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) |
| 448 return; | 450 return; |
| 449 extension_item_map_[menu_id] = item->id(); | 451 extension_item_map_[menu_id] = item->id(); |
| 450 string16 title = item->TitleWithReplacement(selection_text, | 452 string16 title = item->TitleWithReplacement(selection_text, |
| 451 kMaxExtensionItemTitleLength); | 453 kMaxExtensionItemTitleLength); |
| 452 if (item->type() == ExtensionMenuItem::NORMAL) { | 454 if (item->type() == MenuItem::NORMAL) { |
| 453 ExtensionMenuItem::List children = | 455 MenuItem::List children = |
| 454 GetRelevantExtensionItems(item->children(), params_, | 456 GetRelevantExtensionItems(item->children(), params_, |
| 455 profile_, can_cross_incognito); | 457 profile_, can_cross_incognito); |
| 456 if (children.empty()) { | 458 if (children.empty()) { |
| 457 menu_model->AddItem(menu_id, title); | 459 menu_model->AddItem(menu_id, title); |
| 458 } else { | 460 } else { |
| 459 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); | 461 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(this); |
| 460 extension_menu_models_.push_back(submenu); | 462 extension_menu_models_.push_back(submenu); |
| 461 menu_model->AddSubMenu(menu_id, title, submenu); | 463 menu_model->AddSubMenu(menu_id, title, submenu); |
| 462 RecursivelyAppendExtensionItems(children, can_cross_incognito, | 464 RecursivelyAppendExtensionItems(children, can_cross_incognito, |
| 463 submenu, index); | 465 submenu, index); |
| 464 } | 466 } |
| 465 } else if (item->type() == ExtensionMenuItem::CHECKBOX) { | 467 } else if (item->type() == MenuItem::CHECKBOX) { |
| 466 menu_model->AddCheckItem(menu_id, title); | 468 menu_model->AddCheckItem(menu_id, title); |
| 467 } else if (item->type() == ExtensionMenuItem::RADIO) { | 469 } else if (item->type() == MenuItem::RADIO) { |
| 468 if (i != items.begin() && | 470 if (i != items.begin() && |
| 469 last_type != ExtensionMenuItem::RADIO) { | 471 last_type != MenuItem::RADIO) { |
| 470 radio_group_id++; | 472 radio_group_id++; |
| 471 | 473 |
| 472 // Auto-append a separator if needed. | 474 // Auto-append a separator if needed. |
| 473 if (last_type != ExtensionMenuItem::SEPARATOR) | 475 if (last_type != MenuItem::SEPARATOR) |
| 474 menu_model->AddSeparator(); | 476 menu_model->AddSeparator(); |
| 475 } | 477 } |
| 476 | 478 |
| 477 menu_model->AddRadioItem(menu_id, title, radio_group_id); | 479 menu_model->AddRadioItem(menu_id, title, radio_group_id); |
| 478 } else if (item->type() == ExtensionMenuItem::SEPARATOR) { | 480 } else if (item->type() == MenuItem::SEPARATOR) { |
| 479 if (i != items.begin() && last_type != ExtensionMenuItem::SEPARATOR) { | 481 if (i != items.begin() && last_type != MenuItem::SEPARATOR) { |
| 480 menu_model->AddSeparator(); | 482 menu_model->AddSeparator(); |
| 481 } | 483 } |
| 482 } | 484 } |
| 483 last_type = item->type(); | 485 last_type = item->type(); |
| 484 } | 486 } |
| 485 } | 487 } |
| 486 | 488 |
| 487 void RenderViewContextMenu::SetExtensionIcon(const std::string& extension_id) { | 489 void RenderViewContextMenu::SetExtensionIcon(const std::string& extension_id) { |
| 488 ExtensionService* service = profile_->GetExtensionService(); | 490 ExtensionService* service = profile_->GetExtensionService(); |
| 489 ExtensionMenuManager* menu_manager = service->menu_manager(); | 491 MenuManager* menu_manager = service->menu_manager(); |
| 490 | 492 |
| 491 int index = menu_model_.GetItemCount() - 1; | 493 int index = menu_model_.GetItemCount() - 1; |
| 492 DCHECK_GE(index, 0); | 494 DCHECK_GE(index, 0); |
| 493 | 495 |
| 494 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); | 496 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); |
| 495 DCHECK(icon.width() == gfx::kFaviconSize); | 497 DCHECK(icon.width() == gfx::kFaviconSize); |
| 496 DCHECK(icon.height() == gfx::kFaviconSize); | 498 DCHECK(icon.height() == gfx::kFaviconSize); |
| 497 | 499 |
| 498 menu_model_.SetIcon(index, icon); | 500 menu_model_.SetIcon(index, icon); |
| 499 } | 501 } |
| 500 | 502 |
| 501 void RenderViewContextMenu::AppendAllExtensionItems() { | 503 void RenderViewContextMenu::AppendAllExtensionItems() { |
| 502 extension_item_map_.clear(); | 504 extension_item_map_.clear(); |
| 503 ExtensionService* service = profile_->GetExtensionService(); | 505 ExtensionService* service = profile_->GetExtensionService(); |
| 504 if (!service) | 506 if (!service) |
| 505 return; // In unit-tests, we may not have an ExtensionService. | 507 return; // In unit-tests, we may not have an ExtensionService. |
| 506 ExtensionMenuManager* menu_manager = service->menu_manager(); | 508 MenuManager* menu_manager = service->menu_manager(); |
| 507 | 509 |
| 508 // Get a list of extension id's that have context menu items, and sort it by | 510 // Get a list of extension id's that have context menu items, and sort it by |
| 509 // the extension's name. | 511 // the extension's name. |
| 510 std::set<std::string> ids = menu_manager->ExtensionIds(); | 512 std::set<std::string> ids = menu_manager->ExtensionIds(); |
| 511 std::vector<std::pair<std::string, std::string> > sorted_ids; | 513 std::vector<std::pair<std::string, std::string> > sorted_ids; |
| 512 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { | 514 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { |
| 513 const Extension* extension = service->GetExtensionById(*i, false); | 515 const Extension* extension = service->GetExtensionById(*i, false); |
| 514 // Platform apps have their context menus created directly in | 516 // Platform apps have their context menus created directly in |
| 515 // AppendPlatformAppItems. | 517 // AppendPlatformAppItems. |
| 516 if (extension && !extension->is_platform_app()) | 518 if (extension && !extension->is_platform_app()) |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 protocol_handler_submenu_model_.AddItem( | 1053 protocol_handler_submenu_model_.AddItem( |
| 1052 IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS, | 1054 IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS, |
| 1053 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH_CONFIGURE)); | 1055 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH_CONFIGURE)); |
| 1054 | 1056 |
| 1055 menu_model_.AddSubMenu( | 1057 menu_model_.AddSubMenu( |
| 1056 IDC_CONTENT_CONTEXT_OPENLINKWITH, | 1058 IDC_CONTENT_CONTEXT_OPENLINKWITH, |
| 1057 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH), | 1059 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH), |
| 1058 &protocol_handler_submenu_model_); | 1060 &protocol_handler_submenu_model_); |
| 1059 } | 1061 } |
| 1060 | 1062 |
| 1061 ExtensionMenuItem* RenderViewContextMenu::GetExtensionMenuItem(int id) const { | 1063 MenuItem* RenderViewContextMenu::GetExtensionMenuItem(int id) const { |
| 1062 ExtensionMenuManager* manager = | 1064 MenuManager* manager = profile_->GetExtensionService()->menu_manager(); |
| 1063 profile_->GetExtensionService()->menu_manager(); | 1065 std::map<int, MenuItem::Id>::const_iterator i = |
| 1064 std::map<int, ExtensionMenuItem::Id>::const_iterator i = | |
| 1065 extension_item_map_.find(id); | 1066 extension_item_map_.find(id); |
| 1066 if (i != extension_item_map_.end()) { | 1067 if (i != extension_item_map_.end()) { |
| 1067 ExtensionMenuItem* item = manager->GetItemById(i->second); | 1068 MenuItem* item = manager->GetItemById(i->second); |
| 1068 if (item) | 1069 if (item) |
| 1069 return item; | 1070 return item; |
| 1070 } | 1071 } |
| 1071 return NULL; | 1072 return NULL; |
| 1072 } | 1073 } |
| 1073 | 1074 |
| 1074 // Menu delegate functions ----------------------------------------------------- | 1075 // Menu delegate functions ----------------------------------------------------- |
| 1075 | 1076 |
| 1076 bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { | 1077 bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { |
| 1077 // If this command is is added by one of our observers, we dispatch it to the | 1078 // If this command is is added by one of our observers, we dispatch it to the |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1103 | 1104 |
| 1104 // Custom items. | 1105 // Custom items. |
| 1105 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 1106 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
| 1106 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 1107 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
| 1107 return IsCustomItemEnabled(params_.custom_items, id); | 1108 return IsCustomItemEnabled(params_.custom_items, id); |
| 1108 } | 1109 } |
| 1109 | 1110 |
| 1110 // Extension items. | 1111 // Extension items. |
| 1111 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 1112 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 1112 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 1113 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 1113 ExtensionMenuItem* item = GetExtensionMenuItem(id); | 1114 MenuItem* item = GetExtensionMenuItem(id); |
| 1114 // If this is the parent menu item, it is always enabled. | 1115 // If this is the parent menu item, it is always enabled. |
| 1115 if (!item) | 1116 if (!item) |
| 1116 return true; | 1117 return true; |
| 1117 return item->enabled(); | 1118 return item->enabled(); |
| 1118 } | 1119 } |
| 1119 | 1120 |
| 1120 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 1121 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 1121 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 1122 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 1122 return true; | 1123 return true; |
| 1123 } | 1124 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 | 1410 |
| 1410 // Custom items. | 1411 // Custom items. |
| 1411 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 1412 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
| 1412 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 1413 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
| 1413 return IsCustomItemChecked(params_.custom_items, id); | 1414 return IsCustomItemChecked(params_.custom_items, id); |
| 1414 } | 1415 } |
| 1415 | 1416 |
| 1416 // Extension items. | 1417 // Extension items. |
| 1417 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 1418 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 1418 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 1419 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 1419 ExtensionMenuItem* item = GetExtensionMenuItem(id); | 1420 MenuItem* item = GetExtensionMenuItem(id); |
| 1420 if (item) | 1421 if (item) |
| 1421 return item->checked(); | 1422 return item->checked(); |
| 1422 else | 1423 else |
| 1423 return false; | 1424 return false; |
| 1424 } | 1425 } |
| 1425 | 1426 |
| 1426 #if defined(OS_MACOSX) | 1427 #if defined(OS_MACOSX) |
| 1427 if (id == IDC_WRITING_DIRECTION_DEFAULT) | 1428 if (id == IDC_WRITING_DIRECTION_DEFAULT) |
| 1428 return params_.writing_direction_default & | 1429 return params_.writing_direction_default & |
| 1429 WebContextMenuData::CheckableMenuItemChecked; | 1430 WebContextMenuData::CheckableMenuItemChecked; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && | 1469 if (id >= IDC_CONTENT_CONTEXT_CUSTOM_FIRST && |
| 1469 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { | 1470 id <= IDC_CONTENT_CONTEXT_CUSTOM_LAST) { |
| 1470 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; | 1471 unsigned action = id - IDC_CONTENT_CONTEXT_CUSTOM_FIRST; |
| 1471 rvh->ExecuteCustomContextMenuCommand(action, params_.custom_context); | 1472 rvh->ExecuteCustomContextMenuCommand(action, params_.custom_context); |
| 1472 return; | 1473 return; |
| 1473 } | 1474 } |
| 1474 | 1475 |
| 1475 // Process extension menu items. | 1476 // Process extension menu items. |
| 1476 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && | 1477 if (id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST && |
| 1477 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { | 1478 id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) { |
| 1478 ExtensionMenuManager* manager = | 1479 MenuManager* manager = profile_->GetExtensionService()->menu_manager(); |
| 1479 profile_->GetExtensionService()->menu_manager(); | 1480 std::map<int, MenuItem::Id>::const_iterator i = |
| 1480 std::map<int, ExtensionMenuItem::Id>::const_iterator i = | |
| 1481 extension_item_map_.find(id); | 1481 extension_item_map_.find(id); |
| 1482 if (i != extension_item_map_.end()) { | 1482 if (i != extension_item_map_.end()) { |
| 1483 manager->ExecuteCommand(profile_, source_web_contents_, params_, | 1483 manager->ExecuteCommand(profile_, source_web_contents_, params_, |
| 1484 i->second); | 1484 i->second); |
| 1485 } | 1485 } |
| 1486 return; | 1486 return; |
| 1487 } | 1487 } |
| 1488 | 1488 |
| 1489 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 1489 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 1490 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 1490 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2004 source_web_contents_->GetRenderViewHost()-> | 2004 source_web_contents_->GetRenderViewHost()-> |
| 2005 ExecuteMediaPlayerActionAtLocation(location, action); | 2005 ExecuteMediaPlayerActionAtLocation(location, action); |
| 2006 } | 2006 } |
| 2007 | 2007 |
| 2008 void RenderViewContextMenu::PluginActionAt( | 2008 void RenderViewContextMenu::PluginActionAt( |
| 2009 const gfx::Point& location, | 2009 const gfx::Point& location, |
| 2010 const WebPluginAction& action) { | 2010 const WebPluginAction& action) { |
| 2011 source_web_contents_->GetRenderViewHost()-> | 2011 source_web_contents_->GetRenderViewHost()-> |
| 2012 ExecutePluginActionAtLocation(location, action); | 2012 ExecutePluginActionAtLocation(location, action); |
| 2013 } | 2013 } |
| OLD | NEW |