OLD | NEW |
1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 { | 615 { |
616 // If we have a delayed vector it cannot be empty. | 616 // If we have a delayed vector it cannot be empty. |
617 if (!m_delayed) | 617 if (!m_delayed) |
618 return; | 618 return; |
619 ASSERT(!m_delayed->isEmpty()); | 619 ASSERT(!m_delayed->isEmpty()); |
620 | 620 |
621 // Add the delayed messages to the page of the active | 621 // Add the delayed messages to the page of the active |
622 // context. If that for some bizarre reason does not | 622 // context. If that for some bizarre reason does not |
623 // exist, we clear the list of delayed messages to avoid | 623 // exist, we clear the list of delayed messages to avoid |
624 // posting messages. We still deallocate the vector. | 624 // posting messages. We still deallocate the vector. |
625 Frame* frame = V8Proxy::retrieveActiveFrame(); | 625 Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); |
626 Page* page = NULL; | 626 Page* page = NULL; |
627 if (frame) | 627 if (frame) |
628 page = frame->page(); | 628 page = frame->page(); |
629 if (!page) | 629 if (!page) |
630 m_delayed->clear(); | 630 m_delayed->clear(); |
631 | 631 |
632 // Iterate through all the delayed messages and add them | 632 // Iterate through all the delayed messages and add them |
633 // to the console. | 633 // to the console. |
634 const int size = m_delayed->size(); | 634 const int size = m_delayed->size(); |
635 for (int i = 0; i < size; i++) { | 635 for (int i = 0; i < size; i++) { |
(...skipping 20 matching lines...) Expand all Loading... |
656 if (!page) | 656 if (!page) |
657 return; | 657 return; |
658 JavaScriptConsoleMessage message(msg, url, 0); | 658 JavaScriptConsoleMessage message(msg, url, 0); |
659 ConsoleMessageManager::AddMessage(page, message); | 659 ConsoleMessageManager::AddMessage(page, message); |
660 } | 660 } |
661 | 661 |
662 static void HandleConsoleMessage(v8::Handle<v8::Message> message, | 662 static void HandleConsoleMessage(v8::Handle<v8::Message> message, |
663 v8::Handle<v8::Value> data) | 663 v8::Handle<v8::Value> data) |
664 { | 664 { |
665 // Use the frame where JavaScript is called from. | 665 // Use the frame where JavaScript is called from. |
666 Frame* frame = V8Proxy::retrieveActiveFrame(); | 666 Frame* frame = V8Proxy::retrieveFrameForEnteredContext(); |
667 if (!frame) | 667 if (!frame) |
668 return; | 668 return; |
669 | 669 |
670 Page* page = frame->page(); | 670 Page* page = frame->page(); |
671 if (!page) | 671 if (!page) |
672 return; | 672 return; |
673 | 673 |
674 v8::Handle<v8::String> errorMessageString = message->Get(); | 674 v8::Handle<v8::String> errorMessageString = message->Get(); |
675 ASSERT(!errorMessageString.IsEmpty()); | 675 ASSERT(!errorMessageString.IsEmpty()); |
676 String errorMessage = ToWebCoreString(errorMessageString); | 676 String errorMessage = ToWebCoreString(errorMessageString); |
(...skipping 16 matching lines...) Expand all Loading... |
693 }; | 693 }; |
694 | 694 |
695 | 695 |
696 static void ReportUnsafeAccessTo(Frame* target, DelayReporting delay) | 696 static void ReportUnsafeAccessTo(Frame* target, DelayReporting delay) |
697 { | 697 { |
698 ASSERT(target); | 698 ASSERT(target); |
699 Document* targetDocument = target->document(); | 699 Document* targetDocument = target->document(); |
700 if (!targetDocument) | 700 if (!targetDocument) |
701 return; | 701 return; |
702 | 702 |
703 Frame* source = V8Proxy::retrieveActiveFrame(); | 703 Frame* source = V8Proxy::retrieveFrameForEnteredContext(); |
704 if (!source || !source->document()) | 704 if (!source || !source->document()) |
705 return; // Ignore error if the source document is gone. | 705 return; // Ignore error if the source document is gone. |
706 | 706 |
707 Document* sourceDocument = source->document(); | 707 Document* sourceDocument = source->document(); |
708 | 708 |
709 // FIXME: This error message should contain more specifics of why the same | 709 // FIXME: This error message should contain more specifics of why the same |
710 // origin check has failed. | 710 // origin check has failed. |
711 String str = String::format("Unsafe JavaScript attempt to access frame " | 711 String str = String::format("Unsafe JavaScript attempt to access frame " |
712 "with URL %s from frame with URL %s. " | 712 "with URL %s from frame with URL %s. " |
713 "Domains, protocols and ports must match.\n", | 713 "Domains, protocols and ports must match.\n", |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1625 return ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, global); | 1625 return ToNativeObject<DOMWindow>(V8ClassIndex::DOMWINDOW, global); |
1626 } | 1626 } |
1627 | 1627 |
1628 | 1628 |
1629 Frame* V8Proxy::retrieveFrame(v8::Handle<v8::Context> context) | 1629 Frame* V8Proxy::retrieveFrame(v8::Handle<v8::Context> context) |
1630 { | 1630 { |
1631 return retrieveWindow(context)->frame(); | 1631 return retrieveWindow(context)->frame(); |
1632 } | 1632 } |
1633 | 1633 |
1634 | 1634 |
1635 Frame* V8Proxy::retrieveActiveFrame() | 1635 Frame* V8Proxy::retrieveFrameForEnteredContext() |
1636 { | 1636 { |
1637 v8::Handle<v8::Context> context = v8::Context::GetEntered(); | 1637 v8::Handle<v8::Context> context = v8::Context::GetEntered(); |
1638 if (context.IsEmpty()) | 1638 if (context.IsEmpty()) |
1639 return 0; | 1639 return 0; |
1640 return retrieveFrame(context); | 1640 return retrieveFrame(context); |
1641 } | 1641 } |
1642 | 1642 |
1643 | 1643 |
| 1644 Frame* V8Proxy::retrieveFrameForCurrentContext() |
| 1645 { |
| 1646 v8::Handle<v8::Context> context = v8::Context::GetCurrent(); |
| 1647 if (context.IsEmpty()) |
| 1648 return 0; |
| 1649 return retrieveFrame(context); |
| 1650 } |
| 1651 |
| 1652 |
1644 Frame* V8Proxy::retrieveFrame() | 1653 Frame* V8Proxy::retrieveFrame() |
1645 { | 1654 { |
1646 DOMWindow* window = retrieveWindow(); | 1655 DOMWindow* window = retrieveWindow(); |
1647 return window ? window->frame() : 0; | 1656 return window ? window->frame() : 0; |
1648 } | 1657 } |
1649 | 1658 |
1650 | 1659 |
1651 V8Proxy* V8Proxy::retrieve() | 1660 V8Proxy* V8Proxy::retrieve() |
1652 { | 1661 { |
1653 DOMWindow* window = retrieveWindow(); | 1662 DOMWindow* window = retrieveWindow(); |
(...skipping 1653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3307 } | 3316 } |
3308 | 3317 |
3309 void V8Proxy::RegisterExtension(v8::Extension* extension, | 3318 void V8Proxy::RegisterExtension(v8::Extension* extension, |
3310 const String& schemeRestriction) { | 3319 const String& schemeRestriction) { |
3311 v8::RegisterExtension(extension); | 3320 v8::RegisterExtension(extension); |
3312 V8ExtensionInfo info = {schemeRestriction, extension}; | 3321 V8ExtensionInfo info = {schemeRestriction, extension}; |
3313 m_extensions.push_back(info); | 3322 m_extensions.push_back(info); |
3314 } | 3323 } |
3315 | 3324 |
3316 } // namespace WebCore | 3325 } // namespace WebCore |
OLD | NEW |